Forcing "main line" nodes into a straight line in Graphviz (or alternatives)

Chad Birch picture Chad Birch · Jan 12, 2011 · Viewed 10.6k times · Source

I'm trying to use Graphviz dot (but am willing to use something else) to generate a graph with a long "main line" of nodes, and many small branches. I'd like the main line to be straight from left to right, with the small branches above or below it. However, Graphviz "balances" the two branches, so I end up with a crooked graph.

To illustrate, here's a sketch similar to what I currently get:

Current Graph

And this is what I actually want:

Wanted graph

Is there any way to force or encourage Graphviz to generate a graph like the second one? I may be able to use "dummy" second branches to have it do a 3-way layout, and then hide/delete the dummies afterward, but if there's a better option that would be preferable.

Answer

marapet picture marapet · Jan 12, 2011

Here is a solution using the weight attribute of edges:

digraph G {
    rankdir="LR";
    node[width=0.15, height=0.15, shape=point];
    edge[weight=2, arrowhead=none];
    1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8;
    edge[weight=1];
    2 -> 9 -> 10 ;
    5-> 11 -> 12;
}

Result:

graphivz