如何布局Graphviz /点布局和顺序问题

时间:2019-04-11 13:12:06

标签: graphviz dot pygraphviz

我正在尝试使用点表示法并设置项目的顺序。在下面的示例中,我希望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; 


}

预先感谢

尼尔

1 个答案:

答案 0 :(得分: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(或它们的同义词,即冒号语法,在下面的示例中使用)将表的特定行连接在一起

这里是例子:

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;

}

结果: