Clusters compress nodes in GraphViz

I have several related subgraphs that I want to combine into GraphViz. When I draw simple nodes, it looks pretty pretty:

enter image description here

Source:

digraph {
  rankdir=LR;

  A1 -> A21;
  A1 -> A22;
  A1 -> A23;
  A1 -> A24;

  B1 -> B21;
  B1 -> B22;
  B1 -> B23;
  B1 -> B24;

  A21 -> A31;
  A22 -> A31;
  A23 -> A31;

  A23 -> A32;

  B21 -> B31;

  B21 -> B32;
  B22 -> B32;

  B21 -> B33;
  B23 -> B33;
}

Since nodes of the same level on several subgraphs are interconnected, I want to group them and assign them a label. I tried to do this using clusters, but it "compresses" the nodes:

enter image description here

Source:

digraph {
  rankdir=LR;

  subgraph cluster_level1 {
    label = "Level 1";
    style=filled;
    color=lightgrey;

    A1;
    B1;
  }

  subgraph cluster_level2 {
    label = "Level 2";
    style=filled;
    color=lightgrey;

    A21;
    A22;
    A23;
    A24;

    B21;
    B22;
    B23;
    B24;
  }

  subgraph cluster_level3 {
    label = "Level 3";
    style=filled;
    color=lightgrey;

    A31;
    A32;

    B31;
    B32;
    B33;
  }

  A1 -> A21;
  A1 -> A22;
  A1 -> A23;
  A1 -> A24;

  B1 -> B21;
  B1 -> B22;
  B1 -> B23;
  B1 -> B24;

  A21 -> A31;
  A22 -> A31;
  A23 -> A31;

  A23 -> A32;

  B21 -> B31;

  B21 -> B32;
  B22 -> B32;

  B21 -> B33;
  B23 -> B33;
}

With just two subgraphs, this is bad, but still not terrible. However, if I add more subgraphs, it becomes more ugly and ugly.

Is there a way to group nodes with some shading and shortcuts while maintaining the original node structure using GraphViz?

+4
source share
1 answer

, , , , , ( ), :

digraph {
  rankdir=LR;

  subgraph cluster_level1 {
    label = "Level 1";
    style=filled;
    color=lightgrey;
    A01[ style = invis ];
    A1;
    A02[ style = invis ];
    A03[ style = invis ];
    A06[ style = invis ];
    A05[ style = invis ];
    B1;
    A04[ style = invis ];
  }

  subgraph cluster_level2 {
    label = "Level 2";
    style=filled;
    color=lightgrey;

    A21;
    A22;
    A23;
    A24;

    B21;
    B22;
    B23;
    B24;
  }

  subgraph cluster_level3 {
    label = "Level 3";
    style=filled;
    color=lightgrey;

    A07[ style = invis ];
    A31;
    A32;
    A08[ style = invis ];            

    B31;
    B32;
    B33;
    A01[ style = invis ];
    A09[ style = invis ];
  }

  A1 -> A21;
  A1 -> A22;
  A1 -> A23;
  A1 -> A24;

  B1 -> B21;
  B1 -> B22;
  B1 -> B23;
  B1 -> B24;

  A21 -> A31;
  A22 -> A31;
  A23 -> A31;

  A23 -> A32;

  B21 -> B31;

  B21 -> B32;
  B22 -> B32;

  B21 -> B33;
  B23 -> B33;
}

enter image description here

+3

Source: https://habr.com/ru/post/1653801/


All Articles