importing d3 with requirejs

16 views
Skip to first unread message

Andrew Kos

unread,
Feb 25, 2018, 3:56:36 PM2/25/18
to d3-js
Hello,

I'm attempting to get d3 working inside a jupyter notebook which appears to use requirejs under the hood. I'm able to import d3, but I cannot figure out what kind of requirejs configuration I need to get d3 imported along with d3-selection-multi.

Here is my requirejs configuration:

require.config({
    paths: {
        d3: '//d3js.org/d3.v4.min',
        'd3-color': '//d3js.org/d3-color.v1.min',
        'd3-dispatch': '//d3js.org/d3-dispatch.v1.min',
        'd3-ease': '//d3js.org/d3-ease.v1.min',
        'd3-interpolate': '//d3js.org/d3-interpolate.v1.min',
        'd3-selection': '//d3js.org/d3-selection.v1.min',
        'd3-selection-multi': '//d3js.org/d3-selection-multi.v1.min',
        'd3-transition': '//d3js.org/d3-transition.v1.min',
        'd3-timer': '//d3js.org/d3-timer.v1.min',
    }
});

And then I require d3 and run my d3 histogram code:

const data = {...};

const chart = document.getElementById('chart1');

require(['./hist.js', 'd3', 'd3-selection-multi'],function (hist) {{
    hist.histogram(chart, data);
}});

An error reports that .append(...).attrs is not a function which means d3-selection-multi has loaded but it hasn't modified the d3.selection.prototype I think.

How do I properly import d3 along with d3-selection-multi with requirejs?
Has anyone tried d3 with dependencies in jupyter before?

Thanks!
Reply all
Reply to author
Forward
0 new messages