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

130
Vistas
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 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