@@ -12,6 +12,10 @@ var mouseEvent = require('../assets/mouse_event');
12
12
var jsLogo = 'https://images.plot.ly/language-icons/api-home/js-logo.png' ;
13
13
var pythonLogo = 'https://images.plot.ly/language-icons/api-home/python-logo.png' ;
14
14
15
+ // Single red pixel png generated with http://png-pixel.com/
16
+ var dataUriImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfF' +
17
+ 'cSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==' ;
18
+
15
19
describe ( 'Layout images' , function ( ) {
16
20
describe ( 'supplyLayoutDefaults' , function ( ) {
17
21
var layoutIn ,
@@ -290,6 +294,31 @@ describe('Layout images', function() {
290
294
291
295
afterEach ( destroyGraphDiv ) ;
292
296
297
+ it ( 'should only create canvas if url image' , function ( done ) {
298
+ var originalCreateElement = document . createElement ;
299
+ var newCanvasElement ;
300
+ spyOn ( document , 'createElement' ) . and . callFake ( function ( elementType ) {
301
+ var element = originalCreateElement . call ( document , elementType ) ;
302
+ if ( elementType === 'canvas' ) {
303
+ newCanvasElement = element ;
304
+ spyOn ( newCanvasElement , 'toDataURL' ) ;
305
+ }
306
+ return element ;
307
+ } ) ;
308
+
309
+ Plotly . relayout ( gd , 'images[0].source' , dataUriImage ) . then ( function ( ) {
310
+ setTimeout ( function ( ) {
311
+ expect ( newCanvasElement ) . toBeUndefined ( ) ;
312
+ Plotly . relayout ( gd , 'images[0].source' , pythonLogo ) . then ( function ( ) {
313
+ expect ( newCanvasElement ) . eventually . toBeDefined ( ) ;
314
+ expect ( newCanvasElement . toDataURL ) . toHaveBeenCalledTimes ( 1 ) ;
315
+ } ) ;
316
+
317
+ done ( ) ;
318
+ } , 500 ) ;
319
+ } ) ;
320
+ } ) ;
321
+
293
322
it ( 'should update the image if changed' , function ( done ) {
294
323
var img = Plotly . d3 . select ( 'image' ) ;
295
324
var url = img . attr ( 'xlink:href' ) ;
0 commit comments