dracula icon indicating copy to clipboard operation
dracula copied to clipboard

click event modification

Open Grummfy opened this issue 8 years ago • 2 comments

Hello, it could be very helpfull to have the possibility to add a click event handler for the nodes.

Thanks

Grummfy avatar Oct 16 '16 04:10 Grummfy

I'll post something up on how to do that.

strathausen avatar Dec 05 '16 16:12 strathausen

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

bagnus avatar Mar 03 '17 17:03 bagnus