How to tune horizontal node position in d3 sankey.js?

你离开我真会死。 提交于 2019-12-11 06:10:01

问题


I am trying to plot some flow diagrams using d3's sankey.js. I am stuck at arranging nodes x positions in the diagrams.

t2_a should be in same column as t2_b as they represent quantity from same time period. However by default this is placed at the end which gives wrong interpretation.

I can arrange manually for small number of nodes but its really difficult when number of nodes increase. Any help or suggestion would be highly appreciated.


回答1:


In sankey.js comment the moveSinksRight call in computeNodeBreadths:

  function computeNodeBreadths() {
    var remainingNodes = nodes,
        nextNodes,
        x = 0;

    while (remainingNodes.length) {
      nextNodes = [];
      remainingNodes.forEach(function(node) {
        node.x = x;
        node.dx = nodeWidth;
        node.sourceLinks.forEach(function(link) {
          nextNodes.push(link.target);
        });
      });
      remainingNodes = nextNodes;
      ++x;
    }

    //
    // moveSinksRight(x); <-- comment this
    scaleNodeBreadths((width - nodeWidth) / (x - 1));
  }


来源:https://stackoverflow.com/questions/45726804/how-to-tune-horizontal-node-position-in-d3-sankey-js

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