1 var INFINITE, JSONToShape, util;
3 util = require('./util');
5 JSONToShape = require('./shapes').JSONToShape;
9 module.exports = function(snapshot, opts) {
10 var allShapes, backgroundShapes, colors, ctx, dummyCanvas, imageSize, s, shapes;
14 shapes = (function() {
15 var i, len, ref, results;
16 ref = snapshot.shapes;
18 for (i = 0, len = ref.length; i < len; i++) {
20 results.push(JSONToShape(s));
24 backgroundShapes = [];
25 if (snapshot.backgroundShapes) {
26 backgroundShapes = (function() {
27 var i, len, ref, results;
28 ref = snapshot.backgroundShapes;
30 for (i = 0, len = ref.length; i < len; i++) {
32 results.push(JSONToShape(s));
37 if (opts.margin == null) {
45 imageSize = snapshot.imageSize || {
49 colors = snapshot.colors || {
50 background: 'transparent'
52 allShapes = shapes.concat(backgroundShapes);
53 dummyCanvas = document.createElement('canvas');
54 ctx = dummyCanvas.getContext('2d');
56 opts.rect.x -= opts.margin.left;
57 opts.rect.y -= opts.margin.top;
58 opts.rect.width += opts.margin.left + opts.margin.right;
59 opts.rect.height += opts.margin.top + opts.margin.bottom;
61 opts.rect = util.getDefaultImageRect((function() {
64 for (i = 0, len = allShapes.length; i < len; i++) {
66 results.push(s.getBoundingRect(ctx));
69 })(), imageSize, opts.margin);
71 return LC.renderShapesToSVG(backgroundShapes.concat(shapes), opts.rect, colors.background);