Skip to content

Commit 2c3009e

Browse files
committed
feat(tooltip): add series name as third parameter to valueFormatter (#21459)
1 parent 0919819 commit 2c3009e

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/component/tooltip/tooltipMarkup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ function buildNameValue(
324324
const noMarker = !fragment.markerType;
325325
const name = fragment.name;
326326
const useUTC = ctx.useUTC;
327-
const valueFormatter = fragment.valueFormatter || ctx.valueFormatter || ((value) => {
327+
const valueFormatter = fragment.valueFormatter || ctx.valueFormatter || ((value, dataIndex, name) => { // Added params here
328328
value = isArray(value) ? value : [value];
329329
return map(value as unknown[], (val, idx) => makeValueReadable(
330330
val, isArray(valueTypeOption) ? valueTypeOption[idx] : valueTypeOption, useUTC
@@ -347,8 +347,8 @@ function buildNameValue(
347347
: makeValueReadable(name, 'ordinal', useUTC);
348348
const valueTypeOption = fragment.valueType;
349349
const readableValueList = noValue
350-
? []
351-
: valueFormatter(fragment.value as OptionDataValue, fragment.dataIndex);
350+
? []
351+
: valueFormatter(fragment.value as OptionDataValue, fragment.dataIndex, fragment.name); // Added fragment.name
352352
const valueAlignRight = !noMarker || !noName;
353353
// It little weird if only value next to marker but far from marker.
354354
const valueCloseToMarker = !noMarker && noName;

src/util/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,11 +1540,11 @@ export interface CommonTooltipOption<FormatterParams> {
15401540
formatter?: string | TooltipFormatterCallback<FormatterParams>
15411541

15421542
/**
1543-
* Formatter of value.
1544-
*
1545-
* Will be ignored if tooltip.formatter is specified.
1546-
*/
1547-
valueFormatter?: (value: OptionDataValue | OptionDataValue[], dataIndex: number) => string
1543+
* Formatter of value.
1544+
*
1545+
* Will be ignored if tooltip.formatter is specified.
1546+
*/
1547+
valueFormatter?: (value: OptionDataValue | OptionDataValue[], dataIndex: number, name?: string) => string | string[]
15481548
/**
15491549
* Absolution pixel [x, y] array. Or relative percent string [x, y] array.
15501550
* If trigger is 'item'. position can be set to 'inside' / 'top' / 'left' / 'right' / 'bottom',

0 commit comments

Comments
 (0)