Skip to content

Commit 6eba3c5

Browse files
authored
Merge pull request #4170 from plotly/annotations-off-screen-during-drag
Remove off-screen annotations during drag
2 parents 240334e + 2d39e2f commit 6eba3c5

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

Diff for: src/components/annotations/draw.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
392392
options['_' + axLetter + 'shift'] = textShift;
393393
}
394394

395-
// We have everything we need for calcAutorange at this point,
396-
// we can safely exit - unless we're currently dragging the plot
397-
if(!gd._dragging && annotationIsOffscreen) {
395+
if(annotationIsOffscreen) {
398396
annTextGroupInner.remove();
399397
return;
400398
}

Diff for: test/jasmine/tests/annotations_test.js

+50
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,56 @@ describe('annotation effects', function() {
16171617
.catch(failTest)
16181618
.then(done);
16191619
});
1620+
1621+
it('should remove annotations if offscreen during axis drag', function(done) {
1622+
gd = createGraphDiv();
1623+
1624+
function _assert(msg, exp) {
1625+
return function() {
1626+
expect(gd._dragging).toBe(exp.dragging, 'is during drag| ' + msg);
1627+
expect(Boolean(textDrag())).toBe(exp.onScreen, 'is annotation on screen| ' + msg);
1628+
};
1629+
}
1630+
1631+
Plotly.plot(gd, [{
1632+
x: [0, 1, 2, 3, 4, 5, 6, 7, 8],
1633+
y: [0, 4, 5, 1, 2, 2, 3, 4, 2],
1634+
}], {
1635+
dragmode: 'pan',
1636+
width: 500, height: 500,
1637+
annotations: [{
1638+
x: 2, y: 5,
1639+
xref: 'x', yref: 'y',
1640+
text: 'Annotation Text',
1641+
arrowhead: 7,
1642+
ax: 0, ay: -40
1643+
}]
1644+
})
1645+
.then(_assert('base', {
1646+
dragging: undefined,
1647+
onScreen: true
1648+
}))
1649+
.then(function() {
1650+
var fns = drag.makeFns({pos0: [250, 250], posN: [500, 250]});
1651+
return fns.start()
1652+
.then(_assert('during drag offscreen', {
1653+
dragging: true,
1654+
onScreen: false
1655+
}))
1656+
.then(fns.end);
1657+
})
1658+
.then(function() {
1659+
var fns = drag.makeFns({pos0: [250, 250], posN: [0, 250]});
1660+
return fns.start()
1661+
.then(_assert('during drag back onscreen', {
1662+
dragging: true,
1663+
onScreen: true
1664+
}))
1665+
.then(fns.end);
1666+
})
1667+
.catch(failTest)
1668+
.then(done);
1669+
});
16201670
});
16211671

16221672
describe('animating annotations', function() {

0 commit comments

Comments
 (0)