Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

277
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda