Sebastialonso
Sebastialonso

Reputation: 1461

Graphviz ignores rank attribute if no edges between nodes

I'musing Graphviz to render some hierarchical structure. So far the use of subgraphs has been sub-optimal for achieving what I'm looking for.

This is what I would like to get

enter image description here

(colors represent different tiers in the hierarchy so they need to follow this order). For making this image I used invisible links, but that's really not an option in a real world scenario.

However, at the moment this is what I'm getting enter image description here

using this .dot file

graph {
    // Global config
    rankdir=BT
    node [style="filled" fontcolor="white" shape="box"]
    // Rank (hierarchies)
    { rank=same; 258 }
    { rank=same; 259 }
    { rank=same; 260 }
    { rank=same; 261 262 }
    // Nodes
    // Tasks
    258 [label="John Cleese" fillcolor="#E8B04D"]
    // Project Goals
    259 [label="Michael Palin" fillcolor="#C0C56B"]
    // Identities
    260 [label="Eric Idle" fillcolor="#FF8D61"]
    // Virtues
    261 [label="Graham Chapman" fillcolor="crimson"]
    262 [label="Terry Jones" fillcolor="crimson"]
    // Edges
    259 -- 260 [style="bold" color="#3790af"]
}

Is it posible for Graphviz to honor rank before edges? If so, how would I proceed?

Upvotes: 3

Views: 1578

Answers (1)

TomServo
TomServo

Reputation: 7409

Your problem is easily solved by the addition of a few invisible edges that make the various ranks (that you set up correctly) work as you want. Note the simple addition of three invisible edges near the bottom:

graph {
    // Global config
    rankdir=BT
    node [style="filled" fontcolor="white" shape="box"]
    // Rank (hierarchies)
    { rank=same; 258 }
    { rank=same; 259 }
    { rank=same; 260 }
    { rank=same; 261 bl 262 }
    // Nodes
    // Tasks
    258 [label="John Cleese" fillcolor="#E8B04D"]

    // Project Goals
    259 [label="Michael Palin" fillcolor="#C0C56B"]

    // Identities
    260 [label="Eric Idle" fillcolor="#FF8D61"]

    // Virtues
    261 [label="Graham Chapman" fillcolor="crimson"]
    262 [label="Terry Jones" fillcolor="crimson"]

    // Edges
    259 -- 260 [style="bold" color="#3790af"]
258--259 [style=invis]
260--261 [style=invis]
260--262 [style=invis]
260--bl [style=invis]

bl [style=invis label="" height=0, width=0]

}

I also added an invisible balancing node in the center, bl to help center the graph better.

enter image description here

Upvotes: 4

Related Questions