Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control subgraphs' layout in dot?

Tags:

graphviz

dot

i have a digraph composed of many independant and simple subgraphs of various sizes. dot lays all these subgraphs horizontally, so i end up with a 40000x200 output file, e.g:

G1 G2 G3 G.....4 G5 

How do i tell dot to layout these subgraphs in both dimensions to get something like:

G1 G2 G3 G.....4 G5 

Thanks.

like image 851
Benoît Avatar asked Nov 03 '11 21:11

Benoît


People also ask

How do I view a .DOT file?

You can open DOT files with Microsoft Word in Windows and macOS. The word processor is also available for Android and iOS devices, but only the iOS version supports DOT files. Other word processors can also open DOT files but they may not fully support the formatting of the original templates.

How do you make a graph on graphviz?

Create a graph object, assemble the graph by adding nodes and edges, and retrieve its DOT source code string. Save the source code to a file and render it with the Graphviz installation of your system. Use the view option/method to directly inspect the resulting (PDF, PNG, SVG, etc.) file with its default application.

What is Pydot in Python?

The pydot package is an interface to Graphviz. It is written in pure Python, and it can parse and dump into the DOT language used by Graphviz. A folder tree structure in a computer comprising of a directory, sub-directory, files, etc. is also an example of a directed graph.

What is graphviz Neato?

neato is a reasonable default tool to use for undirected graphs that aren't too large (about 100 nodes), when you don't know anything else about the graph. neato attempts to minimize a global energy function, which is equivalent to statistical multi-dimensional scaling.


1 Answers

The steps to achieve this uses multiple graphviz tools which can be piped together.

The following line is a possible configuration, graph.dot being the file which contains your graph(s). You may have to fiddle with the options.

ccomps -x graph.dot | dot | gvpack -array3 | neato -Tpng -n2 -o graph.png 

And here's the explanation:


1. Separate disconnected graphs

Tool: ccomps

decomposes graphs into their connected components

The -x option (Only the connected components are printed, as separate graphs) is probably all that is needed.


2. Layout each graph

Tool: dot

Each directed graph is layed out, one by one. This step is needed to get the position of the nodes and edges.


3. Pack all layed out graphs into one

Tool: gvpack

reads in a stream of graphs, combines the graphs into a single layout, and produces a single graph serving as the union of the input graphs.

You should read the documentation of the options for this tool and play with the options. For example, -array is used to lay out the graphs in a grid like manner, and offers several flags to control the layout.


4. Create the output

Tool: neato

The option -n2 tells neato to not layout the input graphs but to use the existing position attributes.


Example graph:

graphiz gvpack

digraph G {  subgraph G1 {     a->{b; c;};  }  subgraph G2 {     d -> {e; f;};  }  subgraph G3 {     g -> h;  }  subgraph G4 {     i -> j;  }  subgraph G5 {     {k; l;} -> m;  } } 

Edit: Sorting the digraphs in gvpack

In order to determine the order of appearance od the subgraphs in the combined layout created by gvpack, each subgraph will need a sortv attribute.

For example, the following graphs:

digraph G1 {  sortv=1;  a->{b; c;}; } digraph G2 {  sortv=2;  d -> {e; f;}; } digraph G3 {  sortv=3;  g -> h; } digraph G4 {  sortv=4;  i -> j; } digraph G5 {  sortv=5;  {k; l;} -> m; } 

can be transformed using

dot graph.dot | gvpack -array_u | neato -Tpng -n2 -o graph.png 

resulting in

packed graph with ordered subgraphs

like image 139
marapet Avatar answered Sep 22 '22 03:09

marapet