igoryonya
igoryonya

Reputation: 277

Subgraph doesn't appear in graphviz chart

I can't figure out, why subgraph doesn't work here:

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
}

but this code works:

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
}

I don't understand, what's different on the top graph, in comparison to the bottom graph, that the bottom works, but the top doesn't. I've already pulled my eyes out. I don't see the problem here.

Please, help

Upvotes: 1

Views: 820

Answers (1)

Robby Cornelissen
Robby Cornelissen

Reputation: 97120

A couple of issues:

  • Sub-graph names have to start with the keyword cluster.
  • You can't connect edges directly to a sub-graph, instead you can use the lhead/ltail workaround described here.

For your graph, it could look as follows:

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
}

Which generates the following output:

graph

Upvotes: 2

Related Questions