Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/component/axisPointer/viewHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ export function getValueLabel(
});

if (zrUtil.isString(formatter)) {
text = formatter.replace('{value}', text);
const value = text;
text = formatter.replace('{value}', () => value);
}
else if (zrUtil.isFunction(formatter)) {
text = formatter(params);
Expand Down
2 changes: 1 addition & 1 deletion src/component/dataZoom/SliderZoomView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ function formatLabel(
return isFunction(labelFormatter)
? labelFormatter(value, valueStr)
: isString(labelFormatter)
? labelFormatter.replace('{value}', valueStr)
? labelFormatter.replace('{value}', () => valueStr)
: valueStr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/component/legend/LegendView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ class LegendView extends ComponentView {
const formatter = legendModel.get('formatter');
let content = name;
if (zrUtil.isString(formatter) && formatter) {
content = formatter.replace('{name}', name != null ? name : '');
content = formatter.replace('{name}', () => (name != null ? name : ''));
}
else if (zrUtil.isFunction(formatter)) {
content = formatter(name);
Expand Down
4 changes: 2 additions & 2 deletions src/component/visualMap/VisualMapModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ class VisualMapModel<Opts extends VisualMapOption = VisualMapOption> extends Com

if (zrUtil.isString(formatter)) {
return formatter
.replace('{value}', isMinMax ? (textValue as string[])[0] : textValue as string)
.replace('{value2}', isMinMax ? (textValue as string[])[1] : textValue as string);
.replace('{value}', () => (isMinMax ? (textValue as string[])[0] : textValue as string))
.replace('{value2}', () => (isMinMax ? (textValue as string[])[1] : textValue as string));
}
else if (zrUtil.isFunction(formatter)) {
return isMinMax
Expand Down
2 changes: 1 addition & 1 deletion src/coord/axisHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export function makeLabelFormatter(axis: Axis): (tick: ScaleTick, idx?: number)
// For category axis, get raw value; for numeric axis,
// get formatted label like '1,333,444'.
const label = axis.scale.getLabel(tick);
const text = labelFormatter.replace('{value}', label != null ? label : '');
const text = labelFormatter.replace('{value}', () => (label != null ? label : ''));
return text;
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/coord/geo/GeoModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class GeoModel extends ComponentModel<GeoOption> implements RoamHostModel {
return formatter(params);
}
else if (zrUtil.isString(formatter)) {
return formatter.replace('{a}', name != null ? name : '');
return formatter.replace('{a}', () => (name != null ? name : ''));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/coord/radar/RadarModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class RadarModel extends ComponentModel<RadarOption> implements CoordinateSystem
} as InnerIndicatorAxisOption, false);
if (zrUtil.isString(nameFormatter)) {
const indName = innerIndicatorOpt.name;
innerIndicatorOpt.name = nameFormatter.replace('{value}', indName != null ? indName : '');
innerIndicatorOpt.name = nameFormatter.replace('{value}', () => (indName != null ? indName : ''));
}
else if (zrUtil.isFunction(nameFormatter)) {
innerIndicatorOpt.name = nameFormatter(
Expand Down
97 changes: 97 additions & 0 deletions test/ut/spec/component/formatterLiteralDollar.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.