Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphViz - How to make subgraph contain shape?

I have a graph that represents one large process made up of two smaller processes. Each of the smaller processes is represented by a subgraph. But when I connect the end of one of those subprocesses (let's say "one") to the start of the other ("two"), the starting shape for the other process ("two") ends up in the same cluster as the ending of "one". How can I get the arrow from the end of one to point to the start of two, but keep the starting shape of two within its cluster?

digraph BigProcess {
   graph [ label="Some big process" ]

   subgraph clusterSubProcess1 {
      graph [ label="Subprocess one", color="red" ]

      start1_1 -> start1_2;
      start1_2 -> start1_3a;
      start1_2 -> start1_3b;
      start1_3a -> start1_4;
      start1_3b -> start1_5;
      start1_4 -> start1_1;
      start1_5 -> start2_1;

   }

   subgraph clusterSubProcess2 {
      graph [ label="Subprocess two", color="blue" ]

      start2_1 -> start2_2;
      start2_2 -> start2_3a;
      start2_2 -> start2_3b;
      start2_3a -> start2_4;
      start2_3b -> start2_5;
      start2_4 -> start2_1;
      start2_5 -> end1;

   }
}

This results in the following, where I really want start2_1 to be the top node within the blue bounded box.

this graph

like image 875
Jeremy Thomerson Avatar asked Feb 13 '23 04:02

Jeremy Thomerson


1 Answers

That's happening because the line start1_5 -> start2_1; in the first subgraph is defining start2_1 in that subgraph. You need to define start1_5 in the first subgraph but leave it unconnected until after you define start2_1 in the second subgraph.

digraph BigProcess {
   graph [ label="Some big process" ]

   subgraph clusterSubProcess1 {
      graph [ label="Subprocess one", color="red" ]

      start1_1 -> start1_2;
      start1_2 -> start1_3a;
      start1_2 -> start1_3b;
      start1_3a -> start1_4;
      start1_3b -> start1_5;
      start1_4 -> start1_1;
      start1_5;

   }

   subgraph clusterSubProcess2 {
      graph [ label="Subprocess two", color="blue" ]

      start2_1 -> start2_2;
      start2_2 -> start2_3a;
      start2_2 -> start2_3b;
      start2_3a -> start2_4;
      start2_3b -> start2_5;
      start2_4 -> start2_1;
      start2_5 -> end1;

   }

   //Now connect the nodes in the two different subgraphs
   start1_5 -> start2_1;
}

Node in the desired subgraph

like image 153
SSteve Avatar answered Mar 09 '23 04:03

SSteve