philogb/jit — Issue #97: using an image as background
Author: bielcardona
Created: 2012-01-04 19:01:40+00:00
State: open

In order to be able to include images in the background canvas (apart from the circles currently implemented) I have made the following changes in the code, which I think (and Nicolas does too) could be included in the main branch.

In Canvas.js add:
if (conf.img) {ctx.drawImage(conf.img, conf.imgx, conf.imgy);}
just before the line with "//TODO(nico): print labels too!".

In order to include an image as background, the user can do:

var img = new Image();
img.onload = function() {
fd.canvas.translate(0,0)
}
img.src = "backg.jpg";

fd = new $jit.ForceDirected({
....,
background: {img:img,imgx:-150,imgy:-150,numberOfCircles:0},
....
})

This way the image is included in the background canvas and both panning and zooming are also applied to the image.

Best,

Biel