我想创建一个看起来像这样的图表,我。即边缘从节点Manufacturer of means of production
到具有相同名称的子图。
我为此编写了以下代码:
digraph G {
rankdir=LR;
compound=true;
graph [fontname="Liberation Mono"];
node [fontname="Liberation Mono"];
edge [fontname="Liberation Mono"];
subgraph cluster0 {
label="System components";
mmp [label="Manufacturer of means of production", shape=box];
}
subgraph cluster1 {
t1start [label="Start of tact 1", shape=point]
t1end [label="End of tact 1", shape=point ]
subgraph cluster1_mmp {
label="Manufacturer of means of production"
cluster1_1 [label="Node 1", color=white]
subgraph cluster1_1_1 {
label="Technological cycle 1"
cluster1_1_1 [label="Node 2", color=white]
}
subgraph cluster1_1_2 {
label="Technological cycle 2"
cluster1_1_2 [label="Node 2", color=white]
}
}
}
subgraph cluster2 {
label="Такт 2"
t2start [label="Start of tact 2", shape=point]
t2end [label="End of tact 2", shape=point]
}
t1end -> t2start
mmp -> cluster1_1 [ltail=cluster1_mmp];
}
如果我尝试编译此代码("C:\Program Files (x86)\Graphviz2.38\bin\"dot.exe -Tpng -ograph.png graph.dot
),我会收到警告Warning: mmp -> cluster1_1: tail not inside tail cluster cluster1_mmp
。
如何修复它并使边缘转到子图?
更新1:
您可以在下面找到预期结果的图像 - 从节点到子图的边(子图,而不是子图内的节点)。此边缘在下图中为红色。
更新2 :更改了如下所示的代码。
digraph G {
rankdir=LR;
compound=true;
graph [fontname="Liberation Mono"];
node [fontname="Liberation Mono"];
edge [fontname="Liberation Mono"];
subgraph cluster0 {
label="System components";
mmp [label="Manufacturer of means of production", shape=box];
}
subgraph cluster1 {
t1start [label="Start of tact 1", shape=point]
t1end [label="End of tact 1", shape=point ]
subgraph cluster1_mmp {
label="Manufacturer of means of production"
testNode [label="Node 1", color=white]
subgraph cluster1_1_1 {
label="Technological cycle 1"
cluster1_1_1 [label="Node 2", color=white]
}
subgraph cluster1_1_2 {
label="Technological cycle 2"
cluster1_1_2 [label="Node 2", color=white]
}
}
}
subgraph cluster2 {
label="Такт 2"
t2start [label="Start of tact 2", shape=point]
t2end [label="End of tact 2", shape=point]
}
t1end -> t2start
mmp -> cluster1 [ltail=cluster0, lhead=cluster1, label=" "];
}
答案 0 :(得分:5)
您需要更改最后一行
mmp -> cluster1_1 [ltail=cluster1_mmp];
到
mmp -> cluster1_1 [lhead=cluster1 label=" "]
然后图表按预期进行
此外,如果您希望边缘从框外开始,那么您可以
mmp -> cluster1_1 [ltail=cluster0 lhead=cluster1 label=" "];
修改强>
使用的最终代码
digraph G {
rankdir=LR;
compound=true;
graph [fontname="Liberation Mono"];
node [fontname="Liberation Mono"];
edge [fontname="Liberation Mono"];
subgraph cluster0 {
label="System components";
mmp [label="Manufacturer of means of production", shape=box];
}
subgraph cluster1 {
t1start [label="Start of tact 1", shape=point]
t1end [label="End of tact 1", shape=point ]
subgraph cluster1_mmp {
label="Manufacturer of means of production"
cluster1_1 [label="Node 1", color=white]
subgraph cluster1_1_1 {
label="Technological cycle 1"
cluster1_1_1 [label="Node 2", color=white]
}
subgraph cluster1_1_2 {
label="Technological cycle 2"
cluster1_1_2 [label="Node 2", color=white]
}
}
}
subgraph cluster2 {
label="Такт 2"
t2start [label="Start of tact 2", shape=point]
t2end [label="End of tact 2", shape=point]
}
t1end -> t2start
mmp -> cluster1_1 [lhead=cluster1 label=" "]
}
相同的小提琴link
答案 1 :(得分:-1)
Urm,你的意思是“lhead = cluster1_mmp”而不是ltail?
您的边缘指定为:
mmp -> cluster1_1 [ltail=cluster1_mmp];
您遇到的错误消息是“警告:mmp - > cluster1_1:尾部不在尾部簇cluster1_mmp内”
这表示你的尾巴不在尾群内。尾簇是cluster1_mmp。 cluster1_1,你要连接的东西肯定在cluster1_mmp里面。这解释了你的困惑。
只有经过GraphvizFiddle的大量调查后,我才最终记得带箭头的尖端是 head (即语法为tail -> head
)。
所以,cluster1_1,你试图说的节点在cluster1_mmp中是箭头的头部。这就是为什么你的ltail规范不起作用的原因。将其更改为lhead可以消除错误消息并生成一个看起来像您的图片的图形。箭头会转到子图,正是您在问题中要求的内容。
这是两个GraphvizFiddles,一个of the original code generating the original error和一个with ltail changed to lhead,与您的图片相匹配。
(我确信我花了很多时间在我自己的图表中调试相同的问题。也许Graphviz可以得到一个更新,以检查ltail参数是否对箭头有意义,反之亦然,并吐出更多有用的错误信息。)