Importing .dot file as subgraph

拥有回忆 提交于 2020-01-02 00:50:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/26239194/importing-dot-file-as-subgraph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!