Graphviz中的循环列表?或如何弯曲边缘

时间:2018-05-23 17:31:34

标签: graphviz

我一直试图在Graphviz中做我认为简单的事情,就像这样:

enter image description here(摘自https://tex.stackexchange.com/questions/394432/how-to-draw-circular-linked-list

我正在尝试使用Graphviz做类似的事情,这就是它现在的样子:

enter image description here

我阅读了文档并尝试使用neato和circo图表但没有成功......我怎样才能以我需要的方式弯曲边缘?我现在可以尝试使用一个坐标,比如p3:e -> p1:w但是会​​从记录中间删除起点。

到目前为止,这是我的代码:

digraph {
  node[shape=record];
  graph[pencolor=transparent];
  rankdir=LR;
  p1[label="{<data> 12|<next>}"];
  p2[label="{<data> 99|<next>}"];
  p3[label="{<data> 37|<next>}"];

  edge[tailclip=false,arrowtail=dot,dir=both];

  p1:next:c -> p2:data;
  p2:next:c -> p3:data;
  p3:next:c -> p1:data[constraint=false];
}

1 个答案:

答案 0 :(得分:1)

你需要一些辅助节点(p0和p4)

digraph {
  node[shape=record];
  graph[pencolor=transparent];
  rankdir=LR;
  p1[label="{<data> 12|<next>}"];
  p2[label="{<data> 99|<next>}"];
  p3[label="{<data> 37|<next>}"];

  edge[tailclip=false,arrowtail=dot,dir=both];

  {node[shape=point height=0] p0 p4} // make p0 and p4 to small to see
  p0:n -> p1[arrowtail=none]
  p0:s -> p4:s[dir=none] // add edge with no arrow to make it look like one long edge, also make p0 the tail so we don't have a recursition that may course dot to rearange the nodes
  p1:next:c -> p2:data;
  p2:next:c -> p3:data;
  //p3:next:c -> p1:data[constraint=false];
  p3:next:c -> p4:n[arrowhead=none]
}

enter image description here

你可以通过使用html表格标签并在其中一个单元格中添加图像来完成尾部的交叉