feat: y-axis SI prefix, hide tick from legend, fix table sort

This commit is contained in:
Sebastian Seedorf
2026-06-03 12:52:45 +02:00
parent 8c83e8b8e8
commit 3506d1f6c5
7 changed files with 59 additions and 8 deletions

22
web/lib/formatNumber.ts Normal file
View File

@@ -0,0 +1,22 @@
const SI_THRESHOLDS = [
{ limit: 1_000_000_000, divisor: 1_000_000_000, suffix: 'G' },
{ limit: 1_000_000, divisor: 1_000_000, suffix: 'M' },
{ limit: 1_000, divisor: 1_000, suffix: 'K' },
] as const;
export function formatSI(v: number, locale?: string): string {
const abs = Math.abs(v);
for (const { limit, divisor, suffix } of SI_THRESHOLDS) {
if (abs >= limit) {
const formatted = new Intl.NumberFormat(locale, {
maximumFractionDigits: 3,
minimumFractionDigits: 0,
}).format(v / divisor);
return `${formatted}${suffix}`;
}
}
return new Intl.NumberFormat(locale, {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(v);
}