Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da1e9d7

Browse filesBrowse files
committed
annotations[i].captureevents
1 parent 919580e commit da1e9d7
Copy full SHA for da1e9d7

File tree

4 files changed

+32
-5
lines changed
Filter options

4 files changed

+32
-5
lines changed

‎src/components/annotations/annotation_defaults.js

Copy file name to clipboardExpand all lines: src/components/annotations/annotation_defaults.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ module.exports = function handleAnnotationDefaults(annIn, annOut, fullLayout, op
120120
color: hoverBorder
121121
});
122122
}
123+
coerce('captureevents', !!hoverText);
123124

124125
return annOut;
125126
};

‎src/components/annotations/attributes.js

Copy file name to clipboardExpand all lines: src/components/annotations/attributes.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,18 @@ module.exports = {
413413
].join(' ')
414414
})
415415
},
416+
captureevents: {
417+
valType: 'boolean',
418+
role: 'info',
419+
description: [
420+
'Determines whether the annotation text box captures mouse move',
421+
'and click events, or allows those events to pass through to data',
422+
'points in the plot that may be behind the annotation. By default',
423+
'`captureevents` is *false* unless `hovertext` is provided.',
424+
'If you use the event `plotly_clickannotation` without `hovertext`',
425+
'you must explicitly enable `captureevents`.'
426+
].join(' ')
427+
},
416428

417429
_deprecated: {
418430
ref: {

‎src/components/annotations/draw.js

Copy file name to clipboardExpand all lines: src/components/annotations/draw.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function drawOne(gd, index) {
105105
.attr('data-index', String(index));
106106

107107
var annTextGroupInner = annTextGroup.append('g')
108-
.style('pointer-events', 'all')
108+
.style('pointer-events', options.captureevents ? 'all' : null)
109109
.call(setCursor, 'default')
110110
.on('click', function() {
111111
gd._dragging = false;

‎test/jasmine/tests/annotations_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/annotations_test.js
+18-4Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,23 +1127,36 @@ describe('annotation effects', function() {
11271127
}
11281128

11291129
makePlot([
1130-
{x: 50, y: 50, text: 'hi', width: 50, ax: 0, ay: -20},
1130+
{x: 50, y: 50, text: 'hi', width: 50, ax: 0, ay: -40},
11311131
{x: 20, y: 20, text: 'bye', height: 40, showarrow: false},
1132-
{x: 80, y: 80, text: 'why?', ax: 0, ay: -20}
1132+
{x: 80, y: 80, text: 'why?', ax: 0, ay: -40}
11331133
], {}) // turn off the default editable: true
11341134
.then(function() {
11351135
clickData = [];
11361136
gd.on('plotly_clickannotation', function(evt) { clickData.push(evt); });
11371137

11381138
gdBB = gd.getBoundingClientRect();
11391139
pos0Head = [gdBB.left + 250, gdBB.top + 250];
1140-
pos0 = [pos0Head[0], pos0Head[1] - 20];
1140+
pos0 = [pos0Head[0], pos0Head[1] - 40];
11411141
pos1 = [gdBB.left + 160, gdBB.top + 340];
11421142
pos2Head = [gdBB.left + 340, gdBB.top + 160];
1143-
pos2 = [pos2Head[0], pos2Head[1] - 20];
1143+
pos2 = [pos2Head[0], pos2Head[1] - 40];
11441144

11451145
return assertHoverLabels([[pos0, ''], [pos1, ''], [pos2, '']]);
11461146
})
1147+
// not going to register either of these because captureevents is off
1148+
.then(function() { return _click(pos1); })
1149+
.then(function() { return _click(pos2Head); })
1150+
.then(function() {
1151+
assertClickData([]);
1152+
1153+
return Plotly.relayout(gd, {
1154+
'annotations[1].captureevents': true,
1155+
'annotations[2].captureevents': true
1156+
});
1157+
})
1158+
// now we'll register the click on #1, but still not on #2
1159+
// because we're clicking the head, not the text box
11471160
.then(function() { return _click(pos1); })
11481161
.then(function() { return _click(pos2Head); })
11491162
.then(function() {
@@ -1168,6 +1181,7 @@ describe('annotation effects', function() {
11681181
'0 only');
11691182
})
11701183
// click and hover work together?
1184+
// this also tests that hover turns on annotation.captureevents
11711185
.then(function() { return _click(pos0); })
11721186
.then(function() {
11731187
assertClickData([{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.