Skip to content

Commit 8cf5135

Browse files
committed
fill lonLabel and latLabel for scattergeo traces
1 parent 6a670ff commit 8cf5135

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

src/traces/scattergeo/hover.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var Fx = require('../../components/fx');
@@ -64,17 +63,19 @@ module.exports = function hoverPoints(pointData, xval, yval) {
6463
pointData.lon = lonlat[0];
6564
pointData.lat = lonlat[1];
6665

66+
var ax = geo.mockAxis;
67+
pointData.lonLabel = Axes.tickText(ax, ax.c2l(pointData.lon), 'hover').text;
68+
pointData.latLabel = Axes.tickText(ax, ax.c2l(pointData.lat), 'hover').text;
69+
6770
pointData.color = getTraceColor(trace, di);
68-
pointData.extraText = getExtraText(trace, di, geo.mockAxis, cd[0].t.labels);
71+
pointData.extraText = getExtraText(trace, di, pointData, cd[0].t.labels);
6972
pointData.hovertemplate = trace.hovertemplate;
7073

7174
return [pointData];
7275
};
7376

74-
function getExtraText(trace, pt, axis, labels) {
75-
if(trace.hovertemplate) {
76-
return;
77-
}
77+
function getExtraText(trace, pt, pointData, labels) {
78+
if(trace.hovertemplate) return;
7879

7980
var hoverinfo = pt.hi || trace.hoverinfo;
8081

@@ -88,18 +89,16 @@ function getExtraText(trace, pt, axis, labels) {
8889
var hasText = (parts.indexOf('text') !== -1);
8990
var text = [];
9091

91-
function format(val) {
92-
return Axes.tickText(axis, axis.c2l(val), 'hover').text + '\u00B0';
93-
}
92+
function format(val) { return val + '\u00B0'; }
9493

9594
if(hasLocation) {
9695
text.push(pt.loc);
9796
} else if(hasLon && hasLat) {
98-
text.push('(' + format(pt.lonlat[0]) + ', ' + format(pt.lonlat[1]) + ')');
97+
text.push('(' + format(pointData.lonLabel) + ', ' + format(pointData.latLabel) + ')');
9998
} else if(hasLon) {
100-
text.push(labels.lon + format(pt.lonlat[0]));
99+
text.push(labels.lon + format(pointData.lonLabel));
101100
} else if(hasLat) {
102-
text.push(labels.lat + format(pt.lonlat[1]));
101+
text.push(labels.lat + format(pointData.latLabel));
103102
}
104103

105104
if(hasText) {

test/jasmine/tests/scattergeo_test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,32 @@ describe('Test scattergeo hover', function() {
358358
.catch(failTest)
359359
.then(done);
360360
});
361+
362+
describe('should preserve lon/lat formatting hovetemplate equivalence', function() {
363+
var pos = [381, 221];
364+
var exp = ['(10.00012°, 10.00088°)\nA'];
365+
366+
it('- base case (truncate z decimals)', function(done) {
367+
Plotly.restyle(gd, {
368+
lon: [[10.0001221321]],
369+
lat: [[10.00087683]]
370+
})
371+
.then(function() { check(pos, exp); })
372+
.catch(failTest)
373+
.then(done);
374+
});
375+
376+
it('- hovertemplate case (same lon/lat truncation)', function(done) {
377+
Plotly.restyle(gd, {
378+
lon: [[10.0001221321]],
379+
lat: [[10.00087683]],
380+
hovertemplate: '(%{lon}°, %{lat}°)<br>%{text}<extra></extra>'
381+
})
382+
.then(function() { check(pos, exp); })
383+
.catch(failTest)
384+
.then(done);
385+
});
386+
});
361387
});
362388

363389
describe('scattergeo drawing', function() {

0 commit comments

Comments
 (0)