Compare commits

...

8 Commits

Author SHA1 Message Date
Dennis Hotson
9654b64f85
Merge pull request #98 from iangilman/render
Changed onRender to onRenderFrame
2018-03-06 11:32:22 +11:00
Ian Gilman
8beaeff267 Changed onRender to onRenderFrame 2018-03-05 16:25:05 -08:00
Dennis Hotson
73ecbc773c
Merge pull request #97 from iangilman/render
Added onRender callback for after each frame
2018-03-01 23:54:53 +11:00
Ian Gilman
73fd49c58a Added onRender callback for after each frame 2018-02-28 16:33:23 -08:00
Dennis Hotson
6158298c9e Merge pull request #85 from mwcz/max-speed
add maxSpeed parameter to Layout.ForceDirected constructor
2016-12-29 10:22:56 +11:00
mwcz
e490969ea0 add maxSpeed parameter to Layout.ForceDirected constructor 2016-07-19 14:38:01 -04:00
Dennis Hotson
559a400331 Merge pull request #70 from shigeruNakajima/node_color
Add nodes a 'color' property.
2014-12-08 10:52:18 +11:00
shigeru.nakajima
322a7bae8b Add node color. 2014-10-10 18:48:27 +09:00
2 changed files with 11 additions and 3 deletions

View File

@ -327,12 +327,13 @@
// ----------- // -----------
var Layout = Springy.Layout = {}; 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.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.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.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
@ -451,6 +452,9 @@
// Is this, along with updatePosition below, the only places that your // Is this, along with updatePosition below, the only places that your
// integration code exist? // integration code exist?
point.v = point.v.add(point.a.multiply(timestep)).multiply(this.damping); 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); point.a = new Vector(0,0);
}); });
}; };
@ -641,14 +645,16 @@
* Renderer handles the layout rendering loop * Renderer handles the layout rendering loop
* @param onRenderStop optional callback function that gets executed whenever rendering stops. * @param onRenderStop optional callback function that gets executed whenever rendering stops.
* @param onRenderStart optional callback function that gets executed whenever rendering starts. * @param onRenderStart optional callback function that gets executed whenever rendering starts.
* @param onRenderFrame optional callback function that gets executed after each frame is rendered.
*/ */
var Renderer = Springy.Renderer = function(layout, clear, drawEdge, drawNode, onRenderStop, onRenderStart) { var Renderer = Springy.Renderer = function(layout, clear, drawEdge, drawNode, onRenderStop, onRenderStart, onRenderFrame) {
this.layout = layout; this.layout = layout;
this.clear = clear; this.clear = clear;
this.drawEdge = drawEdge; this.drawEdge = drawEdge;
this.drawNode = drawNode; this.drawNode = drawNode;
this.onRenderStop = onRenderStop; this.onRenderStop = onRenderStop;
this.onRenderStart = onRenderStart; this.onRenderStart = onRenderStart;
this.onRenderFrame = onRenderFrame;
this.layout.graph.addGraphListener(this); this.layout.graph.addGraphListener(this);
} }
@ -679,6 +685,8 @@
t.layout.eachNode(function(node, point) { t.layout.eachNode(function(node, point) {
t.drawNode(node, point.p); t.drawNode(node, point.p);
}); });
if (t.onRenderFrame !== undefined) { t.onRenderFrame(); }
}, this.onRenderStop, this.onRenderStart); }, this.onRenderStop, this.onRenderStart);
}; };

View File

@ -324,7 +324,7 @@ jQuery.fn.springy = function(params) {
ctx.textAlign = "left"; ctx.textAlign = "left";
ctx.textBaseline = "top"; ctx.textBaseline = "top";
ctx.font = (node.data.font !== undefined) ? node.data.font : nodeFont; ctx.font = (node.data.font !== undefined) ? node.data.font : nodeFont;
ctx.fillStyle = "#000000"; ctx.fillStyle = (node.data.color !== undefined) ? node.data.color : "#000000";
var text = (node.data.label !== undefined) ? node.data.label : node.id; var text = (node.data.label !== undefined) ? node.data.label : node.id;
ctx.fillText(text, s.x - contentWidth/2, s.y - contentHeight/2); ctx.fillText(text, s.x - contentWidth/2, s.y - contentHeight/2);
} else { } else {