Moving Graphviz edge out of the way

2019-07-11 23:31发布

In this graph:

graphviz

Rendered using Graphviz/Dot, the red edge connects two nodes, whereas the other edges connect ports inside the nodes. The nodes have HTML labels, and the TDs for the inputs and outputs have a PORT attribute.

Is there a way to make Dot move the red node "out of the way", that is to the left or to the right, possibly curved, so that it does not go over the black edges.

It is for an automatically generated graph that can contain more than two nodes, not necessarily all vertically aligned.

The source code of this graph:

digraph G {
rankdir=TB
src [shape=plaintext label=<<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD BORDER="0"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD WIDTH="20"></TD><TD PORT="in1" BORDER="1" CELLPADDING="1"><FONT POINT-SIZE="10">in1</FONT></TD><TD WIDTH="10"></TD><TD PORT="in2" BORDER="1" CELLPADDING="1"><FONT POINT-SIZE="10">in2</FONT></TD><TD WIDTH="10"></TD><TD PORT="in3" BORDER="1" CELLPADDING="1"><FONT POINT-SIZE="10">in3</FONT></TD><TD WIDTH="20"></TD></TR></TABLE></TD></TR><TR><TD BORDER="1" STYLE="ROUNDED" CELLPADDING="4" COLOR="black">A<BR/><FONT POINT-SIZE="10">node</FONT></TD></TR><TR><TD BORDER="0"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD WIDTH="20"></TD><TD PORT="out1" BORDER="1" CELLPADDING="1"><FONT POINT-SIZE="10">out1</FONT></TD><TD WIDTH="10"></TD><TD PORT="out2" BORDER="1" CELLPADDING="1"><FONT POINT-SIZE="10">out2</FONT></TD><TD WIDTH="20"></TD></TR></TABLE></TD></TR></TABLE>>];


rankdir=TB
snk [shape=plaintext label=<<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD BORDER="0"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD WIDTH="20"></TD><TD PORT="in1" BORDER="1" CELLPADDING="1"><FONT POINT-SIZE="10">in1</FONT></TD><TD WIDTH="10"></TD><TD PORT="in2" BORDER="1" CELLPADDING="1"><FONT POINT-SIZE="10">in2</FONT></TD><TD WIDTH="10"></TD><TD PORT="in3" BORDER="1" CELLPADDING="1"><FONT POINT-SIZE="10">in3</FONT></TD><TD WIDTH="20"></TD></TR></TABLE></TD></TR><TR><TD BORDER="1" STYLE="ROUNDED" CELLPADDING="4" COLOR="black">B<BR/><FONT POINT-SIZE="10">node</FONT></TD></TR><TR><TD BORDER="0"><TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD WIDTH="20"></TD><TD PORT="out1" BORDER="1" CELLPADDING="1"><FONT POINT-SIZE="10">out1</FONT></TD><TD WIDTH="10"></TD><TD PORT="out2" BORDER="1" CELLPADDING="1"><FONT POINT-SIZE="10">out2</FONT></TD><TD WIDTH="20"></TD></TR></TABLE></TD></TR></TABLE>>];

    snk -> src [style="", arrowhead="vee", color=red, headlabel=<>, fontsize=10, labelangle=45, labeldistance=2.0, labelfontcolor=black];

    src:out1 -> snk:in1 [style="", arrowhead="normal", color=black, headlabel=<>, fontsize=10, labelangle=45, labeldistance=2.0, labelfontcolor=black];
    src:out1 -> snk:in2 [style="", arrowhead="normal", color=black, headlabel=<>, fontsize=10, labelangle=45, labeldistance=2.0, labelfontcolor=black];
    src:out2 -> snk:in3 [style="", arrowhead="normal", color=black, headlabel=<>, fontsize=10, labelangle=45, labeldistance=2.0, labelfontcolor=black];

    {rank=source; src}
    {rank=sink; snk}

}

1条回答
可以哭但决不认输i
2楼-- · 2019-07-11 23:41

You could add compass points to your edge definition:

snk:se -> src:ne

or

snk:e -> src:e

for an arrow to the right, or

snk:sw -> src:nw

or

snk:w -> src:w

for an arrow on the left side.

Of course, I'm not sure whether this would work when there are several nodes which are not aligned.

graph with edge out of the way

查看更多
登录 后发表回答