Updated to latest springy version

This commit is contained in:
Dennis Hotson 2013-03-14 21:56:07 +11:00
parent 8b12e8b038
commit 69cfbb490d
3 changed files with 16 additions and 3 deletions

View File

@ -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));

View File

@ -168,6 +168,10 @@ of nodes and edges:
} }
**/ **/
// parse if a string is passed (EC5+ browsers)
if (typeof json == 'string' || json instanceof String) {
json = JSON.parse( json );
}
if ('nodes' in json || 'edges' in json) { if ('nodes' in json || 'edges' in json) {
this.addNodes.apply(this, json['nodes']); this.addNodes.apply(this, json['nodes']);
@ -464,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();
@ -477,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 {
@ -486,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};
@ -624,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 ) {

View File

@ -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);
}, },