本文介绍了如何调整d3 sankey.js中的水平节点位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用d3的sankey.js绘制一些流程图.我被困在安排图中的节点x位置.

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应该与t2_b在同一列中,因为它们表示同一时间段内的数量.但是,默认情况下,此选项位于错误解释的末尾.

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.

推荐答案

在sankey.js中,注释一下configureNodeBreadths中的moveSinksRight调用:

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));
  }

这篇关于如何调整d3 sankey.js中的水平节点位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 01:42