graphviz - 如何布局 Graphviz / dot layout 和 order 问题
问题描述
我正在尝试使用点表示法并设置项目的顺序。在下面的示例中,我希望 FLIP/FLOPA 位于顶部,而 FLIP/FLOPB 位于底部。把所有东西都排列起来也很好。
我有点困惑隐形边缘是如何工作的?
这就是我所在的位置:
digraph G {
graph [pad ="1", rankdir = LR, splines=ortho];
size = "16.66,8.33!"; // 1200x600 at 72px/in, "!" to force
ratio = "fill";
node[shape=record];
flipa[label="FLIPA", height=3];
flopa[label="FLOPA", height=3];
flipb[label="FLIPB", height=3];
flopb[label="FLOPB", height=3];
source1[shape=rarrow];
source2[shape=rarrow];
sink1[shape=rarrow];
sink2[shape=rarrow];
source1 -> flipa;
flipa -> flopa [label="red" color=red,penwidth=3.0];
flipa -> flopa [label="blue" color=blue,penwidth=3.0];
flopa -> sink1;
source2 -> flipb;
flipb -> flopb [label="red" color=red,penwidth=3.0];
flipb -> flopb [label="blue" color=blue,penwidth=3.0];
flopb -> sink2;
label="Graph";
labelloc=top;
labeljust=left;
}
提前致谢
尼尔
解决方案
您在布局中提到节点的顺序很重要。
如果你有水平布局(rankdir=LR
),节点从下到上出现在你的布局中,看这个,例如:
digraph {
rankdir=LR
node1
node2
node3
}
这导致:
现在如果我们颠倒顺序:
digraph {
rankdir=LR
node3
node2
node1
}
我们得到这个:
PS:我不建议使用正交样条,它们可能会导致各种伪影,包括边缘标签的处理非常差。您排队的问题可能是由它们引起的。即使当我在我的机器上编译您的代码时,节点也正确排列。
要在评论中回答您的问题:
如何在没有平行边的情况下实现splines=ortho
但让我警告你,它非常难看。
在 graphviz 中,您可以使用类似 HTML 的语法来定义一些结构,其中最重要的是表格。任何足够老的前端都会告诉您,您几乎可以使用表格设计任何东西。我在使用 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;
}
结果:
推荐阅读
- jmeter - JMeter BackendListenerClient 发送 SampleResults 太慢
- java - Camera 如何在 Libgdx 和 Viewport 中工作
- javascript - 自动调整 Kendo-Grid 高度
- python - 多变量函数的优化
- blockchain - Corda Quickstart 的 Notary 节点中是否有任何功能?
- ruby-on-rails - 启动 rails 应用程序时会生成不必要的文件
- url-rewriting - 如何为 ASP 站点设置重写规则?
- c# - 将字符串解析为 IPV6 问题
- terraform - 如何在terraform中实现动态匹配?
- java - 了解 Gradle 项目依赖关系,Gradle 站点示例似乎不完整