mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 13:47:15 +01:00
37 lines
1 KiB
TypeScript
37 lines
1 KiB
TypeScript
import { useLocale } from '@/components/hooks';
|
|
import { formatDate } from '@/lib/date';
|
|
import { formatLongCurrency, formatLongNumber } from '@/lib/format';
|
|
import { Flexbox, StatusLight } from '@umami/react-zen';
|
|
|
|
const formats = {
|
|
millisecond: 'T',
|
|
second: 'pp',
|
|
minute: 'p',
|
|
hour: 'h:mm aaa - PP',
|
|
day: 'PPPP',
|
|
week: 'PPPP',
|
|
month: 'LLLL yyyy',
|
|
quarter: 'qqq',
|
|
year: 'yyyy',
|
|
};
|
|
|
|
export function BarChartTooltip({ tooltip, unit, currency }) {
|
|
const { locale } = useLocale();
|
|
const { labelColors, dataPoints } = tooltip;
|
|
|
|
return (
|
|
<Flexbox direction="column" gap={10}>
|
|
<div>
|
|
{formatDate(new Date(dataPoints[0].raw.d || dataPoints[0].raw.x), formats[unit], locale)}
|
|
</div>
|
|
<div>
|
|
<StatusLight color={labelColors?.[0]?.backgroundColor}>
|
|
{currency
|
|
? formatLongCurrency(dataPoints[0].raw.y, currency)
|
|
: formatLongNumber(dataPoints[0].raw.y)}{' '}
|
|
{dataPoints[0].dataset.label}
|
|
</StatusLight>
|
|
</div>
|
|
</Flexbox>
|
|
);
|
|
}
|