Commit acd2e7ef authored by Yuri Mikhin's avatar Yuri Mikhin Committed by Yuri Mikhin

Add metric prefixes for stats and charts.

parent 4b71c2b4
export default function formatNumberToMetricPrefix(number: number) {
return Intl.NumberFormat('en-US', {
notation: 'compact',
maximumFractionDigits: 3,
}).format(number);
}
...@@ -3,6 +3,8 @@ import { useMemo } from 'react'; ...@@ -3,6 +3,8 @@ import { useMemo } from 'react';
import type { TimeChartData } from 'ui/shared/chart/types'; import type { TimeChartData } from 'ui/shared/chart/types';
import formatNumberToMetricPrefix from 'lib/formatNumberToMetricPrefix';
interface Props { interface Props {
data: TimeChartData; data: TimeChartData;
width: number; width: number;
...@@ -50,7 +52,7 @@ export default function useTimeChartController({ data, width, height }: Props) { ...@@ -50,7 +52,7 @@ export default function useTimeChartController({ data, width, height }: Props) {
); );
const xTickFormat = (d: d3.AxisDomain) => d.toLocaleString(); const xTickFormat = (d: d3.AxisDomain) => d.toLocaleString();
const yTickFormat = (d: d3.AxisDomain) => d.toLocaleString(); const yTickFormat = (d: d3.AxisDomain) => formatNumberToMetricPrefix(Number(d));
return { return {
xTickFormat, xTickFormat,
......
...@@ -2,6 +2,7 @@ import { Grid } from '@chakra-ui/react'; ...@@ -2,6 +2,7 @@ import { Grid } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import useApiQuery from 'lib/api/useApiQuery'; import useApiQuery from 'lib/api/useApiQuery';
import formatNumberToMetricPrefix from 'lib/formatNumberToMetricPrefix';
import { numberWidgetsScheme } from './constants/number-widgets-scheme'; import { numberWidgetsScheme } from './constants/number-widgets-scheme';
import NumberWidget from './NumberWidget'; import NumberWidget from './NumberWidget';
...@@ -12,15 +13,23 @@ const skeletonsCount = 8; ...@@ -12,15 +13,23 @@ const skeletonsCount = 8;
const NumberWidgetsList = () => { const NumberWidgetsList = () => {
const { data, isLoading } = useApiQuery('stats_counters'); const { data, isLoading } = useApiQuery('stats_counters');
const skeletonElement = [ ...Array(skeletonsCount) ]
.map((e, i) => <NumberWidgetSkeleton key={ i }/>);
return ( return (
<Grid <Grid
gridTemplateColumns={{ base: 'repeat(2, 1fr)', lg: 'repeat(4, 1fr)' }} gridTemplateColumns={{ base: 'repeat(2, 1fr)', lg: 'repeat(4, 1fr)' }}
gridGap={ 4 } gridGap={ 4 }
> >
{ isLoading ? [ ...Array(skeletonsCount) ] { isLoading ? skeletonElement :
.map((e, i) => <NumberWidgetSkeleton key={ i }/>) :
numberWidgetsScheme.map(({ id, title }) => numberWidgetsScheme.map(({ id, title }) =>
data?.counters[id] ? <NumberWidget key={ id } label={ title } value={ Number(data.counters[id]).toLocaleString() }/> : null) } data?.counters[id] ? (
<NumberWidget
key={ id }
label={ title }
value={ formatNumberToMetricPrefix(Number(data.counters[id])) }
/>
) : null) }
</Grid> </Grid>
); );
}; };
......
...@@ -35,8 +35,4 @@ export const numberWidgetsScheme: Array<{id: Key; title: string}> = [ ...@@ -35,8 +35,4 @@ export const numberWidgetsScheme: Array<{id: Key; title: string}> = [
id: 'totalNativeCoinTransfers', id: 'totalNativeCoinTransfers',
title: 'Total native coin transfers', title: 'Total native coin transfers',
}, },
{
id: 'totalAccounts',
title: 'Total accounts',
},
]; ];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment