简体   繁体   English

Graphviz 节点的点垂直对齐

[英]Graphviz Dot vertical alignment of nodes

I got this dot graph and want the nodes A and D, B and E and C and F to be aligned.我得到了这个点图,并希望节点 A 和 D、B 和 E 以及 C 和 F 对齐。 Here is the related dot code:这是相关的点代码:

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
}

As you can see I already tried to apply weights to the edges, but that didn't work out如您所见,我已经尝试将权重应用于边缘,但没有成功

在此处输入图片说明

It is possible to use the group attribute of the nodes to suggest aligning the edges between nodes of the same group in a straight line.可以使用节点的group属性来建议将同一组的节点之间的边沿直线对齐。

Declare the nodes with the group attribute:使用 group 属性声明节点:

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

Then make sure all of those nodes have an (invisible) edge between them:然后确保所有这些节点之间都有(不可见的)边:

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

Everything together:一切都在一起:

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
}

Graphviz 图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM