我想这样做: 可调整大小的力布局
但是使用 d3v4 !
我想,我必须将此行从 v3 转换为 v4
force.size([width, height]).resume();
Run Code Online (Sandbox Code Playgroud)
在 v4 文档中,我发现了这个: v4 Doc about centering force / center.x & center.y
我尝试了很多东西!但没有成功。
提前致谢 :)
(非常感谢mbostock创建 d3js :D)
我看懂了医生!
var simulation = d3
.forceSimulation()
.force("center", d3.forceCenter(window.innerWidth / 2, window.innerHeight / 2))
Run Code Online (Sandbox Code Playgroud)
改变中心
simulation.force("center")
.x(window.innerWidth / 2)
.y(window.innerHeight / 2);
simulation.alpha(0.3).restart();
Run Code Online (Sandbox Code Playgroud)