Skip to content

Commit e719f74

Browse files
committed
Rename object keys
1 parent 84fc044 commit e719f74

File tree

13 files changed

+95
-103
lines changed

13 files changed

+95
-103
lines changed

src/components/drawing/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,11 +1300,11 @@ drawing.textPointStyle = function (s, trace, gd) {
13001300
var pointValues = {};
13011301
appendArrayPointValue(pointValues, trace, d.i);
13021302
text = Lib.texttemplateString({
1303-
args: [pointValues, d, trace._meta],
1304-
d3locale: fullLayout._d3locale,
1303+
data: [pointValues, d, trace._meta],
13051304
fallback: trace.texttemplatefallback,
13061305
labels,
1307-
string: text
1306+
locale: fullLayout._d3locale,
1307+
template: text
13081308
});
13091309
}
13101310

src/components/fx/hover.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,11 +1249,11 @@ function createHoverText(hoverData, opts) {
12491249
var mainText = !unifiedhovertitleText
12501250
? t0
12511251
: Lib.hovertemplateString({
1252-
args:
1252+
data:
12531253
hovermode === 'x unified' ? [{ xa: item0.xa, x: item0.xVal }] : [{ ya: item0.ya, y: item0.yVal }],
1254-
d3locale: fullLayout._d3locale,
12551254
fallback: item0.trace.hovertemplatefallback,
1256-
string: unifiedhovertitleText
1255+
locale: fullLayout._d3locale,
1256+
template: unifiedhovertitleText
12571257
});
12581258

12591259
var mockLayoutIn = {
@@ -1673,11 +1673,11 @@ function getHoverLabelText(d, showCommonLabel, hovermode, fullLayout, t0, g) {
16731673
}
16741674

16751675
text = Lib.hovertemplateString({
1676-
args: [d.eventData[0] || {}, d.trace._meta],
1677-
d3locale: fullLayout._d3locale,
1676+
data: [d.eventData[0] || {}, d.trace._meta],
16781677
fallback: d.trace.hovertemplatefallback,
16791678
labels,
1680-
string: hovertemplate
1679+
locale: fullLayout._d3locale,
1680+
template: hovertemplate
16811681
});
16821682

16831683
text = text.replace(EXTRA_STRING_REGEX, (_, extra) => {

src/components/shapes/display_labels.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ module.exports = function drawLabel(gd, index, options, shapeGroup) {
3333
}
3434
}
3535
text = Lib.texttemplateStringForShapes({
36-
args: [templateValues],
37-
d3locale: gd._fullLayout._d3locale,
36+
data: [templateValues],
3837
fallback: options.label.texttemplatefallback,
39-
labels: {},
40-
string: options.label.texttemplate
38+
locale: gd._fullLayout._d3locale,
39+
template: options.label.texttemplate
4140
});
4241
} else {
4342
text = options.label.text;

src/lib/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,22 +1112,22 @@ var TEMPLATE_STRING_FORMAT_SEPARATOR = /^[:|\|]/;
11121112
* or fallback to associated labels.
11131113
*
11141114
* Examples:
1115-
* Lib.hovertemplateString({ string 'name: %{trace}', labels: {trace: 'asdf'} }) --> 'name: asdf'
1116-
* Lib.hovertemplateString({ string: 'name: %{trace[0].name}', labels: { trace: [{ name: 'asdf' }] } }) --> 'name: asdf'
1117-
* Lib.hovertemplateString({ string: 'price: %{y:$.2f}', labels: { y: 1 } }) --> 'price: $1.00'
1115+
* Lib.templateFormatString({ template 'name: %{trace}', labels: {trace: 'asdf'} }) --> 'name: asdf'
1116+
* Lib.templateFormatString({ template: 'name: %{trace[0].name}', labels: { trace: [{ name: 'asdf' }] } }) --> 'name: asdf'
1117+
* Lib.templateFormatString({ template: 'price: %{y:$.2f}', labels: { y: 1 } }) --> 'price: $1.00'
11181118
*
11191119
* @param {object} options - Configuration object
1120-
* @param {array} options.args - Data objects containing substitution values
1121-
* @param {object} options.d3locale - D3 locale for formatting
1120+
* @param {array} options.data - Data objects containing substitution values
11221121
* @param {string} options.fallback - Fallback value when substitution fails
11231122
* @param {object} options.labels - Data object containing fallback text when no formatting is specified, ex.: {yLabel: 'formattedYValue'}
1123+
* @param {object} options.locale - D3 locale for formatting
11241124
* @param {object} options.opts - Additional options
1125-
* @param {string} options.string - Input string containing %{...:...} template strings
1125+
* @param {string} options.template - Input string containing %{...:...} template strings
11261126
*
11271127
* @return {string} templated string
11281128
*/
1129-
function templateFormatString({ args = [], d3locale, fallback, labels = {}, opts, string }) {
1130-
return string.replace(lib.TEMPLATE_STRING_REGEX, (_, rawKey, format) => {
1129+
function templateFormatString({ data = [], locale, fallback, labels = {}, opts, template }) {
1130+
return template.replace(lib.TEMPLATE_STRING_REGEX, (_, rawKey, format) => {
11311131
const isOther = ['xother', 'yother'].includes(rawKey);
11321132
const isSpaceOther = ['_xother', '_yother'].includes(rawKey);
11331133
const isSpaceOtherSpace = ['_xother_', '_yother_'].includes(rawKey);
@@ -1154,7 +1154,7 @@ function templateFormatString({ args = [], d3locale, fallback, labels = {}, opts
11541154
if (labels[key] === undefined) return '';
11551155
value = labels[key];
11561156
} else {
1157-
for (const obj of args) {
1157+
for (const obj of data) {
11581158
if (!obj) continue;
11591159
if (obj.hasOwnProperty(key)) {
11601160
value = obj[key];
@@ -1184,15 +1184,15 @@ function templateFormatString({ args = [], d3locale, fallback, labels = {}, opts
11841184
if (format) {
11851185
var fmt;
11861186
if (format[0] === ':') {
1187-
fmt = d3locale ? d3locale.numberFormat : lib.numberFormat;
1187+
fmt = locale ? locale.numberFormat : lib.numberFormat;
11881188
if (value !== '') {
11891189
// e.g. skip missing data on heatmap
11901190
value = fmt(format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''))(value);
11911191
}
11921192
}
11931193

11941194
if (format[0] === '|') {
1195-
fmt = d3locale ? d3locale.timeFormat : utcFormat;
1195+
fmt = locale ? locale.timeFormat : utcFormat;
11961196
var ms = lib.dateTime2ms(value);
11971197
value = lib.formatDate(ms, format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''), false, fmt);
11981198
}

src/traces/bar/plot.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,11 +1074,11 @@ function calcTexttemplate(fullLayout, cd, index, xa, ya) {
10741074
var customdata = Lib.castOption(trace, cdi.i, 'customdata');
10751075
if (customdata) obj.customdata = customdata;
10761076
return Lib.texttemplateString({
1077-
args: [pt, obj, trace._meta],
1078-
d3locale: fullLayout._d3locale,
1077+
data: [pt, obj, trace._meta],
10791078
fallback: trace.texttemplatefallback,
10801079
labels: obj,
1081-
string: texttemplate
1080+
locale: fullLayout._d3locale,
1081+
template: texttemplate
10821082
});
10831083
}
10841084

src/traces/heatmap/plot.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,11 @@ module.exports = function (gd, plotinfo, cdheatmaps, heatmapLayer) {
451451
obj.text = theText;
452452

453453
var _t = Lib.texttemplateString({
454-
args: [obj, trace._meta],
455-
d3locale: gd._fullLayout._d3locale,
454+
data: [obj, trace._meta],
456455
fallback: trace.texttemplatefallback,
457456
labels: obj,
458-
string: texttemplate
457+
locale: gd._fullLayout._d3locale,
458+
template: texttemplate
459459
});
460460
if (!_t) continue;
461461

src/traces/pie/plot.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,11 +1272,11 @@ function formatSliceLabel(gd, pt, cd0) {
12721272
var ptTx = helpers.getFirstFilled(trace.text, pt.pts);
12731273
if (isValidTextValue(ptTx) || ptTx === '') obj.text = ptTx;
12741274
pt.text = Lib.texttemplateString({
1275-
args: [obj, trace._meta],
1276-
d3locale: gd._fullLayout._d3locale,
1275+
data: [obj, trace._meta],
12771276
fallback: trace.texttemplatefallback,
12781277
labels: obj,
1279-
string: txt
1278+
locale: gd._fullLayout._d3locale,
1279+
template: txt
12801280
});
12811281
}
12821282
}

src/traces/scatter3d/convert.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ function convertPlotlyOptions(scene, data) {
258258
var pointValues = {};
259259
appendArrayPointValue(pointValues, data, i);
260260
text[i] = Lib.texttemplateString({
261-
args: [pointValues, d, data._meta],
262-
d3locale,
261+
data: [pointValues, d, data._meta],
263262
fallback: data.texttemplatefallback,
264263
labels,
265-
string: txt(i)
264+
locale: d3locale,
265+
template: txt(i)
266266
});
267267
}
268268
}

src/traces/scattergl/convert.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ function convertTextStyle(gd, trace) {
143143
appendArrayPointValue(pointValues, trace, i);
144144
optsOut.text.push(
145145
Lib.texttemplateString({
146-
args: [pointValues, d, trace._meta],
147-
d3locale,
146+
data: [pointValues, d, trace._meta],
148147
fallback: trace.texttemplatefallback,
149148
labels,
150-
string: txt(i)
149+
locale: d3locale,
150+
template: txt(i)
151151
})
152152
);
153153
}

src/traces/scattermap/convert.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,11 @@ function makeSymbolGeoJSON(calcTrace, gd) {
301301
var pointValues = {};
302302
appendArrayPointValue(pointValues, trace, calcPt.i);
303303
text = Lib.texttemplateString({
304-
args: [pointValues, calcPt, trace._meta],
305-
d3locale: fullLayout._d3locale,
304+
data: [pointValues, calcPt, trace._meta],
306305
fallback: trace.texttemplatefallback,
307306
labels,
308-
string: tt
307+
locale: fullLayout._d3locale,
308+
template: tt
309309
});
310310
} else {
311311
text = fillText(i);

0 commit comments

Comments
 (0)