import type { Payload, ValueType } from 'recharts/types/component/DefaultTooltipContent' import { cn } from 'ui' import { Attribute, COLOR_MAP } from './Usage.constants' export interface SingleAttributeTooltipContentProps { name: string unit: 'bytes' | 'percentage' | 'absolute' | 'hours' | 'gigabytes' value: any isAfterToday: boolean tooltipFormatter?: (value: any) => any } export const SingleAttributeTooltipContent = ({ name, unit, value, isAfterToday, tooltipFormatter, }: SingleAttributeTooltipContentProps) => { const formattedValue = unit === 'percentage' ? Number(value).toFixed(2) : Number(value) return ( <>

{name}

{isAfterToday ? (

No data yet

) : (

{tooltipFormatter !== undefined ? tooltipFormatter(formattedValue) : formattedValue}

)} ) } export interface MultiAttributeTooltipContentProps { attributes: Attribute[] values: Payload[] isAfterToday: boolean tooltipFormatter?: (value: any) => any unit: 'bytes' | 'percentage' | 'absolute' | 'hours' | 'gigabytes' } const AttributeContent = ({ attribute, attributeMeta, sumValue, tooltipFormatter, unit, }: { attribute: Attribute attributeMeta?: Payload sumValue: number tooltipFormatter?: (value: any) => any unit: 'bytes' | 'percentage' | 'absolute' | 'hours' | 'gigabytes' }) => { const attrValue = Number(attributeMeta?.value ?? 0) const percentageContribution = ((attrValue / sumValue) * 100).toFixed(1) return (

{attribute.name} ({percentageContribution}%):{' '}

{tooltipFormatter !== undefined ? tooltipFormatter(attrValue) : `${attrValue}${unit === 'hours' ? ' H' : ''}`}

) } export const MultiAttributeTooltipContent = ({ attributes, values, isAfterToday, tooltipFormatter, unit, }: MultiAttributeTooltipContentProps) => { const sumValue = values.reduce((a, b) => a + Number(b.value), 0) return ( <> {isAfterToday ? (

No data yet

) : (
{attributes.flatMap((attr) => { const attributeMeta = values.find((x) => x.dataKey === attr.key) // Filter out empty attributes if (Number(attributeMeta?.value ?? 0) === 0) return [] return ( ) })}
)} ) }