graphchartsgraphviz

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


Solution

  • A couple of issues:

    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