Skip to content

Commit 63863f1

Browse files
Added: [DI-28776] - Use customized humanize method for cloudpulse metrics (#13224)
* Added: [DI-28776] - Use customized humanize method for cloudpulse metrics * Added: [DI-28776] - Use customized humanize method for cloudpulse metrics * Added: [DI-28776] - Update import * Added: [DI-28776] - Changeset
1 parent 8c8d916 commit 63863f1

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Added
3+
---
4+
5+
Add customized humanize method for `cloudpulse metric` graphs ([#13224](https://github.com/linode/manager/pull/13224))

packages/manager/src/features/CloudPulse/Utils/CloudPulseWidgetUtils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { formatPercentage } from '@linode/utilities';
22

3-
import * as utilities from 'src/components/AreaChart/utils';
43
import { widgetFactory } from 'src/factories';
54

65
import {
@@ -12,6 +11,7 @@ import {
1211
getTimeDurationFromPreset,
1312
mapResourceIdToName,
1413
} from './CloudPulseWidgetUtils';
14+
import * as utilities from './utils';
1515

1616
import type {
1717
DimensionNameProperties,

packages/manager/src/features/CloudPulse/Utils/CloudPulseWidgetUtils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { Alias } from '@linode/design-language-system';
22
import { DateTimeRangePicker } from '@linode/ui';
33
import { getMetrics } from '@linode/utilities';
44

5-
import { humanizeLargeData } from 'src/components/AreaChart/utils';
6-
75
import { DIMENSION_TRANSFORM_CONFIG } from '../shared/DimensionTransform';
86
import {
97
convertValueToUnit,
@@ -13,6 +11,7 @@ import {
1311
} from './unitConversion';
1412
import {
1513
convertTimeDurationToStartAndEndTimeRange,
14+
humanizeLargeData,
1615
seriesDataFormatter,
1716
} from './utils';
1817

packages/manager/src/features/CloudPulse/Utils/utils.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useAccount, useRegionsQuery } from '@linode/queries';
2-
import { isFeatureEnabledV2 } from '@linode/utilities';
2+
import { isFeatureEnabledV2, roundTo } from '@linode/utilities';
33
import React from 'react';
44

55
import { convertData } from 'src/features/Longview/shared/formatters';
@@ -676,3 +676,26 @@ export const arraysEqual = (
676676
[...b].sort((x, y) => x - y)
677677
);
678678
};
679+
680+
/**
681+
* @param value The numeric value to humanize
682+
* @returns The humanized string representation of the value
683+
*/
684+
export const humanizeLargeData = (value: number) => {
685+
if (value >= 1000000000000) {
686+
return +(value / 1000000000000).toFixed(1) + 'T';
687+
}
688+
if (value >= 1000000000) {
689+
return +(value / 1000000000).toFixed(1) + 'B';
690+
}
691+
if (value >= 1000000) {
692+
return +(value / 1000000).toFixed(1) + 'M';
693+
}
694+
if (value >= 100000) {
695+
return +(value / 1000).toFixed(0) + 'K';
696+
}
697+
if (value >= 1000) {
698+
return +(value / 1000).toFixed(1) + 'K';
699+
}
700+
return `${roundTo(value, 1)}`;
701+
};

packages/manager/src/features/CloudPulse/Widget/components/CloudPulseLineGraph.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { Box, useMediaQuery, useTheme } from '@mui/material';
44
import * as React from 'react';
55

66
import { AreaChart } from 'src/components/AreaChart/AreaChart';
7-
import { humanizeLargeData } from 'src/components/AreaChart/utils';
87
import { useFlags } from 'src/hooks/useFlags';
98

9+
import { humanizeLargeData } from '../../Utils/utils';
10+
1011
import type { AreaChartProps } from 'src/components/AreaChart/AreaChart';
1112

1213
export interface CloudPulseLineGraph extends AreaChartProps {
@@ -69,7 +70,9 @@ export const CloudPulseLineGraph = React.memo((props: CloudPulseLineGraph) => {
6970
}
7071
yAxisProps={
7172
isHumanizableUnit
72-
? undefined
73+
? {
74+
tickFormat: (value: number) => `${humanizeLargeData(value)}`,
75+
}
7376
: {
7477
tickFormat: (value: number) => `${roundTo(value, 3)}`,
7578
}

0 commit comments

Comments
 (0)