Attach graph and layout objects to springyui element.

This commit is contained in:
Dennis Hotson 2011-08-15 14:10:13 +10:00
parent a918da30a4
commit 193e99a619
2 changed files with 8 additions and 6 deletions

View File

@ -4,7 +4,6 @@
<script src="springy.js"></script>
<script src="springyui.js"></script>
<script>
var graph = new Graph();
var dennis = graph.newNode({label: 'Dennis'});
@ -29,10 +28,11 @@ graph.newEdge(barbara, timothy, {color: '#6A4A3C'});
graph.newEdge(dennis, bianca, {color: '#CC333F'});
graph.newEdge(bianca, monty, {color: '#EB6841'});
jQuery(document).ready(function(){
jQuery('#springydemo').springy({ 'graph': graph });
jQuery(function(){
var springy = jQuery('#springydemo').springy({
graph: graph
});
});
</script>
<canvas id="springydemo" width="640" height="480" />

View File

@ -26,7 +26,7 @@ Copyright (c) 2010 Dennis Hotson
(function() {
jQuery.fn.springy = function(params) {
var graph = params.graph || new Graph();
this.graph = params.graph || new Graph();
var stiffness = params.stiffness || 400.0;
var repulsion = params.repulsion || 400.0;
@ -34,7 +34,7 @@ jQuery.fn.springy = function(params) {
var canvas = this[0];
var ctx = canvas.getContext("2d");
var layout = new Layout.ForceDirected(graph, stiffness, repulsion, damping);
this.layout = new Layout.ForceDirected(graph, stiffness, repulsion, damping);
// calculate bounding box of graph layout.. with ease-in
var currentBB = layout.getBoundingBox();
@ -281,6 +281,8 @@ jQuery.fn.springy = function(params) {
return false;
}
return this;
}
})();