Zooming to a clicked node on a D3 Force Directed Graph

后端 未结 1 938
无人共我
无人共我 2021-01-15 03:56

I am trying to apply the van Wijk Smooth Zooming example to a D3 force-directed graph I am working that already has the drag+zoom functioning on it. However, I don\'t know h

相关标签:
1条回答
  • 2021-01-15 04:23

    Actually, I just figured it out based on the clicked function in this example. My equation was wrong for my scale and translate numbers. I needed to get my translate numbers this way:

    translate = [width / 2 - scale * x, height / 2 - scale * y]
    

    Then I needed to call() the zoom behavior with the transition on the zoom behavior itself like below with the ".event" at the end to make it fire:

    svg.transition().duration(750)
       .call(zoom.translate(translate).scale(scale).event);
    

    and not doing it the wrong way by translating the svg like I was doing before:

    svg.transition().duration(750)
       .attr("transform", translate(translate).scale(scale));
    
    0 讨论(0)
提交回复
热议问题