import { TooltipContentProps } from 'recharts'; import { LegendShape } from '../legend/ChartLegend'; import { ChartTooltipPortal, ChartTooltipHeader, ChartTooltipItem, ChartTooltipItemsContainer, TooltipHeader, } from '../common/ChartTooltip'; import { BarchartBars, BarchartTooltipFn } from './Barchart'; import { CategoryType, TimeType, UnitRange } from '../types'; import { getCurrentPoint } from './Barchart.utils'; import { formatTooltipValueWithUnit } from '../common/chartUtils'; export const BarchartTooltip = ({ type, tooltipProps, colorSet, hoveredValue, tooltip, unitLabel, unitRange, valueBase = 1, chartContainerRef, }: { type: TimeType | CategoryType; tooltipProps: TooltipContentProps; colorSet?: Record; hoveredValue: string | undefined; tooltip?: BarchartTooltipFn; unitLabel?: string; unitRange?: UnitRange; valueBase?: number; chartContainerRef: React.RefObject; }) => { const { active, coordinate } = tooltipProps; if (!active) { return null; } const currentPoint = getCurrentPoint(tooltipProps, hoveredValue); const duration = type.type === 'time' ? type.timeRange.startDate.getTime() - type.timeRange.endDate.getTime() : 0; const tooltipContent = tooltip ? ( tooltip(currentPoint) ) : ( <> {type.type === 'time' ? ( ) : ( currentPoint.category )} {currentPoint.values.map((value) => { const legendIcon = colorSet && ( ); const valueWithUnit = formatTooltipValueWithUnit( value.value, valueBase, unitRange, unitLabel, false, ); return ( ); })} ); return ( {tooltipContent} ); };