Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

273
Vistas
How can i calculate a zoom object transformation after zoom selection?

Actually i'm using d3js to implement a complex graphic chart with zoom behavior. but for few days i'm facing a real problem with zooming line chart using zoom brush selection. The error that i'm facing is that i cannot calculate the good transformation object to get the correct domain in x and y axis that matches with the zoom selection domain.

Below it's my zoom function, and what i expect when the user makes a zoom selection, the new calculated zoom transformation will show the x and y domain that user wants.



    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(t.k)

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda