@@ -74,49 +74,54 @@ module.exports = function draw(gd) {
7474 function setImage ( d ) {
7575 var thisImage = d3 . select ( this ) ;
7676
77- if ( this . img && this . img . src === d . source ) {
77+ if ( this . _imgSrc === d . source ) {
7878 return ;
7979 }
8080
8181 thisImage . attr ( 'xmlns' , xmlnsNamespaces . svg ) ;
8282
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 ;
8690
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 ;
9498
95- var ctx = canvas . getContext ( '2d' ) ;
96- ctx . drawImage ( this , 0 , 0 ) ;
99+ var ctx = canvas . getContext ( '2d' ) ;
100+ ctx . drawImage ( this , 0 , 0 ) ;
97101
98- var dataURL = canvas . toDataURL ( 'image/png' ) ;
102+ var dataURL = canvas . toDataURL ( 'image/png' ) ;
99103
100- thisImage . attr ( 'xlink:href' , dataURL ) ;
104+ thisImage . attr ( 'xlink:href' , dataURL ) ;
101105
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+ } ;
107111
112+ thisImage . on ( 'error' , errorHandler ) ;
108113
109- thisImage . on ( 'error' , errorHandler ) ;
114+ img . src = d . source ;
115+ this . _imgSrc = d . source ;
110116
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 ) ) ;
118122
119- gd . _promises . push ( imagePromise ) ;
123+ gd . _promises . push ( imagePromise ) ;
124+ }
120125 }
121126
122127 function applyAttributes ( d ) {
0 commit comments