Browse Source

- Fixed the `'stabilized'` event, it's now guaranteed to fire only once and fire after the graph is fully stabilized.

- Fixed an initial rendering before the graph has been stabilized (introduced at fixing #131).
v3_develop
jos 9 years ago
parent
commit
37e5003f2c
6 changed files with 63 additions and 36 deletions
  1. +3
    -0
      HISTORY.md
  2. +23
    -11
      dist/vis.js
  3. +1
    -1
      dist/vis.map
  4. +3
    -3
      dist/vis.min.js
  5. +11
    -11
      examples/network/02_random_nodes.html
  6. +22
    -10
      lib/network/Network.js

+ 3
- 0
HISTORY.md View File

@ -32,6 +32,9 @@ http://visjs.org
- Implemented option `clickToUse`.
- Fixed page scroll event not being blocked when moving around in Network
using arrow keys.
- Fixed the `'stabilized'` event, it's now guaranteed to fire only once and
fire after the graph is fully stabilized.
- Fixed an initial rendering before the graph has been stabilized.
### Graph2D

+ 23
- 11
dist/vis.js View File

@ -5,7 +5,7 @@
* A dynamic, browser-based visualization library.
*
* @version 3.2.1-SNAPSHOT
* @date 2014-08-25
* @date 2014-08-26
*
* @license
* Copyright (C) 2011-2014 Almende B.V, http://almende.com
@ -14069,6 +14069,8 @@ return /******/ (function(modules) { // webpackBootstrap
// other vars
this.freezeSimulation = false;// freeze the simulation
this.cachedFunctions = {};
this.stabilized = false;
this.stabilizationIterations = null;
// containers for nodes and edges
this.calculationNodes = {};
@ -14351,12 +14353,9 @@ return /******/ (function(modules) { // webpackBootstrap
if (!disableStart) {
// find a stable position or start animating to a stable position
if (this.constants.stabilize) {
var me = this;
setTimeout(function() {me._stabilize(); me.start();},0)
}
else {
this.start();
this._stabilize();
}
this.start();
}
};
@ -15696,7 +15695,6 @@ return /******/ (function(modules) { // webpackBootstrap
if (this.constants.freezeForStabilization == true) {
this._restoreFrozenNodes();
}
this.emit("stabilized",{iterations:count});
};
/**
@ -15790,11 +15788,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
else {
this.moving = this._isMoving(vminCorrected);
if (this.moving == false) {
this.emit("stabilized",{iterations:null});
}
this.moving = this.moving || this.configurePhysics;
}
}
};
@ -15813,6 +15807,10 @@ return /******/ (function(modules) { // webpackBootstrap
this._doInSupportSector("_discreteStepNodes", false);
}
this._findCenter(this._getRange())
if (!this.stabilized) {
this.stabilizationIterations++;
}
}
}
};
@ -15883,6 +15881,20 @@ return /******/ (function(modules) { // webpackBootstrap
}
else {
this._redraw();
if (!this.stabilized) {
// trigger the "stabilized" event.
// The event is triggered on the next tick, to prevent the case that
// it is fired while initializing the Network, in which case you would not
// be able to catch it
this.stabilized = true;
var me = this;
setTimeout(function () {
me.emit("stabilized",{
iterations: me.stabilizationIterations
});
}, 0);
}
}
};

+ 1
- 1
dist/vis.map
File diff suppressed because it is too large
View File


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


+ 11
- 11
examples/network/02_random_nodes.html View File

@ -77,17 +77,17 @@
edges: edges
};
var options = {
edges: {
},
stabilize: false
};
network = new vis.Network(container, data, options);
// add event listeners
network.on('select', function(params) {
document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
});
var options = {
edges: {
},
stabilize: false
};
network = new vis.Network(container, data, options);
// add event listeners
network.on('select', function(params) {
document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
});
}
</script>
</head>

+ 22
- 10
lib/network/Network.js View File

@ -252,6 +252,8 @@ function Network (container, data, options) {
// other vars
this.freezeSimulation = false;// freeze the simulation
this.cachedFunctions = {};
this.stabilized = false;
this.stabilizationIterations = null;
// containers for nodes and edges
this.calculationNodes = {};
@ -534,12 +536,9 @@ Network.prototype.setData = function(data, disableStart) {
if (!disableStart) {
// find a stable position or start animating to a stable position
if (this.constants.stabilize) {
var me = this;
setTimeout(function() {me._stabilize(); me.start();},0)
}
else {
this.start();
this._stabilize();
}
this.start();
}
};
@ -1879,7 +1878,6 @@ Network.prototype._stabilize = function() {
if (this.constants.freezeForStabilization == true) {
this._restoreFrozenNodes();
}
this.emit("stabilized",{iterations:count});
};
/**
@ -1973,11 +1971,7 @@ Network.prototype._discreteStepNodes = function(checkMovement) {
}
else {
this.moving = this._isMoving(vminCorrected);
if (this.moving == false) {
this.emit("stabilized",{iterations:null});
}
this.moving = this.moving || this.configurePhysics;
}
}
};
@ -1996,6 +1990,10 @@ Network.prototype._physicsTick = function() {
this._doInSupportSector("_discreteStepNodes", false);
}
this._findCenter(this._getRange())
if (!this.stabilized) {
this.stabilizationIterations++;
}
}
}
};
@ -2066,6 +2064,20 @@ Network.prototype.start = function() {
}
else {
this._redraw();
if (!this.stabilized) {
// trigger the "stabilized" event.
// The event is triggered on the next tick, to prevent the case that
// it is fired while initializing the Network, in which case you would not
// be able to catch it
this.stabilized = true;
var me = this;
setTimeout(function () {
me.emit("stabilized",{
iterations: me.stabilizationIterations
});
}, 0);
}
}
};

Loading…
Cancel
Save