Graphviz Precise vertical alignment of nodes

I got this scatter graph and want the nodes A and D, B and E and C and F to be aligned. Here is the associated point code:

digraph{ A B C D E F {rank = same; B; C} {rank = same; E; F} A -> B [label="2", weight=2] A -> C [label="0", style=dashed, weight=2] B -> C [label="0", style=dashed, weight=2] B -> D [label="2", style=dashed, weight=2] C -> D [label="0", weight=2] D -> E [label="1", style=dashed, weight=2] D -> F [label="0", weight=2] E -> F [label="0", weight=2] F -> A } 

As you can see, I already tried to apply weights to the edges, but that didn't work

enter image description here

+6
source share
1 answer

You can use the group attribute for nodes to suggest that the edges are aligned between the nodes of the same group in a straight line.

Declare nodes with group attribute:

 A [group=g1] {rank = same; B[group=g2]; C[group=g3]} D [group=g1] {rank = same; E[group=g2]; F[group=g3]} 

Then, make sure that all of these nodes have an (invisible) edge between them:

 edge[style=invis]; A -> D B -> E C -> F 

Together:

 digraph G { A [group=g1] {rank = same; B[group=g2]; C[group=g3]} D [group=g1] {rank = same; E[group=g2]; F[group=g3]} A -> B [label="2", weight=2] A -> C [label="0", style=dashed, weight=2] B -> C [label="0", style=dashed, weight=2] B -> D [label="2", style=dashed, weight=2] C -> D [label="0", weight=2] D -> E [label="1", style=dashed, weight=2] D -> F [label="0", weight=2] E -> F [label="0", weight=2] F -> A edge[style=invis]; A -> D B -> E C -> F } 
+16
source

Source: https://habr.com/ru/post/978580/


All Articles