How can I control within level node order in graphviz's dot?
To help fill-out @TomServo's answer (for people struggling with "rank"), I've made the invisible edges visible:
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;
}
}
You don't need those magic rank1
and rank2
.
Just:
- Make the graph as usual.
- Add nodes one again in a subgraph.
digraph test{
// declare nodes all out of desired order
A -> D;
A -> B;
A -> C;
A -> E;
B;C;D;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
edge[ style=invis];
B -> C -> D -> E ;
rankdir = LR;
}
}