Importing .dot file as subgraph
Asked Answered
B

1

20

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?

Baram answered 7/10, 2014 at 15:5 Comment(0)
G
18

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.

Grain answered 10/10, 2014 at 1:0 Comment(2)
Is there any documentation on this?Jackboot
@Jackboot There is documentation on using gvpr and on using m4 but not explicit documentation on using m4 to process dot files, to my knowledge.Grain

© 2022 - 2024 — McMap. All rights reserved.