Graphviz: Is there a way to force a node to the bottom?
-
22-07-2019 - |
Question
I'm building a CFG (Context-free grammar), and I'd like the exit node to always be at the bottom of the graph. Sometimes it happens naturally, sometimes it doesn't.
Example:
digraph G {
0;
1;
4;
5;
7;
8;
0 -> 4;
5 -> 7;
7 -> 8;
7 -> 1;
8 -> 5;
4 -> 7;
}
Draws (using dot):
Node 1 is my exit node, I'd like that to be at the bottom. Suggestions?
Solution
Use rank specification for the subgraph. In this case sink should make it at the bottom and max will make it on the same level as 5:
digraph G {
0;
{ rank = sink; 1; }
5;
4;
7;
8;
0 -> 4;
5 -> 7;
7 -> 8;
7 -> 1;
8 -> 5;
4 -> 7;
}
OTHER TIPS
In DOT try the option "-y"
-y - Invert y coordinate in output
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow