Alban Alban - 4 months ago 71
Javascript Question

how to know the current Zoom level in D3.js

i have a probleme since few days.
i have a graph when i use Zoom Behavior, it's works but, I need to know when I reach the maximum zoom to load the 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

Answer[1,10]).on("zoom", draw));

After a new test i have the answer :

var currentZoom = d3.event.scale;

But only available/readable in the draw() function called by .on("zoom", draw) zm = d3.behavior.zoom().x(x).scaleExtent([1,10]).on("zoom", draw));

function draw() {
    // trace l'axe X"g.x.axis").call(xAxis);
    // trace l'axe Y"g.y.axis").call(yAxis);
    // trace la courbe"path.line").attr("d", line);

    console.log(zm.scale(), zm.translate()); // , zm.translate[1] = Y
    console.log(d3.event.scale, d3.event.translate[0]); // , d3.event.translate[1] = Y