Browse Source

added freezeForStabilization option - experimental and undocumented

css_transitions
Alex de Mulder 10 years ago
parent
commit
7faa4e5dd2
2 changed files with 22 additions and 4 deletions
  1. +11
    -2
      dist/vis.js
  2. +11
    -2
      src/graph/Graph.js

+ 11
- 2
dist/vis.js View File

@ -16151,6 +16151,7 @@ function Graph (container, data, options) {
nodeSpacing: 100, nodeSpacing: 100,
direction: "UD" // UD, DU, LR, RL direction: "UD" // UD, DU, LR, RL
}, },
freezeForStabilization: false,
smoothCurves: true, smoothCurves: true,
maxVelocity: 10, maxVelocity: 10,
minVelocity: 0.1, // px/s minVelocity: 0.1, // px/s
@ -16479,6 +16480,7 @@ Graph.prototype.setOptions = function (options) {
if (options.stabilize !== undefined) {this.stabilize = options.stabilize;} if (options.stabilize !== undefined) {this.stabilize = options.stabilize;}
if (options.selectable !== undefined) {this.selectable = options.selectable;} if (options.selectable !== undefined) {this.selectable = options.selectable;}
if (options.smoothCurves !== undefined) {this.constants.smoothCurves = options.smoothCurves;} 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.configurePhysics !== undefined){this.constants.configurePhysics = options.configurePhysics;}
if (options.stabilizationIterations !== undefined) {this.constants.stabilizationIterations = options.stabilizationIterations;} if (options.stabilizationIterations !== undefined) {this.constants.stabilizationIterations = options.stabilizationIterations;}
@ -17721,6 +17723,10 @@ Graph.prototype._drawEdges = function(ctx) {
* @private * @private
*/ */
Graph.prototype._stabilize = function() { Graph.prototype._stabilize = function() {
if (this.constants.freezeForStabilization == true) {
this._freezeDefinedNodes();
}
// find stable position // find stable position
var count = 0; var count = 0;
while (this.moving && count < this.constants.stabilizationIterations) { while (this.moving && count < this.constants.stabilizationIterations) {
@ -17728,11 +17734,14 @@ Graph.prototype._stabilize = function() {
count++; count++;
} }
this.zoomExtent(false,true); this.zoomExtent(false,true);
if (this.constants.freezeForStabilization == true) {
this._restoreFrozenNodes();
}
this.emit("stabilized",{iterations:count}); this.emit("stabilized",{iterations:count});
}; };
Graph.prototype.freezeDefinedNodes = function() {
Graph.prototype._freezeDefinedNodes = function() {
var nodes = this.nodes; var nodes = this.nodes;
for (var id in nodes) { for (var id in nodes) {
if (nodes.hasOwnProperty(id)) { if (nodes.hasOwnProperty(id)) {
@ -17746,7 +17755,7 @@ Graph.prototype.freezeDefinedNodes = function() {
} }
}; };
Graph.prototype.restoreFrozenNodes = function() {
Graph.prototype._restoreFrozenNodes = function() {
var nodes = this.nodes; var nodes = this.nodes;
for (var id in nodes) { for (var id in nodes) {
if (nodes.hasOwnProperty(id)) { if (nodes.hasOwnProperty(id)) {

+ 11
- 2
src/graph/Graph.js View File

@ -146,6 +146,7 @@ function Graph (container, data, options) {
nodeSpacing: 100, nodeSpacing: 100,
direction: "UD" // UD, DU, LR, RL direction: "UD" // UD, DU, LR, RL
}, },
freezeForStabilization: false,
smoothCurves: true, smoothCurves: true,
maxVelocity: 10, maxVelocity: 10,
minVelocity: 0.1, // px/s minVelocity: 0.1, // px/s
@ -474,6 +475,7 @@ Graph.prototype.setOptions = function (options) {
if (options.stabilize !== undefined) {this.stabilize = options.stabilize;} if (options.stabilize !== undefined) {this.stabilize = options.stabilize;}
if (options.selectable !== undefined) {this.selectable = options.selectable;} if (options.selectable !== undefined) {this.selectable = options.selectable;}
if (options.smoothCurves !== undefined) {this.constants.smoothCurves = options.smoothCurves;} 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.configurePhysics !== undefined){this.constants.configurePhysics = options.configurePhysics;}
if (options.stabilizationIterations !== undefined) {this.constants.stabilizationIterations = options.stabilizationIterations;} if (options.stabilizationIterations !== undefined) {this.constants.stabilizationIterations = options.stabilizationIterations;}
@ -1716,6 +1718,10 @@ Graph.prototype._drawEdges = function(ctx) {
* @private * @private
*/ */
Graph.prototype._stabilize = function() { Graph.prototype._stabilize = function() {
if (this.constants.freezeForStabilization == true) {
this._freezeDefinedNodes();
}
// find stable position // find stable position
var count = 0; var count = 0;
while (this.moving && count < this.constants.stabilizationIterations) { while (this.moving && count < this.constants.stabilizationIterations) {
@ -1723,11 +1729,14 @@ Graph.prototype._stabilize = function() {
count++; count++;
} }
this.zoomExtent(false,true); this.zoomExtent(false,true);
if (this.constants.freezeForStabilization == true) {
this._restoreFrozenNodes();
}
this.emit("stabilized",{iterations:count}); this.emit("stabilized",{iterations:count});
}; };
Graph.prototype.freezeDefinedNodes = function() {
Graph.prototype._freezeDefinedNodes = function() {
var nodes = this.nodes; var nodes = this.nodes;
for (var id in nodes) { for (var id in nodes) {
if (nodes.hasOwnProperty(id)) { if (nodes.hasOwnProperty(id)) {
@ -1741,7 +1750,7 @@ Graph.prototype.freezeDefinedNodes = function() {
} }
}; };
Graph.prototype.restoreFrozenNodes = function() {
Graph.prototype._restoreFrozenNodes = function() {
var nodes = this.nodes; var nodes = this.nodes;
for (var id in nodes) { for (var id in nodes) {
if (nodes.hasOwnProperty(id)) { if (nodes.hasOwnProperty(id)) {

Loading…
Cancel
Save