From 7faa4e5dd2b52aaaa1d35d19da1ad23e78c6c7ee Mon Sep 17 00:00:00 2001 From: Alex de Mulder Date: Mon, 24 Mar 2014 12:07:37 +0100 Subject: [PATCH] added freezeForStabilization option - experimental and undocumented --- dist/vis.js | 13 +++++++++++-- src/graph/Graph.js | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/dist/vis.js b/dist/vis.js index 6713752c..aa6cbfef 100644 --- a/dist/vis.js +++ b/dist/vis.js @@ -16151,6 +16151,7 @@ function Graph (container, data, options) { nodeSpacing: 100, direction: "UD" // UD, DU, LR, RL }, + freezeForStabilization: false, smoothCurves: true, maxVelocity: 10, minVelocity: 0.1, // px/s @@ -16479,6 +16480,7 @@ Graph.prototype.setOptions = function (options) { if (options.stabilize !== undefined) {this.stabilize = options.stabilize;} if (options.selectable !== undefined) {this.selectable = options.selectable;} if (options.smoothCurves !== undefined) {this.constants.smoothCurves = options.smoothCurves;} + if (options.freezeForStabilization !== undefined) {this.constants.freezeForStabilization = options.freezeForStabilization;} if (options.configurePhysics !== undefined){this.constants.configurePhysics = options.configurePhysics;} if (options.stabilizationIterations !== undefined) {this.constants.stabilizationIterations = options.stabilizationIterations;} @@ -17721,6 +17723,10 @@ Graph.prototype._drawEdges = function(ctx) { * @private */ Graph.prototype._stabilize = function() { + if (this.constants.freezeForStabilization == true) { + this._freezeDefinedNodes(); + } + // find stable position var count = 0; while (this.moving && count < this.constants.stabilizationIterations) { @@ -17728,11 +17734,14 @@ Graph.prototype._stabilize = function() { count++; } this.zoomExtent(false,true); + if (this.constants.freezeForStabilization == true) { + this._restoreFrozenNodes(); + } this.emit("stabilized",{iterations:count}); }; -Graph.prototype.freezeDefinedNodes = function() { +Graph.prototype._freezeDefinedNodes = function() { var nodes = this.nodes; for (var id in nodes) { if (nodes.hasOwnProperty(id)) { @@ -17746,7 +17755,7 @@ Graph.prototype.freezeDefinedNodes = function() { } }; -Graph.prototype.restoreFrozenNodes = function() { +Graph.prototype._restoreFrozenNodes = function() { var nodes = this.nodes; for (var id in nodes) { if (nodes.hasOwnProperty(id)) { diff --git a/src/graph/Graph.js b/src/graph/Graph.js index a72a8d08..28ddfa39 100644 --- a/src/graph/Graph.js +++ b/src/graph/Graph.js @@ -146,6 +146,7 @@ function Graph (container, data, options) { nodeSpacing: 100, direction: "UD" // UD, DU, LR, RL }, + freezeForStabilization: false, smoothCurves: true, maxVelocity: 10, minVelocity: 0.1, // px/s @@ -474,6 +475,7 @@ Graph.prototype.setOptions = function (options) { if (options.stabilize !== undefined) {this.stabilize = options.stabilize;} if (options.selectable !== undefined) {this.selectable = options.selectable;} if (options.smoothCurves !== undefined) {this.constants.smoothCurves = options.smoothCurves;} + if (options.freezeForStabilization !== undefined) {this.constants.freezeForStabilization = options.freezeForStabilization;} if (options.configurePhysics !== undefined){this.constants.configurePhysics = options.configurePhysics;} if (options.stabilizationIterations !== undefined) {this.constants.stabilizationIterations = options.stabilizationIterations;} @@ -1716,6 +1718,10 @@ Graph.prototype._drawEdges = function(ctx) { * @private */ Graph.prototype._stabilize = function() { + if (this.constants.freezeForStabilization == true) { + this._freezeDefinedNodes(); + } + // find stable position var count = 0; while (this.moving && count < this.constants.stabilizationIterations) { @@ -1723,11 +1729,14 @@ Graph.prototype._stabilize = function() { count++; } this.zoomExtent(false,true); + if (this.constants.freezeForStabilization == true) { + this._restoreFrozenNodes(); + } this.emit("stabilized",{iterations:count}); }; -Graph.prototype.freezeDefinedNodes = function() { +Graph.prototype._freezeDefinedNodes = function() { var nodes = this.nodes; for (var id in nodes) { if (nodes.hasOwnProperty(id)) { @@ -1741,7 +1750,7 @@ Graph.prototype.freezeDefinedNodes = function() { } }; -Graph.prototype.restoreFrozenNodes = function() { +Graph.prototype._restoreFrozenNodes = function() { var nodes = this.nodes; for (var id in nodes) { if (nodes.hasOwnProperty(id)) {