如何在graphviz点中控制级别节点顺序? [英] How can I control within level node order in graphviz's dot?
问题描述
我有一个以树为骨干的图.因此,例如,我有一个带有子B,C和D的节点A.假设该图是自上而下绘制的,则A将处于一个级别,然后是B,C和D.按其等级按B,C,D顺序排列它们.这可能吗?如果可以,怎么办?
I have a graph that has a tree as its backbone. So I have, for example a node A with children B, C, and D. Assuming the graph is being drawn top-down, A will be on one level, then B, C, and D. I would like to force graphviz to lay them out in B, C, D order within their rank. Is this possible? If so, how?
如果只有A,B,C和D,则可以通过将B,C和D依次放入输入点文件中来获得这种效果.但是,如果B,C和/或D之外还有其他边缘,则有时顺序会变得混乱.这就是我要避免的事情.
If there are only A, B, C, and D, I can get this effect by just putting B, C, and D in that order in the input dot file. But if there are other edges out of B, C, and/or D, sometimes the order gets scrambled. That's what I would like to avoid.
推荐答案
这可以通过显示的不可见"边缘来实现.请注意说明其工作原理的注释.
This can be achieved with "invisible" edges as shown. Please note well the comments that describe how it works.
digraph test{
// make invisible ranks
rank1 [style=invisible];
rank2 [style=invisible];
// make "invisible" (white) link between them
rank1 -> rank2 [color=white];
// declare nodes all out of desired order
A -> D;
A -> B;
A -> C;
A -> E;
// even these new connection don't mess up the order
B -> F -> G;
C -> F -> G;
{
rank = same;
// Here you enforce the desired order with "invisible" edges and arrowheads
rank2 -> B -> C -> D -> E [ style=invis ];
rankdir = LR;
}
}
这篇关于如何在graphviz点中控制级别节点顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!