我向 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];
}
它产生:
如何对齐节点
O
使其与 D
和 W
具有相同的等级?也就是说,一个图形看起来像:A Z
| |
B Y
| |
C X
| |
D-O-W
添加
{ rank=same; D; O; W; }
产生错误
Warning: D was already in a rankset, ignored in cluster G
Warning: W was already in a rankset, ignored in cluster G
我想我可以通过向
O
的子图中添加不可见的节点和边来破解它,但我想知道我是否错过了一些点魔法。
最佳答案
您可以使用 rankdir=LR
的方法,并将 constraint=false
用于集群内的边缘:
digraph G {
rankdir=LR;
subgraph cluster1 {
fontsize = 20;
label = "Group 1";
rank=same;
A -> B -> C -> D [constraint=false];
style = "dashed";
}
subgraph cluster2 {
fontsize = 20;
label = "Group 2";
rank=same;
Z -> Y -> X -> W [dir=back, constraint=false];
style = "dashed";
}
O [shape=box];
D -> O -> W;
}
这不是点魔法:-),但它实现了这一点:
使用隐形节点进行黑客攻击也有效:
digraph G {
subgraph cluster1 {
fontsize = 20;
label = "Group 1";
A -> B -> C -> D;
style = "dashed";
}
subgraph {
O1[style=invis];
O2[style=invis];
O3[style=invis];
O [shape=box];
O1 -> O2 -> O3 -> O [style=invis];
}
subgraph cluster2 {
fontsize = 20;
label = "Group 2";
Z -> Y -> X -> W [dir=back];
style = "dashed";
}
edge[constraint=false];
D -> O -> W;
}
结果几乎相同:
关于alignment - 在Graphviz中垂直对齐连接子图的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16628525/