Preventing graphviz from rearranging nodes

Hamza Yerlikaya picture Hamza Yerlikaya · Feb 6, 2012 · Viewed 13.2k times · Source

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.

Answer

dgw picture dgw · Feb 7, 2012

I tried the following

digraph g {
  ordering=out ;
  node [shape=box] ;

  a -> b ;  a -> c ;  a -> d ;  a -> e ;  a -> f ;
  a -> g ;  a -> h ;  a -> i ;  a -> j ;  a -> k ;
  a -> l ;  a -> m ;  a -> n ;  a -> o ;  a -> p ;
  a -> q ;  a -> r ;  a -> s ;  a -> t ;  a -> u ;
  a -> v ;  a -> w ;  a -> x ;  a -> y ;  a -> z ;
}

and all nodes b-z are on the same level in the correct order. What version are you using?