我使用Graphviz (点)绘制了一个双链接列表,如下所示,但是节点没有对齐。如何对齐节点?
digraph "Doubly Linked List" {
rankdir=LR;
node [shape=record];
e [label="nil" shape=circle];
a [label="{ <ref1> | <data> 1 | <ref2> }"]
b [label="{ <ref1> | <data> 5 | <ref2> }"];
c [label="{ <ref1> | <data> 7 | <ref2> }"];
d [label="nil" shape=circle];
e -> a:ref1:c [arrowhead=dot, arrowtail=vee, dir=both, headclip=false];
a:ref2:c -> b:data:n [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
b:ref2:c -> c:data:n [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
c:ref2:c -> d [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
c:ref1:c -> b:data:s [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
b:ref1:c -> a:data:s [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
}
发布于 2021-12-22 00:07:26
在高层次上,答案是{rank=same ... nodes here ... }
但是,记录形状的节点和排序相同的边缘会导致点心灼伤,或者更准确地产生以下错误消息:
Warning: flat edge between adjacent nodes one of which has a record shape - replace records with HTML-like labels
Edge e -> a
Error: lost e a edge
Error: lost a b edge
Error: lost b a edge
Error: lost b c edge
Error: lost c b edge
Error: lost c d edge
因此,如果我们将节点更改为“html样”形状(https://graphviz.org/doc/info/shapes.html#href),您将得到:
digraph "Doubly Linked List" {
node [shape=plaintext] // for correct display of table
{rank=same // all on same rank
e [label="nil" shape=circle];
a [label=<<table border="0" cellspacing="0" cellborder="1"><tr>
<td port="ref1" width="28" height="36" fixedsize="true"></td>
<td port="data" width="28" height="36" fixedsize="true">1</td>
<td port="ref2" width="28" height="36" fixedsize="true"></td>
</tr></table>>]
b [label=<<table border="0" cellspacing="0" cellborder="1"><tr>
<td port="ref1" width="28" height="36" fixedsize="true"></td>
<td port="data" width="28" height="36" fixedsize="true">5</td>
<td port="ref2" width="28" height="36" fixedsize="true"></td></tr>
</table>>]
c [label=<<table border="0" cellspacing="0" cellborder="1"><tr>
<td port="ref1" width="28" height="36" fixedsize="true"></td>
<td port="data" width="28" height="36" fixedsize="true">7</td>
<td port="ref2" width="28" height="36" fixedsize="true"></td>
</tr></table>>]
d [label="nil" shape=circle];
}
e -> a:ref1:c [arrowhead=dot, arrowtail=vee, dir=both, headclip=false];
a:ref2:c -> b:data:n [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
b:ref2:c -> c:data:n [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
// added :w to straighten edge
c:ref2:c -> d:w [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
c:ref1:c -> b:data:s [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
b:ref1:c -> a:data:s [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
}
(对不起)但它给了你:
发布于 2021-12-22 01:20:54
Sroush提供了一种类似html形状的解决方案,但我找到了一种使用记录节点here的方法,如下所示:
digraph "Doubly Linked List" {
rankdir=LR;
node [shape=record];
e [label="nil" shape=circle];
a [label="{ <ref1> | <data> 1 | <ref2> }"]
b [label="{ <ref1> | <data> 5 | <ref2> }"];
c [label="{ <ref1> | <data> 7 | <ref2> }"];
d [label="nil" shape=circle];
e -> a:ref1:c [arrowhead=dot, arrowtail=vee, dir=both, headclip=false];
a:ref2:c -> b:data:n [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
b:ref2:c -> c:data:n [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
c:ref2:c -> d [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
c:ref1:c -> b:data:s [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
c:ref1:c -> b:data:w[weight = 100, style = invis]; <- add this
b:ref1:c -> a:data:s [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
b:ref1:c -> a:data:w[weight = 100, style = invis]; <- add this
}
https://stackoverflow.com/questions/70441786
复制相似问题