MCPcopy
hub / github.com/apache/echarts / formatTpl

Function formatTpl

src/util/format.ts:124–153  ·  view source on GitHub ↗
(
    tpl: string,
    paramsList: TplFormatterParam | TplFormatterParam[],
    encode?: boolean
)

Source from the content-addressed store, hash-verified

122 * @param {Array.<Object>|Object} paramsList
123 */
124export function formatTpl(
125 tpl: string,
126 paramsList: TplFormatterParam | TplFormatterParam[],
127 encode?: boolean
128): string {
129 if (!zrUtil.isArray(paramsList)) {
130 paramsList = [paramsList];
131 }
132 const seriesLen = paramsList.length;
133 if (!seriesLen) {
134 return '';
135 }
136
137 const $vars = paramsList[0].$vars || [];
138 for (let i = 0; i < $vars.length; i++) {
139 const alias = TPL_VAR_ALIAS[i];
140 tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));
141 }
142 for (let seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
143 for (let k = 0; k < $vars.length; k++) {
144 const val = paramsList[seriesIdx][$vars[k]];
145 tpl = tpl.replace(
146 wrapVar(TPL_VAR_ALIAS[k], seriesIdx),
147 encode ? encodeHTML(val) : val
148 );
149 }
150 }
151
152 return tpl;
153}
154
155/**
156 * simple Template formatter

Callers 2

_showTooltipContentMethod · 0.90
getFormattedLabelMethod · 0.90

Calls 2

wrapVarFunction · 0.85
encodeHTMLFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…