Updated to latest springy
This commit is contained in:
parent
0c410b76fc
commit
c6ed340b3e
21
springy.js
21
springy.js
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Springy v2.3.0
|
* Springy v2.5.0
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010-2013 Dennis Hotson
|
* Copyright (c) 2010-2013 Dennis Hotson
|
||||||
*
|
*
|
||||||
|
@ -325,11 +325,12 @@
|
||||||
|
|
||||||
// -----------
|
// -----------
|
||||||
var Layout = Springy.Layout = {};
|
var Layout = Springy.Layout = {};
|
||||||
Layout.ForceDirected = function(graph, stiffness, repulsion, damping) {
|
Layout.ForceDirected = function(graph, stiffness, repulsion, damping, minEnergyThreshold) {
|
||||||
this.graph = graph;
|
this.graph = graph;
|
||||||
this.stiffness = stiffness; // spring stiffness constant
|
this.stiffness = stiffness; // spring stiffness constant
|
||||||
this.repulsion = repulsion; // repulsion constant
|
this.repulsion = repulsion; // repulsion constant
|
||||||
this.damping = damping; // velocity damping factor
|
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.nodePoints = {}; // keep track of points associated with nodes
|
||||||
this.edgeSprings = {}; // keep track of springs associated with edges
|
this.edgeSprings = {}; // keep track of springs associated with edges
|
||||||
|
@ -497,18 +498,14 @@
|
||||||
if (onRenderStart !== undefined) { onRenderStart(); }
|
if (onRenderStart !== undefined) { onRenderStart(); }
|
||||||
|
|
||||||
Springy.requestAnimationFrame(function step() {
|
Springy.requestAnimationFrame(function step() {
|
||||||
t.applyCoulombsLaw();
|
t.tick(0.03);
|
||||||
t.applyHookesLaw();
|
|
||||||
t.attractToCentre();
|
|
||||||
t.updateVelocity(0.03);
|
|
||||||
t.updatePosition(0.03);
|
|
||||||
|
|
||||||
if (render !== undefined) {
|
if (render !== undefined) {
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop simulation when energy of the system goes below a threshold
|
// 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;
|
t._started = false;
|
||||||
if (onRenderStop !== undefined) { onRenderStop(); }
|
if (onRenderStop !== undefined) { onRenderStop(); }
|
||||||
} else {
|
} else {
|
||||||
|
@ -521,6 +518,14 @@
|
||||||
this._stop = true;
|
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
|
// 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};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user