In other words, swap Y pos values of topmost and bottom-most nodes and extrapolate in-between.
Assuming you are using dot, add rankdir=BT
(see rankdir | Graphviz)
I have client-side code for further drag-and-drop editing after a graphviz layout. For reasons I won’t go into, that code has the origin defined differently than graphviz, so everything is flipped. I want to export a layout directly from graphviz. In order to match the client, it would need to be flipped.
I already did a substitution, if rankdir=BT make it TB, and vs., but I use circo and twopi in addition to dot, so that won’t work for those. Actually, in order to exactly match any editing changes that have been made on the client, I may use fdp with pin=true, rather than dot/circo/twopi. But the same need for flipping would apply.
Essentially, I’m wanting to redefine the origin in graphviz.
This is only lightly tested, but it seems to work:
- use any engine, but set output format to dot (DOT | Graphviz) (e.g.
twopi -Tdot myfile >myfile.out1
) - use the GVPR (https://graphviz.org/pdf/gvpr.1.pdf) program (see below) to change the sign of the Y component of each node’s pos (pos | Graphviz) value. (e.g.
gvpr -c -f flip.gvpr myfile.out1 >myfile.out2
) - run that output into
neato -n
(FAQ | Graphviz). Neato will re-establish all the edge and misc. label positions. (e.g.neato -n -Tpng myfile.out2 >myfile.png
)
flip.gvpr:
BEG_G{
//print("// old bb: ", $G.bb);
$G.bb=xOf(llOf($G.bb)) + "," + "-" + yOf(llOf($G.bb)) + "," + xOf(urOf($G.bb)) + "," + "-" + yOf(urOf($G.bb));
//print("// new bb: ", $G.bb);
}
N{
//print("// old pos: ", $.pos);
$.pos=(string)$.X + "," + (string)(- $.Y);
//print("// new pos: ", $.pos);
}
So far your solution works on every graph I’ve tried it on. Much appreciated.