Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding to zoom ending with the zoom behavior

Tags:

zooming

d3.js

It would be convenient if there was a way to easily bind to an event at the end of a zoom behavior transition - when the user mouseup or touchends something that moves the chart. Is this possible by just binding all of the up events, or is this something that people have done some other way?

like image 515
tmcw Avatar asked Nov 12 '12 22:11

tmcw


2 Answers

In d3 v4 the the zoom.on typenames have changed. They are "start", "zoom" and "end" now.

  var d3zoom = d3.zoom()
    .on("start", zoomStartFunction)
    .on("zoom", zoomFunction)
    .on("end", zoomEndFunction);

  svg.call(d3zoom);

Check out the very helpful docs.

like image 164
Immanuel Avatar answered Nov 15 '22 09:11

Immanuel


I was looking for the same thing, and I found this post.

You can write something like this:

var svg = outer.append("svg:g")
            .call(d3.behavior.zoom()
                    .on("zoom", rescale)
                    .on("zoomstart", zoomStart)
                    .on("zoomend", zoomEnd))
            .on("dblclick.zoom", null)
            .append("svg:g");

function zoomStart(){
    console.log("ZOOM START");
}

function zoomEnd(){
    console.log("ZOOM END");
}

Hope it helps.

like image 38
Fran Gimenez Avatar answered Nov 15 '22 09:11

Fran Gimenez