Search code examples
graphvizdot

Reordering of nodes in ranked subgraph Graphviz


I am creating a workflow document that identifies where we have some tools. As the workflow branches out, I need the tools to stay next to the step they go with. In other words, I need to move two of my columns from the workflow to make room for other nodes to sit next to the node they go with, before the other columns are drawn out. Sorry, it's hard to explain. Here is the code, and below is a picture of what it outputs now, and what I want it to do.

digraph notebook {
  /* Pills */
  node [shape=box, style="rounded,filled", fillcolor="#d4eba7"]; pill1;  pill2; pill3; pill4; pill5

  pill1 [label="Pill 1"]
  pill2 [label="Pill 2"]
  pill3 [label="Pill 3"]
  pill4 [label="Pill 4"]
  pill5 [label="Pill 5"]

  /* Objects */
  node [shape=box, style="rounded,filled", fillcolor="#999999"]; obj1; obj2; obj3; obj4

  obj1 [label="Obj1"]
  obj2 [label="Obj2"]
  obj3 [label="Obj3"]
  obj4 [label="Obj4"]


  /* Steps */
  node [shape=box, style=filled, fillcolor="#ff9999"]; step1; step2; step3; step4; step5; step6 

  step1 [label="Step 1"]
  step2 [label="Step 2"]
  step3 [label="Step 3"]
  step4 [label="Step 4"]
  step5 [label="Step 5"]
  step6 [label="Step 6"]

  /* Tools */
  node[shape=rect, style=filled, fillcolor="#b1ddf0"]; tool1; tool2; tool3; tool4; tool5; tool6; tool7_1; tool7_2; tool8; tool9;  

  tool1 [label="Tool 1", tooltip="description..."]  
  tool2 [label="Tool 2", tooltip="description..."]  
  tool3 [label="Tool 3", tooltip="description..."]  
  tool4 [label="Tool 4", tooltip="description..."]  
  tool5 [label="Tool 5", tooltip="description..."]  
  tool6 [label="Tool 6", tooltip="description..."]  
  tool7 [label="Tool 7", tooltip="description..."]  
  tool8 [label="Tool 8", tooltip="description..."]  
  tool9 [label="Tool 9", tooltip="description..."]  
  tool10 [label="Tool 10", tooltip="description..."]  

  /* Workflow */

  subgraph subs1 {rank="same" step1 tool1 tool2}
  subgraph subs2 {rank="same" step2 tool3 tool4}
  subgraph subs3 {rank="same" step3 tool5 tool6 tool7}
  subgraph subs4 {rank="same" obj2 obj3 obj4}
  subgraph subs5 {rank="same" step4 tool8}
  subgraph subs6 {rank="same" step5 tool9}
  subgraph subs7 {rank="same" step6 tool10}
  subgraph subs8 {rank="same" pill3 pill4 pill5}

  pill1 -> obj1 -> step1 -> step2 -> step3 -> pill2
  pill2 -> obj2 -> step4 -> step5 -> pill3
  pill2 -> obj3 -> step6 -> pill4
  pill2 -> obj4 -> pill5
}

Current output: Current Output:

Desired Output:


Solution

  • Invisible nodes and edges are a commonly used to get nodes located where you would like them. Your graph required just a few:

    digraph notebook {
      /* Pills */
      node [shape=box, style="rounded,filled", fillcolor="#d4eba7"]; pill1;  pill2; pill3; pill4; pill5
    
      pill1 [label="Pill 1"]
      pill2 [label="Pill 2"]
      pill3 [label="Pill 3"]
      pill4 [label="Pill 4"]
      pill5 [label="Pill 5"]
    
      /* Objects */
      node [shape=box, style="rounded,filled", fillcolor="#999999"]; obj1; obj2; objInvis2_1 objInvis2_2;  obj3; obj4
    
      obj1 [label="Obj1"]
      obj2 [label="Obj2"]
      objInvis2_1 [label="" style=invis]
      objInvis2_2 [label="" style=invis]
      obj3 [label="Obj3"]
      obj4 [label="Obj4"]
    
      /* Steps */
      node [shape=box, style=filled, fillcolor="#ff9999"]; step1; step2; step3; step4; step5; step6 
    
      step1 [label="Step 1"]
      step2 [label="Step 2"]
      step3 [label="Step 3"]
      step4 [label="Step 4"]
      step5 [label="Step 5"]
      step6 [label="Step 6"]
    
      /* Tools */
      /* removed tool7_1 and tool7_2 ???
      node[shape=rect, style=filled, fillcolor="#b1ddf0"]; tool1; tool2; tool3; tool4; tool5; tool6; tool7_1; tool7_2; tool8; tool9;  
      */
      node[shape=rect, style=filled, fillcolor="#b1ddf0"]; tool1; tool2; tool3; tool4; tool5; tool6; tool8; tool9;  
    
      tool1 [label="Tool 1", tooltip="description..."]  
      tool2 [label="Tool 2", tooltip="description..."]  
      tool3 [label="Tool 3", tooltip="description..."]  
      tool4 [label="Tool 4", tooltip="description..."]  
      tool5 [label="Tool 5", tooltip="description..."]  
      tool6 [label="Tool 6", tooltip="description..."]  
      tool7 [label="Tool 7", tooltip="description..."]  
      tool8 [label="Tool 8", tooltip="description..."]  
      tool9 [label="Tool 9", tooltip="description..."]  
      tool10 [label="Tool 10", tooltip="description..."]  
    
      /* Workflow */
    
      subgraph subs1 {rank="same" step1 tool1 tool2}
      subgraph subs2 {rank="same" step2 tool3 tool4}
      subgraph subs3 {rank="same" step3 tool5 tool6 tool7}
      subgraph subs4 {rank="same" obj2 objInvis2_1 objInvis2_2 obj3 obj4}
      subgraph subs5 {rank="same" step4 tool8}
      subgraph subs6 {rank="same" step5 tool9}
      subgraph subs7 {rank="same" step6 tool10}
      subgraph subs8 {rank="same" pill3 pill4 pill5}
    
      pill1 -> obj1 -> step1 -> step2 -> step3 -> pill2
      pill2 -> obj2 -> step4 -> step5 -> pill3
      pill2 -> obj3 -> step6 -> pill4
      pill2 -> obj4 -> pill5
    
      edge [style=invis]
      node [style=invis label=""]
      pill2 -> objInvis2_1 -> tool8 -> tool9 
      pill2 -> objInvis2_2 -> toolInvis -> tool10
    }
    

    enter image description here