Skip to content

Commit

Permalink
upcoming: [DI-21842] - Fixed recharts issues in Cloudpulse (#11317)
Browse files Browse the repository at this point in the history
* upcoming: [DI-21842] - Updated logic to handle 1 xAxisTickCount

* upcoming: [DI-21842] - Updated legends height

* upcoming: [DI-21842] - Removed legends height breakpoint

* added changeset

* upcoming: [DI-21842] - Round y-axis value to 2 digits

* upcoming: [DI-21842] - Updated y-axis margin

* upcoming: [DI-21842] - Updated top margin to graph
  • Loading branch information
nikhagra-akamai authored Nov 27, 2024
1 parent 4d59953 commit 1241222
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Modify `generate12HoursTicks` method in AreaChart `utils.ts`, Remove breakpoint condition in `MetricsDisplay.tsx`, modify `legendHeight` and `xAxisTickCount` in `CloudPulseLineGraph.tsx` ([#11317](https://github.com/linode/manager/pull/11317))
2 changes: 1 addition & 1 deletion packages/manager/src/components/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ interface YAxisProps {
/**
* The formatter function for the y-axis tick.
*/
tickFormat: () => string;
tickFormat: (value: number) => string;
}

export interface AreaChartProps {
Expand Down
4 changes: 4 additions & 0 deletions packages/manager/src/components/AreaChart/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export const generate12HourTicks = (
const startTime = data[0].timestamp;
const endTime = data[data.length - 1].timestamp;

if (tickCount === 1) {
return [(startTime + endTime) / 2];
}

// Calculate duration in hours
const duration = DateTime.fromMillis(endTime, { zone: timezone }).diff(
DateTime.fromMillis(startTime, { zone: timezone }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const convertValueToUnit = (value: number, maxUnit: string) => {
if (convertingValue === 1) {
return roundTo(value);
}
return value / convertingValue;
return roundTo(value / convertingValue);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as React from 'react';

import { AreaChart } from 'src/components/AreaChart/AreaChart';
import { ErrorState } from 'src/components/ErrorState/ErrorState';
import { roundTo } from 'src/utilities/roundTo';

import type { AreaChartProps } from 'src/components/AreaChart/AreaChart';

Expand Down Expand Up @@ -38,9 +39,20 @@ export const CloudPulseLineGraph = React.memo((props: CloudPulseLineGraph) => {
) : (
<AreaChart
{...rest}
margin={{
bottom: 0,
left: -15,
right: 30,
top: 2,
}}
xAxisTickCount={
isSmallScreen ? undefined : Math.min(rest.data.length, 7)
}
yAxisProps={{
tickFormat: (value: number) => `${roundTo(value, 3)}`,
}}
fillOpacity={0.5}
legendHeight="150px"
xAxisTickCount={isSmallScreen ? undefined : 7}
/>
)}
{rest.data.length === 0 && (
Expand Down

0 comments on commit 1241222

Please sign in to comment.