graphvizdot

Swap two parts of a dot layout


I have the following dot layout.

digraph {
  subgraph {
    rank=same;
    node [shape=plain] work
    node [shape=rectangle,group=work] w2
  }

  subgraph {
    rank=same;
    node [shape=plain] main
    node [shape=rectangle,group=main] m3
  }

  node [shape=rectangle,group=work] w1
  node [shape=rectangle,group=main] m1 m2
  edge [arrowhead=open] m2 -> m1 m3 -> m2 w1 -> m1 w2 -> w1 m3 -> w2
  edge [style=dashed] main -> m3 work -> w2
}

result of the dot above

I would like the left part of the graph (the "work" label along with the "w1" and "w2" nodes) to be on the right part of the graph instead. I want something like this instead:

This is what I want

I tried reordering nodes and subgraphs but nothing I do makes the graph closer to what I want.


Solution

  • Two parts to this:

    digraph {
      subgraph {
        rank=same;
        node [shape=plain] work
        node [shape=rectangle,group=work] w2
      }
    
      subgraph {
        rank=same;
        node [shape=plain] main
        node [shape=rectangle,group=main] m3
      }
    
      node [shape=rectangle,group=work] w1
      node [shape=rectangle,group=main] m1 m2
      edge [arrowhead=open arrowtail=open]
      m2 -> m1 m3 -> m2 w1 -> m1 w2 -> w1 m3 -> w2
      edge [style=dashed] main -> m3
      w2 -> work [dir=back]  // reversed direction of arrowhead
      {rank=same m2 w1}      // next two reverse the order of the two columns
      m2 -> w1 [style=invis] //
    }
    

    Giving:
    enter image description here