您在布局中提及节点的顺序很重要。
如果你有水平布局(rankdir=LR),节点从下到上出现在你的布局中,看这个,例如:
digraph {
rankdir=LR
node1
node2
node3
}
这会导致:
现在如果我们颠倒顺序:
digraph {
rankdir=LR
node3
node2
node1
}
我们得到这个:
PS:我不建议使用正交样条,它们可能会导致各种伪影,包括对边缘标签的处理非常差。您排队的问题可能是由它们引起的。即使当我在我的机器上编译您的代码时,节点也正确排列。
在 cmets 中回答您的问题:
如何在没有splines=ortho的情况下实现平行边
但是让我警告你,它非常丑陋。
在graphviz 中,您可以使用HTML-like syntax 定义一些结构,其中最重要的是表格。任何足够老的前端都会告诉您,您几乎可以使用表格设计任何东西。我在使用 graphviz 时经常使用它们。
在你的情况下你可以做什么:代替你的普通矩形节点放置一个三行表格。顶行和底行将是空的。中间的将包含您的标签:FLIPA 或 FLOPA。
接下来将port 属性分配给所有单元格。这样,您将能够使用headport 和tailport(或它们的同义词,冒号语法,我在下面的示例中使用)将表的特定行连接在一起。
示例如下:
digraph G {
graph [pad ="1", rankdir = LR];
size = "16.66,8.33!"; // 1200x600 at 72px/in, "!" to force
ratio = "fill";
node[shape=record];
flipb[
shape=plain
label=<
<table border="1" cellspacing="0" cellborder="0">
<tr>
<td height="80" port="upper"> </td>
</tr>
<tr>
<td height="80" port="middle">FLIPB</td>
</tr>
<tr>
<td height="80" port="bottom"> </td>
</tr>
</table>
>
];
flopb[
shape=plain
label=<
<table border="1" cellspacing="0" cellborder="0">
<tr>
<td height="80" port="upper"> </td>
</tr>
<tr>
<td height="80" port="middle">FLOPB</td>
</tr>
<tr>
<td height="80" port="bottom"> </td>
</tr>
</table>
>
];
flipa[
shape=plain
label=<
<table border="1" cellspacing="0" cellborder="0">
<tr>
<td height="80" port="upper"> </td>
</tr>
<tr>
<td height="80" port="middle">FLIPA</td>
</tr>
<tr>
<td height="80" port="bottom"> </td>
</tr>
</table>
>
];
flopa[
shape=plain
label=<
<table border="1" cellspacing="0" cellborder="0">
<tr>
<td height="80" port="upper"> </td>
</tr>
<tr>
<td height="80" port="middle">FLOPA</td>
</tr>
<tr>
<td height="80" port="bottom"> </td>
</tr>
</table>
>
];
source1[shape=rarrow];
source2[shape=rarrow];
sink1[shape=rarrow];
sink2[shape=rarrow];
source1 -> flipa;
flipa:upper -> flopa:upper [label="red" color=red,penwidth=3.0];
flipa:bottom -> flopa:bottom [label="blue" color=blue,penwidth=3.0];
flopa -> sink1;
source2 -> flipb;
flipb:upper -> flopb:upper [label="red" color=red,penwidth=3.0];
flipb:bottom -> flopb:bottom [label="blue" color=blue,penwidth=3.0];
flopb -> sink2;
label="Graph";
labelloc=top;
labeljust=left;
}
结果: