Skip to content

Commit

Permalink
feat: tooltip key/content support config by field, close #2576
Browse files Browse the repository at this point in the history
  • Loading branch information
xile611 committed Oct 24, 2024
1 parent 5919b8f commit 2751621
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/vchart/src/component/tooltip/utils/get-value.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isFunction, isNil } from '@visactor/vutils';
import { get, isFunction, isNil, isPlainObject, isValid } from '@visactor/vutils';
import type {
Datum,
TooltipContentCallback,
Expand All @@ -19,6 +19,8 @@ export const getTooltipContentValue = <T>(
let value: T;
if (isFunction(field)) {
value = (field as TooltipContentCallback<T>)(datum, params);
} else if (isPlainObject(field) && isValid(field.field)) {
value = get(datum, field.field) as T;
} else {
value = field as T;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vchart/src/typings/tooltip/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Datum } from '../common';
import type { TooltipHandlerParams } from '../../component/tooltip/interface';
import type { TooltipData } from './handler';

export type TooltipContentProperty<T> = T | TooltipContentCallback<T>;
export type TooltipContentProperty<T> = T | TooltipContentCallback<T> | { field: string };
export type TooltipContentCallback<T> = (datum?: Datum, params?: TooltipHandlerParams) => T | undefined;

export type TooltipPatternProperty<T> = T | TooltipPatternCallback<T>;
Expand Down

0 comments on commit 2751621

Please sign in to comment.