function translateSvg(d){ //获取svg的父元素 const parentBox = svg.node().parentElement //获取父元素的宽度 const fullWidth = parentBox.clientWidth //获取父元素的高度 const fullHeight = parentBox.clientHeight /*画布的移动,加上移动时平滑的动画效果 *下面的fullWidth / 2 ,fullHeight / 2 基于画布的x,y,就是画布的正中间 *scale就是画布的放大缩小,小于1是缩放,大于1是放大 * d 的数据来源是点击表格的当前行的数据,就是你选中的几点的数据,取数据的x和y的坐标值 */ svg.transition() .duration(500) .call(zoom.transform, d3.zoomIdentity.translate(fullWidth / 2, fullHeight / 2).scale(1).translate(-d.x,-d.y)) }
记录d3.js 力导向图的平移缩放,类似地图导航点击某一项移动到当前位置
原文:https://www.cnblogs.com/smedas/p/12485880.html