summaryrefslogtreecommitdiff
path: root/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'main.js')
-rw-r--r--main.js22
1 files changed, 16 insertions, 6 deletions
diff --git a/main.js b/main.js
index bc488f4..291b694 100644
--- a/main.js
+++ b/main.js
@@ -159,9 +159,17 @@
})
var drawImage = function(image, coords) {
+ if (!image.height) {
+ image.height = image.width ? image.width * image.naturalHeight / image.naturalWidth : image.naturalHeight;
+ }
+ if (!image.width) {
+ image.width = image.height ? image.height * image.naturalWidth / image.naturalHeight : image.naturalWidth;
+ }
ctx.drawImage(image,
coords.x - image.width / 2,
- coords.y - image.height / 2);
+ coords.y - image.height / 2,
+ image.width,
+ image.height);
};
@@ -174,7 +182,7 @@
drawImage(node.data.imageObject, pt);
}
else {
- var img = new Image();
+ var img = new Image(node.data.width, node.data.height);
img.onload = function() {
node.data.imageObject = img;
drawImage(node.data.imageObject, pt);
@@ -240,11 +248,13 @@
}
$(document).ready(function() {
- var sys = arbor.ParticleSystem(500, 2000, 0.7); // create the system with sensible repulsion/stiffness/friction
- sys.parameters({gravity:true}); // use center-gravity to make the graph settle nicely (ymmv)
- sys.renderer = Renderer("#viewport"); // our newly created renderer will have its .init() method called shortly by sys...
-
$.getJSON('graph.json', function(graph) {
+ graph.repulsion = graph.repulsion || 1000;
+ graph.stiffness = graph.stiffness || 600;
+ graph.friction = graph.friction || 0.5;
+ var sys = arbor.ParticleSystem(graph.repulsion, graph.stiffness, graph.friction); // create the system with sensible repulsion/stiffness/friction
+ sys.parameters({gravity:true}); // use center-gravity to make the graph settle nicely (ymmv)
+ sys.renderer = Renderer("#viewport"); // our newly created renderer will have its .init() method called shortly by sys...
sys.graft(graph);
});
})