Graphviz Vertical Ordering

2019-02-05 00:03发布

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?

标签: graphviz dot
1条回答
劫难
2楼-- · 2019-02-05 00:34

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

查看更多
登录 后发表回答