如何布局Graphviz /点布局和订单问题

问题描述 投票:0回答:1

我正在尝试使用点表示法并设置项目的顺序。在下面的示例中,我希望FLIP / FLOPA位于顶部,FLIP / FLOPB位于底部。排列一切也很好。

enter image description here

我有点困惑隐形边缘可能如何工作?

这是我在的地方:


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; 


}

提前致谢

尼尔

graphviz dot pygraphviz
1个回答
0
投票

您在布局中提及节点的顺序非常重要。

如果你有水平布局(rankdir=LR),节点从下到上显示在你的布局中,看看这个,例如:

digraph {
    rankdir=LR

    node1
    node2
    node3
}

这导致:

现在,如果我们颠倒顺序:

digraph {
    rankdir=LR

    node3
    node2
    node1
}

我们得到这个:

PS:我不建议使用正交样条,它们可能会导致各种伪影,包括对边缘标签的处理非常差。排队问题可能是由他们引起的。即使我在我的机器上编译代码时,节点也正确排列。


在评论中回答您的问题:

如何在没有splines=ortho的情况下实现平行边缘但是让我警告你,它非常难看。

在graphviz中,您可以使用HTML-like syntax来定义一些结构,其中最重要的是表。任何年龄都足够大的人都会告诉你,你几乎可以用桌子设计任何东西。使用graphviz时我经常使用它们。

在您的情况下您可以做什么:而不是您的普通矩形节点放置一个有三行的表。顶行和底行将为空。中间的标签将包含您的标签:FLIPA或FLOPA。

接下来,将port属性分配给所有单元格。这样,您就可以使用headporttailport(或它们的synonims,冒号语法,我在下面的示例中使用)将特定的表行连接在一起。

这是一个例子:

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;

}

结果:

© www.soinside.com 2019 - 2024. All rights reserved.