@@ -22,6 +22,9 @@ var enableSVGDownload = function (classView) {
2222
2323 var par = svg . parentNode ;
2424 svg = svg . cloneNode ( true ) ;
25+ svg . style . position = "fixed" ;
26+ svg . style . left = 0 ;
27+ svg . style . top = 0 ;
2528 par . appendChild ( svg ) ;
2629 var gGroup = svg . childNodes [ 0 ] ;
2730
@@ -40,9 +43,12 @@ var enableSVGDownload = function (classView) {
4043 svg . setAttributeNS ( prefix . xmlns , "xmlns:xlink" , prefix . xlink ) ;
4144 }
4245
46+ svg . style . zIndex = 0 ;
47+ gGroup . setAttribute ( "transform" , "" ) ;
48+ var gRect = gGroup . getBoundingClientRect ( ) ;
49+ gGroup . setAttribute ( "transform" , "translate(" + ( - gRect . left ) + "," + ( - gRect . top ) + ")" ) ;
4350 svg . setAttribute ( "width" , gGroup . getBBox ( ) . width ) ;
4451 svg . setAttribute ( "height" , gGroup . getBBox ( ) . height ) ;
45- gGroup . setAttribute ( "transform" , "" ) ;
4652
4753 setInlineStyles ( svg , emptySvgDeclarationComputed ) ;
4854
@@ -82,12 +88,17 @@ var enableSVGDownload = function (classView) {
8288
8389 img . onload = function ( ) {
8490 ctx . drawImage ( img , 0 , 0 ) ;
85- var dataURL = canvas . toDataURL ( "image/png" ) ;
86- var a = document . createElement ( "a" ) ;
87- a . setAttribute ( "download" , filename + ".png" ) ;
88- a . setAttribute ( "href" , dataURL /*url*/ ) ;
89- document . body . appendChild ( a ) ;
90- a . click ( ) ;
91+ try {
92+ var a = document . createElement ( "a" ) ;
93+ a . setAttribute ( "download" , filename + ".png" ) ;
94+ var dataURL = canvas . toDataURL ( "image/png" ) ;
95+ a . setAttribute ( "href" , dataURL /*url*/ ) ;
96+ document . body . appendChild ( a ) ;
97+ a . click ( ) ;
98+ } catch ( e ) {
99+ alert ( "This browser does not allow usage of canvas.toDataURL function. Please,"
100+ + " use different browser to download the image." ) ;
101+ }
91102 setTimeout ( function ( ) {
92103 a . parentNode . removeChild ( a ) ;
93104 document . body . removeChild ( emptySvg ) ;
0 commit comments