Skip to content

Commit b21154b

Browse files
committedApr 6, 2017
remove unnecessary annotation clip paths
1 parent 2e132bd commit b21154b

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed
 

‎src/components/annotations/draw.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,14 @@ function drawOne(gd, index) {
7272
var optionsIn = (layout.annotations || [])[index],
7373
options = fullLayout.annotations[index];
7474

75+
var annClipID = 'clip' + fullLayout._uid + '_ann' + index;
76+
7577
// this annotation is gone - quit now after deleting it
7678
// TODO: use d3 idioms instead of deleting and redrawing every time
77-
if(!optionsIn || options.visible === false) return;
79+
if(!optionsIn || options.visible === false) {
80+
d3.selectAll('#' + annClipID).remove();
81+
return;
82+
}
7883

7984
var xa = Axes.getFromId(gd, options.xref),
8085
ya = Axes.getFromId(gd, options.yref),
@@ -120,7 +125,6 @@ function drawOne(gd, index) {
120125

121126
var isSizeConstrained = options.width || options.height;
122127

123-
var annClipID = 'clip' + fullLayout._uid + '_ann' + index;
124128
var annTextClip = fullLayout._defs.select('.clips')
125129
.selectAll('#' + annClipID)
126130
.data(isSizeConstrained ? [0] : []);

‎test/jasmine/tests/annotations_test.js

+48
Original file line numberDiff line numberDiff line change
@@ -1041,3 +1041,51 @@ describe('annotation dragging', function() {
10411041
.then(done);
10421042
});
10431043
});
1044+
1045+
describe('annotation clip paths', function() {
1046+
var gd;
1047+
1048+
beforeEach(function(done) {
1049+
gd = createGraphDiv();
1050+
1051+
// we've already tested autorange with relayout, so fix the geometry
1052+
// completely so we know exactly what we're dealing with
1053+
// plot area is 300x300, and covers data range 100x100
1054+
Plotly.plot(gd, [{x: [0, 100], y: [0, 100]}], {
1055+
annotations: [
1056+
{x: 50, y: 50, text: 'hi', width: 50},
1057+
{x: 20, y: 20, text: 'bye', height: 40},
1058+
{x: 80, y: 80, text: 'why?'}
1059+
]
1060+
})
1061+
.then(done);
1062+
});
1063+
1064+
afterEach(destroyGraphDiv);
1065+
1066+
it('should only make the clippaths it needs and delete others', function(done) {
1067+
expect(d3.select(gd).selectAll('.annclip').size()).toBe(2);
1068+
1069+
Plotly.relayout(gd, {'annotations[0].visible': false})
1070+
.then(function() {
1071+
expect(d3.select(gd).selectAll('.annclip').size()).toBe(1);
1072+
1073+
return Plotly.relayout(gd, {'annotations[2].width': 20});
1074+
})
1075+
.then(function() {
1076+
expect(d3.select(gd).selectAll('.annclip').size()).toBe(2);
1077+
1078+
return Plotly.relayout(gd, {'annotations[1].height': null});
1079+
})
1080+
.then(function() {
1081+
expect(d3.select(gd).selectAll('.annclip').size()).toBe(1);
1082+
1083+
return Plotly.relayout(gd, {'annotations[2]': null});
1084+
})
1085+
.then(function() {
1086+
expect(d3.select(gd).selectAll('.annclip').size()).toBe(0);
1087+
})
1088+
.catch(failTest)
1089+
.then(done);
1090+
});
1091+
});

0 commit comments

Comments
 (0)
Please sign in to comment.