Richard
Richard

Reputation: 61239

Graphviz Vertical Ordering

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?

Upvotes: 14

Views: 11043

Answers (1)

marapet
marapet

Reputation: 56446

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

Upvotes: 22

Related Questions