I have written some code to do this client side.
I started with svgenie (
https://github.com/Causata/svgenie) which is a
wrapper around canvg.
svgenie by default only supports one svg, but I changed the function
_toCanvas to accept a
2 dimensional array of svgs. It will draw the svgs in a matrix like arrangement.
The problem with this approach (doing it client side) is that canvg
does't support all svg.
For me it was not a problem since my graphs were pretty simple.
If the client side approach doesn't work for you, you might be able to
use the ideas in my script
to do something similar server side.
Here is my change to _toCanvas:
var _toCanvas = function (svgArray, options, callback) {
var numCols = svgArray[0].length;
var numRows = svgArray.length;
var maxWidth = -1;
var maxHeight = -1;
for (var row = 0; row < svgArray.length; row++) {
for (var col = 0; col < svgArray[0].length; col++) {
if (svgArray[row][col]) {
if (svgArray[row][col].scrollWidth > maxWidth) {
maxWidth = svgArray[row][col].scrollWidth;
}
if (svgArray[row][col].scrollHeight > maxHeight) {
maxHeight = svgArray[row][col].scrollHeight;
}
}
}
}
var imageSeparation = 20; //pixel
var canvasWidth = numCols * maxWidth + (numCols - 1) * imageSeparation;
var canvasHeight = numRows * maxHeight + (numRows - 1) *
imageSeparation;
var bgColor = window.getComputedStyle(document.body,
null).getPropertyValue('background-color');
// Hopefully don't need to attach anything to the DOM
var canvas = document.createElement("canvas");
canvas.height = canvasHeight;
canvas.width = canvasWidth;
//Create a rectangle with body background color
var ctx = canvas.getContext('2d');
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
//draw all svgs to canvas
for (var row = 0; row < svgArray.length; row++) {
for (var col = 0; col < svgArray[0].length; col++) {
var svg = svgArray[row][col];
if (svg) {
var leftX = col * (maxWidth + imageSeparation);
var leftY = row * (maxHeight + imageSeparation);
if (typeof svg == "string") {
if (svg.substr(0, 1) == "#") { svg = svg.substr(1); }
svg = document.getElementById(svg);
}
var serSvg = _serializeXmlNode(svg);
canvg(canvas, serSvg, {
ignoreMouse: true,
ignoreClear: true,
ignoreDimensions: true,
ignoreAnimation: true,
offsetX: leftX,
offsetY: leftY
});
}
}
}
//Output the canvas
canvg(canvas, "<svg></svg>", {
ignoreMouse: true,
ignoreClear: true,
ignoreAnimation: true,
ignoreDimensions: true,
offsetX: 0,
offsetY: 0,
renderCallback: function () { callback(canvas); }
});
};