1

D3 automatically disables global namespace pollution when it detects AMD like require.js. Dimple.js expects d3 to be in the global namespace. This guy says he can load dimple using a shim, and I can find similar claims for nvd3, and yet another incomplete example here.

However, I can find no complete working examples. Here's a non-working example of a require.config:

require.config({
    shim: {
        d3: { exports: "d3" },
        dimple: {
            exports: "dimple",
            deps: ["d3"]
        }
    },
    paths: {
        d3: "http://d3js.org/d3.v3.min",
        dimple: "http://dimplejs.org/dist/dimple.v1.1.5.min"
    }
});

And an example of something that doesn't work:

require(["dimple"], function(dimple) {
    var svg = dimple.newSvg("#awesome_bars", 800, 600);
}
// -> dimple is undefined

Dimple is (I think!) a proper CommonJS library, and I'm able to load d3 (without a shim) just fine. And if you're wondering, yes, I have an appropriate div, and that wouldn't be relevant to the undefined result.

So, how can I get access to dimple in the context of require.js?

Community
  • 1
  • 1
Dav Clark
  • 1,430
  • 1
  • 13
  • 26
  • Also - I should be clear that I'm trying to run this in the context of the IPython notebook server - so I don't get to have control over the inclusion of require.js (or specify the data-main attribute). – Dav Clark Mar 05 '14 at 00:08
  • stephen-james generously provided a rather complete response to this issue here: https://github.com/PMSI-AlignAlytics/dimple/pull/56 – Dav Clark Mar 06 '14 at 23:32
  • Hi Dav, did you get to a solution in the end? I'm not 100% clear from your comment "so I don't get to have control over the inclusion of require.js"... are saying that you can't use requirejs at all with IPython notebook? I haven't played much with IPython notebook but a few of the guys here have, except they use the standard matplotlib charts. But if you're saying its possible to reference external javascript for rendering I'd be keen to help, so let me know! – Stephen James Mar 07 '14 at 12:14
  • I have just gone with workarounds for now (working outside of the IPython notebook). You can use require.js with modules that support AMD, so I guess I'm not that motivated to solve the problem given that the pull-request will solve it for us. cf. http://nbviewer.ipython.org/github/rdhyee/working-open-data-2014/blob/master/notebooks/Day_07_A_D3_Choropleth.ipynb @rdhyee and I are working on plotting with JS in the notebook... that said, I'll report back if I get dimple working before you update it to support AMD (it seems a general problem). – Dav Clark Mar 07 '14 at 19:15

1 Answers1

1

Require.js does not support shims attribute. it should be shim.

Artyom Trityak
  • 647
  • 6
  • 17