Home » Javascript » D3.js V4 – Change the link's source(Parent node) and target(Child node) of each node

D3.js V4 – Change the link's source(Parent node) and target(Child node) of each node

Posted by: admin June 30, 2018 Leave a comment

Questions:

I using D3.js V4 to draw the diagram. My issue is that I have 3 nodes called “A”, “B” and “C”. All of them placed by the position data indicated from JSON (x and y) and do the Force simulation. The sequence of nodes is that

A —-> B and A —-> C which will result as
enter image description here

What I trying to do is to change by dragging the source’s link of A to B so the link between A —-> C removed and become B —-> C so it will be like:

enter image description here

I tried to find the example of similar concept to this but still no clue for few days.

Answers: