graphviz 树形布局
我是第一次使用 graphviz。我只需要一个树布局,以便所有子级都处于同一级别。
例如, A→B A→C A->D
那么 B、C 和 D 应该处于同一水平。
以下是我正在使用的代码。
digraph unix {
size="6,6";
node [color=lightblue2, style=filled];
"A:1000" -> "B:300";
"A:1000" -> "C:300";
"A:1000" -> "D:200";
"B:300" -> "E:140";
"B:300" -> "F:164";
"B:300" -> "G:75";
"C:300" -> "H:135";
"C:300" -> "I:91";
"D:200" -> "E:140";
"D:200" -> "F:164";
"D:200" -> "G:75";
"E:140" -> "F:164";
"E:140" -> "G:75";
"F:164" -> "G:75";
"G:75" -> "H:135";
"H:135" -> "I:91";
}
如何确保孩子处于同一水平?
I am using graphviz for the first time. I just need a tree layout so that all the childs are at the same level.
For example,
A->B
A->C
A->D
THEN B, C AND D SHOULD BE AT THE SAME LEVEL.
Following is the code I am using.
digraph unix {
size="6,6";
node [color=lightblue2, style=filled];
"A:1000" -> "B:300";
"A:1000" -> "C:300";
"A:1000" -> "D:200";
"B:300" -> "E:140";
"B:300" -> "F:164";
"B:300" -> "G:75";
"C:300" -> "H:135";
"C:300" -> "I:91";
"D:200" -> "E:140";
"D:200" -> "F:164";
"D:200" -> "G:75";
"E:140" -> "F:164";
"E:140" -> "G:75";
"F:164" -> "G:75";
"G:75" -> "H:135";
"H:135" -> "I:91";
}
How do I make sure that the childs are at the same level?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要使节点处于同一级别,例如“B:300”和“C:300”,请添加以下行:
To get nodes on the same level, say "B:300" and "C:300", add the following line:
您提供的图并不代表一棵树,而是一个有向无环图(在树中,每对节点之间只有一条不同的路径)。如果您的输入是一棵树,那么只需使用
dot
就会产生您想要的结果。如果您还想添加非树边,例如"C:300" ->在您的示例中,“H:135”
可以为它们指定较低的权重,以确保dot
不会尝试针对这些边缘优化布局。请注意,使用此设置,这两条边会变得非常长(并且变成点,丑陋),这就是节点
"C:300"
被按原样放置的原因在你的原始图表中。The graph you presented does not represent a tree, but a directed acyclic graph (In a tree there is only one distinct path between every pair of nodes). If your input would have been a tree, then just using
dot
would produce what you want. If you also want to add non-tree edges, like"C:300" -> "H:135"
in your example, you could specify a lower weight for them, to make sure thatdot
doesn't try to optimize the layout with respect to these edges.Note that these two edges become very long (and to
dot
, ugly) with this setting, and this is the reason why the node"C:300"
is placed as it is in your original graph.