[英]Graphviz - Vertical order of leaf nodes
I'm trying to generate a Tree graph (left to right one), to illustrate an object reference tree. 我正在尝试生成一个树形图(从左到右),以说明对象引用树。 Beside this, I want the leafs to appear vertically consequent, because this indicates some order of execution. 除此之外,我希望叶子垂直出现,因为这表明执行的顺序。
The dot code is as follows: 点代码如下:
digraph G {
rankdir=LR
subgraph cluster_0 {
L1 L2 L3 L4 L5 L6
L10 L20 L30 L40 L50 L60
{ rank=same;
L1 -> L2 -> L3 -> L4 -> L5 -> L6 ->
L10 -> L20 -> L30 -> L40 -> L50 -> L60
}
}
subgraph cluster_1 {
R
D10 D11
D20 D21 D22 D23
D30 D31 D32 D33 D34 D35 D36 D37
}
R->D10
R->D11
D10 -> D20
D10 -> D21
D11 -> D22
D11 -> D23
D20 -> D30
D20 -> D31
D21 -> D32
D21 -> D33
D22 -> D34
D22 -> D35
D23 -> D36
D23 -> D37
D30 -> L1
D20 -> L2
D31 -> L3
D32 -> L4
D21 -> L5
D33 -> L6
D34 -> L10
D22 -> L20
D35 -> L30
D36 -> L40
D23 -> L50
D37 -> L60
}
What I've got far (using https://dreampuf.github.io/GraphvizOnline/ to render SVG): 我已经学到了什么(使用https://dreampuf.github.io/GraphvizOnline/渲染SVG):
The problem is, I want the leafs to show up in the order of declaration. 问题是,我希望叶子按声明的顺序显示。 Following some posts on SO, I've been playing around with constraint / invisible edges / ranking system but couldn't quite get my hands on it. 在SO上的一些帖子之后,我一直在尝试使用约束/不可见的边缘/排名系统,但还不太了解。
It'd be nice if some graphvizard could extend their hand over here. 如果一些图形蜥蜴可以伸出他们的手,那就太好了。 note that this procedure will be later automated with python, so some robust idea will be more than appreciated. 请注意,此过程稍后将通过python自动执行,因此,一些可靠的想法将不胜感激。
note 2, the tree could have up to hundreds of leafs. 注意2,树上最多可以有数百片叶子。
note 3, if you know some good python lib to generate Graphs which is more intuitive (for you at least) than Graphviz, please comment. 注意3,如果您知道一些比Graphviz更直观(至少对您而言)的python lib来生成Graph,请发表评论。 I'm currently using pydot & graphviz (py3) 我目前正在使用pydot和graphviz(py3)
By moving the leaf nodes out and adding weights to them I have the following: 通过将叶节点移出并为其添加权重,我得到以下信息:
I changed the dot input to: 我将点输入更改为:
digraph G {
rankdir=LR
subgraph cluster_0 {
L1 L2 L3 L4 L5 L6
L10 L20 L30 L40 L50 L60
}
subgraph cluster_1 {
R
D10 D11
D20 D21 D22 D23
D30 D31 D32 D33 D34 D35 D36 D37
}
R->D10
R->D11
D10 -> D20
D10 -> D21
D11 -> D22
D11 -> D23
D20 -> D30
D20 -> D31
D21 -> D32
D21 -> D33
D22 -> D34
D22 -> D35
D23 -> D36
D23 -> D37
D30 -> L1
D20 -> L2
D31 -> L3
D32 -> L4
D21 -> L5
D33 -> L6
D34 -> L10
D22 -> L20
D35 -> L30
D36 -> L40
D23 -> L50
D37 -> L60
{ rank=same;
L1-> L2 [style=invis, weight=1000]
L2-> L3 [style=invis, weight=1100]
L3-> L4 [style=invis, weight=1200]
L4-> L5 [style=invis, weight=1300]
L5-> L6 [style=invis, weight=1400]
L6-> L10 [style=invis, weight=1500]
L10-> L20 [style=invis, weight=1600]
L20-> L30 [style=invis, weight=1700]
L30-> L40 [style=invis, weight=1800]
L40-> L50 [style=invis, weight=1900]
L50-> L60 [style=invis, weight=2000]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.