Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz: How can I create edges between HTML table cells?

Tags:

graphviz

Please consider the following code:

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;
}

I get a fair amount of warnings:

laci@nitehawk ~ $ 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. According to the documentation the ID attribute of TD should be legal. What am I missing?
  2. How can I reference individual cells and create edges between them?
like image 216
László Monda Avatar asked Nov 13 '12 22:11

László Monda


2 Answers

For completeness sake here's the full source that actually works:

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;
}
like image 137
László Monda Avatar answered Oct 19 '22 01:10

László Monda


You can simply use PORT instead of ID and then use the edge definition as in your example.

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

ID's purpose is downstream use, so unless you're using SVG output and reuse the id's elsewhere, they are probably not really useful.

As to the warnings, I do not get them with graphviz 2.28. If you use an older version of graphviz, I suggest to update.

graphviz html label ports

like image 45
marapet Avatar answered Oct 19 '22 03:10

marapet