Want to add button in inner node

Short answer - Graphviz does not support this
Longer answers, if you are willing to fiddle around:

  • If you can use non-HTML records, Marc’s answer may work for you (uses class attribute): Can I make a Digraph node interactive
  • If HTML-record shape is necessary, maybe this “kludge” will work:
    • use/abuse the href attribute to insert a version of your javascript code
    • postprocess the SVG output to fix the href-related text (using awk, python, sed, …)
digraph structs {
    node [shape=plaintext]
    struct3 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
  <TR>
    <TD ROWSPAN="3" href="!!alert('done')">hello<BR/>world</TD>
    <TD COLSPAN="3">b</TD>
    <TD ROWSPAN="3">g</TD>
    <TD ROWSPAN="3" href="!!alert('hello there')">h</TD>
  </TR>
</TABLE>>];
}

postprocessing:

gawk '
  /href="!!/{
    sub("><.*!!"," onclick=\"");
    sub(/xlink[^>]*/,"")
  }
 $0=="</a>"{next}
{print}' myfile.svg

Ugly, but seems to work

1 Like