Chakresh
Chakresh

Reputation: 67

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

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

diagram example

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.

Upvotes: 2

Views: 1796

Answers (1)

Chirag Kothari
Chirag Kothari

Reputation: 1410

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

Upvotes: 1

Related Questions