-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upcoming: [M3-7301] - Replace Linode Network Transfer History chart w…
…ith Recharts (#9938) ## Description 📝 This PR is part of a bigger effort to replace chart.js with the more modern Recharts. As a first step, replace the Linode Network Transfer History chart. ### Verification steps - Go to the Network tab of a Linode that's been running for a while - Confirm the updated UI and that there are no regressions in the graph, units, etc
- Loading branch information
1 parent
5ebe15e
commit 9eee3aa
Showing
7 changed files
with
358 additions
and
2 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-9938-upcoming-features-1701201054946.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Upcoming Features | ||
--- | ||
|
||
Replace Linode Network Transfer History chart with Recharts ([#9938](https://github.com/linode/manager/pull/9938)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...des/LinodesDetail/LinodeNetworking/NetworkingSummaryPanel/NetworkTransferHistoryChart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { Typography, useTheme } from '@mui/material'; | ||
import { styled } from '@mui/material/styles'; | ||
import { DateTime } from 'luxon'; | ||
import React from 'react'; | ||
import { | ||
Area, | ||
AreaChart, | ||
CartesianGrid, | ||
ResponsiveContainer, | ||
Tooltip, | ||
TooltipProps, | ||
XAxis, | ||
YAxis, | ||
} from 'recharts'; | ||
|
||
import { Box } from 'src/components/Box'; | ||
import { Paper } from 'src/components/Paper'; | ||
import { NetworkUnit } from 'src/features/Longview/shared/utilities'; | ||
import { roundTo } from 'src/utilities/roundTo'; | ||
|
||
interface NetworkTransferHistoryChartProps { | ||
data: [number, null | number][]; | ||
timezone: string; | ||
unit: NetworkUnit; | ||
} | ||
|
||
export const NetworkTransferHistoryChart = ( | ||
props: NetworkTransferHistoryChartProps | ||
) => { | ||
const { data, timezone, unit } = props; | ||
|
||
const theme = useTheme(); | ||
|
||
const xAxisTickFormatter = (t: number) => { | ||
return DateTime.fromMillis(t, { zone: timezone }).toFormat('LLL dd'); | ||
}; | ||
|
||
const tooltipLabelFormatter = (t: number) => { | ||
return DateTime.fromMillis(t, { zone: timezone }).toFormat( | ||
'LLL dd, yyyy, h:mm a' | ||
); | ||
}; | ||
|
||
const tooltipValueFormatter = (value: number) => | ||
`${roundTo(value)} ${unit}/s`; | ||
|
||
const CustomTooltip = ({ | ||
active, | ||
label, | ||
payload, | ||
}: TooltipProps<any, any>) => { | ||
if (active && payload && payload.length) { | ||
return ( | ||
<StyledPaper> | ||
<Typography>{tooltipLabelFormatter(label)}</Typography> | ||
<Typography fontFamily={theme.font.bold}> | ||
Public outbound traffic: {tooltipValueFormatter(payload[0].value)} | ||
</Typography> | ||
</StyledPaper> | ||
); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
return ( | ||
<Box marginLeft={-5}> | ||
<ResponsiveContainer height={190} width="100%"> | ||
<AreaChart data={data}> | ||
<CartesianGrid | ||
stroke={theme.color.grey7} | ||
strokeDasharray="3 3" | ||
vertical={false} | ||
/> | ||
<XAxis | ||
dataKey="t" | ||
domain={['dataMin', 'dataMax']} | ||
interval="preserveEnd" | ||
minTickGap={15} | ||
scale="time" | ||
stroke={theme.color.label} | ||
tickFormatter={xAxisTickFormatter} | ||
type="number" | ||
/> | ||
<YAxis dataKey="Public Outbound Traffic" stroke={theme.color.label} /> | ||
<Tooltip | ||
contentStyle={{ | ||
color: '#606469', | ||
}} | ||
itemStyle={{ | ||
color: '#606469', | ||
fontFamily: theme.font.bold, | ||
}} | ||
content={<CustomTooltip />} | ||
/> | ||
<Area | ||
dataKey="Public Outbound Traffic" | ||
fill="#1CB35C" | ||
isAnimationActive={false} | ||
stroke="#1CB35C" | ||
type="monotone" | ||
/> | ||
</AreaChart> | ||
</ResponsiveContainer> | ||
</Box> | ||
); | ||
}; | ||
|
||
const StyledPaper = styled(Paper, { | ||
label: 'StyledPaper', | ||
})(({ theme }) => ({ | ||
border: `1px solid ${theme.color.border2}`, | ||
padding: theme.spacing(1), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.