I am transferring my d3 code from v3 to v4 and you are having trouble finding an equivalent for the d3.zoom.x, d3.zoom.y properties.
Here's a short piece of code, including the most important elements:
this.init = function(obj, def) { /* X-axis */ x = d3.scaleTime() .range([0, width]); xAxis = d3.axisBottom(x) .ticks(ticks); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + height + ")"); /* Y-axis */ for (var i = 0; i < 1; i++) { // Returns the y and yAxis as arrays createYAxis(i); } initZoom(); }; // Zoom trigger var drawUpdXY = function(){ setPause(true); drawUpd(); zoomY.y(y[0]); zoomX.x(x); zoom = d3.zoom() .on("zoom", drawUpdXY); zoomX = d3.zoom() .on("zoom", drawUpdX); zoomY = d3.zoom() .on("zoom", drawUpdY); };
I tried using this to replace "zoom.x (x); zoom.y (y [0])"
xAxis.scale(d3.event.transform.rescaleX(x)); yAxis[0].scale(d3.event.transform.rescaleY(y[0]));
However, they only change the scale of the axis, leaving the data open.
Pety petyy
source share