Skip to content

Commit

Permalink
Merge pull request #19123 from ChepteaCatalin/fix-18997
Browse files Browse the repository at this point in the history
feat(tooltip): add dataIndex to valueFormatter callback. close #18997
  • Loading branch information
Ovilia committed Sep 26, 2023
2 parents a51f449 + ba44156 commit 80b251f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/component/tooltip/seriesFormatTooltip.ts
Expand Up @@ -96,7 +96,8 @@ export function defaultSeriesFormatTooltip(opt: {
// be not readable. So we check trim here.
noName: !trim(inlineName),
value: inlineValue,
valueType: inlineValueType
valueType: inlineValueType,
dataIndex
})
].concat(subBlocks || [] as any)
});
Expand Down
5 changes: 4 additions & 1 deletion src/component/tooltip/tooltipMarkup.ts
Expand Up @@ -163,6 +163,7 @@ export interface TooltipMarkupNameValueBlock extends TooltipMarkupBlock {
// null/undefined/NaN/''... (displayed as '-').
noName?: boolean;
noValue?: boolean;
dataIndex?: number;

valueFormatter?: CommonTooltipOption<unknown>['valueFormatter']
}
Expand Down Expand Up @@ -332,7 +333,9 @@ function buildNameValue(
? ''
: makeValueReadable(name, 'ordinal', useUTC);
const valueTypeOption = fragment.valueType;
const readableValueList = noValue ? [] : valueFormatter(fragment.value as OptionDataValue);
const readableValueList = noValue
? []
: valueFormatter(fragment.value as OptionDataValue, fragment.dataIndex);
const valueAlignRight = !noMarker || !noName;
// It little weird if only value next to marker but far from marker.
const valueCloseToMarker = !noMarker && noName;
Expand Down
2 changes: 1 addition & 1 deletion src/util/types.ts
Expand Up @@ -1265,7 +1265,7 @@ export interface CommonTooltipOption<FormatterParams> {
*
* Will be ignored if tooltip.formatter is specified.
*/
valueFormatter?: (value: OptionDataValue | OptionDataValue[]) => string
valueFormatter?: (value: OptionDataValue | OptionDataValue[], dataIndex: number) => string
/**
* Absolution pixel [x, y] array. Or relative percent string [x, y] array.
* If trigger is 'item'. position can be set to 'inside' / 'top' / 'left' / 'right' / 'bottom',
Expand Down
39 changes: 38 additions & 1 deletion test/tooltip-valueFormatter.html

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

0 comments on commit 80b251f

Please sign in to comment.