I am trying to visualize a tree structure using graphviz, problem is as the graph gets bigger graphviz starts to rearrange the order of the nodes. Say I have the following,
A
/ | \
B C D
it becomes,
A
/ | \
B D C
it probably does this to save space but in my context order of the nodes matter I have tried adding,
graph [ordering="out"];
but it did not change the output.
EDIT:
digraph bt {
graph [ordering="out"];
node [style="rounded", shape=box]
N_2386 -> N_2387
N_2387 -> N_2388
N_2388 -> N_2389
N_2388 -> N_2390
N_2387 -> N_2391
N_2386 -> N_2392
subgraph cluster_2393 {
labeljust = "l";
style=dashed;color="#B0B0B0"
N_2392 -> N_2394
N_2394 -> N_2395
N_2395 -> N_2396
N_2396 -> N_2397
N_2397 -> N_2398
N_2397 -> N_2399
N_2396 -> N_2400
N_2400 -> N_2401
N_2400 -> N_2402
N_2395 -> N_2403
N_2403 -> N_2404
N_2404 -> N_2405
N_2405 -> N_2406
N_2403 -> N_2407
N_2407 -> N_2408
N_2408 -> N_2409
N_2409 -> N_2410
N_2410 -> N_2411
N_2411 -> N_2412
N_2412 -> N_2413
N_2412 -> N_2414
N_2412 -> N_2415
N_2411 -> N_2416
N_2416 -> N_2417
N_2416 -> N_2418
N_2416 -> N_2419
N_2408 -> N_2420
N_2408 -> N_2421
N_2403 -> N_2422
N_2395 -> N_2423
N_2392 -> N_2424
}
}
graph in question What I need is, N_2387 should be on the right N_2392 should be on the left. Which is the order I insert them.
If you change the first branch to a subgraph the two subgraphs will be ordered as written in the file.
It seems that the subgraph as a higher precedence as a normal node and therefor the ordering=out
seems not to be honored.
This works:
digraph bt {
graph [ordering="out"];
node [style="rounded", shape=box]
N_2386 -> N_2387
subgraph cluster_first {
N_2387 -> N_2388
N_2388 -> N_2389
N_2388 -> N_2390
N_2387 -> N_2391
}
N_2386 -> N_2392
subgraph cluster_2393 {
labeljust = "l";
style=dashed;color="#B0B0B0"
N_2392 -> N_2394
N_2394 -> N_2395
N_2395 -> N_2396
N_2396 -> N_2397
N_2397 -> N_2398
N_2397 -> N_2399
N_2396 -> N_2400
N_2400 -> N_2401
N_2400 -> N_2402
N_2395 -> N_2403
N_2403 -> N_2404
N_2404 -> N_2405
N_2405 -> N_2406
N_2403 -> N_2407
N_2407 -> N_2408
N_2408 -> N_2409
N_2409 -> N_2410
N_2410 -> N_2411
N_2411 -> N_2412
N_2412 -> N_2413
N_2412 -> N_2414
N_2412 -> N_2415
N_2411 -> N_2416
N_2416 -> N_2417
N_2416 -> N_2418
N_2416 -> N_2419
N_2408 -> N_2420
N_2408 -> N_2421
N_2403 -> N_2422
N_2395 -> N_2423
N_2392 -> N_2424
}
}
If you want to control ordering of specific items use an invisible edge between them. Combining this with the rank directive gives you a lot of control.
eg: here's a sample tagcloud layout from Graphviz:
/*
Using a graph and relationships just to push things onto different lines.
Two layout rules:
1) all items on a given line go into a "rank=same" phrase
2) a relationship is needed between the first word on each line and the next line down to
force the vertical alignment.
*/
digraph {
edge[style=invisible]
node[shape=none]
fred [fontsize=18]
harry [fontsize=8]
jack [fontsize=12]
sally [fontsize=12]
mika
amy
jan
jack -> fred
fred -> mika
{rank=same;fred;harry}
{rank=same;mika amy; jan}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With