How can I control inside the node level at a point in the graph?

I have a graph that has a tree as a basis. So, I have, for example, node A with children B, C and D. Assuming the graph is drawn from top to bottom, A will be on the same level, then B, C and D. I would like to get graphviz to lay them out in order B , C, D within their rank. Is it possible? If so, how?

If there is only A, B, C, and D, I can get this effect by simply placing B, C, and D in that order in the input points file. But if there are other edges from B, C and / or D, sometimes the order is upset. This is what I would like to avoid.

enter image description here

+10
source share
2 answers

"" , . , , , .

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;
}
}

enter image description here

+11

@TomServo ( , ""), :

After adding <code> rank1 </code> and <code> rank2 </code>.

+10

Source: https://habr.com/ru/post/1678212/


All Articles