Brent
Brent

Reputation: 4283

How can I achieve strict reverse ranking of graphviz dot?

Edit: If posted a new question to supersede this question. Align Ranks in Graphviz

First, let me apologize for inventing/abusing some terminology in the title. By "strict" I mean all nodes of the same rank need the same y position in the output image, whereas by default they are shifted around slightly. Second, by "reverse" I mean all the leafs are the same rank, appearing at the same row at the bottom of the graph, and all of their ancestors to be ranked and aligned accordingly (without reversing the edge directions). The graphs I'm working with are bounded semilattices, so there's no cyclical portions and all nodes have a well defined rank.

Abstract Syntax Tree

I tried reversing the edge direction (and "dir=back" can make the edges look like the original direction), but the "strict" part is still a problem

enter image description here

Upvotes: 1

Views: 1398

Answers (3)

sroush
sroush

Reputation: 6773

The TBbalance attribute TBbalance=max (https://graphviz.org/docs/attrs/TBbalance/), (in conjunction with rank=max) should do just what you want.
rank=max to bring the terminal nodes to the bottom, and TBbalance=max to bring all ancestors to the maximal possible rank.
FYI, TBbalance has only been available for a year or so.

Upvotes: 2

Brent
Brent

Reputation: 4283

I ended up changing the algorithm that generates the graphviz to place several { rank = same; ... } items in the output

Upvotes: 1

marapet
marapet

Reputation: 56466

How to put all the leaves on the bottom (max) rank ?

You may include a subgraph containing all the leave nodes and add the attribute rank=max:

{
    rank=max;
    leaf1; leaf2; leaf3;
}

This should place all your leaf-nodes on the bottom.

Upvotes: 2

Related Questions