Vertical sort of nodes in D3 Sankey diagram

北战南征 提交于 2019-12-06 13:39:18

问题


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:

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


回答1:


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?



来源:https://stackoverflow.com/questions/32777116/vertical-sort-of-nodes-in-d3-sankey-diagram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!