Browse Source

- Added condition to Repulsion similar to BarnesHut to ensure nodes do not overlap.

v3_develop
Alex de Mulder 10 years ago
parent
commit
4d7bcd4504
3 changed files with 15 additions and 2 deletions
  1. +1
    -0
      HISTORY.md
  2. +7
    -1
      dist/vis.js
  3. +7
    -1
      lib/network/mixins/physics/RepulsionMixin.js

+ 1
- 0
HISTORY.md View File

@ -17,6 +17,7 @@ http://visjs.org
- Made the node/edge selected by the popup system the same as selected by the click-to-select system. Thank you @pavlos256! - Made the node/edge selected by the popup system the same as selected by the click-to-select system. Thank you @pavlos256!
- Improved edit edge control nodes positions, altered style a little. - Improved edit edge control nodes positions, altered style a little.
- Fixed issue #564 by resetting state to initial when no callback is performed in the return function. - Fixed issue #564 by resetting state to initial when no callback is performed in the return function.
- Added condition to Repulsion similar to BarnesHut to ensure nodes do not overlap.
### Timeline ### Timeline

+ 7
- 1
dist/vis.js View File

@ -29990,6 +29990,12 @@ return /******/ (function(modules) { // webpackBootstrap
dy = node2.y - node1.y; dy = node2.y - node1.y;
distance = Math.sqrt(dx * dx + dy * dy); distance = Math.sqrt(dx * dx + dy * dy);
// same condition as BarnesHut, making sure nodes are never 100% overlapping.
if (distance == 0) {
distance = 0.1*Math.random();
dx = distance;
}
minimumDistance = (combinedClusterSize == 0) ? nodeDistance : (nodeDistance * (1 + combinedClusterSize * this.constants.clustering.distanceAmplification)); minimumDistance = (combinedClusterSize == 0) ? nodeDistance : (nodeDistance * (1 + combinedClusterSize * this.constants.clustering.distanceAmplification));
var a = a_base / minimumDistance; var a = a_base / minimumDistance;
if (distance < 2 * minimumDistance) { if (distance < 2 * minimumDistance) {
@ -29999,13 +30005,13 @@ return /******/ (function(modules) { // webpackBootstrap
else { else {
repulsingForce = a * distance + b; // linear approx of 1 / (1 + Math.exp((distance / minimumDistance - 1) * steepness)) repulsingForce = a * distance + b; // linear approx of 1 / (1 + Math.exp((distance / minimumDistance - 1) * steepness))
} }
// amplify the repulsion for clusters. // amplify the repulsion for clusters.
repulsingForce *= (combinedClusterSize == 0) ? 1 : 1 + combinedClusterSize * this.constants.clustering.forceAmplification; repulsingForce *= (combinedClusterSize == 0) ? 1 : 1 + combinedClusterSize * this.constants.clustering.forceAmplification;
repulsingForce = repulsingForce / Math.max(distance,0.01*minimumDistance); repulsingForce = repulsingForce / Math.max(distance,0.01*minimumDistance);
fx = dx * repulsingForce; fx = dx * repulsingForce;
fy = dy * repulsingForce; fy = dy * repulsingForce;
node1.fx -= fx; node1.fx -= fx;
node1.fy -= fy; node1.fy -= fy;
node2.fx += fx; node2.fx += fx;

+ 7
- 1
lib/network/mixins/physics/RepulsionMixin.js View File

@ -31,6 +31,12 @@ exports._calculateNodeForces = function () {
dy = node2.y - node1.y; dy = node2.y - node1.y;
distance = Math.sqrt(dx * dx + dy * dy); distance = Math.sqrt(dx * dx + dy * dy);
// same condition as BarnesHut, making sure nodes are never 100% overlapping.
if (distance == 0) {
distance = 0.1*Math.random();
dx = distance;
}
minimumDistance = (combinedClusterSize == 0) ? nodeDistance : (nodeDistance * (1 + combinedClusterSize * this.constants.clustering.distanceAmplification)); minimumDistance = (combinedClusterSize == 0) ? nodeDistance : (nodeDistance * (1 + combinedClusterSize * this.constants.clustering.distanceAmplification));
var a = a_base / minimumDistance; var a = a_base / minimumDistance;
if (distance < 2 * minimumDistance) { if (distance < 2 * minimumDistance) {
@ -40,13 +46,13 @@ exports._calculateNodeForces = function () {
else { else {
repulsingForce = a * distance + b; // linear approx of 1 / (1 + Math.exp((distance / minimumDistance - 1) * steepness)) repulsingForce = a * distance + b; // linear approx of 1 / (1 + Math.exp((distance / minimumDistance - 1) * steepness))
} }
// amplify the repulsion for clusters. // amplify the repulsion for clusters.
repulsingForce *= (combinedClusterSize == 0) ? 1 : 1 + combinedClusterSize * this.constants.clustering.forceAmplification; repulsingForce *= (combinedClusterSize == 0) ? 1 : 1 + combinedClusterSize * this.constants.clustering.forceAmplification;
repulsingForce = repulsingForce / Math.max(distance,0.01*minimumDistance); repulsingForce = repulsingForce / Math.max(distance,0.01*minimumDistance);
fx = dx * repulsingForce; fx = dx * repulsingForce;
fy = dy * repulsingForce; fy = dy * repulsingForce;
node1.fx -= fx; node1.fx -= fx;
node1.fy -= fy; node1.fy -= fy;
node2.fx += fx; node2.fx += fx;

Loading…
Cancel
Save