Ordering Nodes (dot)

I’m making trees with dot and I generally want GV to arrange the nodes, but occasionally I want to pick the order of parent or child nodes. This page Node, Edge and Graph Attributes tells me dot has a node/graph attribute called “ordering” that can be set to “in” or “out,” but there’s no sample code, so I tried every variation I could think of and finally got “ordering=out” to work. I’m putting in a pared-down version of my code; I want to swap dotD and orsD where noted.
[dot verbose=true]
strict digraph ors {
node [shape=none]
ors ordering=out // this puts orso, orsa in order
ors -> orso -> arsazGm -> {earsOE aersMD}
earsOE -> arsME -> ass
aersMD -> orsD
{dotD orsD} -> dodorsD // dotD, orsD are swapped; I want them in this order
dodorsD -> dodoP -> dodo
ors -> orsa -> ouraG
{skia ouraG} -> skiourosG -> sciurusL -> scuriolusL -> esquirelAN -> squirelME -> squirrel
kwon -> kuon
{kuon ouraG} -> kunosuraG -> cyosuraL -> cynosureF -> cynosure
ouraG -> ouroG -> uroNL -> uroE
subgraph E { rank=same ass dodo squirrel cynosure uroE }
}
[/dot]

1 Like

I believe that this should do what you want: dodorsD [ordering=in]
But, there is a known bug: https://gitlab.com/graphviz/graphviz/-/issues/1152
So here is a work-around:
strict digraph ors {
node [shape=none]
ors ordering=out // this puts orso, orsa in order
ors -> orso -> arsazGm -> {earsOE aersMD}
earsOE -> arsME -> ass
aersMD -> orsD
dodorsD [ordering=in] // I believe this should do it, but there is a bug
{rank=same dotD -> orsD [style=invis]} // dotD, orsD are swapped; I want them in this order
dotD -> dodorsD // dotD, orsD are swapped; I want them in this order
orsD -> dodorsD // dotD, orsD are swapped; I want them in this order
dodorsD -> dodoP -> dodo
ors -> orsa -> ouraG
{skia ouraG} -> skiourosG -> sciurusL -> scuriolusL -> esquirelAN -> squirelME -> squirrel
kwon -> kuon
{kuon ouraG} -> kunosuraG -> cyosuraL -> cynosureF -> cynosure
ouraG -> ouroG -> uroNL -> uroE
subgraph E { rank=same ass dodo squirrel cynosure uroE }
}

The invisible edge fixes things:

1 Like