I'd like to draw a graph composed of nodes and edges, using a spring layout algorithm (a kind of force directed layout) Once the graph is laid out, I'd like to let the user interactively add new nodes, and let the layout evolve, i.e. positioning the new nodes while maintaining the previous "shape" (not moving the already positioned nodes too much).
I mean something like what WordVis is doing at http://www.wordvis.com.
I'm currently using the spring layouter available in the GraphDracula library. It's a "simple" one, meaning that if you re-layout the graph, you may get a completely different layout (this is due, I think, to the calls to Math.rand
in the algorithm)
What is the algorithm/strategy to do what I'd like to do?
I see that the graphdracula's layouter sets the initial node pos to zero, and then iterates to calculate the final nodes' positions.
Suppose I add a set of nodes newNodes
adjacent to an expandedNode
: to maintain the existing shape, is it enough to set the initial pos of each of the newNodes
to the one of expandedNode
and then apply the forces to the all of the nodes once again?
Do you have any pointer to an algorithm that not only lays out the graph once, but also lets you add new nodes re-layouting the whole graph without changing the drawing too much?
Any hint is welcome.
I'm currently working with javascript, but the language is not important.