Twintail
Twintail

Reputation: 23

Is it possible to control node position in 2D ? ( graphviz )

enter image description hereIs it possible to set rank attirbute in both direction?

I know that it is possible to set in one direction. But I want to set both direction.

For example, the next code will generate attached graph. But I want to control vertical position of "d" node.

digraph G {
    rankdir=LR
    a -> b -> c
    b -> d
    { rank=same b d }
}

I tried source code position like "d" first, but it did not affect its vertical position.

Upvotes: 0

Views: 173

Answers (2)

Twintail
Twintail

Reputation: 23

After trying some time I can found workaround for this case. Thank you Sroush.

digraph G {
    rankdir=LR

    a -> b -> c
    up
    down
    {rank=same; b up down }

    up -> b [dir=back]
    b -> down [style=invis]
    down      [style=invis]

}

work around using one dummy node

Upvotes: 0

sroush
sroush

Reputation: 6763

Graphviz does not allow two directional ranking. However, the group attribute (https://graphviz.org/docs/attrs/group/) usually (but not always) accomplishes your goal. Note that group requires edges connecting all the nodes in the group. Also group is applied to nodes, while rank is applied to subgroups.

In this case, the group attribute did not produce the desired result until other changes were made. The graph below has TB rankdir and associated changes to rank=same plus the use of group

digraph G {
    //rankdir=LR

    c [group=G]
    d [group=G]
    { rank=same a -> b -> c}
    b -> d 
    c -> d [style=invis]
}

Giving:
enter image description here

Upvotes: 1

Related Questions