Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/traces/choropleth/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ plotChoropleth.plot = function(geo, choroplethData, geoLayout) {
cleanHoverLabelsFunc = makeCleanHoverLabelsFunc(geo, trace),
eventDataFunc = makeEventDataFunc(trace);

// keep ref to event data in this scope for plotly_unhover
var eventData = null;

function handleMouseOver(pt, ptIndex) {
if(!geo.showHover) return;

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

geo.graphDiv.emit('plotly_hover', eventDataFunc(pt, ptIndex));
eventData = eventDataFunc(pt, ptIndex);

geo.graphDiv.emit('plotly_hover', eventData);
}

function handleClick(pt, ptIndex) {
Expand All @@ -111,6 +116,8 @@ plotChoropleth.plot = function(geo, choroplethData, geoLayout) {
.on('click', handleClick)
.on('mouseout', function() {
Fx.loneUnhover(geo.hoverContainer);

geo.graphDiv.emit('plotly_unhover', eventData);
})
.on('mousedown', function() {
// to simulate the 'zoomon' event
Expand Down
9 changes: 8 additions & 1 deletion src/traces/scattergeo/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ plotScatterGeo.plot = function(geo, scattergeoData) {
hoverinfo.indexOf('name') !== -1
);

// keep ref to event data in this scope for plotly_unhover
var eventData = null;

function handleMouseOver(pt, ptIndex) {
if(!geo.showHover) return;

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

geo.graphDiv.emit('plotly_hover', eventDataFunc(pt, ptIndex));
eventData = eventDataFunc(pt, ptIndex);

geo.graphDiv.emit('plotly_hover', eventData);
}

function handleClick(pt, ptIndex) {
Expand All @@ -189,6 +194,8 @@ plotScatterGeo.plot = function(geo, scattergeoData) {
.on('click', handleClick)
.on('mouseout', function() {
Fx.loneUnhover(geo.hoverContainer);

geo.graphDiv.emit('plotly_unhover', eventData);
})
.on('mousedown', function() {
// to simulate the 'zoomon' event
Expand Down
55 changes: 55 additions & 0 deletions test/jasmine/tests/geo_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,34 @@ describe('Test geo interactions', function() {
});
});

describe('scattergeo unhover events', function() {
var ptData;

beforeEach(function() {
gd.on('plotly_unhover', function(eventData) {
ptData = eventData.points[0];
});

mouseEventScatterGeo('mouseover');
mouseEventScatterGeo('mouseout');
});

it('should contain the correct fields', function() {
expect(Object.keys(ptData)).toEqual([
'data', 'fullData', 'curveNumber', 'pointNumber',
'lon', 'lat', 'location'
]);
});

it('should show the correct point data', function() {
expect(ptData.lon).toEqual(0);
expect(ptData.lat).toEqual(0);
expect(ptData.location).toBe(null);
expect(ptData.curveNumber).toEqual(0);
expect(ptData.pointNumber).toEqual(0);
});
});

describe('choropleth hover labels', function() {
beforeEach(function() {
mouseEventChoropleth('mouseover');
Expand Down Expand Up @@ -196,6 +224,33 @@ describe('Test geo interactions', function() {
});
});

describe('choropleth unhover events', function() {
var ptData;

beforeEach(function() {
gd.on('plotly_unhover', function(eventData) {
ptData = eventData.points[0];
});

mouseEventChoropleth('mouseover');
mouseEventChoropleth('mouseout');
});

it('should contain the correct fields', function() {
expect(Object.keys(ptData)).toEqual([
'data', 'fullData', 'curveNumber', 'pointNumber',
'location', 'z'
]);
});

it('should show the correct point data', function() {
expect(ptData.location).toBe('RUS');
expect(ptData.z).toEqual(10);
expect(ptData.curveNumber).toEqual(1);
expect(ptData.pointNumber).toEqual(2);
});
});

describe('trace visibility toggle', function() {
it('should toggle scattergeo elements', function(done) {
expect(countTraces('scattergeo')).toBe(1);
Expand Down