Skip to content

Instantly share code, notes, and snippets.

@alecgorge
Created April 18, 2012 22:23
Show Gist options
  • Save alecgorge/2417034 to your computer and use it in GitHub Desktop.
Save alecgorge/2417034 to your computer and use it in GitHub Desktop.
Go to the print friendly version on anything using HighCharts and run the bookmarklet. It will turn all the SVGs into copyable PNGs.
javascript:(function(a){var b=function(){a(".highcharts-container svg").map(function(){var b=a(this).parent(),c=b.html();b.html(""),a("<canvas></canvas>").css("width",b.css("width")).css("height",b.css("height")).appendTo(b);var d=b.find("canvas")[0];canvg(d,c,{ignoreMouse:!0,ignoreAnimation:!0,renderCallback:function(){var a=d.toDataURL("image/png");b.html('<img src="'+a+'"/>')}})})};if(typeof window.canvg!="undefined"){b();return}var c=["http://canvg.googlecode.com/svn/trunk/rgbcolor.js","http://canvg.googlecode.com/svn/trunk/canvg.js"];a.getScript(c[0],function(){a.getScript(c[1],function(){b()})})})(jQuery)
(function ($) {
var go = function () {
$('.highcharts-container svg').map(function () {
var $parent = $(this).parent()
, svg = $parent.html()
;
$parent.html('');
$('<canvas></canvas>').css('width', $parent.css('width')).css('height', $parent.css('height')).appendTo($parent);
var ca = $parent.find('canvas')[0];
canvg(ca, svg, {ignoreMouse: true, ignoreAnimation: true, renderCallback: function () {
var img = ca.toDataURL('image/png')
$parent.html('<img src="'+img+'" />')
}})
})
};
if(typeof window.canvg != 'undefined') {
go(); return;
}
// load the canvg library
var urls = ["http://canvg.googlecode.com/svn/trunk/rgbcolor.js", "http://canvg.googlecode.com/svn/trunk/canvg.js"];
$.getScript(urls[0], function () {
$.getScript(urls[1], function () {
go();
});
});
})(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment