How can I optimize GraphViz output width?

2019-02-16 05:56发布

问题:

I make graphs that have huge width ratio: they are 51706 x 503 pixels in size. How can I tell GraphViz to optimize width ?

Note 1: the graph is in fact a tree with each node having a lot of children. Here is a sample.

Note 2: I think I use dot :)

Note 3: Here is the Ruby code

回答1:

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.



回答2:

You can try to play with the ratio parameter.



回答3:

I also had the problem that neato kept lots of space between the boxes. Finally I achieved a reasonable result using following graph settings in addition:

overlap=prism, overlap_scaling=0.01, ratio=0.7

It's especially useful testing different values for overlap_scaling and ratio. It's the quickest to use smaller examples (<50 nodes) and use gvedit.exe to see the effects.

It took me quite a while to identify these settings, which are documented at http://www.graphviz.org/doc/info/attrs.html



标签: graphviz