Megidd
Megidd

Reputation: 7952

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

Upvotes: 4

Views: 6705

Answers (4)

Alex Leon
Alex Leon

Reputation: 1

I got a better answer

http://www.bound-t.com/manuals/ref-manual.pdf

The -dot_dir option and the names of drawing files

The -dot option creates a single file that contains all drawings from one Bound-T run. If you then use the dot tool to create a PostScript file, each drawing will go on its own page in the PostScript file. However, dot can also generate graphical formats that do not have a concept of "page" and then it may happen that only the first drawing is visible. If you want to use such non-paged graphical formats it is better to create a directory (folder) to hold the drawing files and use the Bound-T option -dot_dir instead of the option -dot. The -dot_dir option creates a separate file for each drawing, named as follows:

• The call-graph of a root subprogram is put in a file called cg_R_nnn.dot, where R is the link-name of the root subprogram, edited to replace most non-alphanumeric characters with underscores '_', and nnn is a sequential number to distinguish root subprograms that have the same name after this editing.

• If the call-graph of some root subrogram is recursive, Bound-T draws the joint call-graph of all roots and puts it in a file called jcg_all_roots_001.dot.

• The flow-graph of a subprogram is put in a file called fg_S_nnn.dot, where S is the linkname of the subprogram, edited as above, and nnn is a sequential number to distinguish subprograms that have the same name after this editing and also to distinguish drawings that show different flow-graphs (execution bounds) for the same subprogram.

The sequential numbers nnn start from 1 and increment by 1 for each drawing file; the same number sequence is shared by all types of drawings and all subprograms. For example, if we analyse the root subprogram main?func that calls the two subprograms start$sense and start$actuate, with the -dot_dir option and -draw options that ask for one flow-graph drawing of each subprogram, the following drawing files are created:

• cg_main_func_001.dot for the call-graph of main?func

• fg_main_func_002.dot for the flow-graph of main?func

• fg_start_sense_003.dot for the flow-graph of start$sense

• fg_start_actuate_004.dot for the flow-graph of start$actuate.

Upvotes: 0

sroush
sroush

Reputation: 6773

It is legal to have multiple graphs defined in one input file. You can then produce multiple output files using the -O option, like this:

dot -Tpng -O multi.gv

This will produce multi.gv.png and multi.gv.2.png

Upvotes: 5

marapet
marapet

Reputation: 56466

Dot can't render 2 graphs into a single file, the output you see is probably the content of one of the graphs as a png.

In order to prevent that, you may run your graphs first through gvpack - something similar to:

gvpack -u supporting.dot | dot -Tpng -o supporting.png

This combines all graphs in supporting.dot into a single graph, which then is rendered with dot.

The layout of the graphs can be influenced by some more options of gvpack.

Upvotes: 4

albert
albert

Reputation: 9047

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.

Upvotes: 3

Related Questions