Added method to stop layout calculations
This commit is contained in:
parent
459904b833
commit
4c0a9e3e28
|
@ -29,7 +29,7 @@ graph.newEdge(dennis, bianca, {color: '#CC333F'});
|
||||||
graph.newEdge(bianca, monty, {color: '#EB6841'});
|
graph.newEdge(bianca, monty, {color: '#EB6841'});
|
||||||
|
|
||||||
jQuery(function(){
|
jQuery(function(){
|
||||||
var springy = jQuery('#springydemo').springy({
|
var springy = window.springy = jQuery('#springydemo').springy({
|
||||||
graph: graph,
|
graph: graph,
|
||||||
nodeSelected: function(node){
|
nodeSelected: function(node){
|
||||||
console.log('Node selected: ' + JSON.stringify(node.data));
|
console.log('Node selected: ' + JSON.stringify(node.data));
|
||||||
|
|
11
springy.js
11
springy.js
|
@ -468,6 +468,7 @@ Layout.ForceDirected.prototype.start = function(render, done) {
|
||||||
|
|
||||||
if (this._started) return;
|
if (this._started) return;
|
||||||
this._started = true;
|
this._started = true;
|
||||||
|
this._stop = false;
|
||||||
|
|
||||||
Layout.requestAnimationFrame(function step() {
|
Layout.requestAnimationFrame(function step() {
|
||||||
t.applyCoulombsLaw();
|
t.applyCoulombsLaw();
|
||||||
|
@ -481,7 +482,7 @@ Layout.ForceDirected.prototype.start = function(render, done) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop simulation when energy of the system goes below a threshold
|
// stop simulation when energy of the system goes below a threshold
|
||||||
if (t.totalEnergy() < 0.01) {
|
if (t._stop || t.totalEnergy() < 0.01) {
|
||||||
t._started = false;
|
t._started = false;
|
||||||
if (done !== undefined) { done(); }
|
if (done !== undefined) { done(); }
|
||||||
} else {
|
} else {
|
||||||
|
@ -490,6 +491,10 @@ Layout.ForceDirected.prototype.start = function(render, done) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Layout.ForceDirected.prototype.stop = function() {
|
||||||
|
this._stop = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Find the nearest point to a particular position
|
// Find the nearest point to a particular position
|
||||||
Layout.ForceDirected.prototype.nearest = function(pos) {
|
Layout.ForceDirected.prototype.nearest = function(pos) {
|
||||||
var min = {node: null, point: null, distance: null};
|
var min = {node: null, point: null, distance: null};
|
||||||
|
@ -628,6 +633,10 @@ Renderer.prototype.start = function() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Renderer.prototype.stop = function() {
|
||||||
|
this.layout.stop();
|
||||||
|
};
|
||||||
|
|
||||||
// Array.forEach implementation for IE support..
|
// Array.forEach implementation for IE support..
|
||||||
//https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
|
//https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
|
||||||
if ( !Array.prototype.forEach ) {
|
if ( !Array.prototype.forEach ) {
|
||||||
|
|
|
@ -131,7 +131,7 @@ jQuery.fn.springy = function(params) {
|
||||||
return 20;
|
return 20;
|
||||||
};
|
};
|
||||||
|
|
||||||
var renderer = new Renderer(layout,
|
var renderer = this.renderer = new Renderer(layout,
|
||||||
function clear() {
|
function clear() {
|
||||||
ctx.clearRect(0,0,canvas.width,canvas.height);
|
ctx.clearRect(0,0,canvas.width,canvas.height);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user