Browse Source

- Fixed error in repulsion physics model.

- Improved physics handling for smoother network simulation.
v3_develop
Alex de Mulder 10 years ago
parent
commit
23cf32638d
4 changed files with 3591 additions and 3575 deletions
  1. +2
    -0
      HISTORY.md
  2. +3552
    -3545
      dist/vis.js
  3. +35
    -28
      lib/network/Network.js
  4. +2
    -2
      lib/network/mixins/physics/RepulsionMixin.js

+ 2
- 0
HISTORY.md View File

@ -19,6 +19,8 @@ http://visjs.org
- Fixed bug where box shaped nodes did not use hover color.
- Fixed Locales docs.
- When hovering over a node that does not have a title, the title of one of the connected edges that HAS a title is no longer shown.
- Fixed error in repulsion physics model.
- Improved physics handling for smoother network simulation.
### Graph2d

+ 3552
- 3545
dist/vis.js
File diff suppressed because it is too large
View File


+ 35
- 28
lib/network/Network.js View File

@ -35,6 +35,7 @@ function Network (container, data, options) {
throw new SyntaxError('Constructor must be called with the new operator');
}
this._determineBrowserMethod();
this._initializeMixinLoaders();
// create variables and set default values
@ -43,8 +44,8 @@ function Network (container, data, options) {
// render and calculation settings
this.renderRefreshRate = 60; // hz (fps)
this.renderTimestep = 1000 / this.renderRefreshRate; // ms -- saves calculation later on
this.renderTime = 0.5 * this.renderTimestep; // measured time it takes to render a frame
this.maxPhysicsTicksPerRender = 3; // max amount of physics ticks per render step.
this.renderTime = 0; // measured time it takes to render a frame
this.physicsTime = 0; // measured time it takes to render a frame
this.physicsDiscreteStepsize = 0.50; // discrete stepsize of the simulation
this.initializing = true;
@ -349,6 +350,22 @@ function Network (container, data, options) {
// Extend Network with an Emitter mixin
Emitter(Network.prototype);
Network.prototype._determineBrowserMethod = function() {
var ua = navigator.userAgent.toLowerCase();
this.requiresTimeout = false;
if (ua.indexOf('msie 9.0') != -1) { // IE 9
this.requiresTimeout = true;
}
else if (ua.indexOf('safari') != -1) { // safari
if (ua.indexOf('chrome') <= -1) {
this.requiresTimeout = true;
}
}
}
/**
* Get the script path where the vis.js library is located
*
@ -2166,26 +2183,26 @@ Network.prototype._physicsTick = function() {
Network.prototype._animationStep = function() {
// reset the timer so a new scheduled animation step can be set
this.timer = undefined;
// handle the keyboad movement
this._handleNavigation();
// this schedules a new animation step
this.start();
// start the physics simulation
var calculationTime = Date.now();
var maxSteps = 1;
var startTime = Date.now();
this._physicsTick();
var timeRequired = Date.now() - calculationTime;
while (timeRequired < 0.9*(this.renderTimestep - this.renderTime) && maxSteps < this.maxPhysicsTicksPerRender) {
// run double speed if it is a little graph
if (this.renderTimestep - this.renderTime > 2*this.physicsTime) {
this._physicsTick();
timeRequired = Date.now() - calculationTime;
maxSteps++;
}
// start the rendering process
var renderTime = Date.now();
this.physicsTime = Date.now() - startTime;
var renderStartTime = Date.now();
this._redraw();
this.renderTime = Date.now() - renderTime;
this.renderTime = Date.now() - renderStartTime;
// this schedules a new animation step
this.start();
};
if (typeof window !== 'undefined') {
@ -2204,23 +2221,13 @@ Network.prototype.start = function() {
}
if (!this.timer) {
var ua = navigator.userAgent.toLowerCase();
var requiresTimeout = false;
if (ua.indexOf('msie 9.0') != -1) { // IE 9
requiresTimeout = true;
}
else if (ua.indexOf('safari') != -1) { // safari
if (ua.indexOf('chrome') <= -1) {
requiresTimeout = true;
}
}
if (requiresTimeout == true) {
if (this.requiresTimeout == true) {
this.timer = window.setTimeout(this._animationStep.bind(this), this.renderTimestep); // wait this.renderTimeStep milliseconds and perform the animation step function
}
else{
this.timer = window.requestAnimationFrame(this._animationStep.bind(this), this.renderTimestep); // wait this.renderTimeStep milliseconds and perform the animation step function
else {
this.timer = window.requestAnimationFrame(this._animationStep.bind(this)); // wait this.renderTimeStep milliseconds and perform the animation step function
}
}
}

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

@ -40,10 +40,9 @@ exports._calculateNodeForces = function () {
else {
repulsingForce = a * distance + b; // linear approx of 1 / (1 + Math.exp((distance / minimumDistance - 1) * steepness))
}
// amplify the repulsion for clusters.
repulsingForce *= (combinedClusterSize == 0) ? 1 : 1 + combinedClusterSize * this.constants.clustering.forceAmplification;
repulsingForce = repulsingForce / distance;
repulsingForce = repulsingForce / Math.max(distance,0.01*minimumDistance);
fx = dx * repulsingForce;
fy = dy * repulsingForce;
@ -52,6 +51,7 @@ exports._calculateNodeForces = function () {
node1.fy -= fy;
node2.fx += fx;
node2.fy += fy;
}
}
}

Loading…
Cancel
Save