Skip to content

Commit f67212e

Browse files
committed
Merge pull request #407 from bcutrell/fixes_pie_unhover_event
Fix pie unhover event
2 parents aaa08ae + b93fe97 commit f67212e

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

src/plots/cartesian/graph_interact.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,14 @@ function hoverChanged(gd, evt, oldhoverdata) {
12771277
}
12781278

12791279
// remove hover effects on mouse out, and emit unhover event
1280-
function unhover(gd, evt) {
1280+
function unhover(gd, evt, subplot) {
1281+
if(subplot === 'pie') {
1282+
gd.emit('plotly_unhover', {
1283+
points: [evt]
1284+
});
1285+
return;
1286+
}
1287+
12811288
var fullLayout = gd._fullLayout;
12821289
if(!evt) evt = {};
12831290
if(evt.target &&

src/traces/pie/plot.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ module.exports = function plot(gd, cdpie) {
129129
hasHoverData = true;
130130
}
131131

132-
function handleMouseOut() {
132+
function handleMouseOut(evt) {
133+
Fx.unhover(gd, evt, 'pie');
133134
if(hasHoverData) {
134135
Fx.loneUnhover(fullLayout._hoverlayer.node());
135136
hasHoverData = false;

test/jasmine/tests/hover_pie_test.js

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,71 @@ describe('pie hovering', function() {
4242
* cyFinal: 160
4343
* }];
4444
*/
45-
var futureData;
45+
var hoverData,
46+
unhoverData;
4647

4748

4849
gd.on('plotly_hover', function(data) {
49-
futureData = data;
50+
hoverData = data;
51+
});
52+
53+
gd.on('plotly_unhover', function(data) {
54+
unhoverData = data;
5055
});
5156

5257
mouseEvent('mouseover', width / 2, height / 2);
53-
expect(futureData.points.length).toEqual(1);
54-
expect(Object.keys(futureData.points[0])).toEqual([
58+
mouseEvent('mouseout', width / 2, height / 2);
59+
60+
expect(hoverData.points.length).toEqual(1);
61+
expect(unhoverData.points.length).toEqual(1);
62+
63+
var fields = [
5564
'v', 'label', 'color', 'i', 'hidden',
5665
'text', 'px1', 'pxmid', 'midangle',
5766
'px0', 'largeArc', 'cxFinal', 'cyFinal'
58-
]);
59-
expect(futureData.points[0].i).toEqual(3);
67+
];
68+
69+
expect(Object.keys(hoverData.points[0])).toEqual(fields);
70+
expect(hoverData.points[0].i).toEqual(3);
71+
72+
expect(Object.keys(unhoverData.points[0])).toEqual(fields);
73+
expect(unhoverData.points[0].i).toEqual(3);
6074
});
6175

62-
it('should fire when moving from one slice to another', function(done) {
76+
it('should fire hover event when moving from one slice to another', function(done) {
6377
var count = 0,
64-
futureData = [];
78+
hoverData = [];
6579

6680
gd.on('plotly_hover', function(data) {
6781
count++;
68-
futureData.push(data);
82+
hoverData.push(data);
83+
});
84+
85+
mouseEvent('mouseover', 180, 140);
86+
setTimeout(function() {
87+
mouseEvent('mouseover', 240, 200);
88+
expect(count).toEqual(2);
89+
expect(hoverData[0]).not.toEqual(hoverData[1]);
90+
done();
91+
}, 100);
92+
});
93+
94+
it('should fire unhover event when the mouse moves off the graph', function(done) {
95+
var count = 0,
96+
unhoverData = [];
97+
98+
gd.on('plotly_unhover', function(data) {
99+
count++;
100+
unhoverData.push(data);
69101
});
70102

71103
mouseEvent('mouseover', 180, 140);
104+
mouseEvent('mouseout', 180, 140);
72105
setTimeout(function() {
73106
mouseEvent('mouseover', 240, 200);
107+
mouseEvent('mouseout', 240, 200);
74108
expect(count).toEqual(2);
75-
expect(futureData[0]).not.toEqual(futureData[1]);
109+
expect(unhoverData[0]).not.toEqual(unhoverData[1]);
76110
done();
77111
}, 100);
78112
});

0 commit comments

Comments
 (0)