Subgraph layout in graphviz

喜欢而已 提交于 2019-12-12 08:03:08

问题


I have code to display two subgraphs:

graph {
    rankdir=LR;
    subgraph cluster01 {
        label="t=0"
        a0 [label="A"];
        a1 [label="B"];
        a2 [label="C"];
        a5 [label="E"];
        a0 -- a1;
        a1 -- a2 ;
        a2 -- a0;
    };

    subgraph cluster02
    {
        label="t=10"
        b0 [label="A"];
        b5 [label="E"];
        b1 [label="B"];
        b2 [label="C"];

        b0 -- b1;
        b2 -- b5;
    };

    a0--b0 [style=dotted];
    a1--b1 [style=dotted];
    a2--b2 [style=dotted];
    a5--b5 [style=dotted];
}

This code displays two subgraphs like this:

But I want to have it like this:

I hope someone will help me fix the "rankdir" to get it done.


回答1:


The following was achieved by using invisible edges and constraint=false on some edges:

graph {
    rankdir=LR;
    subgraph cluster01 {
        label="t=0";
        a0 [label="A"];
        a1 [label="B"];
        a2 [label="C"];
        a5 [label="E"];
        a0 -- a1;
        a1 -- a2;
        a2 -- a5 [style=invis];
        a2 -- a0 [constraint=false];
    };

    subgraph cluster02
    {
        label="t=10"
        b0 [label="A"];
        b5 [label="E"];
        b1 [label="B"];
        b2 [label="C"];

        b0 -- b1;
        b1 -- b2 [style=invis];
        b2 -- b5;
    };

    edge[constraint=false];
    a0--b0 [style=dotted];
    a1--b1 [style=dotted];
    a2--b2 [style=dotted];
    a5--b5 [style=dotted];
}


来源:https://stackoverflow.com/questions/12463541/subgraph-layout-in-graphviz

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