Graphviz点垂直对齐节点

时间:2014-11-23 16:52:22

标签: graphviz dot

我得到了这个点图,并希望节点A和D,B和E以及C和F对齐。这是相关的点代码:

digraph{

A
B
C
D
E
F

{rank = same; B; C}
{rank = same; E; F}

A -> B [label="2", weight=2]
A -> C [label="0", style=dashed, weight=2]
B -> C [label="0", style=dashed, weight=2]
B -> D [label="2", style=dashed, weight=2]
C -> D [label="0", weight=2]
D -> E [label="1", style=dashed, weight=2]
D -> F [label="0", weight=2]
E -> F [label="0", weight=2]
F -> A
}

正如你所看到的,我已经尝试过将重量应用于边缘,但这并没有成功

enter image description here

1 个答案:

答案 0 :(得分:23)

可以使用节点的group属性来建议在一条直线上对齐同一组节点之间的边缘。

使用group属性声明节点:

A [group=g1]
{rank = same; B[group=g2]; C[group=g3]}
D [group=g1]
{rank = same; E[group=g2]; F[group=g3]}

然后确保所有这些节点之间都有一条(不可见的)边缘:

edge[style=invis];
A -> D
B -> E
C -> F

一切都在一起:

digraph G {
  A [group=g1]
  {rank = same; B[group=g2]; C[group=g3]}
  D [group=g1]
  {rank = same; E[group=g2]; F[group=g3]}

  A -> B [label="2", weight=2]
  A -> C [label="0", style=dashed, weight=2]
  B -> C [label="0", style=dashed, weight=2]
  B -> D [label="2", style=dashed, weight=2]
  C -> D [label="0", weight=2]
  D -> E [label="1", style=dashed, weight=2]
  D -> F [label="0", weight=2]
  E -> F [label="0", weight=2]
  F -> A

  edge[style=invis];
  A -> D
  B -> E
  C -> F
}