graphviz - How to pick which side a node is on in a simple binary tree? -


in simple binary tree, able make graph right adding invisible nodes , invisible edges, instance from:

digraph {         vertex_1 [label="a"];         vertex_2 [label="b"];         vertex_2 -> vertex_1 [label="left"]; } 

which produces:

enter image description here

to:

digraph {         vertex_1 [label="a"];         vertex_2 [label="b"];         vertex_0 [style=invis];         vertex_2 -> vertex_1 [label="left"];         vertex_2 -> vertex_0 [style=invis]; } 

which produces:

enter image description here

but when tried trick 4 node graph (it straight , down) here got:

digraph {         vertex_1 [label="a"];         vertex_2 [label="b"];         vertex_3 [label="f"];         vertex_4 [label="g"];         vertex_01 [style=invis];         vertex_02 [style=invis];         vertex_03 [style=invis];         vertex_4 -> vertex_3 [label="left"];         vertex_3 -> vertex_1 [label="left"];         vertex_1 -> vertex_02 [style=invis];         vertex_4 -> vertex_03 [style=invis];         vertex_3 -> vertex_01 [style=invis];         vertex_1 -> vertex_2 [label="right"]; } 

which produced:

enter image description here

obviously want b on right side of a. tried switching order of invisible edge statement , actual edge b a, 1 came first make no difference. how can tell program put specific node or edge on specific side?

for order left right node creation order relevant. left node must created before right sibling.

digraph {     vertex_1 [label="a"];     vertex_02 [style=invis];     vertex_2 [label="b"];     vertex_3 [label="f"];     vertex_4 [label="g"];     vertex_01 [style=invis];     vertex_03 [style=invis];     vertex_4 -> vertex_3 [label="left"];     vertex_3 -> vertex_1 [label="left"];     vertex_1 -> vertex_02 [style=invis];     vertex_4 -> vertex_03 [style=invis];     vertex_3 -> vertex_01 [style=invis];     vertex_1 -> vertex_2 [label="right"]; } 

enter image description here


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -