谁能帮我弄清楚为什么下面的图表永远不会生成点?我认为这个问题与前排气口和后排气口有关。如果我把它们去掉就行了,但理想情况下,出于风格上的原因,我希望保留它们。
digraph G {
nodesep = 0.5;
0 [width=0.75, height=0.75, fontsize=20];
1 [width=0.75, height=0.75, fontsize=20, shape=square];
2 [width=0.75, height=0.75, fontsize=20];
3 [width=0.75, height=0.75, fontsize=20];
4 [width=0.75, height=0.75, fontsize=20];
5 [width=0.75, height=0.75, fontsize=20, shape=square];
6 [width=0.75, height=0.75, fontsize=20];
7 [width=0.75, height=0.75, fontsize=20, shape=square];
8 [width=0.75, height=0.75, fontsize=20, shape=square];
9 [width=0.75, height=0.75, fontsize=20, shape=square];
10 [width=0.75, height=0.75, fontsize=20, shape=square];
11 [width=0.75, height=0.75, fontsize=20, shape=square];
12 [width=0.75, height=0.75, fontsize=20];
subgraph directed{
rankdir= LR;rank= max;
0->1->2->3->4->5->6->7->8->9->10->11->12;
}
subgraph undirected{
rankdir= LR;rank= min;edge[tailport=n,headport=n];
0->1[dir=none, color=red];
0->2[dir=none, color=red];
1->9[dir=none, color=red];
2->3[dir=none, color=red];
2->8[dir=none, color=red];
3->4[dir=none, color=red];
4->8[dir=none, color=red];
7->9[dir=none, color=red];
8->9[dir=none, color=red];
9->10[dir=none, color=red];
9->11[dir=none, color=red];
10->11[dir=none, color=red];
}
}
如果不花费大量的时间来挖掘源代码,就很难说明原因,但是您可以将麻烦的元素移出第二个子图来解决问题:
从无向子图中删除1->9和2->8,并将它们添加到它的下面:
digraph G {
nodesep = 0.5;
0 [width=0.75, height=0.75, fontsize=20];
1 [width=0.75, height=0.75, fontsize=20, shape=square];
2 [width=0.75, height=0.75, fontsize=20];
3 [width=0.75, height=0.75, fontsize=20];
4 [width=0.75, height=0.75, fontsize=20];
5 [width=0.75, height=0.75, fontsize=20, shape=square];
6 [width=0.75, height=0.75, fontsize=20];
7 [width=0.75, height=0.75, fontsize=20, shape=square];
8 [width=0.75, height=0.75, fontsize=20, shape=square];
9 [width=0.75, height=0.75, fontsize=20, shape=square];
10 [width=0.75, height=0.75, fontsize=20, shape=square];
11 [width=0.75, height=0.75, fontsize=20, shape=square];
12 [width=0.75, height=0.75, fontsize=20];
subgraph directed{
rankdir= LR;rank= max;
0->1->2->3->4->5->6->7->8->9->10->11->12;
}
subgraph undirected{
rankdir= LR;rank= min;edge[tailport=n,headport=n];
0->1[dir=none, color=red];
0->2[dir=none, color=red];
2->3[dir=none, color=red];
3->4[dir=none, color=red];
4->8[dir=none, color=red];
7->9[dir=none, color=red];
8->9[dir=none, color=red];
9->10[dir=none, color=red];
9->11[dir=none, color=red];
10->11[dir=none, color=red];
}
1->9[dir="none", color="red", headport="n"];
2->8[dir="none", color="red", headport="n"];
}
很难知道自己在追求什么。然而,该图有一些问题:
- 节点不能是多个子图的一部分——它们要么在图中,要么在子图中,无论它们首先出现在哪里。你的应该出现在哪里?
-
rankdir
是图形属性,不能应用于子图形
编辑
根据你的评论,这是一个没有子图的版本。然而,你不会喜欢边缘的路由,这将很难控制。
这个想法是在一条直线上对齐节点,然后用constraint=false
添加其他边,以便不让它们影响节点的排名。
digraph G {
nodesep = 0.5;
node[width=0.75, height=0.75, fontsize=20];
rankdir=LR;
0;
1 [shape=square];
2;
3;
4;
5 [shape=square];
6;
7 [shape=square];
8 [shape=square];
9 [shape=square];
10 [shape=square];
11 [shape=square];
12;
0->1->2->3->4->5->6->7->8->9->10->11->12;
edge[constraint=false, tailport=n,headport=n,dir=none, color=red];
0->1;
0->2;
1->9;
2->3;
2->8;
3->4;
4->8;
7->9;
8->9;
9->10;
9->11;
10->11;
}
不幸的是,这遇到了一个长期存在的错误,与两个端口指定的某些边缘有关:
Warning: Unable to reclaim box space in spline routing for edge "4" -> "8". Something is probably seriously wrong.
Warning: Unable to reclaim box space in spline routing for edge "1" -> "9". Something is probably seriously wrong.
(https://gitlab.com/graphviz/graphviz/-/issues/241)。
有两个边似乎击中了这个错误(4->8 & 1→9 )。如果为这两条边设置了[tailport="],则图将正确生成。