I give the following input to Dot:
digraph G {
subgraph cluster1 {
fontsize = 20;
label = "Group 1";
A -> B -> C -> D;
style = "dashed";
}
subgraph {
O [shape=box];
}
subgraph cluster2 {
fontsize = 20;
label = "Group 2";
Z -> Y -> X -> W [dir=back];
style = "dashed";
}
D -> O [constraint=false];
W -> O [constraint=false, dir=back];
}
And it produces:
How can I align node O
so that it has the same rank as D
and W
? That is, a graph that looks like:
A Z
| |
B Y
| |
C X
| |
D-O-W
Adding
{ rank=same; D; O; W; }
yields the error
Warning: D was already in a rankset, ignored in cluster G
Warning: W was already in a rankset, ignored in cluster G
I'm thinking I can hack it by adding invisible nodes and edges to the subgraph of O
, but I was wondering if I was missing some Dot magic.
Best Answer
You could use an approach with
rankdir=LR
and useconstraint=false
for the edges inside the clusters:It's not dot magic :-), but it achieves this:
Hacking with invisible nodes does also work:
The result is almost identical: