diff options
| author | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
| commit | 396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch) | |
| tree | b9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/lib/charts.ts | |
| download | umami-396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b.tar.xz umami-396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b.zip | |
Created from https://vercel.com/new
Diffstat (limited to 'src/lib/charts.ts')
| -rw-r--r-- | src/lib/charts.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/charts.ts b/src/lib/charts.ts new file mode 100644 index 0000000..7d4208e --- /dev/null +++ b/src/lib/charts.ts @@ -0,0 +1,27 @@ +import { formatDate } from '@/lib/date'; +import { formatLongNumber } from '@/lib/format'; + +export function renderNumberLabels(label: string) { + return +label > 1000 ? formatLongNumber(+label) : label; +} + +export function renderDateLabels(unit: string, locale: string) { + return (label: string, index: number, values: any[]) => { + const d = new Date(values[index].value); + + switch (unit) { + case 'minute': + return formatDate(d, 'h:mm', locale); + case 'hour': + return formatDate(d, 'p', locale); + case 'day': + return formatDate(d, 'PP', locale).replace(/\W*20\d{2}\W*/, ''); // Remove year + case 'month': + return formatDate(d, 'MMM', locale); + case 'year': + return formatDate(d, 'yyyy', locale); + default: + return label; + } + }; +} |