Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical sort of nodes in D3 Sankey diagram

I'm trying to achieve a basic sankey diagram building on top of this example: http://bl.ocks.org/d3noob/c9b90689c1438f57d649

By default they get sorted by value. I want to customize the vertical order of the nodes. Here is an example:

enter image description here

In this case I'd like to always keep "A" on top.

Any thoughts on how to do that?

Similar question: D3 sankey diagram - enforce node position

like image 761
Jens Avatar asked Nov 23 '25 18:11

Jens


1 Answers

You can modify this function:

function center(node) {
  return node.y + node.dy / 2;
}

like this:

function center(node) {
   return 0;
}

and after modify ascendingDepth's function like this:

function ascendingDepth(a, b) {
  return b.y - a.y;
}

I found this in another question How to force y position of one branch in d3 sankey plugin?

like image 116
Giordano Avatar answered Nov 26 '25 06:11

Giordano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!