novus / nvd3

A reusable charting library written in d3.js
http://nvd3.org/
Other
7.23k stars 2.14k forks source link

Missing nodes in sunburst chart #1535

Open brockj opened 8 years ago

brockj commented 8 years ago

After updating to the latest nvd3 (4d51a33) we are now missing nodes in our sunburst chart

This line seems to be the cause, but i don't know why var cG = wrap.selectAll('.arc-container').data(nodes, key)

removing the key parameter fixes the issue, but i assume that isn't the solution. We have a few nodes with the same name, but they never have the same parent node.

If this is a breaking change it would be helpful if it were documented.

mrijke commented 8 years ago

I ran into this issue as well, for anyone interested how I fixed it: the idea is to generate an 'id' for each node, consisting of the names of the parent, grandparent, great-grandparent, etc. and the name of the node itself.

function setNodeID(node, parentLabel) {
    node._id = parentLabel + node.name;
    if (node.children) {
        node.children.forEach(function (e) {
            setNodeID(e, node._id + "-");
        });
    }

Then this function is called from your setData function or something similar like

setNodeID(rootNode, "");

Finally, to inform nvd3 sunburst to use that _id property instead:

chart.sunburst.key(function (d) {
    return d._id;
});