2012-11-13 70 views
4

请考虑下面的代码:Graphviz:如何在HTML表格单元格之间创建边?

digraph G { 
    node [shape=plaintext] 

    a [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> 
          <TR><TD ID="first" BGCOLOR="gray">first</TD></TR> 
          <TR><TD ID="second" PORT="f1">second</TD></TR> 
          <TR><TD ID="third" PORT="f2">third</TD></TR> 
       </TABLE>>]; 

    b [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> 
          <TR><TD ID="first" BGCOLOR="gray">first</TD></TR> 
          <TR><TD ID="second" PORT="f1">second</TD></TR> 
          <TR><TD ID="third" PORT="f2">third</TD></TR> 
       </TABLE>>]; 

    a:first -> b:first; 
} 

我得到警告了相当数量的:

[email protected] ~ $ dot records.gv -T pdf > records.pdf 
Warning: Illegal attribute ID in <TD> - ignored 
Warning: Illegal attribute ID in <TD> - ignored 
Warning: Illegal attribute ID in <TD> - ignored 
in label of node a 
Warning: Illegal attribute ID in <TD> - ignored 
Warning: Illegal attribute ID in <TD> - ignored 
Warning: Illegal attribute ID in <TD> - ignored 
in label of node b 
Warning: node a, port first unrecognized 
Warning: node b, port first unrecognized 
  1. 按照documentation TD的ID属性应该是合法的。我错过了什么?
  2. 如何引用单个单元格并在它们之间创建边?

回答

7

您可以简单地使用PORT而不是ID,然后使用边缘定义,如您的示例中所示。

<TD PORT="first" BGCOLOR="gray">first</TD> 

ID的目的是下游使用,所以除非你正在使用SVG输出和重用ID的其他地方,他们很可能不是真的有用。

至于警告,我没有得到他们graphviz 2.28。如果您使用旧版本的graphviz,我建议更新。

graphviz html label ports

+0

谢谢,完美的作品! –

6

为了完整起见,下面是实际工作的完整源:

digraph G { 
    node [shape=plaintext] 

    a [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> 
          <TR><TD PORT="c" BGCOLOR="gray">first</TD></TR> 
          <TR><TD PORT="d">second</TD></TR> 
          <TR><TD PORT="e">third</TD></TR> 
       </TABLE>>]; 

    b [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> 
          <TR><TD PORT="c" BGCOLOR="gray">first</TD></TR> 
          <TR><TD PORT="d">second</TD></TR> 
          <TR><TD PORT="e">third</TD></TR> 
       </TABLE>>]; 

    a:c -> b:c; 
} 
+0

很适合发布完整的解决方案。对于那些偶然发现这个问题的人来说,让生活变得更容易。 –

相关问题