Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set fixed depth levels in DOT graphs

I'm creating a DOT graph visualization from a tree-like data structure but am having difficulties setting fixed level depths based upon data type. For example, if I had 4 nodes in a tree and A denotes a specific data type and B represents another it would like Graph_1:

                                      ROOT   
                                     /    \  
                                   A[0]    B[1]
                                   /        
                                 B[0]    

as opposed to Graph_2:

                                      ROOT   
                                     /    \  
                                   A[0]    \
                                   /        \
                                 B[0]       B[1]   

Graph_2 is what I would like to end up with.

The fixed levels are what I'm looking for. How can I achieve this? I can easily identify what data type I'm adding to the graph, but am having trouble on how to tag nodes to achieve this. Can this be done using subgraphs?

FYI, this is my first time playing with DOT.

like image 463
Jagid Avatar asked Jul 23 '10 22:07

Jagid


1 Answers

Yes, subgraphs will work.

digraph {
  subgraph { rank = same; A0 };
  subgraph { rank = same; B0; B1 };
  root -> A0;
  A0 -> B0;
  root -> B1;
}

results in

alt text
(source: brool.com)

like image 147
brool Avatar answered Oct 23 '22 19:10

brool