summaryrefslogtreecommitdiff
path: root/main.js
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2015-03-27 15:52:57 +0100
committeremkael <emkael@tlen.pl>2015-03-27 15:52:57 +0100
commit42b68c12683c434fc2f7620fed18a6cdc2fb2241 (patch)
treef7e4ad99ae85e25696f292968fb1adea30007b5e /main.js
parent407d07723df7d2e472d0928f79227ed4cb5dc218 (diff)
* configurable graph parameters and image dimensions
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);
});
})