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

Method formatValueText

src/component/visualMap/VisualMapModel.ts:346–403  ·  view source on GitHub ↗

* @example * this.formatValueText(someVal); // format single numeric value to text. * this.formatValueText(someVal, true); // format single category value to text. * this.formatValueText([min, max]); // format numeric min-max to text. * this.formatValueText([this.dataBound[0], ma

(
        value: number | string | number[],
        isCategory?: boolean,
        edgeSymbols?: string[]
    )

Source from the content-addressed store, hash-verified

344 * @protected
345 */
346 formatValueText(
347 value: number | string | number[],
348 isCategory?: boolean,
349 edgeSymbols?: string[]
350 ): string {
351 const option = this.option;
352 const precision = option.precision;
353 const dataBound = this.dataBound;
354 const formatter = option.formatter;
355 let isMinMax: boolean;
356 edgeSymbols = edgeSymbols || ['<', '>'] as [string, string];
357
358 if (zrUtil.isArray(value)) {
359 value = value.slice();
360 isMinMax = true;
361 }
362
363 const textValue = isCategory
364 ? value as string // Value is string when isCategory
365 : (isMinMax
366 ? [toFixed((value as number[])[0]), toFixed((value as number[])[1])]
367 : toFixed(value as number)
368 );
369
370 if (zrUtil.isString(formatter)) {
371 return formatter
372 .replace('{value}', isMinMax ? (textValue as string[])[0] : textValue as string)
373 .replace('{value2}', isMinMax ? (textValue as string[])[1] : textValue as string);
374 }
375 else if (zrUtil.isFunction(formatter)) {
376 return isMinMax
377 ? formatter((value as number[])[0], (value as number[])[1])
378 : formatter(value as number);
379 }
380
381 if (isMinMax) {
382 if ((value as number[])[0] === dataBound[0]) {
383 return edgeSymbols[0] + ' ' + textValue[1];
384 }
385 else if ((value as number[])[1] === dataBound[1]) {
386 return edgeSymbols[1] + ' ' + textValue[0];
387 }
388 else {
389 return textValue[0] + ' - ' + textValue[1];
390 }
391 }
392 else { // Format single value (includes category case).
393 return textValue as string;
394 }
395
396 function toFixed(val: number) {
397 return val === dataBound[0]
398 ? 'min'
399 : val === dataBound[1]
400 ? 'max'
401 : (+val).toFixed(Math.min(precision, 20));
402 }
403 }

Callers 5

splitNumberFunction · 0.80
categoriesFunction · 0.80
piecesFunction · 0.80
_updateHandleMethod · 0.80
_showIndicatorMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected