Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid Graphviz dot layouts wasting space, with nodes of disparate sizes at the same rank?

Tags:

graphviz

dot

When one has a graphviz directed graph that is best suited to arrange using dot, is there a way to get around the issue of a large node creating excess padding around other nodes of the same rank?

For example, with the following graph:

digraph {
    b[label="line 1\nline 2\nline 3\nline 4\nline 5\nline 6\n"];

    a -> b;
    a -> c;
    b -> f;
    c -> d;
    d -> e;
    e -> f;
}

(result of the above)

The graph is obviously taller than necessary due to the left-hand path increasing the height of a rank that doesn't need to be so tall in the right-hand path.

Is there perhaps a way to do layout the two paths separately? I thought using cluster subgraphs might help, but it seems that rank heights are completely global even in that case.

I'm hoping for a result akin to this image edit (please excuse it's crudeness): enter image description here

like image 549
Rednaxela Avatar asked Dec 16 '17 22:12

Rednaxela


1 Answers

As a workaround you may try to add edge[constraint = false];.
This will set constraint attribute value for all edges:

Rendered graph

Or specify constraint attribute only for some of edges.


EDIT: Quite close result we can achieve with the help of subgraphs:

digraph {

    rankdir = LR;

    b[label="line 1\nline 2\nline 3\nline 4\nline 5\nline 6\n"];

    subgraph cluster_0 {

        rank = same;

        style = invis;

        a -> c -> d -> e -> f [constraint = false];

    }

    a -> b;
    b -> f;

}

Will be rendered as follows:

Rendered graph

like image 102
user882813 Avatar answered Nov 05 '22 09:11

user882813