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
}
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
}
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
}
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
Problem Running Thinking Sphinx with Rails 2.3.5
Search for "Enabled" Users in Net-Ldap for Ruby
Activerecord::Associationtypemismatch in Controller#Create on Dropdown Select for a Rails Self Join
Ruby/Rails Array of Strings to Postgresql Insert
How to Get a Reference to a Method
How to Define a Simple Global Variable in an Rspec Test That Can Be Accesed by Helper Functions
Why #!/Usr/Bin/Env Ruby Doesn't Work in Crontab
Array#Rotate Equivalent in Ruby 1.8.7
Exec the Cd Command in a Ruby Script
Ruby: Cannot Install Watir Gem on Windows
Activerecord_Postgis_Adapter: Undefined Method 'Point' for Nil:Nilclass
How to Figure Out Which Step I'Ve Just Executed in Cucumber's Afterstep Hook
In Rspec, Using Let Variable Inside Before :All Block
How to Replace the Characters in a String