Skip to content

Commit

Permalink
feat: Implement showDatumInTooltip in TooltipOptions to allow hiding …
Browse files Browse the repository at this point in the history
…certain datums in regular TooltipRenderer. (#360)

* Implement showDatumInTooltip in TooltipOptions to allow hiding certain datums in regular TooltipRenderer.

* Run format over code.
  • Loading branch information
Zandor300 authored Nov 2, 2023
1 parent e4b1c9c commit 582bc33
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function defaultTooltip<TDatum>(
arrowPadding: options.arrowPadding ?? 7,
// anchor: options.anchor ?? 'closest',
render: options.render ?? TooltipRenderer,
showDatumInTooltip: options.showDatumInTooltip ?? (() => true),
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/components/TooltipRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ function TooltipRenderer<TDatum>(props: TooltipRendererProps<TDatum>) {

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
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export type TooltipOptions<TDatum> = {
render?: (props: TooltipRendererProps<TDatum>) => React.ReactNode
// formatSecondary?: (d: unknown) => string | number
// formatTertiary?: (d: unknown) => string | number
invert?: boolean
invert?: boolean,
showDatumInTooltip?: (datum: Datum<TDatum>) => boolean
}

export type ResolvedTooltipOptions<TDatum> = TSTB.Object.Required<
Expand Down

0 comments on commit 582bc33

Please sign in to comment.