d3.js - How can I use drag behavior and dblclick event with d3? -
i have been trying many hours , couldn't working. have element d3 draggable using drag behavior, , want add dblclick event, performs action when double clicked. couldn't dblclick event reached. have studied many ways of trying stop propagation within drag, , changing order of declaration of events, no success far. code like:
switch = box.append('rect') .data([{x: point.x, y: point.y}]) .attr('transform', function (d) { return 'translate(' + d.x + ',' + d.y + ')'; }) .attr('height', 8) .attr('width', 8) .attr('stroke', color) .attr('fill', color) .on('dblclick', function () { d3.event.stoppropagation(); alert('hello'); // doesn't enter }, true).call(d3.behavior.drag().on('dragstart', function () { d3.event.sourceevent.stoppropagation(); }).on('drag', function (d) { d.x += d3.event.dx; d.y += d3.event.dy; d3.select(this).attr('transform', 'translate(' + d.x + ',' + d.y + ')'); }).on('dragend', function (d) { }));
note "true" after on('dblclick', ..., true) declaration. trying prevent propagation.
any appreciated.
Comments
Post a Comment