嵌套有向子图

时间:2019-02-08 15:37:53

标签: graphviz

我正在尝试在graphviz中获取嵌套的子图。

Graphviz版本为2.38.0(20140413.2041)

代码如下:

digraph G {
        subgraph cluster_win {
                style=filled;
                color=lightgrey;
                label = "Windows"

                subgraph extra_enabled {
                    fillcolor = "#EDF1F2"; 
                    color = "#028d35";
                    label="Subdirectory extra included";

                    node [style=filled,color=white];
                    config_debug1 [label = "Configure Debug"];
                    config_release1 [label = "Configure Release"];
                    build_debug1 [label = "Build"];
                    build_release1 [label = "Build"];

                    config_debug1 -> build_debug1;
                    config_release1 -> build_release1;

                    shape=rect;
                    style=rounded; 
                }

                subgraph extra_disabled {
                    label = "Subdirectory extra excluded";

                    config_debug2 [label = "Configure Debug"];
                    config_release2 [label = "Configure Release"];
                    build_debug2 [label = "Build"];
                    build_release2 [label = "Build"];
                    config_debug2 -> build_debug2;
                    config_release2 -> build_release2;
                }

                checkout [style=filled, color=white];
                checkout -> extra_enabled;
                checkout -> extra_disabled;
        }

        start -> checkout;

        start [label="git push"; shape=Mdiamond];
}

这就是结果。 no nested subgraphs

Graphviz绘制两个普通节点“ extra_enabled”和“ extra_disabled”。但是,我希望它们是包含子节点“ Configure Release”,“ Configure Debug”,“ Build”和另一个“ Build”的子图。

我该如何解决?

1 个答案:

答案 0 :(得分:1)

您需要做两件事:

  • 仅连接节点,您无法连接到集群
  • 集群名称必须以cluster_开头

将此应用于您的代码

digraph G {
        subgraph cluster_win {
                style=filled;
                color=lightgrey;
                label = "Windows                  "

                subgraph cluster_extra_enabled {
                    fillcolor = "#EDF1F2"; 
                    color = "#028d35";
                    label="Subdirectory extra included";

                    node [style=filled,color=white];
                    config_debug1 [label = "Configure Debug"];
                    config_release1 [label = "Configure Release"];
                    build_debug1 [label = "Build"];
                    build_release1 [label = "Build"];

                    config_debug1 -> build_debug1;
                    config_release1 -> build_release1;

                    shape=rect;
                    style=rounded; 
                }

                subgraph cluster_extra_disabled {
                    label = "Subdirectory extra excluded";

                    config_debug2 [label = "Configure Debug"];
                    config_release2 [label = "Configure Release"];
                    build_debug2 [label = "Build"];
                    build_release2 [label = "Build"];
                    config_debug2 -> build_debug2;
                    config_release2 -> build_release2;
                }

                checkout [style=filled, color=white];
                checkout -> config_debug1;
                checkout -> config_release2;
        }

        start -> checkout;

        start [label="git push"; shape=Mdiamond];
}

我明白了

enter image description here

这可能接近您想要的。请注意,我在标签“ Windows”上添加了一些空格,以使其脱离箭头的方向。您也可以使用labeljust。还有一些方法可以使边缘在群集的边界处结束,但是这对我来说需要更多的编辑,我不确定您是否想要。