如何使子图可见?

时间:2014-11-17 14:49:44

标签: graphviz subgraph

在下图中,两个子图不可见,但所有节点似乎都是随机放置的。如何创建可见的子图,例如一个内置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"];
  }
}

this is NOT how it should look like...

1 个答案:

答案 0 :(得分:3)

您正在寻找的内容在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];
}

enter image description here