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?

Potherca
  • 13,207
  • 5
  • 76
  • 94
Richard
  • 56,349
  • 34
  • 180
  • 251

1 Answers1

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

Potherca
  • 13,207
  • 5
  • 76
  • 94
marapet
  • 54,856
  • 12
  • 170
  • 184
  • Thanks! The one of adding the invisible links to express the sequential relationship works beautifully for me. Simple and sweet! – Yu Shen Apr 02 '18 at 20:26