Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06523d6

Browse files
committed
test and fix clip path removal on changing an image to full paper-ref
1 parent 20a47fd commit 06523d6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/components/images/draw.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ module.exports = function draw(gd) {
143143
yId = ya ? ya._id : '',
144144
clipAxes = xId + yId;
145145

146-
if(clipAxes) {
147-
thisImage.call(Drawing.setClipUrl, 'clip' + fullLayout._uid + clipAxes);
148-
}
146+
thisImage.call(Drawing.setClipUrl, clipAxes ?
147+
('clip' + fullLayout._uid + clipAxes) :
148+
null
149+
);
149150
}
150151

151152
var imagesBelow = fullLayout._imageLowerLayer.selectAll('image')

test/jasmine/tests/layout_images_test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ describe('Layout images', function() {
307307

308308
afterEach(destroyGraphDiv);
309309

310-
it('should properly add and removing image', function(done) {
310+
it('should properly add and remove image', function(done) {
311311
var gd = createGraphDiv(),
312312
data = [{ x: [1, 2, 3], y: [1, 2, 3] }],
313313
layout = { width: 500, height: 400 };
@@ -425,23 +425,38 @@ describe('images log/linear axis changes', function() {
425425
// we don't try to figure out the position on a new axis / canvas
426426
// automatically when you change xref / yref, we leave it to the caller.
427427

428+
// initial clip path should end in 'xy' to match xref/yref
429+
expect(d3.select('image').attr('clip-path') || '').toMatch(/xy\)$/);
430+
428431
// linear to log
429432
Plotly.relayout(gd, {'images[0].yref': 'y2'})
430433
.then(function() {
431434
expect(gd.layout.images[0].y).toBe(1);
432435

436+
expect(d3.select('image').attr('clip-path') || '').toMatch(/xy2\)$/);
437+
433438
// log to paper
434439
return Plotly.relayout(gd, {'images[0].yref': 'paper'});
435440
})
436441
.then(function() {
437442
expect(gd.layout.images[0].y).toBe(1);
438443

444+
expect(d3.select('image').attr('clip-path') || '').toMatch(/x\)$/);
445+
446+
// change to full paper-referenced, to make sure the clip path disappears
447+
return Plotly.relayout(gd, {'images[0].xref': 'paper'});
448+
})
449+
.then(function() {
450+
expect(d3.select('image').attr('clip-path')).toBe(null);
451+
439452
// paper to log
440453
return Plotly.relayout(gd, {'images[0].yref': 'y2'});
441454
})
442455
.then(function() {
443456
expect(gd.layout.images[0].y).toBe(1);
444457

458+
expect(d3.select('image').attr('clip-path') || '').toMatch(/^[^x]+y2\)$/);
459+
445460
// log to linear
446461
return Plotly.relayout(gd, {'images[0].yref': 'y'});
447462
})

0 commit comments

Comments
 (0)