Ever have questions about the ranking of a large graph?
- how many ranks, total?
- which rank has the most (or fewest) nodes?
- what rank is node XYZ on?
- what are all the nodes(ranks) “between” two (or three or more) nodes(ranks)
OK, I admit I can’t get you all the way to such answers, but this will get you closer. It uses the recently discovered (undocumented) phase attribute (Document undocumented attributes (#75) · Issues · graphviz / graphviz.gitlab.io · GitLab). If you run dot with the phase attribute set to 1 graph[phase=1], dot will do the ranking, report the result (see below) and then quit.
(And it is blazingly fast)
like so:
dot -Tdot -Gphase=1 myfile.gv >myfile.dot
It produces a valid, but incomplete, Graphiz input/output file in the dot format. Node ranking is done (A is on rank 0 and B is on rank 1) and sizing is complete, but node positioning and edge positioning are not done.
Example output:
graph test {
graph [bb="0,0,0,0",
phase=1
];
node [shape=plaintext,
label="\N"
];
edge [dir=none];
subgraph clusterA {
graph [bb="0,0,0,0",
margin=19
];
A [height=0.5,
pos="0,0",
rank=0,
width=0.75];
}
subgraph clusterB {
graph [bb="0,0,0,0"];
B [height=0.5,
pos="0,0",
rank=1,
width=0.75];
}
A -- B;
}
OK, back to the questions above.
A simple(?) python, or gvpr (see below), or C or whatever, program can turn the above file into node name / rank value data pairs.
gvpr 'N{print($.rank, " ",$.name)}' myfile.dot
Producing:
0 C
0 E
2 F
3 G
1 D
4 H
Take this data and most any programming language or spreadsheet system (Excel) can start answering the questions listed at the top.
Fun!
p.s. If you want to further use the output of a phase=1 output as input to dot remember to set phase=“”, or dot will stop early (phase=1 is added to the output)