Search code examples
graphvizdot

Graphviz: Layout multiple clusters


digraph G {
  rankdir=LR;
  subgraph cluster_one {
    one_x -> one_y -> one_z;
  }
  subgraph cluster_two {
    two_x -> two_y;
  }
  subgraph cluster_three {
    three_x -> three_y;
  }
}

enter image description here

  1. The order of the clusters is reversed. They should be in the order they appear in the source file.
  2. I want all clusters to be of the same width (determined by the largest sub-graph) and aligned.

Solution

  • The order of the clusters is reversed. They should be in the order they appear in the source file.

    The following code should work:

    digraph G {
      rankdir=LR;
      subgraph cluster_one {
        shape=rect;
        one_x -> one_y -> one_z;
      }
      subgraph cluster_two {
        two_x -> two_y;
      }
      subgraph cluster_three {
        three_x -> three_y;
      }
      one_x->two_y[style=invis];
      two_x->three_y[style=invis];
    }
    

    I want all clusters to be of the same width (determined by the largest sub-graph) and aligned.

    I have found this answer. It is a bad solution, but I can't give a better one.