Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to know the current Zoom level in D3.js

I have a problem since a few days. I have a graph and when I use Zoom Behavior it works, but I need to know when I reach maximum zoom to load new given

// Specifies the zoom scale's allowed range, [min, max]
d3.behavior.zoom().x(x).scaleExtent([1,10]).on("zoom", draw)

See my code http://jsfiddle.net/albanlopez/D4MRP/

like image 640
Alban Avatar asked Feb 28 '13 22:02

Alban


1 Answers

In the draw function the current event will have the zoom level (d3.event.scale as you mentioned). Also if you keep the behaviour around like:

var zm = d3.behavior.zoom().x(x).scaleExtent([1,10]).on("zoom", draw);

Then you can find the current zoom level by calling:

zm.scale();
like image 169
Superboggly Avatar answered Oct 16 '22 00:10

Superboggly