集群在GraphViz中挤压节点

时间:2016-09-06 14:27:27

标签: graphviz dot

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

enter image description here

来源:

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

由于几个子图中相同级别的节点是相关的,我想将它们分组并给它一个标签。 我试图使用集群来做,但它“挤压”节点:

enter image description here

来源:

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保持原始节点布局?

1 个答案:

答案 0 :(得分:3)

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

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