vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
656 B

  1. import CentralGravitySolver from "./CentralGravitySolver"
  2. class ForceAtlas2BasedCentralGravitySolver extends CentralGravitySolver {
  3. constructor(body, physicsBody, options) {
  4. super(body, physicsBody, options);
  5. }
  6. /**
  7. * Calculate the forces based on the distance.
  8. * @private
  9. */
  10. _calculateForces(distance, dx, dy, forces, node) {
  11. if (distance > 0) {
  12. let degree = (node.edges.length + 1);
  13. let gravityForce = this.options.centralGravity * degree * node.options.mass;
  14. forces[node.id].x = dx * gravityForce;
  15. forces[node.id].y = dy * gravityForce;
  16. }
  17. }
  18. }
  19. export default ForceAtlas2BasedCentralGravitySolver;