Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz Vertical Ordering

Tags:

graphviz

dot

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?

like image 466
Richard Avatar asked Oct 11 '13 01:10

Richard


People also ask

How do you make a graph on Graphviz?

Create a graph object, assemble the graph by adding nodes and edges, and retrieve its DOT source code string. Save the source code to a file and render it with the Graphviz installation of your system. Use the view option/method to directly inspect the resulting (PDF, PNG, SVG, etc.) file with its default application.

What is rank in Graphviz?

Ranks and Subgraphs To work out the layout, Graphviz uses a system it calls "ranks". Each node is assigned a higher rank than the highest ranked node that point to it. If your rank direction is set to left to right ( rankdir=LR ), then nodes with a higher rank are placed further to the right.

What language does Graphviz use?

Abstract grammar for defining Graphviz nodes, edges, graphs, subgraphs, and clusters. Terminals are shown in bold font and nonterminals in italics. Literal characters are given in single quotes.

What is the shape of a node?

There are three main types of shapes : polygon-based, record-based and user-defined. The record-based shape has largely been superseded and greatly generalized by HTML-like labels. That is, instead of using shape=record , one might consider using shape=none , margin=0 and an HTML-like label.


1 Answers

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

like image 133
marapet Avatar answered Sep 19 '22 01:09

marapet