how to know the current Zoom level in D3.js

后端 未结 3 1037
独厮守ぢ
独厮守ぢ 2021-01-04 07:40

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

// Sp         


        
3条回答
  •  迷失自我
    2021-01-04 08:13

    rect.call(zm=d3.behavior.zoom().x(x).scaleExtent([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)

    rect.call( zm = d3.behavior.zoom().x(x).scaleExtent([1,10]).on("zoom", draw));
    
    function draw() {
        // trace l'axe X
        svg.select("g.x.axis").call(xAxis);
        // trace l'axe Y
        svg.select("g.y.axis").call(yAxis);
        // trace la courbe
        svg.select("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
    }
    

提交回复
热议问题