d3 / d3-plugins

[DEPRECATED] A repository for sharing D3.js V3 plugins.
https://github.com/d3/d3/wiki/Plugins
Other
1.81k stars 684 forks source link

[sankey.js] nodesByBreadth not sorting numerically #131

Open avocadostorm opened 9 years ago

avocadostorm commented 9 years ago

Not sure if this is something you intended but it caused me some issues. d3.ascending used as the sort key here doesn't sort the "columns" of the sankey diagram in numerical order (d3.ascending is a natural ordering iirc). So if you are trying to do operations right-to-left or reversed, it doesn't work.

var nodesByBreadth = d3.nest()
        .key(function(d) { return d.tier; }) //originally d.x; I added a "tier" int index
        .sortKeys(d3.ascending) //using this the tiers are ordered 0, 1, 10, 2, 3 ... 
        .entries(nodes)
        .map(function(d) { return d.values; });

I swapped out your d3.ascending with a numerical ordering (identical except casting a and b to Numbers) and the "tiers" were then sorted in numerical order. Probably not a big deal but it seemed counter to your intent with this data structure.