graphvizdotflowchart

Multiple graphs inside Graphviz DOT file


I have this Graphviz DOT graph:

digraph unit_test {
    label="Unit test"
    
    edge [fillcolor="#a6cee3" color="#1f78b4"]

    node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
        start
        end
    node[shape="box" style="filled" fillcolor="#ff7f0e"]
        process
        
    subgraph cluster_process {
        label = "Major logic"
        process
    }
    
    start -> process
    process -> end
    
}

The above renders as:

First graph

I have this second graph:

digraph details {
    label = "Process details"
    
    edge [fillcolor="#a6cee3" color="#1f78b4"]
    
    node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
        start
        end
    node[shape="box" style="filled" fillcolor="#ff7f0e"]
        details
    
    subgraph cluster_details {
        label = "Details"
        details
    }
    
    start -> details
    details -> end
}

Which renders to:

Second graph

Problem

When I put the above two graphs inside the same DOT file named supporting.dot and I run dot -Tpng -o supporting.png supporting.dot command, terminal prints out some jiberish and the output image file won't contain both graphs, it just contains the first one. Is it possible to use multiple graphs inside a single DOT file? If so, what am I missing?

Terminal output


Solution

  • Question is unclear about what is to be accomplished, but maybe the following is a starting point

    digraph G{
    subgraph unit_test {
        label="Unit test"
        
        edge [fillcolor="#a6cee3" color="#1f78b4"]
    
        node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
            start
            end
        node[shape="box" style="filled" fillcolor="#ff7f0e"]
            process
            
        subgraph cluster_process {
            label = "Major logic"
            process
        }
        
        start -> process
        process -> end
        
    }
    
    subgraph details {
        label = "Process details"
        
        edge [fillcolor="#a6cee3" color="#1f78b4"]
        
        node[shape="ellipse" style="filled" fillcolor="#1f77b4"]
            start1 [label="start"]
            end1 [label="end"]
        node[shape="box" style="filled" fillcolor="#ff7f0e"]
            details
        
        subgraph cluster_details {
            label = "Details"
            details
        }
        
        start1 -> details
        details -> end1
    }
    
    }
    

    Note the naming / labels in the second subgraph.