How to force y position of one branch in d3 sankey plugin?

前端 未结 1 989
渐次进展
渐次进展 2020-12-30 10:30

I would like to force one branch of sankey diagram to be on top.

Instead of diagram like this: \"Current

相关标签:
1条回答
  • 2020-12-30 11:16

    Note To be honest, I never used that plugin. I don't see an option to get the desired behaviour directly - thus I looked at the source of sankey.js to make the adjustments. Below I show how I'd modify - you might want to do it more thoroughly :)

    Idea

    Looking at the code of sankey.js, you see that the nodes are placed (y-direction) using the center function:

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

    As I don't see a parameter to change that behaviour, you can change it to:

    function center(node) {
      return 0;
    }
    

    If you then also revert the sorting order:

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

    you get the following picture:

    enter image description here

    0 讨论(0)
提交回复
热议问题