简体   繁体   English

使用D3.js版本4设置重力中心

[英]Set Gravity center using D3.js Version 4

I am trying to create a similar app as http://mbostock.github.io/d3/talk/20111018/collision.html using D3.js VERSION 4. 我正在尝试使用D3.js VERSION 4创建类似于http://mbostock.github.io/d3/talk/20111018/collision.html的应用程序。

Here is the force used in my simulation: 这是我模拟中使用的力:

    svg.on('mousemove', function() {
        let p1 = d3.mouse(this);
        root.x = p1[0];
        root.y = p1[1];
        simulation.restart();
    });
    simulation
            .force('charge_force',
                d3.forceManyBody()
            )
            .force('center_force',
                d3.forceCenter(480, 300)
            )
            .force('x_force', d3.forceX(960).strength(0.5))
            .force('y_force', d3.forceY(600).strength(0.5))
            .force('collide', d3.forceCollide(10).strength(1)
                .radius((d, i) => { return i ? d.radius : d.radius + 100; })
    );

The issue I have is that the repelled dots never return back to the center. 我遇到的问题是被击退的点永远不会回到中心。 See my screenshots below. 请参阅下面的屏幕截图。

In the first picture, all the dots are surrounding the gravity center. 在第一张图片中,所有点都围绕着重心。 After I move the mouse, the dots are repelled everywhere and do not return to their original positions. 移动鼠标后,点到处都被排斥,不会返回原来的位置。

原始的聚集点 移动鼠标后点会被击退,但不会返回重力中心

What did I miss? 我错过了什么? Any help is really appreciated!!! 任何帮助真的很感激!!!

The issue was resolved after I changed 我改变后问题得到了解决

simulation.restart();

as

simulation.alpha(1).restart();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM