使用Graphviz显示彼此相邻且在单元格之间有线的两个表 [英] Use Graphviz to show two tables adjacent to each other with lines between cells

查看:52
本文介绍了使用Graphviz显示彼此相邻且在单元格之间有线的两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示下面的图,除了两个表在同一水平面上.我希望第二个表格显示在第一个表格的右侧,而不是当前的下方.

我当前使用的graphviz代码是:

  digraph G {节点[shape = record,fontname ="Arial"];set1 [label ="{Blue Crosses | B1 | B2 | B3 | B4} | {正方形|< b1>左侧|< b2>左侧|< b3>右侧|左侧}"]]set2 [label ="{Blue Crosses |< b1> B1 |< b2> B2 |< b3> B3} | {坐标|(1,1)|(2,2)|(4,2)}"];set1:b1->set2:b1;set1:b2->set2:b2;set1:b3->set2:b3;} 

解决方案

为实现所需的功能,您需要添加以下行

  {rank = same;set1 set2} 

创建节点后,在代码中

.但是,在这种情况下,您会发现 graphviz 感到困惑,无法再识别端口了.因此,您需要使用

I would like to show the diagram below, except with the two tables on the same horizontal level. I would like the second table to be shown to the right of the first table and not below it like it is currently.

The current code for graphviz that I have is:

digraph G  {

   node [shape=record, fontname="Arial"];

   set1 [label = "{Blue Crosses | B1 | B2 | B3 | B4 }|{ Square |<b1>  Left |<b2> Left |<b3> Right | Left }"];
   set2 [label = "{Blue Crosses |<b1> B1 |<b2> B2 |<b3> B3 }|{ Coordinates | (1, 1) | (2, 2) | (4, 2) }"];

  set1:b1 -> set2:b1;
  set1:b2 -> set2:b2;
  set1:b3 -> set2:b3;

}

解决方案

In order to achieve what you want, you need to add the line

{ rank = same; set1 set2 }

to your code after you have created the nodes. However, in this situation, you will find that graphviz gets confused and doesn't recognise the ports anymore. So instead of using record = shape you will need to re-code your graph with HTML-like labels. I have done that for the example provided (thanks for a clear question with code and desired outcome, by the way):

digraph G  
{
   node[ shape = none, fontname = "Arial" ];

    set1[ label=<
    <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
        <TR>
            <TD>Blue Crosses</TD>
            <TD>Square</TD>
        </TR>
        <TR>
            <TD>B1</TD>
            <TD PORT="b1">Left</TD>
        </TR>
        <TR>
            <TD>B2</TD>
            <TD PORT="b2">Left</TD>
        </TR>
        <TR>
            <TD>Right</TD>
            <TD PORT="b3">Right</TD>
        </TR>
        <TR>
            <TD>B4</TD>
            <TD>Left</TD>
        </TR>
    </TABLE>>];

    set2[ label=<
    <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
        <TR>
            <TD>Blue Crosses</TD>
            <TD>Coordinates</TD>
        </TR>
        <TR>
            <TD PORT="b1">B1</TD>
            <TD>(1, 1)</TD>
        </TR>
        <TR>
            <TD PORT="b2">B2</TD>
            <TD>(2, 2)</TD>
        </TR>
        <TR>
            <TD PORT="b3">B3</TD>
            <TD>(4, 2)</TD>
        </TR>
    </TABLE>>];    

    # layout
    nodesep = 2;                /* increase distance between nodes */
    { rank = same; set1 set2 }

    set1:b1 -> set2:b1;
    set1:b2 -> set2:b2;
    set1:b3 -> set2:b3;
}

yields

这篇关于使用Graphviz显示彼此相邻且在单元格之间有线的两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆