Brent
Brent

Reputation: 4283

Align Ranks in Graphviz

This is a follow-up question to How can I achieve strict reverse ranking of graphviz dot?, but a little easier. This graph is contrived, but demonstrates the problem:

digraph nfa {
    A -> B
    B -> C
    C -> D
    D -> E
    A -> F
    F -> E
}

Nodes B and F are the same rank, but they are not displayed at the same rank. How can achieve this?

enter image description here

Upvotes: 3

Views: 1486

Answers (2)

sroush
sroush

Reputation: 6773

An "easier" solution, using the new-ish TBbalance attribute (http://www.graphviz.org/docs/attrs/TBbalance/). TBbalance does just what you want.

digraph nfa {
  TBbalance=min
    A -> B
    B -> C
    C -> D
    D -> E
    A -> F
    F -> E
}

Giving:
enter image description here

Upvotes: 1

Brent
Brent

Reputation: 4283

I used subgraphs with rank = same, and manually computed the ranks and grouped them in said subgraphs.

digraph {
    { rank = same; A }
    { rank = same; B; F }
    { rank = same; C }
    { rank = same; D }
    { rank = same; E }
    A -> B
    B -> C
    C -> D
    D -> E
    A -> F
    F -> E
}

Upvotes: 2

Related Questions