Skip to content

hide off-plot annotations #1786

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

Merged
merged 1 commit into from
Jun 14, 2017
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
2 changes: 1 addition & 1 deletion src/components/annotations/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
annotationIsOffscreen = true;
}

if(annotationIsOffscreen) return;
if(annotationIsOffscreen) continue;
}
basePx = ax._offset + ax.r2p(options[axLetter]);
autoAlignFraction = 0.5;
Expand Down
45 changes: 44 additions & 1 deletion test/jasmine/tests/annotations_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,13 +552,16 @@ describe('annotations log/linear axis changes', function() {
describe('annotations autorange', function() {
'use strict';

var mock = Lib.extendDeep({}, require('@mocks/annotations-autorange.json'));
var mock;
var gd;

beforeAll(function() {
jasmine.addMatchers(customMatchers);
});

beforeEach(function() {
gd = createGraphDiv();
mock = Lib.extendDeep({}, require('@mocks/annotations-autorange.json'));
});

afterEach(destroyGraphDiv);
Expand Down Expand Up @@ -588,13 +591,30 @@ describe('annotations autorange', function() {
expect(fullLayout.yaxis3.range).toBeCloseToArray(y3, PREC, 'yaxis3');
}

function assertVisible(indices) {
// right now we keep the annotation groups around when they're invisible,
// they just don't have any graphical elements in them. Might be better
// to get rid of the groups even, but this test will produce the right
// results either way, showing that the annotation is or isn't drawn.
for(var i = 0; i < gd.layout.annotations.length; i++) {
var selectorBase = '.annotation[data-index="' + i + '"]';
var annotationGraphicalItems = d3.selectAll(
selectorBase + ' text,' +
selectorBase + ' rect,' +
selectorBase + ' path');
expect(annotationGraphicalItems.size() > 0)
.toBe(indices.indexOf(i) !== -1, selectorBase);
}
}

it('should adapt to relayout calls', function(done) {
Plotly.plot(gd, mock).then(function() {
assertRanges(
[0.91, 2.09], [0.91, 2.09],
['2000-11-13', '2001-04-21'], [-0.069, 3.917],
[0.88, 2.05], [0.92, 2.08]
);
assertVisible([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);

return Plotly.relayout(gd, {
'annotations[0].visible': false,
Expand All @@ -608,6 +628,7 @@ describe('annotations autorange', function() {
['2001-01-18', '2001-03-27'], [-0.069, 3.917],
[1.44, 2.1], [0.92, 2.08]
);
assertVisible([1, 2, 3, 5, 6, 7, 9, 10, 11, 12, 13]);

return Plotly.relayout(gd, {
'annotations[2].visible': false,
Expand All @@ -621,6 +642,7 @@ describe('annotations autorange', function() {
['2001-01-31 23:59:59.999', '2001-02-01 00:00:00.001'], [-0.069, 3.917],
[0.5, 2.5], [0.92, 2.08]
);
assertVisible([1, 3, 6, 7, 10, 11, 12, 13]);

return Plotly.relayout(gd, {
'annotations[0].visible': true,
Expand All @@ -637,6 +659,27 @@ describe('annotations autorange', function() {
['2000-11-13', '2001-04-21'], [-0.069, 3.917],
[0.88, 2.05], [0.92, 2.08]
);
assertVisible([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);

// check that off-plot annotations are hidden - zoom in to
// only one of the four on each subplot
return Plotly.relayout(gd, {
'xaxis.range': [1.4, 1.6],
'yaxis.range': [0.9, 1.1],
'xaxis2.range': ['2001-01-15', '2001-02-15'],
'yaxis2.range': [0.9, 1.1],
'xaxis3.range': [1.9, 2.1],
'yaxis3.range': [1.4, 1.6]
});
})
.then(function() {
assertRanges([1.4, 1.6], [0.9, 1.1],
['2001-01-15', '2001-02-15'], [0.9, 1.1],
[1.9, 2.1], [1.4, 1.6]
);
// only one annotation on each subplot, plus the two paper-referenced
// are visible after zooming in
assertVisible([3, 7, 9, 12, 13]);
})
.catch(failTest)
.then(done);
Expand Down