2016-07-11 49 views
-2

我立足我的問題在下面的例子中力佈局多弧: http://bl.ocks.org/mbostock/1153292d3js用箭頭

如果我創建一個具有相同源和目標兩個環節,說

{source: "Microsoft", target: "HTC", type: "licensing"}, 
{source: "Microsoft", target: "HTC", type: "suit"}, 

那麼這兩個鏈接將坐在彼此的頂部,只有一個可見。我怎麼可以重寫代碼,以便在這種情況下,兩個環節將形成一個循環,就像它發生了倒置的源和目標兩個環節,例如

{source: "Microsoft", target: "Motorola", type: "suit"}, 
{source: "Motorola", target: "Microsoft", type: "suit"}, 
+2

[用d3繪製兩個節點之間的多條邊]的可能副本(http://stackoverflow.com/questions/11368339/drawing-multiple-edges-between-two-nodes-with-d3) – altocumulus

回答

0

好吧,我找到解決這一個自己。在

function linkArc(d) { 
    var dx = d.target.x - d.source.x, 
     dy = d.target.y - d.source.y, 
     dr = Math.sqrt(dx * dx + dy * dy); 
    return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y; 
} 

如果" 0 0,1 "部分改爲" 0 0,0 "它改變了圓弧的手性,所以if語句中需要區分那裏有長着相同的源和目標兩個環節的案件。