2017-08-17 61 views
1

我想用d3的sankey.js來繪製一些流程圖。 我被困在圖中的節點x位置。如何調整d3 sankey.js中的水平節點位置?

diagram example

t2_a應該在相同的列中t2_b因爲它們代表從相同的時間週期數量。然而,默認情況下,這被放置在給出錯誤解釋的末尾。

我可以手動安排少量節點,但節點數量增加時確實很困難。任何幫助或建議將不勝感激。

回答

0

在sankey.js評論中computeNodeBreadths的moveSinksRight電話:

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

@Chakresh:你有沒有嘗試這種解決方案? –

+0

是的,我做到了。此解決方案有效:) – Chakresh