在GraphViz中绘制时如何在相同高度上连接相邻节点?

时间:2014-08-26 14:24:57

标签: graph graphviz suffix-tree

我正在尝试使用GraphViz绘制以下内容(后缀树):

digraph G {
  1[label = " "];
  2[label = " "];
  3[label = " "];
  4[label = " "];
  5[label = " "];
  6[label = " "];
  7[label = " "];
  8[label = " "];

  // edges drawn vertically, all fine.
  1 -> 2 [label="ab"];
  1 -> 3 [label=" b"];
  1 -> 4 [label=" c$"];
  2 -> 5 [label="abc$"];
  2 -> 6 [label="c$"];
  3 -> 7 [label=" abc$"];
  3 -> 8 [label="c$"];

  // node 3 should be on the right side of node 2, and
  // a cross line should be drawn horizontally

  2 -> 3 [style=dotted,label="abc$"];

}

问题是,跟随边缘“abc $”和“b”到达的节点与跟随“ab”和“c $”到达的那两个节点的高度不同。

是否有人遇到过相同的情况并可以共享解决方案?

1 个答案:

答案 0 :(得分:0)

啊,好吧,没有找到合适的条款! "placing nodes on a horizontal line",提供解决方案。

此代码现在将节点2,3,4正确定位在同一“水平线”上。

digraph G {
  1[label = " "];
  2[label = " "];
  3[label = " "];
  4[label = " "];
  5[label = " "];
  6[label = " "];
  7[label = " "];
  8[label = " "];

  node[group=sameheight];
    { rank = same; 2; 3; 4; }

  1 -> 2 [label="ab"];
  1 -> 3 [label=" b"];
  1 -> 4 [label=" c$"];
  2 -> 3 [style=dotted];
  2 -> 5 [label="abc$"];
  2 -> 6 [label="c$"];
  3 -> 7 [label=" abc$"];
  3 -> 8 [label="c$"];
}

希望它有所帮助。