Graphviz subgraph doesn't get visualized

2019-02-02 02:19发布

问题:

I'm trying to create a graph with two subgraphs in dot. The code is as follows:

digraph G {
        subgraph step1 {
                style=filled;
                node [label="Compiler"] step1_Compiler;
                node [label="Maschine"] step1_Maschine;
                color=lightgrey;
        }

        subgraph step2 {
                style=filled;
                color=lightgrey;
                node [label="Interpretierer"] step2_Interpretierer;
                node [label="Maschine"] step2_Maschine;
                label="Virtuelle Maschine";
        }

        "Programm (Java)" -> step1_Compiler;
        step1_Compiler -> step1_Maschine;
        step1_Maschine -> "Bytecode";
        "Bytecode" -> step2_Interpretierer;
        step2_Interpretierer -> step2_Maschine;
        step2_Maschine -> "Ergebnis";
}

The result I am getting looks like the following:

I expected to see a box around both subgraphs. What am I missing here?

回答1:

You'll have to prefix the name of your subgraphs with cluster:

subgraph clusterstep1 {

and

subgraph clusterstep2 {

in order to get the style and label.

From the graphiz documentation, section "Subgraphs and Clusters":

The third role for subgraphs directly involves how the graph will be laid out by certain layout engines. If the name of the subgraph begins with cluster, Graphviz notes the subgraph as a special cluster subgraph. If supported, the layout engine will do the layout so that the nodes belonging to the cluster are drawn together, with the entire drawing of the cluster contained within a bounding rectangle. Note that, for good and bad, cluster subgraphs are not part of the DOT language, but solely a syntactic convention adhered to by certain of the layout engines.



标签: graphviz dot