Graphviz点的节点垂直对齐 [英] Graphviz Dot vertical alignment of nodes

查看:328
本文介绍了Graphviz点的节点垂直对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I got this dot graph and want the nodes A and D, B and E and C and F to be aligned. 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

推荐答案

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

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:

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

所有内容:

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点的节点垂直对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆