我想创建一个看起来像这样的图形,即边缘从节点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];
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试编译此代码("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=" "];
}
Run Code Online (Sandbox Code Playgroud)
你需要改变你的最后一行
mmp -> cluster1_1 [ltail=cluster1_mmp];
Run Code Online (Sandbox Code Playgroud)
至
mmp -> cluster1_1 [lhead=cluster1 label=" "]
Run Code Online (Sandbox Code Playgroud)
然后图表按预期进行
此外,如果您希望边缘从框外开始,那么您可以这样做
mmp -> cluster1_1 [ltail=cluster0 lhead=cluster1 label=" "];
Run Code Online (Sandbox Code Playgroud)
编辑
使用的最终代码
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=" "]
}
Run Code Online (Sandbox Code Playgroud)
相同的小提琴链接