From c6ed340b3e2132613ecd89bfa3d4616bdb0cef99 Mon Sep 17 00:00:00 2001 From: Dennis Hotson Date: Sun, 1 Jun 2014 18:49:26 +1000 Subject: [PATCH] Updated to latest springy --- springy.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/springy.js b/springy.js index 2304747..0e785e9 100644 --- a/springy.js +++ b/springy.js @@ -1,5 +1,5 @@ /** - * Springy v2.3.0 + * Springy v2.5.0 * * Copyright (c) 2010-2013 Dennis Hotson * @@ -325,11 +325,12 @@ // ----------- var Layout = Springy.Layout = {}; - Layout.ForceDirected = function(graph, stiffness, repulsion, damping) { + Layout.ForceDirected = function(graph, stiffness, repulsion, damping, minEnergyThreshold) { this.graph = graph; this.stiffness = stiffness; // spring stiffness constant this.repulsion = repulsion; // repulsion constant this.damping = damping; // velocity damping factor + this.minEnergyThreshold = minEnergyThreshold || 0.01; //threshold used to determine render stop this.nodePoints = {}; // keep track of points associated with nodes this.edgeSprings = {}; // keep track of springs associated with edges @@ -497,18 +498,14 @@ if (onRenderStart !== undefined) { onRenderStart(); } Springy.requestAnimationFrame(function step() { - t.applyCoulombsLaw(); - t.applyHookesLaw(); - t.attractToCentre(); - t.updateVelocity(0.03); - t.updatePosition(0.03); + t.tick(0.03); if (render !== undefined) { render(); } // stop simulation when energy of the system goes below a threshold - if (t._stop || t.totalEnergy() < 0.01) { + if (t._stop || t.totalEnergy() < t.minEnergyThreshold) { t._started = false; if (onRenderStop !== undefined) { onRenderStop(); } } else { @@ -521,6 +518,14 @@ this._stop = true; } + Layout.ForceDirected.prototype.tick = function(timestep) { + this.applyCoulombsLaw(); + this.applyHookesLaw(); + this.attractToCentre(); + this.updateVelocity(timestep); + this.updatePosition(timestep); + }; + // Find the nearest point to a particular position Layout.ForceDirected.prototype.nearest = function(pos) { var min = {node: null, point: null, distance: null};