1

我使用graphvizhackmd绘制这样的图表 在此处输入图像描述

我的代码是:

digraph G {
    rankdir=LR
    node [color=black,shape=record]
    node0 [label="{<data>node 0|<next>}"]
    node1 [label="{<data>node 1|<next>}"]
    new_node [label="{<data>new_node|<next>}"]
    null0 [shape=none, label="NULL"]
    null1 [shape=none, label="NULL"]
    head [shape=none, label="head"]
    ptr [shape=none, label="ptr"]
    indirect [shape=none]
    
    head->ptr
    indirect->node0:next [constraint=false headport=s tailport=n];
    ptr->node0
    node0:next:c->node1 [arrowhead=normal, arrowtail=dot, dir=both, tailclip=false];
    node1:next:c -> null0 [tailclip=false, arrowtail=dot, dir=both]
    
    
    new_node:next:c->null1 [arrowhead=normal, arrowtail=dot, dir=both, tailclip=false];
    {rank=same; indirect node1;}
}

我想node0和间接在同一级别。然而,当我改变

{rank=same; indirect node1;} -> {rank=same; indirect node0;}

他们将有错误消息:"Error: lost indirect node0 edge" 我想要的实际图表:

在此处输入图像描述

4

1 回答 1

0

更改布局以使用 html 样式标签而不是 shape=record

digraph G {
    rankdir=LR
    node [color=black shape=none margin=0 height=.3 ]
    node0 [label=<<table border="0" cellborder="1" cellspacing="0"><tr><td port="data">node 0</td><td port="next">&nbsp;</td></tr></table>>]
    node1 [label=<<table border="0" cellborder="1" cellspacing="0"><tr><td port="data">node 1</td><td port="next">&nbsp;</td></tr></table>>]
    new_node [label=<<table border="0" cellborder="1" cellspacing="0"><tr><td port="data">new_node</td><td port="next">&nbsp;</td></tr></table>>]
    null0 [shape=none, label="NULL"]
    null1 [shape=none, label="NULL"]
    head [shape=none, label="head"]
    ptr [shape=none, label="ptr"]
    indirect [shape=none]
    
    head->ptr
    indirect->node0:next [constraint=false headport=s tailport=n];
    ptr->node0
    node0:next:c->node1 [arrowhead=normal, arrowtail=dot, dir=both, tailclip=false];
    node1:next:c -> null0 [tailclip=false, arrowtail=dot, dir=both]
    
    
    new_node:next:c->null1 [arrowhead=normal, arrowtail=dot, dir=both, tailclip=false];
    {rank=same indirect node0}
}

在此处输入图像描述

于 2020-11-02T18:47:24.107 回答