Update D3 Band Zoom from v3 to v4

I am trying to upgrade this script to D3 v4

http://jsfiddle.net/AdamMills/Ljeh2etj/

This is the original zoom function.

bars.attr("transform", "translate(" + d3.event.translate[0]+",0)scale(" + d3.event.scale + ",1)");
chart.select(".x.axis").attr("transform", "translate(" + d3.event.translate[0]+","+(height)+")")
    .call(xAxis.scale(x.rangeRoundBands([0, width * d3.event.scale],.1 * d3.event.scale)));
chart.select(".y.axis").call(yAxis);

I tried updating it for docs for d3-zoom

    bars.attr("transform", d3.event.transform);
chart.select(".x.axis").attr("transform", d3.event.transform)
    .call(xAxis.scale(d3.event.transform.rescaleX(x)));
chart.select(".y.axis").call(yAxis);

I get an undefined error in recaleX What am I missing?

+4
source share
1 answer

You can change the second row in scaling from the script:

chart.select(".x.axis")
                    .attr("transform", "translate(" + d3.event.transform.x + "," + (height) + ")")
                        .call(
                             xAxis.scale(
                                 x.rangeRound([0, width * d3.event.transform.k])
                                     .paddingInner(.1 * d3.event.transform.k)));;
0
source

All Articles