File tree 4 files changed +19
-8
lines changed
4 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -74,8 +74,6 @@ var attrs = {
74
74
}
75
75
} ;
76
76
77
- var IMAGE_URL_PREFIX = / ^ d a t a : i m a g e \/ \w + ; b a s e 6 4 , / ;
78
-
79
77
/** Plotly.toImage
80
78
*
81
79
* @param {object | string | HTML div } gd
@@ -179,7 +177,7 @@ function toImage(gd, opts) {
179
177
if ( imageDataOnly ) {
180
178
return resolve ( svg ) ;
181
179
} else {
182
- return resolve ( 'data:image/svg+xml,' + encodeURIComponent ( svg ) ) ;
180
+ return resolve ( helpers . encodeSVG ( svg ) ) ;
183
181
}
184
182
}
185
183
@@ -206,7 +204,7 @@ function toImage(gd, opts) {
206
204
207
205
function urlToImageData ( url ) {
208
206
if ( imageDataOnly ) {
209
- return url . replace ( IMAGE_URL_PREFIX , '' ) ;
207
+ return url . replace ( helpers . IMAGE_URL_PREFIX , '' ) ;
210
208
} else {
211
209
return url ;
212
210
}
Original file line number Diff line number Diff line change 8
8
9
9
'use strict' ;
10
10
11
- var toImage = require ( '../plot_api/to_image' ) ;
12
11
var Lib = require ( '../lib' ) ;
12
+
13
+ var toImage = require ( '../plot_api/to_image' ) ;
14
+
13
15
var fileSaver = require ( './filesaver' ) ;
16
+ var helpers = require ( './helpers' ) ;
14
17
15
18
/** Plotly.downloadImage
16
19
*
@@ -41,7 +44,7 @@ function downloadImage(gd, opts) {
41
44
// does not allow toDataURL
42
45
// svg format will work though
43
46
if ( Lib . isIE ( ) && opts . format !== 'svg' ) {
44
- reject ( new Error ( 'Sorry IE does not support downloading from canvas. Try {format:\'svg\'} instead.' ) ) ;
47
+ reject ( new Error ( helpers . MSG_IE_BAD_FORMAT ) ) ;
45
48
}
46
49
47
50
if ( _gd ) _gd . _snapshotInProgress = true ;
Original file line number Diff line number Diff line change @@ -31,3 +31,11 @@ exports.getRedrawFunc = function(gd) {
31
31
}
32
32
} ;
33
33
} ;
34
+
35
+ exports . encodeSVG = function ( svg ) {
36
+ return 'data:image/svg+xml,' + encodeURIComponent ( svg ) ;
37
+ } ;
38
+
39
+ exports . IMAGE_URL_PREFIX = / ^ d a t a : i m a g e \/ \w + ; b a s e 6 4 , / ;
40
+
41
+ exports . MSG_IE_BAD_FORMAT = 'Sorry IE does not support downloading from canvas. Try {format:\'svg\'} instead.' ;
Original file line number Diff line number Diff line change 11
11
var Lib = require ( '../lib' ) ;
12
12
var EventEmitter = require ( 'events' ) . EventEmitter ;
13
13
14
+ var helpers = require ( './helpers' ) ;
15
+
14
16
function svgToImg ( opts ) {
15
17
var ev = opts . emitter || new EventEmitter ( ) ;
16
18
@@ -21,7 +23,7 @@ function svgToImg(opts) {
21
23
22
24
// IE only support svg
23
25
if ( Lib . isIE ( ) && format !== 'svg' ) {
24
- var ieSvgError = new Error ( 'Sorry IE does not support downloading from canvas. Try {format:\'svg\'} instead.' ) ;
26
+ var ieSvgError = new Error ( helpers . MSG_IE_BAD_FORMAT ) ;
25
27
reject ( ieSvgError ) ;
26
28
// eventually remove the ev
27
29
// in favor of promises
@@ -45,7 +47,7 @@ function svgToImg(opts) {
45
47
// for Safari support, eliminate createObjectURL
46
48
// this decision could cause problems if content
47
49
// is not restricted to svg
48
- var url = 'data:image/svg+xml,' + encodeURIComponent ( svg ) ;
50
+ var url = helpers . encodeSVG ( svg ) ;
49
51
50
52
canvas . width = w1 ;
51
53
canvas . height = h1 ;
You can’t perform that action at this time.
0 commit comments