Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove off-screen annotations during drag #4170

Merged
merged 1 commit into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/components/annotations/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
options['_' + axLetter + 'shift'] = textShift;
}

// We have everything we need for calcAutorange at this point,
// we can safely exit - unless we're currently dragging the plot
if(!gd._dragging && annotationIsOffscreen) {
if(annotationIsOffscreen) {
annTextGroupInner.remove();
return;
}
Expand Down
50 changes: 50 additions & 0 deletions test/jasmine/tests/annotations_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,56 @@ describe('annotation effects', function() {
.catch(failTest)
.then(done);
});

it('should remove annotations if offscreen during axis drag', function(done) {
gd = createGraphDiv();

function _assert(msg, exp) {
return function() {
expect(gd._dragging).toBe(exp.dragging, 'is during drag| ' + msg);
expect(Boolean(textDrag())).toBe(exp.onScreen, 'is annotation on screen| ' + msg);
};
}

Plotly.plot(gd, [{
x: [0, 1, 2, 3, 4, 5, 6, 7, 8],
y: [0, 4, 5, 1, 2, 2, 3, 4, 2],
}], {
dragmode: 'pan',
width: 500, height: 500,
annotations: [{
x: 2, y: 5,
xref: 'x', yref: 'y',
text: 'Annotation Text',
arrowhead: 7,
ax: 0, ay: -40
}]
})
.then(_assert('base', {
dragging: undefined,
onScreen: true
}))
.then(function() {
var fns = drag.makeFns({pos0: [250, 250], posN: [500, 250]});
return fns.start()
.then(_assert('during drag offscreen', {
dragging: true,
onScreen: false
}))
.then(fns.end);
})
.then(function() {
var fns = drag.makeFns({pos0: [250, 250], posN: [0, 250]});
return fns.start()
.then(_assert('during drag back onscreen', {
dragging: true,
onScreen: true
}))
.then(fns.end);
})
.catch(failTest)
.then(done);
});
});

describe('animating annotations', function() {
Expand Down