diff --git a/springy.js b/springy.js index 392f94b..c93c399 100644 --- a/springy.js +++ b/springy.js @@ -327,12 +327,13 @@ // ----------- var Layout = Springy.Layout = {}; - Layout.ForceDirected = function(graph, stiffness, repulsion, damping, minEnergyThreshold) { + Layout.ForceDirected = function(graph, stiffness, repulsion, damping, minEnergyThreshold, maxSpeed) { 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.maxSpeed = maxSpeed || Infinity; // nodes aren't allowed to exceed this speed this.nodePoints = {}; // keep track of points associated with nodes this.edgeSprings = {}; // keep track of springs associated with edges @@ -451,6 +452,9 @@ // Is this, along with updatePosition below, the only places that your // integration code exist? point.v = point.v.add(point.a.multiply(timestep)).multiply(this.damping); + if (point.v.magnitude() > this.maxSpeed) { + point.v = point.v.normalise().multiply(this.maxSpeed); + } point.a = new Vector(0,0); }); };