Skip to content

Commit 1d5606a

Browse files
committed
include subplotId in clickannotation event data
- add hover/click tests for 3d annotations
1 parent 8b8a088 commit 1d5606a

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/components/annotations/draw.js

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
135135
gd._dragging = false;
136136
gd.emit('plotly_clickannotation', {
137137
index: index,
138+
subplotId: subplotId,
138139
annotation: options._input,
139140
fullAnnotation: options,
140141
event: d3.event

test/jasmine/tests/gl_plot_interact_test.js

+50
Original file line numberDiff line numberDiff line change
@@ -1659,4 +1659,54 @@ describe('Test gl3d annotations', function() {
16591659
.catch(fail)
16601660
.then(done);
16611661
});
1662+
1663+
it('should display hover labels and trigger *plotly_clickannotation* event', function(done) {
1664+
function dispatch(eventType) {
1665+
var target = d3.select('g.annotation-text-g').select('g').node();
1666+
target.dispatchEvent(new MouseEvent(eventType));
1667+
}
1668+
1669+
Plotly.plot(gd, [{
1670+
type: 'scatter3d',
1671+
x: [1, 2, 3],
1672+
y: [1, 2, 3],
1673+
z: [1, 2, 1]
1674+
}], {
1675+
scene: {
1676+
annotations: [{
1677+
text: 'hello',
1678+
x: 2, y: 2, z: 2,
1679+
ax: 0, ay: -100,
1680+
hovertext: 'HELLO',
1681+
hoverlabel: {
1682+
bgcolor: 'red',
1683+
font: { size: 20 }
1684+
}
1685+
}]
1686+
},
1687+
width: 500,
1688+
height: 500
1689+
})
1690+
.then(function() {
1691+
dispatch('mouseover');
1692+
expect(d3.select('.hovertext').size()).toEqual(1);
1693+
})
1694+
.then(function() {
1695+
return new Promise(function(resolve, reject) {
1696+
gd.once('plotly_clickannotation', function(eventData) {
1697+
expect(eventData.index).toEqual(0);
1698+
expect(eventData.subplotId).toEqual('scene');
1699+
resolve();
1700+
});
1701+
1702+
setTimeout(function() {
1703+
reject('plotly_clickannotation did not get called!');
1704+
}, 100);
1705+
1706+
dispatch('click');
1707+
});
1708+
})
1709+
.catch(fail)
1710+
.then(done);
1711+
});
16621712
});

0 commit comments

Comments
 (0)