diff --git a/src/components/Tooltip.tsx b/src/components/Tooltip.tsx index 0c60cbe..6238212 100644 --- a/src/components/Tooltip.tsx +++ b/src/components/Tooltip.tsx @@ -41,6 +41,7 @@ export function defaultTooltip( arrowPadding: options.arrowPadding ?? 7, // anchor: options.anchor ?? 'closest', render: options.render ?? TooltipRenderer, + showDatumInTooltip: options.showDatumInTooltip ?? (() => true), } } diff --git a/src/components/TooltipRenderer.tsx b/src/components/TooltipRenderer.tsx index cd98ed8..e4d9761 100644 --- a/src/components/TooltipRenderer.tsx +++ b/src/components/TooltipRenderer.tsx @@ -54,7 +54,9 @@ function TooltipRenderer(props: TooltipRendererProps) { const { tooltip, dark } = props.getOptions() - const groupDatums = props.focusedDatum?.tooltipGroup ?? [] + const groupDatums = (props.focusedDatum?.tooltipGroup ?? []).filter( + datum => tooltip.showDatumInTooltip?.(datum) ?? true + ) const resolvedShowCount = showCount % 2 === 0 ? showCount : showCount + 1 const length = groupDatums.length diff --git a/src/types.ts b/src/types.ts index 8fab658..6ef1250 100644 --- a/src/types.ts +++ b/src/types.ts @@ -124,7 +124,8 @@ export type TooltipOptions = { render?: (props: TooltipRendererProps) => React.ReactNode // formatSecondary?: (d: unknown) => string | number // formatTertiary?: (d: unknown) => string | number - invert?: boolean + invert?: boolean, + showDatumInTooltip?: (datum: Datum) => boolean } export type ResolvedTooltipOptions = TSTB.Object.Required<