How to Optimize Graphviz Output Width

How can I optimize GraphViz output width?

In case the graph consists of several trees which are not connected, you could split them up (as mentioned in Graphviz: break flat but sparsely connected graph into multiple rows?)

Depending on your particular graph, you may obtain a smaller graph when using

ratio="compress"

(You'll have to specify size though)

For detailed optimizations on a specific graph, you may add rank attributes and distribute the nodes manually on different ranks.


Edit:

There is a graphviz tool called unflatten which seems to exist exactly for this purpose :

unflatten is a preprocessor to dot that is used to improve the aspect
ratio of graphs having many leaves or disconnected nodes. The usual
layout for such a graph is generally very wide or tall. unflatten
inserts invisible edges or adjusts the minlen on edges to improve
layout compaction.

Never had the need to use it, but I think it's worth a try.

Change Size (Width and Height) of Graph (GraphViz & dot)

DEFAULT

I will start with a simple graph that is laid out by the dot engine in the default manner:

digraph {
node [shape=circle, width=0.4];
A->B
A->D
B->C
D->E
}

Sample Image

CHANGING HEIGHT

As you can see, the layout is quite tight. Notice that my ranks (rows) naturally go from top to bottom. I can affect the height of the graph by exploiting this and using the ranksep (rank separation) variable to explicitly set the space between the ranks:

digraph { 
node [shape=circle, width=0.4];
ranksep = 1;
A->B
A->D
B->C
D->E
}

Sample Image

CHANGING WIDTH

Finally, we may want to widen the diagram. Here we use the nodesep variable to increase the space between the nodes (columns):

digraph { 
node [shape=circle, width=0.4];
nodesep=1.5;
A->B
A->D
B->C
D->E
}

Sample Image

GraphViz: Compress automatically generated graph

Here's an idea:

  • Instead of one graph with x clusters create a dot file with x graphs
  • unflatten them
  • then use gvpack to pack all graphs together
  • and neato to layout

The basic idea is to use graphs instead of clusters so you can use gvpack to pack the graphs.

Something like:

unflatten -f -l 4 -c 6 input.dot | dot | gvpack -array_t6 | neato -s -n2 -Tpng -o output.png

Not sure though whether unflatten handles files with several graphs.

(Sorry, no time to check it).



Related Topics



Leave a reply



Submit