Graphviz Array LR但堆叠TB

时间:2018-06-13 21:58:13

标签: graphviz dot

digraph G
{
    rankdir=LR;

    Array1 [ shape = record, label = "{ <a1>A(1) | <a2>A(2) | <a3>A(...) | <an>A(n)}"] ; 
    Array2 [ shape = record, label = "{ <b1>B(1) | <b2>B(2) | <b3>B(...) | <bn1>B(n+1)}"] ;  
    Array1:a1 -> Array2:b1 [style=solid];
    Array1:an -> Array2:bn1 [style=solid];
    {rank=same; Array1; Array2;}
}

我试图让graphviz从左到右绘制两个数组,但顶部是Array1,底部是Array2。

Output with rank=same

正如您在图片中看到的那样,没有绘制箭头,但布局就像它应该的那样。我也从dot获得了一些错误,但我找不到任何有用的信息:

dot -Tpng algoA.dot -o algoA.png                                         :(
Warning: flat edge between adjacent nodes one of which has a record shape - replace records with HTML-like labels
  Edge Array2 -> Array1
Error: lost Array1 Array2 edge
Error: lost Array1 Array2 edge
digraph G
{
    rankdir=LR;

    Array1 [ shape = record, label = "{ <a1>A(1) | <a2>A(2) | <a3>A(...) | <an>A(n)}"] ; 
    Array2 [ shape = record, label = "{ <b1>B(1) | <b2>B(2) | <b3>B(...) | <bn1>B(n+1)}"] ;  
    Array1:a1 -> Array2:b1 [style=solid];
    Array1:an -> Array2:bn1 [style=solid];
    //{rank=same; Array1; Array2;}
}

Output with rank=same removed

如果代码中没有rank =相同,我会得到我想要的箭头,但不是我想要它顶部的Array1和底部的Array2。错误消息消失了。我究竟做错了什么?我尝试了几种方法,并且所有这些方法都不适合我,我总是得到一个错误的布局,或者我必须添加其他几个节点来绘制它们,那些看不见的数组的箭头也是#39; t得到。

1 个答案:

答案 0 :(得分:0)

密钥位于错误消息中:replace records with HTML-like labels。可以找到详细信息here

使用您的代码和我想要实现的内容,可以将数组创建为两个类似HTML的标签。代码中的评论。

digraph so 
{
    # plaintext is being used to create HTML-like labels
    node [shape=plaintext]

    # no border for the table, a single border for each cell and
    # no distance between individual cells looks like record shape

    # PORTs being defined as addresses of individual cells
    # that edges can be directed to

    array1 [label=< 
        <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR>
            <TD PORT="a1">A(1)</TD>
            <TD PORT="a2">A(2)</TD>
            <TD PORT="ax">A(...)</TD>
            <TD PORT="an">A(n)</TD>
        </TR> </TABLE>>];

    array2 [label=< 
        <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR>
            <TD PORT="b1">B(1)</TD>
            <TD PORT="b2">B(2)</TD>
            <TD PORT="bx">B(...)</TD>
            <TD PORT="bn">B(n+1)</TD>
    </TR> </TABLE>>]; 

    array1:a1 -> array2:b1;
    array1:an -> array2:bn;
}

这会产生你想要的东西:

enter image description here