MCPcopy Index your code
hub / github.com/apache/echarts / getFormattedLabel

Method getFormattedLabel

src/model/mixin/dataFormat.ts:108–175  ·  view source on GitHub ↗

* Format label * @param dataIndex * @param status 'normal' by default * @param dataType * @param labelDimIndex Only used in some chart that * use formatter in different dimensions, like radar. * @param formatter Formatter given outside. * @return return null

(
        dataIndex: number,
        status?: DisplayState,
        dataType?: SeriesDataType,
        labelDimIndex?: number,
        formatter?: string | ((params: object) => string),
        extendParams?: {
            interpolatedValue: InterpolatableValue
        }
    )

Source from the content-addressed store, hash-verified

106 * @return return null/undefined if no formatter
107 */
108 getFormattedLabel(
109 dataIndex: number,
110 status?: DisplayState,
111 dataType?: SeriesDataType,
112 labelDimIndex?: number,
113 formatter?: string | ((params: object) => string),
114 extendParams?: {
115 interpolatedValue: InterpolatableValue
116 }
117 ): string {
118 status = status || 'normal';
119 const data = this.getData(dataType);
120
121 const params = this.getDataParams(dataIndex, dataType);
122
123 if (extendParams) {
124 params.value = extendParams.interpolatedValue;
125 }
126
127 if (labelDimIndex != null && zrUtil.isArray(params.value)) {
128 params.value = params.value[labelDimIndex];
129 }
130
131 if (!formatter) {
132 const itemModel = data.getItemModel(dataIndex);
133 // @ts-ignore
134 formatter = itemModel.get(status === 'normal'
135 ? ['label', 'formatter']
136 : [status, 'label', 'formatter']
137 );
138 }
139
140 if (zrUtil.isFunction(formatter)) {
141 params.status = status;
142 params.dimensionIndex = labelDimIndex;
143 return formatter(params);
144 }
145 else if (zrUtil.isString(formatter)) {
146 const str = formatTpl(formatter, params);
147
148 // Support 'aaa{@[3]}bbb{@product}ccc'.
149 // Do not support '}' in dim name util have to.
150 return str.replace(DIMENSION_LABEL_REG, function (origin, dimStr: string) {
151 const len = dimStr.length;
152
153 let dimLoose: DimensionLoose = dimStr;
154 if (dimLoose.charAt(0) === '[' && dimLoose.charAt(len - 1) === ']') {
155 dimLoose = +dimLoose.slice(1, len - 1); // Also support: '[]' => 0
156 if (__DEV__) {
157 if (isNaN(dimLoose)) {
158 error(`Invalide label formatter: @${dimStr}, only support @[0], @[1], @[2], ...`);
159 }
160 }
161 }
162
163 let val = retrieveRawValue(data, dataIndex, dimLoose) as OptionDataValue;
164
165 if (extendParams && zrUtil.isArray(extendParams.interpolatedValue)) {

Callers

nothing calls this directly

Calls 8

getDataParamsMethod · 0.95
formatTplFunction · 0.90
errorFunction · 0.90
retrieveRawValueFunction · 0.90
getItemModelMethod · 0.80
getDimensionIndexMethod · 0.80
getDataMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected