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.

38 lines
1.1 KiB

  1. import CentralGravitySolver from "./CentralGravitySolver"
  2. /**
  3. * @class ForceAtlas2BasedCentralGravitySolver
  4. * @extends CentralGravitySolver
  5. */
  6. class ForceAtlas2BasedCentralGravitySolver extends CentralGravitySolver {
  7. /**
  8. * @param {Object} body
  9. * @param {{physicsNodeIndices: Array, physicsEdgeIndices: Array, forces: {}, velocities: {}}} physicsBody
  10. * @param {Object} options
  11. * @constructor ForceAtlas2BasedCentralGravitySolver
  12. */
  13. constructor(body, physicsBody, options) {
  14. super(body, physicsBody, options);
  15. }
  16. /**
  17. * Calculate the forces based on the distance.
  18. *
  19. * @param {number} distance
  20. * @param {number} dx
  21. * @param {number} dy
  22. * @param {Object<vis.Node.id, vis.Node>} forces
  23. * @param {vis.Node} node
  24. * @private
  25. */
  26. _calculateForces(distance, dx, dy, forces, node) {
  27. if (distance > 0) {
  28. let degree = (node.edges.length + 1);
  29. let gravityForce = this.options.centralGravity * degree * node.options.mass;
  30. forces[node.id].x = dx * gravityForce;
  31. forces[node.id].y = dy * gravityForce;
  32. }
  33. }
  34. }
  35. export default ForceAtlas2BasedCentralGravitySolver;