Skip to content

Commit c783c33

Browse files
authored
Merge pull request #5676 from plotly/mapbox-latlon
Provide latLon hover labels on scattermapbox and densitymapbox
2 parents 1bc2eb5 + 424f990 commit c783c33

File tree

5 files changed

+15
-40
lines changed

5 files changed

+15
-40
lines changed

Diff for: src/traces/densitymapbox/hover.js

+2-32
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
var Lib = require('../../lib');
43
var Axes = require('../../plots/cartesian/axes');
5-
var scatterMapboxHoverPoints = require('../scattermapbox/hover');
4+
var scatterMapboxHoverPoints = require('../scattermapbox/hover').hoverPoints;
5+
var getExtraText = require('../scattermapbox/hover').getExtraText;
66

77
module.exports = function hoverPoints(pointData, xval, yval) {
88
var pts = scatterMapboxHoverPoints(pointData, xval, yval);
@@ -26,33 +26,3 @@ module.exports = function hoverPoints(pointData, xval, yval) {
2626

2727
return [newPointData];
2828
};
29-
30-
function getExtraText(trace, di, labels) {
31-
if(trace.hovertemplate) return;
32-
33-
var hoverinfo = di.hi || trace.hoverinfo;
34-
var parts = hoverinfo.split('+');
35-
var isAll = parts.indexOf('all') !== -1;
36-
var hasLon = parts.indexOf('lon') !== -1;
37-
var hasLat = parts.indexOf('lat') !== -1;
38-
var lonlat = di.lonlat;
39-
var text = [];
40-
41-
function format(v) {
42-
return v + '\u00B0';
43-
}
44-
45-
if(isAll || (hasLon && hasLat)) {
46-
text.push('(' + format(lonlat[0]) + ', ' + format(lonlat[1]) + ')');
47-
} else if(hasLon) {
48-
text.push(labels.lon + format(lonlat[0]));
49-
} else if(hasLat) {
50-
text.push(labels.lat + format(lonlat[1]));
51-
}
52-
53-
if(isAll || parts.indexOf('text') !== -1) {
54-
Lib.fillText(di, trace, text);
55-
}
56-
57-
return text.join('<br>');
58-
}

Diff for: src/traces/scattermapbox/hover.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var getTraceColor = require('../scatter/get_trace_color');
66
var fillText = Lib.fillText;
77
var BADNUM = require('../../constants/numerical').BADNUM;
88

9-
module.exports = function hoverPoints(pointData, xval, yval) {
9+
function hoverPoints(pointData, xval, yval) {
1010
var cd = pointData.cd;
1111
var trace = cd[0].trace;
1212
var xa = pointData.xa;
@@ -66,7 +66,7 @@ module.exports = function hoverPoints(pointData, xval, yval) {
6666
pointData.hovertemplate = trace.hovertemplate;
6767

6868
return [pointData];
69-
};
69+
}
7070

7171
function getExtraText(trace, di, labels) {
7272
if(trace.hovertemplate) return;
@@ -86,7 +86,7 @@ function getExtraText(trace, di, labels) {
8686
}
8787

8888
if(isAll || (hasLon && hasLat)) {
89-
text.push('(' + format(lonlat[0]) + ', ' + format(lonlat[1]) + ')');
89+
text.push('(' + format(lonlat[1]) + ', ' + format(lonlat[0]) + ')');
9090
} else if(hasLon) {
9191
text.push(labels.lon + format(lonlat[0]));
9292
} else if(hasLat) {
@@ -99,3 +99,8 @@ function getExtraText(trace, di, labels) {
9999

100100
return text.join('<br>');
101101
}
102+
103+
module.exports = {
104+
hoverPoints: hoverPoints,
105+
getExtraText: getExtraText
106+
};

Diff for: src/traces/scattermapbox/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
formatLabels: require('./format_labels'),
88
calc: require('../scattergeo/calc'),
99
plot: require('./plot'),
10-
hoverPoints: require('./hover'),
10+
hoverPoints: require('./hover').hoverPoints,
1111
eventData: require('./event_data'),
1212
selectPoints: require('./select'),
1313

Diff for: test/jasmine/tests/densitymapbox_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ describe('Test densitymapbox hover:', function() {
330330

331331
var specs = [{
332332
desc: 'basic',
333-
nums: '3\n(20°, 25°)',
333+
nums: '3\n(25°, 20°)',
334334
name: '',
335335
evtPts: [{lon: 20, lat: 25, z: 3, pointNumber: 1, curveNumber: 0}]
336336
}, {
@@ -352,7 +352,7 @@ describe('Test densitymapbox hover:', function() {
352352
});
353353
return fig;
354354
},
355-
nums: '(20°, 25°)',
355+
nums: '(25°, 20°)',
356356
name: 'trace 0',
357357
evtPts: [{lon: 20, lat: 25, z: 3, pointNumber: 1, curveNumber: 0}]
358358
}, {
@@ -363,7 +363,7 @@ describe('Test densitymapbox hover:', function() {
363363
});
364364
return fig;
365365
},
366-
nums: '(20°, 25°)',
366+
nums: '(25°, 20°)',
367367
name: '',
368368
evtPts: [{lon: 20, lat: 25, pointNumber: 1, curveNumber: 0}]
369369
}];

Diff for: test/jasmine/tests/scattermapbox_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ describe('scattermapbox hover', function() {
731731
expect([out.x0, out.x1, out.y0, out.y1]).toBeCloseToArray([
732732
1122.33, 1124.33, 105.41, 107.41
733733
]);
734-
expect(out.extraText).toEqual('(300°, 10°)<br>D');
734+
expect(out.extraText).toEqual('(10°, 300°)<br>D');
735735
expect(out.color).toEqual('#1f77b4');
736736
});
737737

0 commit comments

Comments
 (0)