Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3.JS 'zoom' undefined

I am trying to make simple zoom/pan solution, using this code

  var map = document.getElementById('map'),
      svg = d3.select('#map')
            .call(d3.behavior.zoom().on("zoom", function () {
                svg.attr("transform", "translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")")
            }))
            .append('g');

But at this moment it gives:

Uncaught TypeError: Cannot read property 'zoom' of undefined

In html I have just this:

<svg id="map" class="map" viewBox="0 0 8000 2000"></svg>

P.S. Inspired by this

like image 629
David Arutiunian Avatar asked Aug 08 '16 19:08

David Arutiunian


1 Answers

Try Below code: in v4 of d3.js, d3.behavior.zoom changed to d3.zoom

var svg;

svg= d3.select("svg")
        .call(d3.zoom().on("zoom", function () {
              svg.attr("transform", d3.event.transform)
         }))
        .append("g");
like image 199
Vinod Selvin Avatar answered Sep 24 '22 20:09

Vinod Selvin