1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-26 13:48:33 +02:00

y axis formatter

This commit is contained in:
Tymoteusz Czech 2025-06-23 22:43:50 +02:00
parent bee42187b9
commit 663f26a12b
No known key found for this signature in database
GPG Key ID: 133555230D88D75F
2 changed files with 20 additions and 1 deletions

View File

@ -19,7 +19,8 @@ import {
getDisplayFormat,
getSeriesLabel,
getTimeUnit,
} from './impact-metrics-utils.ts';
formatLargeNumbers,
} from './utils.ts';
import { fromUnixTime } from 'date-fns';
import { useSeriesColor } from './hooks/useSeriesColor.ts';
@ -254,6 +255,14 @@ export const ImpactMetrics: FC = () => {
},
ticks: {
precision: 0,
callback: (
value: unknown,
): string | number =>
typeof value === 'number'
? formatLargeNumbers(
value,
)
: (value as number),
},
},
},

View File

@ -48,3 +48,13 @@ export const getSeriesLabel = (metric: Record<string, string>): string => {
return `${__name__} (${labelParts})`;
};
export const formatLargeNumbers = (value: number): string => {
if (value >= 1000000) {
return `${(value / 1000000).toFixed(0)}M`;
}
if (value >= 1000) {
return `${(value / 1000).toFixed(0)}k`;
}
return value.toString();
};