Drawing a single node link in a node-link diagram can be done as described here: D3 Power layout Self-tuning Node
What would you change if you need to draw multiple links on the same node?
I tried to add a “twist” to it, based on the number of existing own links. Given the code from the linked example, I made the following changes:
function tick() {
link.attr("d", function(d) {
var x1 = d.source.x,
y1 = d.source.y,
x2 = d.target.x,
y2 = d.target.y,
dx = x2 - x1,
dy = y2 - y1,
dr = Math.sqrt(dx * dx + dy * dy),
drx = dr,
dry = dr,
xRotation = 0,
largeArc = 0,
sweep = 1;
if ( x1 === x2 && y1 === y2 ) {
var index = getIndexOfDuplicateEdge();
var degree = 360 / numberOfDuplicateEdges();
var degreeForIndex = degree * index;
xRotation = degreeForIndex;
largeArc = 1;
drx = 30;
dry = 20;
x2 = x2 + 1;
y2 = y2 + 1;
}
return "M" + x1 + "," + y1 + "A" + drx + "," + dry + " " + xRotation + "," + largeArc + "," + sweep + " " + x2 + "," + y2;
});
, , . SVG Mozilla 1. Sweep 0 1 " " . xRotation 90-180 0/1, 180 . , 180- .
, "" .
:
