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.

28 lines
818 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. *
  9. * @param {number} distance
  10. * @param {number} dx
  11. * @param {number} dy
  12. * @param {Object<vis.Node.id, vis.Node>} forces
  13. * @param {vis.Node} node
  14. * @private
  15. */
  16. _calculateForces(distance, dx, dy, forces, node) {
  17. if (distance > 0) {
  18. let degree = (node.edges.length + 1);
  19. let gravityForce = this.options.centralGravity * degree * node.options.mass;
  20. forces[node.id].x = dx * gravityForce;
  21. forces[node.id].y = dy * gravityForce;
  22. }
  23. }
  24. }
  25. export default ForceAtlas2BasedCentralGravitySolver;