D3 force layout: making pan on drag (zoom) smoother

元气小坏坏 提交于 2019-12-03 12:43:50

The problem is that d3.behavior.zoom retrieves the current mouse position relative to the clicked item's container element, and you are moving the container element! So the relative position is constantly changing, hence the jittering effect you're seeing.

You probably want to move the background <rect> so that it's a direct child of the <svg> element. This achieves two things:

  1. The position will now be relative to the <svg> container, which isn't moving.
  2. Currently, you are moving the <rect> when you zoom or pan, so the zoomable area changes and some parts of the viewport are no longer zoomable. Having the background <rect> in the same place fixes this problem too.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!