In our previous recipe, we touched upon force simulation node object and its {x, y
} attributes, which determine the location of a node on the layout. In this recipe, we will discuss another interesting aspect of physical motion simulation: velocity. The D3 force layout has a built-in support for velocity simulation, which relies on the {vx, vy
} attributes on the node object. Let's see how this can be done in the example described in this recipe.
Open your local copy of the following file in your web browser:
https://github.com/NickQiZhu/d3-cookbook-v2/blob/master/src/chapter11/velocity.html .
In this recipe, we will modify the previous recipe by first disabling both positioning and charge and then giving newly added node some initial velocity. As a result, now, the faster you move the mouse higher the initial velocity and momentum will be for each node. Here is the code to do that:
<script type="text/javascript"> var r = 4.5...