dracula
dracula copied to clipboard
click event modification
Hello, it could be very helpfull to have the possibility to add a click event handler for the nodes.
Thanks
I'll post something up on how to do that.
Hello, a quick & dirty way could be adding id and/or class to the svg object:
case test:
graph.addNode('Dragonfruit', { cl:'xxxx' });
in function drawNode(), change code to:
node.shape = this.canvas.set();
//=========================== start mod
var elli = this.canvas.ellipse(0, 0, 30, 20);
elli.node.id = node.label || node.id;
if(node.cl) {elli.node.setAttribute("class", node.cl)};
node.shape.push(elli.attr({ stroke: color, 'stroke-width': 2, fill: color, 'fill-opacity': 0 })).push(this.canvas.text(0, 30, node.label || node.id)).translate(node.point[0], node.point[1]);
//=========================== end mod
then in your program you can add:
$('#Dragonfruit').on("click", function(){
alert($(this).attr('id'));
});
or:
$('.xxxx').on("click", function(){
alert($(this).attr('id'));
});