-2

I am basing my question on the following example: http://bl.ocks.org/mbostock/1153292

If I create two links with the same source and target, say

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

then the two links will sit on top of each other and only one will be visible. How can I rewrite the code so that in this case the two links would form a loop just as it happens for two links with inverted sources and targets, for example

{source: "Microsoft", target: "Motorola", type: "suit"},
{source: "Motorola", target: "Microsoft", type: "suit"},
  • 2
    Possible duplicate of [Drawing multiple edges between two nodes with d3](http://stackoverflow.com/questions/11368339/drawing-multiple-edges-between-two-nodes-with-d3) – altocumulus Jul 11 '16 at 17:15

1 Answers1

0

Ok, I find the solution to this one myself. In

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

if the " 0 0,1 " part is changed to " 0 0,0 " it changes the chirality of the arc, so an if statement in needed to distinguish cases where there are two links with the same source and target.