@@ -23,7 +23,7 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
2323 var xa = plotinfo . xaxis ;
2424 var ya = plotinfo . yaxis ;
2525
26- var supportsPixelatedImage = ! Lib . isIOS ( ) && ! Lib . isSafari ( ) && ! Lib . isIE && ! gd . _context . _exportedPlot ;
26+ var supportsPixelatedImage = ! Lib . isIOS ( ) && ! Lib . isSafari ( ) && ! Lib . isIE ( ) && ! gd . _context . _exportedPlot ;
2727
2828 Lib . makeTraceGroups ( imageLayer , cdimage , 'im' ) . each ( function ( cd ) {
2929 var plotGroup = d3 . select ( this ) ;
@@ -128,25 +128,14 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
128128 return canvas ;
129129 }
130130
131- function sizeImage ( image ) {
132- image . attr ( {
133- height : imageHeight ,
134- width : imageWidth ,
135- x : left ,
136- y : top
137- } ) ;
138- }
139-
140- var data = ( trace . _isFromSource && ! fastImage ) ? [ cd , { hidden : true } ] : [ cd ] ;
141131 var image3 = plotGroup . selectAll ( 'image' )
142- . data ( data ) ;
132+ . data ( [ cd ] ) ;
143133
144134 image3 . enter ( ) . append ( 'svg:image' ) . attr ( {
145135 xmlns : xmlnsNamespaces . svg ,
146136 preserveAspectRatio : 'none'
147137 } ) ;
148138
149- if ( fastImage ) sizeImage ( image3 ) ;
150139 image3 . exit ( ) . remove ( ) ;
151140
152141 // Pixelated image rendering
@@ -159,7 +148,7 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
159148 if ( trace . _isFromZ ) {
160149 resolve ( ) ;
161150 } else if ( trace . _isFromSource ) {
162- // Check if canvas already exists
151+ // Check if canvas already exists and has the right data
163152 if (
164153 trace . _canvas &&
165154 trace . _canvas . el . width === w &&
@@ -174,16 +163,8 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
174163 canvas . height = h ;
175164 var context = canvas . getContext ( '2d' ) ;
176165
177- var sel ;
178- if ( fastImage ) {
179- // Use the displayed image
180- sel = image3 ;
181- } else {
182- // Use the hidden image
183- sel = d3 . select ( image3 [ 0 ] [ 1 ] ) ;
184- }
185-
186- var image = sel . node ( ) ;
166+ trace . _image = trace . _image || new Image ( ) ;
167+ var image = trace . _image ;
187168 image . onload = function ( ) {
188169 context . drawImage ( image , 0 , 0 ) ;
189170 trace . _canvas = {
@@ -192,12 +173,15 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
192173 } ;
193174 resolve ( ) ;
194175 } ;
195- sel . attr ( 'xlink:href ', trace . source ) ;
176+ image . setAttribute ( 'src ', trace . source ) ;
196177 }
197178 }
198179 } )
199180 . then ( function ( ) {
200- if ( ! fastImage ) {
181+ var href ;
182+ if ( fastImage ) {
183+ href = trace . source ;
184+ } else {
201185 var canvas ;
202186 if ( trace . _isFromZ ) {
203187 canvas = drawMagnifiedPixelsOnCanvas ( function ( i , j ) { return z [ j ] [ i ] ; } ) ;
@@ -214,11 +198,16 @@ module.exports = function plot(gd, plotinfo, cdimage, imageLayer) {
214198 ] ;
215199 } ) ;
216200 }
217- var href = canvas . toDataURL ( 'image/png' ) ;
218- var displayImage = d3 . select ( image3 . node ( ) ) ;
219- sizeImage ( displayImage ) ;
220- displayImage . attr ( 'xlink:href' , href ) ;
201+ href = canvas . toDataURL ( 'image/png' ) ;
221202 }
203+
204+ image3 . attr ( {
205+ 'xlink:href' : href ,
206+ height : imageHeight ,
207+ width : imageWidth ,
208+ x : left ,
209+ y : top
210+ } ) ;
222211 } ) ;
223212
224213 gd . _promises . push ( p ) ;
0 commit comments