Skip to content

Commit afa6da9

Browse files
fix: [M3-8872] - Table and Chart Legend Improvements (#11294)
* fix: [M3-8872] - Table and Chart Legend Improvements * Update spacing in test * Added changeset: Table and Chart Legend Spacing * Add scroll shadows, remove scrollbar * Remove shadows * Add space for CPU % * Add y-axis formatter --------- Co-authored-by: Jaalah Ramos <[email protected]>
1 parent 640d7a6 commit afa6da9

File tree

11 files changed

+47
-21
lines changed

11 files changed

+47
-21
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Fixed
3+
---
4+
5+
Table and Chart Legend Spacing ([#11294](https://github.com/linode/manager/pull/11294))

packages/manager/src/components/AreaChart/AreaChart.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,26 @@ interface XAxisProps {
5555
tickFormat: string;
5656

5757
/**
58-
* represents the pixer gap between two x-axis ticks
58+
* represents the pixel gap between two x-axis ticks
5959
*/
6060
tickGap: number;
6161
}
6262

63+
interface YAxisProps {
64+
/**
65+
* The formatter function for the y-axis tick.
66+
*/
67+
tickFormat: () => string;
68+
}
69+
6370
export interface AreaChartProps {
6471
/**
6572
* list of areas to be displayed
6673
*/
6774
areas: AreaProps[];
6875

6976
/**
70-
* arialabel for the graph
77+
* aria-label for the graph
7178
*/
7279
ariaLabel: string;
7380

@@ -154,6 +161,11 @@ export interface AreaChartProps {
154161
* non-zero value : this many ticks will be generated based on the starting & ending timestamp in the data
155162
*/
156163
xAxisTickCount?: number;
164+
165+
/**
166+
* y-axis properties
167+
*/
168+
yAxisProps?: YAxisProps;
157169
}
158170

159171
export const AreaChart = (props: AreaChartProps) => {
@@ -176,6 +188,7 @@ export const AreaChart = (props: AreaChartProps) => {
176188
width = '100%',
177189
xAxis,
178190
xAxisTickCount,
191+
yAxisProps,
179192
} = props;
180193

181194
const theme = useTheme();
@@ -277,7 +290,12 @@ export const AreaChart = (props: AreaChartProps) => {
277290
tickFormatter={xAxisTickFormatter}
278291
type="number"
279292
/>
280-
<YAxis stroke={theme.color.label} tickFormatter={humanizeLargeData} />
293+
<YAxis
294+
tickFormatter={
295+
yAxisProps?.tickFormat ? yAxisProps.tickFormat : humanizeLargeData
296+
}
297+
stroke={theme.color.label}
298+
/>
281299
<Tooltip
282300
contentStyle={{
283301
color: theme.tokens.color.Neutrals[70],

packages/manager/src/components/AreaChart/utils.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ describe('tooltipLabelFormatter', () => {
3131

3232
describe('tooltipValueFormatter', () => {
3333
it('should return the rounded value up to a max of 2 decimals', () => {
34-
expect(tooltipValueFormatter(5.434939999999999, ' Kb/s')).toBe('5.43 Kb/s');
35-
expect(tooltipValueFormatter(5, ' Kb/s')).toBe('5 Kb/s');
36-
expect(tooltipValueFormatter(0.000234, '%')).toBe('0%');
34+
expect(tooltipValueFormatter(5.434939999999999, 'Kb/s')).toBe('5.43 Kb/s');
35+
expect(tooltipValueFormatter(5, 'Kb/s')).toBe('5 Kb/s');
36+
expect(tooltipValueFormatter(0.000234, '%')).toBe('0 %');
3737
});
3838
});
3939

packages/manager/src/components/AreaChart/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const tooltipLabelFormatter = (timestamp: number, timezone: string) =>
1616
);
1717

1818
export const tooltipValueFormatter = (value: number, unit: string) =>
19-
`${roundTo(value)}${unit}`;
19+
`${roundTo(value)} ${unit}`;
2020

2121
export const humanizeLargeData = (value: number) => {
2222
if (value >= 1000000000000) {

packages/manager/src/components/LineGraph/MetricsDisplay.styles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const StyledButton = styled(Button, {
3636
label: 'StyledButton',
3737
shouldForwardProp: omittedProps(['legendColor', 'hidden']),
3838
})<{ legendColor?: string }>(({ hidden, legendColor, theme }) => ({
39+
padding: 0,
3940
...(legendColor && {
4041
'&:before': {
4142
backgroundColor: hidden

packages/manager/src/components/LineGraph/MetricsDisplay.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,13 @@ export const MetricsDisplay = ({
112112
rows,
113113
}: Props) => (
114114
<StyledTable
115-
sx={(theme) => ({
115+
sx={{
116116
'.MuiTable-root': {
117117
border: 0,
118118
},
119+
height: legendHeight,
119120
overflowY: 'auto',
120-
[theme.breakpoints.up(1100)]: {
121-
height: legendHeight,
122-
},
123-
})}
121+
}}
124122
aria-label="Stats and metrics"
125123
stickyHeader
126124
>

packages/manager/src/components/Table/Table.styles.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export const StyledTableWrapper = styled('div', {
2626
borderRight: `1px solid ${theme.borderColors.borderTable}`,
2727
borderTop: `1px solid ${theme.borderColors.borderTable}`,
2828
fontFamily: theme.font.bold,
29-
padding: '10px 15px',
3029
},
3130
},
3231
marginBottom: props.spacingBottom !== undefined ? props.spacingBottom : 0,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const CloudPulseLineGraph = React.memo((props: CloudPulseLineGraph) => {
3939
<AreaChart
4040
{...rest}
4141
fillOpacity={0.5}
42-
legendHeight={theme.spacing(16)}
42+
legendHeight="150px"
4343
xAxisTickCount={isSmallScreen ? undefined : 7}
4444
/>
4545
)}

packages/manager/src/features/CloudPulse/shared/CloudPulseResourcesSelect.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const CloudPulseResourcesSelect = React.memo(
5656
},
5757
};
5858

59-
const { data: resources, isLoading, isError } = useResourcesQuery(
59+
const { data: resources, isError, isLoading } = useResourcesQuery(
6060
disabled !== undefined ? !disabled : Boolean(region && resourceType),
6161
resourceType,
6262
{},
@@ -123,6 +123,9 @@ export const CloudPulseResourcesSelect = React.memo(
123123

124124
return (
125125
<Autocomplete
126+
helperText={
127+
!isError ? `Select up to ${maxResourceSelectionLimit} ${label}` : ''
128+
}
126129
onChange={(e, resourceSelections) => {
127130
setSelectedResources(resourceSelections);
128131

@@ -167,8 +170,13 @@ export const CloudPulseResourcesSelect = React.memo(
167170
textFieldProps={{
168171
InputProps: {
169172
sx: {
173+
'::-webkit-scrollbar': {
174+
display: 'none',
175+
},
170176
maxHeight: '55px',
177+
msOverflowStyle: 'none',
171178
overflow: 'auto',
179+
scrollbarWidth: 'none',
172180
svg: {
173181
color: themes.light.color.grey3,
174182
},
@@ -181,9 +189,6 @@ export const CloudPulseResourcesSelect = React.memo(
181189
disableSelectAll={resourcesLimitReached} // Select_All option will not be available if number of resources are higher than resource selection limit
182190
disabled={disabled}
183191
errorText={isError ? `Failed to fetch ${label || 'Resources'}.` : ''}
184-
helperText={
185-
!isError ? `Select up to ${maxResourceSelectionLimit} ${label}` : ''
186-
}
187192
isOptionEqualToValue={(option, value) => option.id === value.id}
188193
label={label || 'Resources'}
189194
limitTags={1}

packages/manager/src/utilities/statMetrics.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const getMetrics = (data: number[][]): Metrics => {
4545

4646
export const formatNumber = (n: number): string => n.toFixed(2);
4747

48-
export const formatPercentage = (value: number) => formatNumber(value) + '%';
48+
export const formatPercentage = (value: number) => formatNumber(value) + ' %';
4949

5050
export const getTraffic = (averageInBits: number): number => {
5151
const averageInBytes = averageInBits / 8;

0 commit comments

Comments
 (0)