Skip to content

Commit b1fd955

Browse files
committed
adapt layout images tests to new direct-unless-staticPlot behavior
and add a draftlog
1 parent 9892ac7 commit b1fd955

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

draftlogs/7199_fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Do not convert url-sourced layout images to data uri unless we're in staticPlot mode, to improve interactivity when images are changed with zoom/pan [[#7199](https://github.com/plotly/plotly.js/pull/7199)]

test/jasmine/tests/layout_images_test.js

+35-7
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,8 @@ describe('Layout images', function() {
319319
var gd;
320320
var data = [{ x: [1, 2, 3], y: [1, 2, 3] }];
321321

322-
beforeEach(function(done) {
323-
gd = createGraphDiv();
324-
Plotly.newPlot(gd, data, {
322+
var layoutFn = function() {
323+
return {
325324
images: [{
326325
source: jsLogo,
327326
x: 2,
@@ -331,12 +330,17 @@ describe('Layout images', function() {
331330
}],
332331
width: 500,
333332
height: 400
334-
}).then(done);
333+
};
334+
}
335+
336+
beforeEach(function(done) {
337+
gd = createGraphDiv();
338+
Plotly.newPlot(gd, data, layoutFn()).then(done);
335339
});
336340

337341
afterEach(destroyGraphDiv);
338342

339-
it('should only create canvas if url image', function(done) {
343+
it('should only create canvas if url image and staticPlot', function(done) {
340344
var originalCreateElement = document.createElement;
341345
var newCanvasElement;
342346
spyOn(document, 'createElement').and.callFake(function(elementType) {
@@ -350,7 +354,21 @@ describe('Layout images', function() {
350354

351355
Plotly.relayout(gd, 'images[0].source', dataUriImage)
352356
.then(function() {
353-
expect(newCanvasElement).toBeUndefined();
357+
expect(newCanvasElement).withContext('non-static data uri').toBeUndefined();
358+
359+
return Plotly.relayout(gd, 'images[0].source', jsLogo);
360+
})
361+
.then(function() {
362+
expect(newCanvasElement).withContext('non-static url').toBeUndefined();
363+
364+
return Plotly.newPlot(gd, data, layoutFn(), {staticPlot: true});
365+
})
366+
.then(function() {
367+
newCanvasElement = undefined;
368+
return Plotly.relayout(gd, 'images[0].source', dataUriImage);
369+
})
370+
.then(function() {
371+
expect(newCanvasElement).withContext('static data uri').toBeUndefined();
354372

355373
return Plotly.relayout(gd, 'images[0].source', jsLogo);
356374
})
@@ -392,11 +410,21 @@ describe('Layout images', function() {
392410
.then(done, done.fail);
393411
});
394412

395-
it('should remove the image tag if an invalid source', function(done) {
413+
it('should remove the image tag if an invalid source and staticPlot', function(done) {
396414
var selection = d3Select('image');
397415
expect(selection.size()).toBe(1);
398416

399417
Plotly.relayout(gd, 'images[0].source', 'invalidUrl')
418+
.then(function() {
419+
var newSelection = d3Select('image');
420+
expect(newSelection.size()).toBe(1);
421+
})
422+
.then(function() {
423+
return Plotly.newPlot(gd, data, layoutFn(), {staticPlot: true});
424+
})
425+
.then(function() {
426+
return Plotly.relayout(gd, 'images[0].source', 'invalidUrl');
427+
})
400428
.then(function() {
401429
var newSelection = d3Select('image');
402430
expect(newSelection.size()).toBe(0);

0 commit comments

Comments
 (0)