Graphviz Vertical Ordering
Asked Answered
S

1

14

I have a set of GraphViz nodes such that:

digraph {
    A->B;
    A->C;
    A->D;
}

But B, C, and D happen sequentially in time!

enter image description here

It would be great if there was some way to indicate the vertical level each node should appear upon (where the number of levels may be unknown beforehand).

Does anyone have thoughts on how to accomplish this?

Soerabaja answered 11/10, 2013 at 1:27 Comment(0)
S
22

One option to have a node display on a different rank (vertical level) than an other node is to add invisible edges. Assigning those nodes the same group indicates graphviz to lay them out in a straight line if possible.

For example:

digraph g{
  A;
 node[group=a];
 B;C;D;
 A -> B;
 A -> C;
 A -> D;
 edge[style=invis];
 B->C->D;
}

enter image description here

An other option is to have one vertical line of (invisible) nodes, then force the same rank by defining the nodes of the same rank within the same subgraph with rank=same:

digraph g{
 {rank=same; l1[style=invis, shape=point]; A;}
 {rank=same; l2[style=invis, shape=point]; B;}
 {rank=same; l3[style=invis, shape=point]; C;}
 {rank=same; l4[style=invis, shape=point]; D;E;F;}

 A -> B;
 A -> C;
 A -> D;
 edge[style=invis];
 l1->l2->l3->l4;
}

enter image description here

Swordfish answered 11/10, 2013 at 15:36 Comment(1)
Thanks! The one of adding the invisible links to express the sequential relationship works beautifully for me. Simple and sweet!Annelieseannelise

© 2022 - 2024 — McMap. All rights reserved.