graphvizdot

graphviz (DOT) node alignment and merging arrows for flow diagram


thanks up-front for taking the time to read this and any help or advice.

I am new to graphviz/DOT and am trying to create a flow diagram, but I am having trouble with node alignment.

Here is what I have managed so far, however, what I would like is for all of the diamond shape conditionals and the oval "Fail" to be vertically aligned, with lines from the right hand side of each diamond merging into a single arrow to the left of the "Do some thing" oval, but I haven't managed to figure it out or even figure out whether it's possible with Google results.

I have tried many different variations of subgraphs and ranking.


Solution

  • digraph {
      //compound=true;  // does not apply to this graph
      concentrate=true
    
      node [group="main"]  // lazy way of assigning group to most nodes
      request [
        label = "Request";
        shape = rect;
      ];
    
      {
        rank=same;
    
        successful [
          label = "Successful?";
          shape = diamond;
        ];
    
        done [
          label = "Done";
          shape = oval;
        ];
      }
    
      condition_1 [
        label = "Condition 1";
        shape = diamond;
      ];
    
      condition_2 [
        label = "Condition 2";
        shape = diamond;
      ];
    
      condition_3 [
        label = "Condition 3";
        shape = diamond;
      ];
    
      condition_n [
        label = "Condition N";
        shape = diamond;
      ];
    
      fail [
        label = "Fail";
        shape = oval;
      ];
    
      do_some_thing [
        label = "Do some thing";
        shape = oval;
        group=Gz
      ];
    
      {
        done [group=gX]
        request -> successful;
        done -> successful [label="Yes"; dir=back];
    
          successful:s -> condition_1:n
          condition_1:s -> condition_2:n
          condition_2:s -> condition_3:n
          condition_3:s -> condition_n:n
          condition_n:s -> fail[label="No"];
    
          condition_1:e  -> do_some_thing:n // [headlabel="Yes"]
          condition_2:e -> do_some_thing:n //[label="Yes"]
          condition_3:e -> do_some_thing:n //[label="Yes"]
          condition_n:e -> do_some_thing:n [headlabel="Yes  "]
     
    
    /************** this should work, but you hit a bug  
        {
          condition_1:e
          condition_2:e
          condition_3:e
          condition_n:e
        } -> do_some_thing[label="Yes"]
    *********************************************/
      }
    }
    

    Giving:
    enter image description here