views:

66

answers:

1

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.

+2  A: 

Yes, subgraphs will work.

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

results in

alt text

brool
Perfect, that's exactly what I was looking for! And even easier than I expected it to be. Thanks.
Jagid