import dayjs from 'dayjs' import { Bar, CartesianGrid, Cell, ComposedChart, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts' import { cn } from 'ui' import { Attribute, COLOR_MAP } from './Usage.constants' import { MultiAttributeTooltipContent, SingleAttributeTooltipContent } from './UsageChartTooltips' import { DataPoint } from '@/data/analytics/constants' // [Joshen] This BarChart is specifically for usage, hence not a reusable component, and not // replacing the existing BarChart in ui/Charts export interface UsageBarChartProps { data: DataPoint[] name: string // Used within the tooltip attributes: Attribute[] unit: 'bytes' | 'absolute' | 'percentage' | 'hours' | 'gigabytes' yLimit?: number yMin?: number yLeftMargin?: number yFormatter?: (value: number | string) => string tooltipFormatter?: (value: number | string) => string } const UsageBarChart = ({ data, name, attributes, unit, yLimit, yLeftMargin = 10, yFormatter, yMin, tooltipFormatter, }: UsageBarChartProps) => { const yDomain = [yMin ?? 0, Math.max(yMin ?? 0, yLimit ?? 0)] return (
{ const { active, payload } = props if (active && payload && payload.length) { const dataPeriod = dayjs(payload[0].payload.period_start) const isAfterToday = dataPeriod.startOf('day').isAfter(dayjs().startOf('day')) return (
1 && !isAfterToday ? 'w-[250px]' : 'w-[170px]' )} > {attributes.length > 1 ? ( ) : ( )}

{dataPeriod.format('DD MMM YYYY')}

) } else return null }} /> {attributes?.map((attr) => ( {data.map((entry) => { return })} ))}
) } export default UsageBarChart