Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: [M3-7735] - Improve Linode Graph X Axis Labels when viewing historic data #10186

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Changed
---

Improve Linode Graph X Axis Labels when viewing historic data ([#10186](https://github.com/linode/manager/pull/10186))
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ const LinodeSummary: React.FC<Props> = (props) => {
debouncedRefetchLinodeStats();
}, [windowWidth, windowHeight, debouncedRefetchLinodeStats]);

/**
* This changes the X-Axis tick labels depending on the selected timeframe.
*
* This is important because the X-Axis should show dates instead of times
* when viewing many days' worth of stats.
*
* @example 'hh a' renders '11am'
* @example 'LLL dd' renders 'Feb 14'
*/
const xAxisTickFormat = isLast24Hours ? 'hh a' : 'LLL dd';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the const here. Readability would be further improved with a short comment about what the tick formats mean in English.


const renderCPUChart = () => {
const data = stats?.data.cpu ?? [];
const metrics = getMetrics(data);
Expand Down Expand Up @@ -147,7 +158,7 @@ const LinodeSummary: React.FC<Props> = (props) => {
},
]}
xAxis={{
tickFormat: 'hh a',
tickFormat: xAxisTickFormat,
tickGap: 60,
}}
ariaLabel="CPU Usage Graph"
Expand Down Expand Up @@ -233,7 +244,7 @@ const LinodeSummary: React.FC<Props> = (props) => {
},
]}
xAxis={{
tickFormat: 'hh a',
tickFormat: xAxisTickFormat,
tickGap: 60,
}}
ariaLabel="Disk I/O Graph"
Expand Down Expand Up @@ -382,7 +393,11 @@ const LinodeSummary: React.FC<Props> = (props) => {
</StyledGrid>
</Grid>
) : null}
<NetworkGraphs stats={stats} {...chartProps} />
<NetworkGraphs
stats={stats}
xAxisTickFormat={xAxisTickFormat}
{...chartProps}
/>
</Grid>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface Props extends ChartProps {
rangeSelection: string;
stats?: Stats;
timezone: string;
xAxisTickFormat: string;
}

interface NetworkMetrics {
Expand All @@ -70,7 +71,7 @@ const _getMetrics = (data: NetworkStats) => {
};

export const NetworkGraphs = (props: Props) => {
const { rangeSelection, stats, ...rest } = props;
const { rangeSelection, stats, xAxisTickFormat, ...rest } = props;

const theme = useTheme();
const flags = useFlags();
Expand Down Expand Up @@ -137,6 +138,7 @@ export const NetworkGraphs = (props: Props) => {
rangeSelection,
theme,
timezone: props.timezone,
xAxisTickFormat,
};

return (
Expand Down Expand Up @@ -187,6 +189,7 @@ interface GraphProps {
timezone: string;
totalTraffic: TotalTrafficProps;
unit: string;
xAxisTickFormat: string;
}

const Graph = (props: GraphProps) => {
Expand All @@ -199,6 +202,7 @@ const Graph = (props: GraphProps) => {
theme,
timezone,
unit,
xAxisTickFormat,
} = props;

const flags = useFlags();
Expand Down Expand Up @@ -286,7 +290,7 @@ const Graph = (props: GraphProps) => {
},
]}
xAxis={{
tickFormat: 'hh a',
tickFormat: xAxisTickFormat,
tickGap: 60,
}}
ariaLabel={ariaLabel}
Expand Down
Loading