Overlapping edges in graphviz

一笑奈何 提交于 2019-12-23 02:01:57

问题


I've two overlapping edges and don't know why:

digraph G {
    graph [rankdir=LR, overlap=false];
    subgraph cluster1 {
       d1;
       n1;
    }
    subgraph cluster2 {
       n2;
       d2;
    }
    n1 -> n2;
    n2 -> n1;
    d0 -> d1;
    d0 -> d2;
}

Is there any way to display both edges n1 -> n2 and n2 -> n1 separately? Removing the clusters is not an option but would help ...


回答1:


Trial-and-error solution (don't ask me why this works...):

digraph G {
    graph [rankdir=LR, overlap=false];
    subgraph cluster1 {
       d1;
       n1;
    }
    subgraph cluster2 {
       n2;
       d2;
    }
    n1 -> n2;
    n1 -> n2[constraint=false, dir=back];
    n2 -> n1[style=invis];
    d0 -> d1;
    d0 -> d2;
}




回答2:


A solution making use of the portPos modifier:

digraph G {
    graph [rankdir=LR, overlap=false];
    subgraph cluster1 {
       d1;
       n1;
    }
    subgraph cluster2 {
       n2;
       d2;
    }
    n1:sw -> n2:nw;
    n2:ne -> n1:se;
    d0 -> d1;
    d0 -> d2;
}

Another solution is to make use of the dir and color modifiers:

digraph G {
    graph [rankdir=LR, overlap=false];
    subgraph cluster1 {
       d1;
       n1;
    }
    subgraph cluster2 {
       n2;
       d2;
    }
    n2 -> n1[dir=both color="red:blue"];
    d0 -> d1;
    d0 -> d2;
}

You can even use color="black:black" if you want to maintain the black and white coloring scheme.



来源:https://stackoverflow.com/questions/9845570/overlapping-edges-in-graphviz

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