I want to add a button and clickable event inside the node is there any way to do it?
digraph structs {
node [shape=plaintext]
struct1 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD>left</TD><TD PORT="f1">mid dle</TD><TD PORT="f2">right</TD></TR>
</TABLE>>];
struct2 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD PORT="f0">one</TD><TD>two</TD></TR>
</TABLE>>];
struct3 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
<TD ROWSPAN="3">hello<BR/>world <BUTTON TYPE="BUTTON" ONCLICK="callBack()">HELLO BUTTON</BUTTON> </TD>
<TD COLSPAN="3">b</TD>
<TD ROWSPAN="3">g</TD>
<TD ROWSPAN="3">h</TD>
</TR>
<TR>
<TD>c</TD><TD PORT="here">d</TD><TD>e</TD>
</TR>
<TR>
<TD COLSPAN="3">f</TD>
</TR>
</TABLE>>];
struct1:f1 -> struct2:f0;
struct1:f2 -> struct3:here;
}
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
i am running this but not working:
digraph G {
//ratio = fill;
node [style=filled];
size="8"
node [shape = rectangle];
subgraph cluster_A {
color=blue;
node [shape=rectangle,style=filled,color=cadetblue2 ];
Process_2 -> Process_3 ;
label = "A";
}
subgraph cluster_B {
color=blue;
node [shape=rectangle,style=filled,color=mediumpurple2 ];
Process_4 -> Process_5 -> Process_6 ;
label = "B";
}
subgraph cluster_C {
color=blue;
node [shape=rectangle,style=filled,color=olivedrab2 ];
Process_7 -> Process_8 -> Process_9 ;
label = "C";
}
"Process_1"
"Process_2"
Process_1 [class="Process_1"]
Process_3 [class="clickme"]
Process_1 -> Process_3;
Process_2 [class="Process_2"]
Process_3 [class="clickme"]
Process_2 -> Process_3;
Process_3 [class="Process_3"]
Process_4 [class="clickme"]
Process_3 -> Process_4;
Process_2 [class="Process_2"]
Process_4 [class="clickme"]
Process_2 -> Process_4;
Process_4 [class="Process_4"]
Process_5 [class="clickme"]
Process_4 -> Process_5;
"Process_6"
"Process_7"
Process_5 [class="Process_5"]
Process_8 [class="clickme"]
Process_5 -> Process_8;
"Process_9"
Process_9 [class="Process_9"]
New_XYZ [class="clickme"]
Process_9 -> New_XYZ;
}
d3.select('#graph').graphviz().renderDot(graphStatic)
.selectAll(".clickme")
.on("renderStart", evt => console.log("Hello and welcome!"));