dot - How I can draw the tree with values stored in nodes with graphviz? -
i need draw tree looks (with values associated nodes):
but find way draw tree next:
i seek utilize subgraphs, , nested subgraphs, there no effect needed. currently, utilize 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 of problems (thanks anne), there of import in wich order nodes , it's values folows in dot script.
after got new problem - nodes not ordered on graph: a, b, c nodes (node 'g' childs) follows in wrong order:
also, there way tell dot place values @ right side nodes? best, of course, values placed under nodes, but, how can find, 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"; }
to grouping "value" node node, have utilize subgraphs name starting cluster_
. instance:
subgraph cluster_n4_0 { rank=same; "4_0" [ label = "f" ]; "v1" [ label = "1", shape = "box" ]; "4_0"->"v1" [ dir = none]; }
to have smaller nodes values, can utilize width
, height
attributes.
i don't think need several level of subgraphs here, using clusters pairs of node should enougt.
graphviz dot
No comments:
Post a Comment