From 42b68c12683c434fc2f7620fed18a6cdc2fb2241 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 27 Mar 2015 15:52:57 +0100 Subject: * configurable graph parameters and image dimensions --- main.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'main.js') 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); }); }) -- cgit v1.2.3