【问题标题】:How to layout Graphviz / dot layout and order question如何布局 Graphviz / dot layout 和 order 问题
【发布时间】:2019-09-02 03:20:06
【问题描述】:

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


}

提前致谢

尼尔

【问题讨论】:

    标签: graphviz dot pygraphviz


    【解决方案1】:

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

    如果你有水平布局(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 属性分配给所有单元格。这样,您将能够使用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;
    
    }
    

    结果:

    【讨论】:

    • 嘿,感谢您的帮助,我意识到围绕该顺序进行操作很重要....我认为它的循环是否正确?无论如何,我使用正交样条的原因是因为我们坐在一起。还有其他模式吗?
    • @NeilBernard 您可以使用属性“headport”和“tailport”控制边缘从哪里开始以及从哪里进入。不幸的是,您只能将它们引导到角落和侧面的中间,中间没有,我也深受其害。如果您绝对需要边缘笔直且分开并且不能选择使用正交样条,还有其他一些解决方案,但它们很丑。您可以使用包含两个单元格并将边缘指向单元格中间的表格。
    • 创建表格是一个点的事情还是我需要创建一个 HTML 表格?对于我的应用程序,您的建议可能会起作用。
    • @NeilBernard 我已经用表格示例和解释更新了答案
    猜你喜欢
    • 2019-09-11
    • 2011-01-17
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 2015-07-31
    • 1970-01-01
    • 2019-12-23
    相关资源
    最近更新 更多