En realidad, estoy usando d3js para implementar un gráfico gráfico complejo con comportamiento de zoom. pero durante algunos días me enfrento a un problema real al hacer zoom en el gráfico de líneas usando la selección del pincel de zoom. El error al que me enfrento es que no puedo calcular el buen objeto de transformación para obtener el dominio correcto en los ejes x e y que coincida con el dominio de selección de zoom.
Debajo está mi función de zoom, y lo que espero cuando el usuario hace una selección de zoom, la nueva transformación de zoom calculada mostrará el dominio x e y que el usuario desea.
let xScale = graphXAxis?.xScale;//original scale let xScaleZoom = graphXAxis?.xScaleZoom;//scale after zoom let yScale = graphYAxis?.yScale;//original scale let yScaleZoom = graphYAxis?.yScaleZoom; // Calc distance on Axis-X to use in scale let totalX = Math.abs(selection.x2 - selection.x1); let totalY = Math.abs(selection.y2 - selection.y1); // Get current point [x,y] on canvas let originalPoint = [xScaleZoom.invert(selection.x1), 0]; if (!zone.isTOR()) { originalPoint = [xScaleZoom.invert(selection.x1), yScaleZoom.invert(selection.y1)]; } // Result in a zoom of 2 let ratioX = graphWidth / totalX; let ratioY = graphHeight / totalY; const t = d3.zoomIdentity.scale(Math.min(ratioX, ratioY) * zoomLastTransformForBrush.k); // Re-scale axis for the new transformation xScaleZoom = t.rescaleX(xScale); let transitionX = xScaleZoom(originalPoint[0]) * -1; let newTransform = null; yScaleZoom = t.rescaleY(yScale); newTransform = d3.zoomIdentity .translate(transitionX, yScaleZoom(originalPoint[1]) * -1) .scale(tk)