From 66c788b9b424d3fa5c477a63437f862dbe4f4db1 Mon Sep 17 00:00:00 2001 From: Alex de Mulder Date: Wed, 27 Aug 2014 11:40:15 +0200 Subject: [PATCH] changed movement parameter to only say stabilized if the support nodes are stabilized as well, though retaining the demand that both nodes and support nodes are stabilized before emitting event and stopping simulation. --- dist/vis.js | 40 +++++++++++++++++---------- examples/network/02_random_nodes.html | 3 +- lib/network/Network.js | 24 ++++++++++------ lib/network/mixins/SectorsMixin.js | 16 +++++++---- 4 files changed, 54 insertions(+), 29 deletions(-) diff --git a/dist/vis.js b/dist/vis.js index 6b46f36c..40b932bd 100644 --- a/dist/vis.js +++ b/dist/vis.js @@ -22605,7 +22605,7 @@ return /******/ (function(modules) { // webpackBootstrap * * @private */ - Network.prototype._discreteStepNodes = function(checkMovement) { + Network.prototype._discreteStepNodes = function() { var interval = this.physicsDiscreteStepsize; var nodes = this.nodes; var nodeId; @@ -22628,16 +22628,16 @@ return /******/ (function(modules) { // webpackBootstrap } } - if (nodesPresent == true && (checkMovement === undefined || checkMovement == true)) { + if (nodesPresent == true) { var vminCorrected = this.constants.minVelocity / Math.max(this.scale,0.05); if (vminCorrected > 0.5*this.constants.maxVelocity) { - this.moving = true; + return true; } else { - this.moving = this._isMoving(vminCorrected); - this.moving = this.moving || this.configurePhysics; + return this._isMoving(vminCorrected); } } + return false; }; /** @@ -22648,13 +22648,21 @@ return /******/ (function(modules) { // webpackBootstrap Network.prototype._physicsTick = function() { if (!this.freezeSimulation) { if (this.moving == true) { + var mainMovingStatus = false; + var supportMovingStatus = false; + this._doInAllActiveSectors("_initializeForceCalculation"); - this._doInAllActiveSectors("_discreteStepNodes"); + var mainMoving = this._doInAllActiveSectors("_discreteStepNodes"); if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) { - this._doInSupportSector("_discreteStepNodes", false); + supportMovingStatus = this._doInSupportSector("_discreteStepNodes"); } + // gather movement data from all sectors, if one moves, we are NOT stabilzied + for (var i = 0; i < mainMoving.length; i++) {mainMovingStatus = mainMoving[0] || mainMovingStatus;} - this.stabilizationIterations++; + // determine if the network has stabilzied + this.moving = mainMovingStatus || supportMovingStatus; + + this.stabilizationIterations++; } } }; @@ -29293,12 +29301,13 @@ return /******/ (function(modules) { // webpackBootstrap * @private */ exports._doInAllActiveSectors = function(runFunction,argument) { + var returnValues = []; if (argument === undefined) { for (var sector in this.sectors["active"]) { if (this.sectors["active"].hasOwnProperty(sector)) { // switch the global references to those of this sector this._switchToActiveSector(sector); - this[runFunction](); + returnValues.push( this[runFunction]() ); } } } @@ -29309,16 +29318,17 @@ return /******/ (function(modules) { // webpackBootstrap this._switchToActiveSector(sector); var args = Array.prototype.splice.call(arguments, 1); if (args.length > 1) { - this[runFunction](args[0],args[1]); + returnValues.push( this[runFunction](args[0],args[1]) ); } else { - this[runFunction](argument); + returnValues.push( this[runFunction](argument) ); } } } } // we revert the global references back to our active sector this._loadLatestSector(); + return returnValues; }; @@ -29332,22 +29342,24 @@ return /******/ (function(modules) { // webpackBootstrap * @private */ exports._doInSupportSector = function(runFunction,argument) { + var returnValues = false; if (argument === undefined) { this._switchToSupportSector(); - this[runFunction](); + returnValues = this[runFunction](); } else { this._switchToSupportSector(); var args = Array.prototype.splice.call(arguments, 1); if (args.length > 1) { - this[runFunction](args[0],args[1]); + returnValues = this[runFunction](args[0],args[1]); } else { - this[runFunction](argument); + returnValues = this[runFunction](argument); } } // we revert the global references back to our active sector this._loadLatestSector(); + return returnValues; }; diff --git a/examples/network/02_random_nodes.html b/examples/network/02_random_nodes.html index 034bb3b5..34c42ebe 100644 --- a/examples/network/02_random_nodes.html +++ b/examples/network/02_random_nodes.html @@ -88,7 +88,7 @@ document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes; }); network.on('stabilized', function (params) { - console.log('stabilized after ' + params.iterations + ' iterations'); + document.getElementById('stabilization').innerHTML = 'Stabilization took ' + params.iterations + ' iterations.'; }); } @@ -106,5 +106,6 @@

+

diff --git a/lib/network/Network.js b/lib/network/Network.js index 4a12792e..1b0551cf 100644 --- a/lib/network/Network.js +++ b/lib/network/Network.js @@ -1947,7 +1947,7 @@ Network.prototype._isMoving = function(vmin) { * * @private */ -Network.prototype._discreteStepNodes = function(checkMovement) { +Network.prototype._discreteStepNodes = function() { var interval = this.physicsDiscreteStepsize; var nodes = this.nodes; var nodeId; @@ -1970,16 +1970,16 @@ Network.prototype._discreteStepNodes = function(checkMovement) { } } - if (nodesPresent == true && (checkMovement === undefined || checkMovement == true)) { + if (nodesPresent == true) { var vminCorrected = this.constants.minVelocity / Math.max(this.scale,0.05); if (vminCorrected > 0.5*this.constants.maxVelocity) { - this.moving = true; + return true; } else { - this.moving = this._isMoving(vminCorrected); - this.moving = this.moving || this.configurePhysics; + return this._isMoving(vminCorrected); } } + return false; }; /** @@ -1990,13 +1990,21 @@ Network.prototype._discreteStepNodes = function(checkMovement) { Network.prototype._physicsTick = function() { if (!this.freezeSimulation) { if (this.moving == true) { + var mainMovingStatus = false; + var supportMovingStatus = false; + this._doInAllActiveSectors("_initializeForceCalculation"); - this._doInAllActiveSectors("_discreteStepNodes"); + var mainMoving = this._doInAllActiveSectors("_discreteStepNodes"); if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) { - this._doInSupportSector("_discreteStepNodes", false); + supportMovingStatus = this._doInSupportSector("_discreteStepNodes"); } + // gather movement data from all sectors, if one moves, we are NOT stabilzied + for (var i = 0; i < mainMoving.length; i++) {mainMovingStatus = mainMoving[0] || mainMovingStatus;} + + // determine if the network has stabilzied + this.moving = mainMovingStatus || supportMovingStatus; - this.stabilizationIterations++; + this.stabilizationIterations++; } } }; diff --git a/lib/network/mixins/SectorsMixin.js b/lib/network/mixins/SectorsMixin.js index 03e0075a..9751f514 100644 --- a/lib/network/mixins/SectorsMixin.js +++ b/lib/network/mixins/SectorsMixin.js @@ -365,12 +365,13 @@ exports._collapseSector = function() { * @private */ exports._doInAllActiveSectors = function(runFunction,argument) { + var returnValues = []; if (argument === undefined) { for (var sector in this.sectors["active"]) { if (this.sectors["active"].hasOwnProperty(sector)) { // switch the global references to those of this sector this._switchToActiveSector(sector); - this[runFunction](); + returnValues.push( this[runFunction]() ); } } } @@ -381,16 +382,17 @@ exports._doInAllActiveSectors = function(runFunction,argument) { this._switchToActiveSector(sector); var args = Array.prototype.splice.call(arguments, 1); if (args.length > 1) { - this[runFunction](args[0],args[1]); + returnValues.push( this[runFunction](args[0],args[1]) ); } else { - this[runFunction](argument); + returnValues.push( this[runFunction](argument) ); } } } } // we revert the global references back to our active sector this._loadLatestSector(); + return returnValues; }; @@ -404,22 +406,24 @@ exports._doInAllActiveSectors = function(runFunction,argument) { * @private */ exports._doInSupportSector = function(runFunction,argument) { + var returnValues = false; if (argument === undefined) { this._switchToSupportSector(); - this[runFunction](); + returnValues = this[runFunction](); } else { this._switchToSupportSector(); var args = Array.prototype.splice.call(arguments, 1); if (args.length > 1) { - this[runFunction](args[0],args[1]); + returnValues = this[runFunction](args[0],args[1]); } else { - this[runFunction](argument); + returnValues = this[runFunction](argument); } } // we revert the global references back to our active sector this._loadLatestSector(); + return returnValues; };