Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3 Prevent Double Click Zoom [duplicate]

I have a D3 Network Graph and I am trying to disable the Double Click zoom function. I have it zooming using:

    var zoom = d3.behavior.zoom().scaleExtent([minZoom, maxZoom]);
    zoom.on("zoom", function() {
            g.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
        });
   svg.call(zoom)

However I cant seem to be able to disable just the Double click zoom. When I use the code below it disables the zoom altogether.

var zoom = d3.behavior.zoom().scaleExtent([minZoom, maxZoom]);
zoom.on("zoom", function() {
            g.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")").on("dblclick.zoom", null);
        });
   svg.call(zoom)

I have also tried calling

    .on("dblclick.zoom", null)

on the svg element by itself and that doesnt work either. Any help would be much appreciated.

like image 805
Caleb Bramwell Avatar asked Jul 29 '14 02:07

Caleb Bramwell


1 Answers

You need to call

    .on("dblclick.zoom", null)

after

    svg.call(zoom)

i.e.

    svg.call(zoom).on("dblclick.zoom", null);
like image 180
SCS Avatar answered Sep 19 '22 13:09

SCS