This example demonstrates how to add and remove nodes and links from a force-directed layout. The graph initially appears with three disconnected nodes A, B and C. After one second, the three are connected in a loop. At two seconds, node C is removed, along with the links A-C and B-C. At three seconds, node C is reintroduced, restoring the original links A-C and B-C. Every subsequent second alternates between these two steps.
This example uses the general update pattern for data joins. See also modifying a force layout with transitions.
I'm hoping to update this gist from d3 v3 to v4 as it will directly help in a project of mine. I've made an attempt to upgrade however the nodes are positioned in the top left corner and the removal of the nodes doesn't appear to be happening.
My fork:
https://gist.github.com/stevescc/f964f8f4658bc11319765f83f67b7f9f
https://bl.ocks.org/stevescc/f964f8f4658bc11319765f83f67b7f9f
Ta