Flow chart vertical alignment, nodes on each side of conditional block

I’d like to have all the blocks (A to G) in my flow chart vertically aligned and vertical branches on each sides of my bottom conditional block.
But with my current solution, obtained after much trial and errors and search, I can’t get the blocks to align.
How could I improve on my code?

[dot verbose=true]

digraph L {

  node [shape=rectangle penwidth=2.5 height=1 fontname=Arial fontsize="18"];

  A [shape=parallelogram, label="A"]
  B [label="B"]
  C [label="C"]
  D [label="D"]
  E [label="E"]
  F [label="F"]
  in01 [ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  in02 [ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  in03 [ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  in1[ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  in2[ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  in3[ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  if_time [shape=diamond 
    label="G ?"]

  A -> in01[arrowhead=none;label=""];
  in01 -> B
  B -> C
  C -> D
  D -> E
  E -> in1[arrowhead=none;label=""]; 
  in1 -> F
  F -> if_time
  
  {rank=same; if_time -> in02[arrowhead=none, minlen = 2 ,label="Yes"] };
  in03 -> in02[arrowhead=none,xlabel=""];
  {rank=same; in01 -> in03[ minlen = 7 ,label="";dir=back]};

  {rank=same; in2 -> if_time [arrowhead=none, minlen = 1 ,label="No"] };
  in3 -> in2[arrowhead=none,xlabel=""];
  {rank=same; in3 -> in1[ minlen = 3 ,label=""]};
}

[/dot]

Add weight attributes to your edges to favor vertical lines. Once the edges align vertically you’ll have to adjust the minlen values to reflect the shifted nodes.


digraph L {

  node [shape=rectangle penwidth=2.5 height=1 fontname=Arial fontsize="18"];

  A [shape=parallelogram, label="A"]
  B [label="B"]
  C [label="C"]
  D [label="D"]
  E [label="E"]
  F [label="F"]
  in01 [ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  in02 [ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  in03 [ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  in1[ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  in2[ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  in3[ shape = circle, width=0.01, height=0.01,label = "",xlabel = "" ]; 
  if_time [shape=diamond 
    label="G ?"]

  A -> in01[arrowhead=none;label="" weight=100];
  in01 -> B [weight=100]
  B -> C [weight=100]
  C -> D [weight=100]
  D -> E [weight=100]
  E -> in1[arrowhead=none;label="" weight=100]; 
  in1 -> F [weight=100]
  F -> if_time [weight=100]
  
  {rank=same; if_time -> in02[arrowhead=none, minlen = 2 ,label="Yes"] };
  in03 -> in02[arrowhead=none,xlabel=""];
  {rank=same; in01 -> in03[ minlen = 3 ,label="";dir=back]};

  {rank=same; in2 -> if_time [arrowhead=none, minlen = 2 ,label="No"] };
  in3 -> in2[arrowhead=none,xlabel=""];
  {rank=same; in3 -> in1[ minlen = 3 ,label=""]};
}

1 Like

Excellent, thanks! I didn’t know about the weight attribute. I was going down the subgraph and vertical alignment with rankdir way but without much success.

1 Like