Reputation: 7359
I have a simple graphviz graph that is drawn as shown in the following image:
digraph G {
"Model" -> "Task";
"Task" -> "Worker 1" -> "Sink";
"Task" -> "Worker 2" -> "Sink";
"Task" -> "Worker 3" -> "Sink";
}
Adding and edge between the sink and task nodes, the graph output is shown the following image:
"Sink" -> "Model";
How could I add this edge and keep the original symmetric node layout shown in the first image?
Upvotes: 2
Views: 610
Reputation: 10841
(Edited to improve my original answer)
Building on the answer to How to control subgraphs' layout in dot?, if we start by laying out the core digraph with dot
, we can then use neato
to add the additional edge. neato
allows nodes that already have defined positions to be pinned using the -n
parameter so one could do something like this (where symmetric.dot
contains the original GraphViz digraph with the addition of graph [splines = true]
):
#!/bin/bash
dot -Tdot symmetric.dot >symmetric1.dot
neato -n2 -Tpng symmetric1.dot -osymmetric1.png
sed 's/^}/"Sink" -> "Model";}/' <symmetric1.dot >symmetric2.dot
neato -n2 -Tdot symmetric2.dot >symmetric3.dot
neato -n2 -Tpng symmetric3.dot -osymmetric3.png
This script:
dot
to lay out the original digraph into a new .dot
file.neato -n2
to plot the original digraph. The -n2
option prevents neato
from moving nodes that already have positions. sed
to insert the "Sink" -> "Model"
edge.neato -n2
to lay out the new edge (which is the only one without pos
defined, and thus the only one not pinned) and plot it as a .png
file.symmetric1.png
looks like this:
... and symmetric3.dot
with the additional edge looks like this:
Upvotes: 1