Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 493ee75

Browse filesBrowse files
committed
fix texttemplate formatting for scattermapbox
... using a new formatLabels method. Notice that now the minus sign render correctly.
1 parent 04503ea commit 493ee75
Copy full SHA for 493ee75

File tree

5 files changed

+62
-17
lines changed
Filter options

5 files changed

+62
-17
lines changed

‎src/traces/scattermapbox/convert.js

Copy file name to clipboardExpand all lines: src/traces/scattermapbox/convert.js
+17-10Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var Drawing = require('../../components/drawing');
1919
var makeBubbleSizeFn = require('../scatter/make_bubble_size_func');
2020
var subTypes = require('../scatter/subtypes');
2121
var convertTextOpts = require('../../plots/mapbox/convert_text_opts');
22+
var appendArrayPointValue = require('../../components/fx/helpers').appendArrayPointValue;
2223

2324
var NEWLINES = require('../../lib/svg_text_utils').NEWLINES;
2425
var BR_TAG_ALL = require('../../lib/svg_text_utils').BR_TAG_ALL;
@@ -233,6 +234,7 @@ function makeCircleOpts(calcTrace) {
233234
}
234235

235236
function makeSymbolGeoJSON(calcTrace, gd) {
237+
var fullLayout = gd._fullLayout;
236238
var trace = calcTrace[0].trace;
237239

238240
var marker = trace.marker || {};
@@ -253,18 +255,23 @@ function makeSymbolGeoJSON(calcTrace, gd) {
253255

254256
if(isBADNUM(calcPt.lonlat)) continue;
255257

256-
var txt = trace.texttemplate;
257-
if(txt) {
258-
var txti = Array.isArray(txt) ? (txt[i] || '') : txt;
259-
calcPt.text = calcPt.tx;
260-
calcPt.lon = calcPt.lonlat[0];
261-
calcPt.lat = calcPt.lonlat[1];
262-
calcPt.customdata = calcPt.data;
263-
calcPt.txt = Lib.texttemplateString(txti, {}, gd._fullLayout._d3locale, calcPt, trace._meta || {});
258+
var texttemplate = trace.texttemplate;
259+
var text;
260+
261+
if(texttemplate) {
262+
var tt = Array.isArray(texttemplate) ? (texttemplate[i] || '') : texttemplate;
263+
var labels = trace._module.formatLabels(calcPt, trace, fullLayout);
264+
var pointValues = {};
265+
appendArrayPointValue(pointValues, trace, calcPt.i);
266+
var meta = trace._meta || {};
267+
text = Lib.texttemplateString(tt, labels, fullLayout._d3locale, pointValues, calcPt, meta);
268+
} else {
269+
text = fillText(calcPt.tx);
264270
}
265271

266-
var text = txt ? calcPt.txt : fillText(calcPt.tx);
267-
if(text) text = text.replace(NEWLINES, '').replace(BR_TAG_ALL, '\n');
272+
if(text) {
273+
text = text.replace(NEWLINES, '').replace(BR_TAG_ALL, '\n');
274+
}
268275

269276
features.push({
270277
type: 'Feature',
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright 2012-2019, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Axes = require('../../plots/cartesian/axes');
12+
13+
module.exports = function formatLabels(cdi, trace, fullLayout) {
14+
var labels = {};
15+
16+
var subplot = fullLayout[trace.subplot]._subplot;
17+
var ax = subplot.mockAxis;
18+
19+
var lonlat = cdi.lonlat;
20+
labels.lonLabel = Axes.tickText(ax, ax.c2l(lonlat[0]), true).text;
21+
labels.latLabel = Axes.tickText(ax, ax.c2l(lonlat[1]), true).text;
22+
23+
return labels;
24+
};

‎src/traces/scattermapbox/hover.js

Copy file name to clipboardExpand all lines: src/traces/scattermapbox/hover.js
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ module.exports = function hoverPoints(pointData, xval, yval) {
6464
pointData.y0 = yc - rad;
6565
pointData.y1 = yc + rad;
6666

67+
var fullLayout = {};
68+
fullLayout[trace.subplot] = {_subplot: subplot};
69+
var labels = trace._module.formatLabels(di, trace, fullLayout);
70+
pointData.lonLabel = labels.lonLabel;
71+
pointData.latLabel = labels.latLabel;
72+
6773
pointData.color = getTraceColor(trace, di);
6874
pointData.extraText = getExtraText(trace, di, cd[0].t.labels);
6975
pointData.hovertemplate = trace.hovertemplate;
@@ -72,9 +78,7 @@ module.exports = function hoverPoints(pointData, xval, yval) {
7278
};
7379

7480
function getExtraText(trace, di, labels) {
75-
if(trace.hovertemplate) {
76-
return;
77-
}
81+
if(trace.hovertemplate) return;
7882

7983
var hoverinfo = di.hi || trace.hoverinfo;
8084
var parts = hoverinfo.split('+');

‎src/traces/scattermapbox/index.js

Copy file name to clipboardExpand all lines: src/traces/scattermapbox/index.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
attributes: require('./attributes'),
1313
supplyDefaults: require('./defaults'),
1414
colorbar: require('../scatter/marker_colorbar'),
15+
formatLabels: require('./format_labels'),
1516
calc: require('../scattergeo/calc'),
1617
plot: require('./plot'),
1718
hoverPoints: require('./hover'),

‎test/jasmine/tests/scattermapbox_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/scattermapbox_test.js
+13-4Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var Plotly = require('@lib');
22
var Plots = require('@src/plots/plots');
33
var Lib = require('@src/lib');
4+
var Axes = require('@src/plots/cartesian/axes');
45

56
var ScatterMapbox = require('@src/traces/scattermapbox');
67
var convert = require('@src/traces/scattermapbox/convert');
@@ -139,7 +140,15 @@ describe('scattermapbox convert', function() {
139140
Plots.doCalcdata(gd, fullTrace);
140141

141142
var calcTrace = gd.calcdata[0];
142-
return convert({_fullLayout: {_d3locale: false}}, calcTrace);
143+
144+
var mockAxis = {type: 'linear'};
145+
Axes.setConvert(mockAxis, gd._fullLayout);
146+
147+
gd._fullLayout.mapbox._subplot = {
148+
mockAxis: mockAxis
149+
};
150+
151+
return convert(gd, calcTrace);
143152
}
144153

145154
function assertVisibility(opts, expectations) {
@@ -536,9 +545,9 @@ describe('scattermapbox convert', function() {
536545
});
537546

538547
expect(actualText).toEqual([
539-
'Montreal (-73.57, 45.5): 1.8M',
540-
'Toronto (-79.24, 43.4): 2.9M',
541-
'Vancouver (-123.06, 49.13): 680k'
548+
'Montreal (73.57, 45.5): 1.8M',
549+
'Toronto (79.24, 43.4): 2.9M',
550+
'Vancouver (123.06, 49.13): 680k'
542551
]);
543552
});
544553

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.