Skip to content

Commit bd759b1

Browse files
committed
Merge pull request #429 from plotly/geo-unhover
trigger plotly_unhover on geo mouseout [fixes #409]
2 parents 5c60dbe + 2e78f40 commit bd759b1

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

src/traces/choropleth/plot.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ plotChoropleth.plot = function(geo, choroplethData, geoLayout) {
8080
cleanHoverLabelsFunc = makeCleanHoverLabelsFunc(geo, trace),
8181
eventDataFunc = makeEventDataFunc(trace);
8282

83+
// keep ref to event data in this scope for plotly_unhover
84+
var eventData = null;
85+
8386
function handleMouseOver(pt, ptIndex) {
8487
if(!geo.showHover) return;
8588

@@ -95,7 +98,9 @@ plotChoropleth.plot = function(geo, choroplethData, geoLayout) {
9598
container: geo.hoverContainer.node()
9699
});
97100

98-
geo.graphDiv.emit('plotly_hover', eventDataFunc(pt, ptIndex));
101+
eventData = eventDataFunc(pt, ptIndex);
102+
103+
geo.graphDiv.emit('plotly_hover', eventData);
99104
}
100105

101106
function handleClick(pt, ptIndex) {
@@ -111,6 +116,8 @@ plotChoropleth.plot = function(geo, choroplethData, geoLayout) {
111116
.on('click', handleClick)
112117
.on('mouseout', function() {
113118
Fx.loneUnhover(geo.hoverContainer);
119+
120+
geo.graphDiv.emit('plotly_unhover', eventData);
114121
})
115122
.on('mousedown', function() {
116123
// to simulate the 'zoomon' event

src/traces/scattergeo/plot.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ plotScatterGeo.plot = function(geo, scattergeoData) {
158158
hoverinfo.indexOf('name') !== -1
159159
);
160160

161+
// keep ref to event data in this scope for plotly_unhover
162+
var eventData = null;
163+
161164
function handleMouseOver(pt, ptIndex) {
162165
if(!geo.showHover) return;
163166

@@ -174,7 +177,9 @@ plotScatterGeo.plot = function(geo, scattergeoData) {
174177
container: geo.hoverContainer.node()
175178
});
176179

177-
geo.graphDiv.emit('plotly_hover', eventDataFunc(pt, ptIndex));
180+
eventData = eventDataFunc(pt, ptIndex);
181+
182+
geo.graphDiv.emit('plotly_hover', eventData);
178183
}
179184

180185
function handleClick(pt, ptIndex) {
@@ -189,6 +194,8 @@ plotScatterGeo.plot = function(geo, scattergeoData) {
189194
.on('click', handleClick)
190195
.on('mouseout', function() {
191196
Fx.loneUnhover(geo.hoverContainer);
197+
198+
geo.graphDiv.emit('plotly_unhover', eventData);
192199
})
193200
.on('mousedown', function() {
194201
// to simulate the 'zoomon' event

test/jasmine/tests/geo_interact_test.js

+55
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,34 @@ describe('Test geo interactions', function() {
121121
});
122122
});
123123

124+
describe('scattergeo unhover events', function() {
125+
var ptData;
126+
127+
beforeEach(function() {
128+
gd.on('plotly_unhover', function(eventData) {
129+
ptData = eventData.points[0];
130+
});
131+
132+
mouseEventScatterGeo('mouseover');
133+
mouseEventScatterGeo('mouseout');
134+
});
135+
136+
it('should contain the correct fields', function() {
137+
expect(Object.keys(ptData)).toEqual([
138+
'data', 'fullData', 'curveNumber', 'pointNumber',
139+
'lon', 'lat', 'location'
140+
]);
141+
});
142+
143+
it('should show the correct point data', function() {
144+
expect(ptData.lon).toEqual(0);
145+
expect(ptData.lat).toEqual(0);
146+
expect(ptData.location).toBe(null);
147+
expect(ptData.curveNumber).toEqual(0);
148+
expect(ptData.pointNumber).toEqual(0);
149+
});
150+
});
151+
124152
describe('choropleth hover labels', function() {
125153
beforeEach(function() {
126154
mouseEventChoropleth('mouseover');
@@ -196,6 +224,33 @@ describe('Test geo interactions', function() {
196224
});
197225
});
198226

227+
describe('choropleth unhover events', function() {
228+
var ptData;
229+
230+
beforeEach(function() {
231+
gd.on('plotly_unhover', function(eventData) {
232+
ptData = eventData.points[0];
233+
});
234+
235+
mouseEventChoropleth('mouseover');
236+
mouseEventChoropleth('mouseout');
237+
});
238+
239+
it('should contain the correct fields', function() {
240+
expect(Object.keys(ptData)).toEqual([
241+
'data', 'fullData', 'curveNumber', 'pointNumber',
242+
'location', 'z'
243+
]);
244+
});
245+
246+
it('should show the correct point data', function() {
247+
expect(ptData.location).toBe('RUS');
248+
expect(ptData.z).toEqual(10);
249+
expect(ptData.curveNumber).toEqual(1);
250+
expect(ptData.pointNumber).toEqual(2);
251+
});
252+
});
253+
199254
describe('trace visibility toggle', function() {
200255
it('should toggle scattergeo elements', function(done) {
201256
expect(countTraces('scattergeo')).toBe(1);

0 commit comments

Comments
 (0)