@@ -74,49 +74,54 @@ module.exports = function draw(gd) {
74
74
function setImage ( d ) {
75
75
var thisImage = d3 . select ( this ) ;
76
76
77
- if ( this . img && this . img . src === d . source ) {
77
+ if ( this . _imgSrc === d . source ) {
78
78
return ;
79
79
}
80
80
81
81
thisImage . attr ( 'xmlns' , xmlnsNamespaces . svg ) ;
82
82
83
- var imagePromise = new Promise ( function ( resolve ) {
84
- var img = new Image ( ) ;
85
- this . img = img ;
83
+ if ( d . source && d . source . slice ( 0 , 5 ) === 'data:' ) {
84
+ thisImage . attr ( 'xlink:href' , d . source ) ;
85
+ this . _imgSrc = d . source ;
86
+ } else {
87
+ var imagePromise = new Promise ( function ( resolve ) {
88
+ var img = new Image ( ) ;
89
+ this . img = img ;
86
90
87
- // If not set, a `tainted canvas` error is thrown
88
- img . setAttribute ( 'crossOrigin' , 'anonymous' ) ;
89
- img . onerror = errorHandler ;
90
- img . onload = function ( ) {
91
- var canvas = document . createElement ( 'canvas' ) ;
92
- canvas . width = this . width ;
93
- canvas . height = this . height ;
91
+ // If not set, a `tainted canvas` error is thrown
92
+ img . setAttribute ( 'crossOrigin' , 'anonymous' ) ;
93
+ img . onerror = errorHandler ;
94
+ img . onload = function ( ) {
95
+ var canvas = document . createElement ( 'canvas' ) ;
96
+ canvas . width = this . width ;
97
+ canvas . height = this . height ;
94
98
95
- var ctx = canvas . getContext ( '2d' ) ;
96
- ctx . drawImage ( this , 0 , 0 ) ;
99
+ var ctx = canvas . getContext ( '2d' ) ;
100
+ ctx . drawImage ( this , 0 , 0 ) ;
97
101
98
- var dataURL = canvas . toDataURL ( 'image/png' ) ;
102
+ var dataURL = canvas . toDataURL ( 'image/png' ) ;
99
103
100
- thisImage . attr ( 'xlink:href' , dataURL ) ;
104
+ thisImage . attr ( 'xlink:href' , dataURL ) ;
101
105
102
- // resolve promise in onload handler instead of on 'load' to support IE11
103
- // see https://github.com/plotly/plotly.js/issues/1685
104
- // for more details
105
- resolve ( ) ;
106
- } ;
106
+ // resolve promise in onload handler instead of on 'load' to support IE11
107
+ // see https://github.com/plotly/plotly.js/issues/1685
108
+ // for more details
109
+ resolve ( ) ;
110
+ } ;
107
111
112
+ thisImage . on ( 'error' , errorHandler ) ;
108
113
109
- thisImage . on ( 'error' , errorHandler ) ;
114
+ img . src = d . source ;
115
+ this . _imgSrc = d . source ;
110
116
111
- img . src = d . source ;
112
-
113
- function errorHandler ( ) {
114
- thisImage . remove ( ) ;
115
- resolve ( ) ;
116
- }
117
- } . bind ( this ) ) ;
117
+ function errorHandler ( ) {
118
+ thisImage . remove ( ) ;
119
+ resolve ( ) ;
120
+ }
121
+ } . bind ( this ) ) ;
118
122
119
- gd . _promises . push ( imagePromise ) ;
123
+ gd . _promises . push ( imagePromise ) ;
124
+ }
120
125
}
121
126
122
127
function applyAttributes ( d ) {
0 commit comments