Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing .dot file as subgraph

Tags:

graphviz

dot

Is there -- either via a language feature or via a preporcessor -- a possiblity to include external .dot files as subgraphs into another one?

I am working on a relatively big graph, though manually maintained, not generated.

It would be convenient to be able to define some

subgraph01.dot:

digraph subgraph01 {
 /* lot of nodes and edges */
}

subgraph02.dot:

digraph subgraph02 {
 /* lot of nodes and edges */
}

And then do something like graph.dot:

digraph BigGraph {
    import subgraph01;
    import subgraph02;
    A -> subgraph01.Node1
    A -> subgraph02.Node1
    subgraph01.Node10 -> subgraph02.Node99
    /* etc. */
}

Is there a way?

like image 215
A Sz Avatar asked Oct 07 '14 15:10

A Sz


1 Answers

Two options immediately occur to me. One would be to use a macro processor, e.g. m4. Given BigGraph.m4:

digraph BigGraph {
    define(`digraph',`subgraph')
    include(`subgraph01.dot')
    include(`subgraph02.dot')
    A -> subgraph01.Node1
    A -> subgraph02.Node1
    subgraph.Node10 -> subgraph.Node99
    /* etc. */
}

... running:

$ m4 BigGraph.m4 

... produces:

digraph BigGraph {
    subgraph subgraph01 {
 /* lot of nodes and edges */
}


    subgraph subgraph02 {
 /* lot of nodes and edges */
}


    A -> subgraph01.Node1
    A -> subgraph02.Node1
    subgraph.Node10 -> subgraph.Node99
    /* etc. */
}

Another option that might allow a more sophisticated approach is to use gvpr from GraphViz. I tried to create an example to do this with gvpr, however and I was unsuccessful, so I suggest only trying it if a graph-aware approach is required rather than the simple approach using m4.

like image 134
Simon Avatar answered Oct 24 '22 15:10

Simon