Skip to content

Commit bc806cc

Browse files
committed
avoid duplicate logic in densitymapbox
1 parent c0b196c commit bc806cc

File tree

3 files changed

+10
-35
lines changed

3 files changed

+10
-35
lines changed

src/traces/densitymapbox/hover.js

Lines changed: 2 additions & 32 deletions
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[1]) + ', ' + format(lonlat[0]) + ')');
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-
}

src/traces/scattermapbox/hover.js

Lines changed: 7 additions & 2 deletions
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;
@@ -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+
};

src/traces/scattermapbox/index.js

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)