Accepted answer

You need to add the update functions for the circles and links.

Since you only had add and remove, the elements were being added and removed properly, but when an element needed to be updated, nothing was being done. By adding the update functions for circles and links when anything changes they will be "updated" to their new position.

node.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })

// *** UPDATE LINK ***
link.attr("d", diagonal);

Here is the corrected fiddle:

Hope this helps.

Related Query

More Query from same tag