I have a use case where the edges should be shown on the button click.
Let’s say, we have a graph with nested clusters without edges.
the edges between nodes and clusters should be shown based on interaction.
This works fine when I call the renderDot function again with a modified src but sometimes the position or order of clusters gets changed.
The first cluster goes to 3r place and vice versa.
Do we have any attribute to force the cluster to place in sequential order? Note: I only modified edges not adding or removing clusters and even the ordering changed when the same src files passed multiple times. I understand that the issue is not because of edges.
There is no such attribute, though maybe not difficult, maybe a good summer intern project. Also, the submitted merge to fix “nondeterministic layout in fdp” might help a lot.
Edges affect the layout of nodes. So adding and removing edges will inherently affect the node positions.
To achieve what you want, I think rendering once with the edges as you want them and once with the edges set to transparent or the same color as the background may do what you want.
I have used the styles i.e. link.classed(“edges_on”, true) to solve my use case.
Note: Not only adding the edges but adding the nodes changed the position of the clusters.
Adding support to retain the cluster position would give more addition to the interaction point of view.
Not sure I understand (other than clusters have a mind of their own!), but here goes:
If you can consistently get the clusters positioned how you want before any changes, then you can use this multi-step approach:
run dot -Tdot against the starting version of your graph. This gives an input file with all objects fully positioned.
every time you add, change, or delete the edges, run the result through neato -n. This will keep all the clusters and nodes in place, but will re-route the edges (FAQ | Graphviz).
If you cannot always get to a happy starting placement (yes, clusters are hard to position), you can try putting each cluster in a separate graph, run dot on each, and then use gvpack (https://graphviz.org/pdf/gvpack.1.pdf) to combine all the clusters in a 1-dimensional or 2-dimensional array.
I started exploring the fdp layout based on your suggestion to place the nodes using pos attribute.
So that I can retain the cluster position/order even after re-rendering some additional nodes(including pos for new nodes).
I am trying to achieve the below diagram using pos and it is working when I have one subgraph.
not sure what values need to be given for other subgraph nodes.
I use d3-graphviz library for rendering.
You can use dot -Tdot to layout the “starting” graph (it will produce explicit pos values), and then add/remove/change edges all you want to the output of the dot -Tdot command.
running that result through neato -n
OR (since you are using a library)
use layout=nop inside the graph after changes (the equivalent to neato -n on the command line, see nop2 | Graphviz)