From 2e78f401c0aca406f8c789b0bdb0d8ee322320bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Fri, 15 Apr 2016 10:55:59 -0400 Subject: [PATCH] trigger plotly_unhover on geo mouseout --- src/traces/choropleth/plot.js | 9 +++- src/traces/scattergeo/plot.js | 9 +++- test/jasmine/tests/geo_interact_test.js | 55 +++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/traces/choropleth/plot.js b/src/traces/choropleth/plot.js index 479910008bc..a338847e582 100644 --- a/src/traces/choropleth/plot.js +++ b/src/traces/choropleth/plot.js @@ -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; @@ -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) { @@ -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 diff --git a/src/traces/scattergeo/plot.js b/src/traces/scattergeo/plot.js index 95962f078b4..921dce93b84 100644 --- a/src/traces/scattergeo/plot.js +++ b/src/traces/scattergeo/plot.js @@ -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; @@ -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) { @@ -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 diff --git a/test/jasmine/tests/geo_interact_test.js b/test/jasmine/tests/geo_interact_test.js index e8b3b92aef4..153ec79e9fe 100644 --- a/test/jasmine/tests/geo_interact_test.js +++ b/test/jasmine/tests/geo_interact_test.js @@ -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'); @@ -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);