d3 / d3-zoom

Pan and zoom SVG, HTML or Canvas using mouse or touch input.
https://d3js.org/d3-zoom
ISC License
502 stars 143 forks source link

svg.call(zoom); throws error #190

Closed Bhuvita closed 4 years ago

Bhuvita commented 4 years ago

I have declare below zoom behaviour

    var zoom = d3.zoom()
            .scaleExtent([0.3, 2])
            .on("zoom", function () {
                svg.attr("transform", d3.event.transform)
            });

Try to use it in below svg element

  var svg = d3.select(component).append('svg')
            .attr('width', width + margin.left + margin.right)
            .attr('height', height + margin.top + margin.bottom)
            .append('g')
            .attr("transform",
                "translate(" + margin.left + "," + margin.top + ")")
            .call(zoom);

It throws error says argument of type zoom behavior is not assignable to parameter of type selection:selection \<SVGGElement>

mbostock commented 4 years ago

This looks like a TypeScript error. Here are a number of d3-zoom examples to consider:

https://observablehq.com/collection/@d3/d3-zoom

Please use Stack Overflow tag d3.js to ask for help. Stack Overflow provides a better collaborative forum: thousands of D3-related questions have been asked there, and some answers may be relevant to you.

When asking for help, please include a link to demonstrate the issue, preferably as an Observable notebook. It is often impossible to debug from code snippets alone. Isolate the issue and reduce your code as much as possible before asking for help. The less code you post, the easier it is for someone to debug, and the more likely you are to get a helpful response.

If you have a question about D3’s behavior and want to discuss it with other users, also consider the d3-js Google Group or joining the d3-js Slack.

Thank you! 🤗