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

136
Visualizações
How do I zoom in on individual circle Nodes within Circle Packing

I recently started working with D3js and I have a bit of trouble zooming in on individual nodes within a packing circle Currently, I am just zooming into the Mouse's X and Y coordinates. It gets difficult to manage when the zoom scale is increased (Jumps around the SVG). I tried following Mike Bostock's circle packing example but found it to be confusing and unclear.

function zoomsTo(e) {
    // coordinate of mouse
    var mouseX = e.layerx
    var mouseY = e.layerY

    let k = 3
    let svg = d3.select("svg")
    svg.transition().call(zoom.scaleTo, k)

    // ZOOMS INTO SPECIFIC COORDINATES
    //1F ELSE STATEMENT Checks if mouse is near edge. Limits jumping around
    if (mouseX > 100 && mouseX < 145 || mouseY > -49 && mouseY < -5) {
        svg.transition().duration(1000)
            .call(zoom.translateTo, mouseX / 3, mouseY / 3)
    }

    else if (mousex > 45 || mouseY > 400) {
        svg.transition().duration(1000)
            .call(zoom.translateTo, mouseX / 2.75, mouseY / 2.85)
    }

    else if (mouseX < -10 && mouseY >= 250)
        svg.transition().duration(1000)
            .call(zoom.translateTo, mouseX / 2.75, mouseY / 2.85)
    else {
        svg.transition().duration(1000)
            .call(zoom.translateTo, mouseX, mouseY)

        // Checks if svg translate is at edge to avoid jumping around as translate value is depended on the scale.
        // If scale is 1.5, x and y(300,300) is not the same as when scale is 2

        let translateValue = svg.attr('transform')

        console.log(svg.attr("transform"))

        // MESSY FOR TESTING PURPOSES
        // instead of default values we need dynamic values

        if (translatevalue >= "(-300,-36)" || translateValue >= '(-380,2)' || translateValue >= '(-400,0)' || translatevalue >= '(0,-250) ' || translatevalue >= "(-150,288) " || translatevalue >= "(8, -500)" || translateValue >= '(-800,0)' || translateValue > "(-1000, 0)" ) 

        //instead of having set value put pixel calculations
        svg.attr("transform', ‘translate(’ + (width/3) +", " + height/3 + ')")
        console.log("AFTER " + svg.attr( "transform"))
    
    }
}

PS. (I have it messy for testing purposes ;) )

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