子图不会出现在graphviz图表中

时间:2018-02-05 21:36:59

标签: graph charts graphviz

我无法弄清楚,为什么子图在这里不起作用:

digraph virtPfr {
    node [
        shape=box
    ]

    Start [
        style=rounded,
        label="create folder profiles"
    ]

    subgraph asd {
        label = "copy files from other profiles"

        cpIfDestFilesExist [
            label = "Check for file existance"
        ]

        Cp [
            label = "Copy"
        ]
    }

    Start -> asd

    cpIfDestFilesExist -> Start
    cpIfDestFilesExist -> Cp
}

但是此代码有效:

digraph G {

    node [
        shape = "record"
    ]

    Animal [
        label = "Animal name and age"
    ]

    subgraph clusterAnimalImpl {
        label = "Package animal.tmpl"

        Dog [
            label = "Dog name and age"
        ]

        Cat [
            label = "Cat name and age"
        ]
    }

    Dog -> Animal
    Cat -> Animal
    Dog -> Cat
}

我不明白,与底部图表相比,顶部图表有什么不同,底部有效,但顶部没有。我已经把眼睛拉了出来。我在这里没有看到问题。

请帮助

1 个答案:

答案 0 :(得分:1)

有几个问题:

  • 子图名称必须以关键字cluster开头。
  • 您无法将边缘直接连接到子图,而是可以使用here所述的lhead / ltail解决方法。

对于您的图表,它可能如下所示:

digraph virtPfr {
    graph [compound=true]
    node [
        shape=box
    ]

    Start [
        style=rounded,
        label="create folder profiles"
    ]

    subgraph cluster_asd {
        label = "copy files from other profiles"

        cpIfDestFilesExist [
            label = "Check for file existance"
        ]

        Cp [
            label = "Copy"
        ]
    }

    Start -> cpIfDestFilesExist [lhead=cluster_asd]

    cpIfDestFilesExist -> Start
    cpIfDestFilesExist -> Cp
}

生成以下输出:

graph