score:1

Accepted answer

The code snippet you have posted shows nothing unusual. May be there is some bug somewhere else in the code you have not shared.

I have made a button to recreate your issue:

  function change(){
    edges.splice(0,1)//remove the one link
    edges.push({source: nodes[0], target: nodes[1]});//add the new inverted link
    graph.updateGraph()//update the graph
  }

Everything works as expected.

Working fiddle here

Hope this helps!

score:1

I am not expert here. But i have done quite a bit of d3 coding. To draw the links i needs unique id. It is created via "M" + d.source.x + "," + d.source.y + "L" + d.target.x + "," + d.target.y;

so when reverse the link add again, it creates new id and adds one more link. but it will on the same link and same xy and coordinates. so it will look like one but two links may there.

Why it works, src and target is required to draw the link, but direction is no concern for d3, it will add link between the src and dst. It will work till you have a unique id for each link and number of links between the node is not problem.

If you provide full working code, it will more easy to comment.


Related Query

More Query from same tag