Open JobLeonard opened 8 years ago
canvas2svg is a simple library that lets us generate an SVG with the canvas draw API, via a "mock" context:
https://github.com/gliffy/canvas2svg
In short, we don't have to change anything about our plotters to save them as SVGs, we just pass them a fake context
object generated by this library.
To save a canvas (either real raster canvas as PNG, or a generated SVG), we need to use FileSaver.js:
https://github.com/eligrey/FileSaver.js
Other notes:
Both Patrick and Martin asked for this, guess it will become more relevant.
Also, there's a mysterious bug where printing the webpage reduces the resolution of the canvas in Chrome:
Chrome print-to-pdf Zeisel Chrome print-to-pdf Oligos All Firefox print-to-pdf Zeisel Firefox print-to-pdf Oligos
Detecting print buttons in JS so I can rerender in higher resolution https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeprint
edit: better explanation:
https://www.tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/
(function() {
var beforePrint = function() {
console.log('Functionality to run before printing.');
};
var afterPrint = function() {
console.log('Functionality to run after printing');
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
}());
The rendered version of the plot should not feature any features of the website, just the plot itself, and result in a PNG or SVG ready to be printed or used in another context (say, a powerpoint slide or a poster)