Browse Source

- Fixed stabilized event not firing if layout algorithm does very well.

webworkersNetwork
Alex de Mulder 9 years ago
parent
commit
985693e123
4 changed files with 39 additions and 9 deletions
  1. +1
    -0
      HISTORY.md
  2. +19
    -4
      dist/vis.js
  3. +3
    -2
      lib/network/modules/LayoutEngine.js
  4. +16
    -3
      lib/network/modules/PhysicsEngine.js

+ 1
- 0
HISTORY.md View File

@ -8,6 +8,7 @@ http://visjs.org
- Fixed Phantom Edges during clustering. - Fixed Phantom Edges during clustering.
- Fixed scaling not doing anything to edges. - Fixed scaling not doing anything to edges.
- Fixed setting font to null so the network won't crash anymore. - Fixed setting font to null so the network won't crash anymore.
- Fixed stabilized event not firing if layout algorithm does very well.
## 2015-09-07, version 4.8.1 ## 2015-09-07, version 4.8.1

+ 19
- 4
dist/vis.js View File

@ -33323,9 +33323,11 @@ return /******/ (function(modules) { // webpackBootstrap
value: function _emitStabilized() { value: function _emitStabilized() {
var _this2 = this; var _this2 = this;
var amountOfIterations = arguments.length <= 0 || arguments[0] === undefined ? this.stabilizationIterations : arguments[0];
if (this.stabilizationIterations > 1) { if (this.stabilizationIterations > 1) {
setTimeout(function () { setTimeout(function () {
_this2.body.emitter.emit('stabilized', { iterations: _this2.stabilizationIterations });
_this2.body.emitter.emit('stabilized', { iterations: amountOfIterations });
_this2.stabilizationIterations = 0; _this2.stabilizationIterations = 0;
}, 0); }, 0);
} }
@ -33697,6 +33699,12 @@ return /******/ (function(modules) { // webpackBootstrap
}, { }, {
key: '_stabilizationBatch', key: '_stabilizationBatch',
value: function _stabilizationBatch() { value: function _stabilizationBatch() {
// this is here to ensure that there is at least one start event.
if (this.startedStabilization === false) {
this.body.emitter.emit('startStabilizing');
this.startedStabilization = true;
}
var count = 0; var count = 0;
while (this.stabilized === false && count < this.options.stabilization.updateInterval && this.stabilizationIterations < this.targetIterations) { while (this.stabilized === false && count < this.options.stabilization.updateInterval && this.stabilizationIterations < this.targetIterations) {
this.physicsTick(); this.physicsTick();
@ -33731,7 +33739,13 @@ return /******/ (function(modules) { // webpackBootstrap
this.body.emitter.emit('_requestRedraw'); this.body.emitter.emit('_requestRedraw');
if (this.stabilized === true) { if (this.stabilized === true) {
this._emitStabilized();
// I want at least one stabilized event if there is nothing to stabilize.
if (this.stabilizationIterations < 2) {
this.stabilizationIterations = 2;
this._emitStabilized(0); // the zero overrules the iterations
} else {
this._emitStabilized();
}
} else { } else {
this.startSimulation(); this.startSimulation();
} }
@ -39261,9 +39275,10 @@ return /******/ (function(modules) { // webpackBootstrap
this._shiftToCenter(); this._shiftToCenter();
// perturb the nodes a little bit to force the physics to kick in // perturb the nodes a little bit to force the physics to kick in
var offset = 70;
for (var i = 0; i < this.body.nodeIndices.length; i++) { for (var i = 0; i < this.body.nodeIndices.length; i++) {
this.body.nodes[this.body.nodeIndices[i]].x += (0.5 - this.seededRandom()) * 50;
this.body.nodes[this.body.nodeIndices[i]].y += (0.5 - this.seededRandom()) * 50;
this.body.nodes[this.body.nodeIndices[i]].x += (0.5 - this.seededRandom()) * offset;
this.body.nodes[this.body.nodeIndices[i]].y += (0.5 - this.seededRandom()) * offset;
} }
// uncluster all clusters // uncluster all clusters

+ 3
- 2
lib/network/modules/LayoutEngine.js View File

@ -224,9 +224,10 @@ class LayoutEngine {
this._shiftToCenter(); this._shiftToCenter();
// perturb the nodes a little bit to force the physics to kick in // perturb the nodes a little bit to force the physics to kick in
let offset = 70;
for (let i = 0; i < this.body.nodeIndices.length; i++) { for (let i = 0; i < this.body.nodeIndices.length; i++) {
this.body.nodes[this.body.nodeIndices[i]].x += (0.5 - this.seededRandom())*50;
this.body.nodes[this.body.nodeIndices[i]].y += (0.5 - this.seededRandom())*50;
this.body.nodes[this.body.nodeIndices[i]].x += (0.5 - this.seededRandom())*offset;
this.body.nodes[this.body.nodeIndices[i]].y += (0.5 - this.seededRandom())*offset;
} }
// uncluster all clusters // uncluster all clusters

+ 16
- 3
lib/network/modules/PhysicsEngine.js View File

@ -273,10 +273,10 @@ class PhysicsEngine {
* trigger the stabilized event. * trigger the stabilized event.
* @private * @private
*/ */
_emitStabilized() {
_emitStabilized(amountOfIterations = this.stabilizationIterations) {
if (this.stabilizationIterations > 1) { if (this.stabilizationIterations > 1) {
setTimeout(() => { setTimeout(() => {
this.body.emitter.emit('stabilized', {iterations: this.stabilizationIterations});
this.body.emitter.emit('stabilized', {iterations: amountOfIterations});
this.stabilizationIterations = 0; this.stabilizationIterations = 0;
}, 0); }, 0);
} }
@ -631,6 +631,12 @@ class PhysicsEngine {
* @private * @private
*/ */
_stabilizationBatch() { _stabilizationBatch() {
// this is here to ensure that there is at least one start event.
if (this.startedStabilization === false) {
this.body.emitter.emit('startStabilizing');
this.startedStabilization = true;
}
var count = 0; var count = 0;
while (this.stabilized === false && count < this.options.stabilization.updateInterval && this.stabilizationIterations < this.targetIterations) { while (this.stabilized === false && count < this.options.stabilization.updateInterval && this.stabilizationIterations < this.targetIterations) {
this.physicsTick(); this.physicsTick();
@ -665,7 +671,14 @@ class PhysicsEngine {
this.body.emitter.emit('_requestRedraw'); this.body.emitter.emit('_requestRedraw');
if (this.stabilized === true) { if (this.stabilized === true) {
this._emitStabilized();
// I want at least one stabilized event if there is nothing to stabilize.
if (this.stabilizationIterations < 2) {
this.stabilizationIterations = 2;
this._emitStabilized(0); // the zero overrules the iterations
}
else {
this._emitStabilized();
}
} }
else { else {
this.startSimulation(); this.startSimulation();

Loading…
Cancel
Save