1

在下图中,两个子图不可见,但所有节点似乎都是随机放置的。如何创建可见的子图,比如一个盒子里面有我的 PlayerChars,另一个盒子里面有 NonPlayerChars?

digraph "All Characters" { 
  subgraph PlayerChars {
    label = "Player Characters";
    node [style=filled,color=yellow];
    Char1 -> Char2 [ label = "is sister of" ];
    Char1 -> Char2 [ label = "is brother of" ];
    label = "PCs";
  }
  subgraph NonPlayerChars {
    label = "Non-Player Characters";
    Person1 -> Char2 [label="hates"];
    Char2 -> Person1 [label="is indifferent"];
    Person2 -> Char2 [label="stole from"];
    Person1 -> Person2 [label="is father of"];
    Person2 -> Person1 [label="is daughter of"];
    Char1 -> Person2 [label="is in love with"];
    Person2 -> Char1 [label="is annoyed by"];
  }
}

这不是它应该的样子......

4

1 回答 1

4

您正在寻找的东西在 Graphviz 中被称为“集群”。使用特殊的子图名称 cluster_ 在矩形区域中绘制子图。例如来自http://www.graphviz.org/Gallery/directed/cluster.html

digraph G {

    subgraph cluster_0 {
        style=filled;
        color=lightgrey;
        node [style=filled,color=white];
        a0 -> a1 -> a2 -> a3;
        label = "process #1";
    }

    subgraph cluster_1 {
        node [style=filled];
        b0 -> b1 -> b2 -> b3;
        label = "process #2";
        color=blue
    }
    start -> a0;
    start -> b0;
    a1 -> b3;
    b2 -> a3;
    a3 -> a0;
    a3 -> end;
    b3 -> end;

    start [shape=Mdiamond];
    end [shape=Msquare];
}

在此处输入图像描述

于 2014-11-17T15:06:23.137 回答