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.

36 lines
1023 B

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