集群挤压 GraphViz 中的节点

Clusters squeeze nodes in GraphViz

我有几个相关的子图想在 GraphViz 中绘制在一起。当我绘制简单的节点时,它看起来很漂亮:

来源:

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;
}

由于几个子图中同一层次的节点是相关的,所以我想把它们分组并给它一个标签。 我尝试使用集群来做到这一点,但它 "squeezes" 节点:

来源:

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;
}

只有两个子图,这很糟糕,但仍然不可怕。但是,如果我添加更多的子图,它会变得越来越丑。

有没有办法用一些阴影和标签对节点进行分组,同时使用 GraphViz 保持原始节点布局?

这可能不是一个好的答案,因为它意味着大量的试验和错误,但至少你得到了你想要的(我猜)不可见的节点:

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;
}

产量