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 } from '../types'; import { getCurrentPoint } from './Barchart.utils'; export const BarchartTooltip = ({ type, tooltipProps, colorSet, hoveredValue, tooltip, unitLabel, chartContainerRef, }: { type: TimeType | CategoryType; tooltipProps: TooltipContentProps; colorSet?: Record; hoveredValue: string | undefined; tooltip?: BarchartTooltipFn; unitLabel?: string; 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 formattedValue = Number.isInteger(value.value) ? `${value.value}` : value.value.toFixed(2); const valueWithUnit = unitLabel ? `${formattedValue} ${unitLabel}` : formattedValue; return ( ); })} ); return ( {tooltipContent} ); };