Question

I (as many others, e.g. Force graphviz to preserve node positions ) need to add new nodes to a graph, leaving the nodes already present unchanged.

Do you know if this could work?

1) I let graphviz draw the first instance of the graph

2) I ask graphviz to report where it placed every node

3) I add some additional nodes, using the coordinates obtained at step 2) as pos option, leaving just the new nodes without a pos attribute, free to be placed where graphviz desires.

Is it possible, or graphviz needs every position set?

Was it helpful?

Solution 2

The pos attribute is only usefule when using neato or fdp - from here:

In neato and fdp, pos can be used to set the initial position of a node.

For neato, typically the -n option is needed to make use of the pos values - from this page :

If set, neato assumes nodes have already been positioned and all nodes have a pos attribute giving the positions.

Therefore, this isn't possible. The linked answer may prove helpful in case you can start with the full graph and hide nodes instead of adding new ones.

OTHER TIPS

mmmm, on second thought I tried it this way:

fdp -Tdot dir.dot -o dir.gv

Now dir.gv contains the pos info for all the nodes; then I used dir.gv to produce the 1st graph:

fdp -Tpng dir.gv -o dir1.png

I then edited dir.gv, adding a single node (without pos attribute), then:

fdp -Tpng dir.gv -o dir2.png

by comparing dir1.png and dir2.png, I see that the 2nd layout is completely unchanged, apart from the new node - that's what I wanted!

(edit) well, more or less: if I start from this: step1

and add a single node, it's rather ok: step2

... but adding a small new cluster of nodes, they end up rather dispersed: step3

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top