I need to draw tree looks like this (with values associated with some nodes):
But I find only the way to draw tree like next:
I try to use subgraphs, and nested subgraphs, but there is no effect needed. Currently, I use the next gv script:
digraph "test-graph" {
graph [rankdir=TB dpi=96]
subgraph n0 {
rank=same;
"0_0" [ label = "a" ];
}
subgraph n1 {
rank=same;
"1_0" [ label = "b" ];
"1_1" [ label = "d" ];
"1_2" [ label = "e" ];
subgraph {
"v3" [ label = "3", shape = "box" ];
"1_1"->"v3" [ dir = none, constraint = false ];
}
}
subgraph n2 {
rank=same;
"2_0" [ label = "g" ];
}
subgraph n3 {
rank=same;
"3_0" [ label = "a" ];
"3_1" [ label = "b" ];
"3_2" [ label = "c" ];
subgraph {
"v2" [ label = "2", shape = "box" ];
"3_0"->"v2" [ dir = none, constraint = false ];
"v0" [ label = "0", shape = "box" ];
"3_1"->"v0" [ dir = none, constraint = false ];
"v5" [ label = "5", shape = "box" ];
"3_2"->"v5" [ dir = none, constraint = false ];
}
}
subgraph n4 {
rank=same;
"4_0" [ label = "f" ];
subgraph {
"v1" [ label = "1", shape = "box" ];
"4_0"->"v1" [ dir = none, constraint = false ];
}
}
subgraph n5 {
rank=same;
"5_0" [ label = "c" ];
subgraph {
"v4" [ label = "4", shape = "box" ];
"5_0"->"v4" [ dir = none, constraint = false ];
}
}
"start"->"0_0";
"0_0"->"1_0";
"0_0"->"1_1";
"0_0"->"1_2";
"1_0"->"5_0";
"1_1"->"2_0";
"1_2"->"4_0";
"2_0"->"3_0";
"2_0"->"3_1";
"2_0"->"3_2";
}
Using "cluster_" prefix solves some of problems (thanks Anne), but there is important in wich order nodes and it's values folows in the dot script.
After all I got new problem - nodes not properly ordered on graph: a, b, c nodes (node 'g' childs) follows in wrong order:
Also, is there a way to tell dot place values at right side from nodes? The best, of course, is then the values are placed under nodes, but, how I can find, this is unsolvable problem.
Dot script is:
digraph "test-graph" {
graph [rankdir=TB dpi=96]
subgraph cluster_n0 {
rank=same;
style=invis;
"0_0" [ label = "a" ];
}
subgraph cluster_n1 {
rank=same;
style=invis;
"1_0" [ label = "b" ];
"1_1" [ label = "d" ];
"v3" [ label = "3", shape = "box", width=.01, height=.01 ];
"1_1"->"v3" [ dir = none, constraint = false ];
"1_2" [ label = "e" ];
}
subgraph cluster_n2 {
rank=same;
style=invis;
"2_0" [ label = "g" ];
}
subgraph cluster_n3 {
rank=same;
style=invis;
"3_0" [ label = "a" ];
"v2" [ label = "2", shape = "box", width=.01, height=.01 ];
"3_0"->"v2" [ dir = none, constraint = false ];
"3_1" [ label = "b" ];
"v0" [ label = "0", shape = "box", width=.01, height=.01 ];
"3_1"->"v0" [ dir = none, constraint = false ];
"3_2" [ label = "c" ];
"v5" [ label = "5", shape = "box", width=.01, height=.01 ];
"3_2"->"v5" [ dir = none, constraint = false ];
}
subgraph cluster_n4 {
rank=same;
style=invis;
"4_0" [ label = "f" ];
"v1" [ label = "1", shape = "box", width=.01, height=.01 ];
"4_0"->"v1" [ dir = none, constraint = false ];
}
subgraph cluster_n5 {
rank=same;
style=invis;
"5_0" [ label = "c" ];
"v4" [ label = "4", shape = "box", width=.01, height=.01 ];
"5_0"->"v4" [ dir = none, constraint = false ];
}
"start"->"0_0";
"0_0"->"1_0";
"0_0"->"1_1";
"0_0"->"1_2";
"1_0"->"5_0";
"1_1"->"2_0";
"1_2"->"4_0";
"2_0"->"3_0";
"2_0"->"3_1";
"2_0"->"3_2";
}