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.
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.
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.