refactor AreaChart to take an array of data keys

This commit is contained in:
Alex Holliday committed 2024-11-25 13:00:28 +08:00
1 parent d75b15b890
commit 8db24e9016
2 files changed
+13 -9

No files matched your search

@@ -45,6 +45,7 @@ import { useId } from "react";
* return ( * return (
* <CustomAreaChart * <CustomAreaChart
* data={data} * data={data}
* dataKeys={["cpu.usage_percent"]}
* xKey="createdAt" * xKey="createdAt"
* xDomain={["2023-01-01T00:00:00Z", "2023-01-01T02:00:00Z"]} * xDomain={["2023-01-01T00:00:00Z", "2023-01-01T02:00:00Z"]}
* yKey="cpu.usage_percent" * yKey="cpu.usage_percent"
@@ -73,7 +74,7 @@ import { useId } from "react";
*/ */
const CustomAreaChart = ({ const CustomAreaChart = ({
data, data,
dataKey, dataKeys,
xKey, xKey,
xDomain, xDomain,
yKey, yKey,
@@ -123,12 +124,15 @@ const CustomAreaChart = ({
fill="transparent" fill="transparent"
vertical={false} vertical={false}
/> />
<Area {dataKeys.map((dataKey) => (
type="monotone" <Area
dataKey={dataKey} key={dataKey}
stroke={strokeColor} type="monotone"
fill={gradient === true ? `url(#${gradientId})` : fillColor} dataKey={dataKey}
/> stroke={strokeColor}
fill={gradient === true ? `url(#${gradientId})` : fillColor}
/>
))}
{customTooltip ? ( {customTooltip ? (
<Tooltip <Tooltip
cursor={{ stroke: theme.palette.border.light }} cursor={{ stroke: theme.palette.border.light }}
@@ -145,7 +149,7 @@ const CustomAreaChart = ({
CustomAreaChart.propTypes = { CustomAreaChart.propTypes = {
data: PropTypes.array.isRequired, data: PropTypes.array.isRequired,
dataKey: PropTypes.string.isRequired, dataKeys: PropTypes.array.isRequired,
xTick: PropTypes.object, // Recharts takes an instance of component, so we can't pass the component itself xTick: PropTypes.object, // Recharts takes an instance of component, so we can't pass the component itself
yTick: PropTypes.object, // Recharts takes an instance of component, so we can't pass the component itself yTick: PropTypes.object, // Recharts takes an instance of component, so we can't pass the component itself
xKey: PropTypes.string.isRequired, xKey: PropTypes.string.isRequired,
@@ -460,7 +460,7 @@ const InfrastructureDetails = () => {
<AreaChart <AreaChart
height={areaChartHeight} height={areaChartHeight}
data={monitor?.checks ?? []} data={monitor?.checks ?? []}
dataKey={config.dataKey} dataKeys={[config.dataKey]}
xKey="createdAt" xKey="createdAt"
yKey={config.dataKey} yKey={config.dataKey}
yDomain={config.yDomain} yDomain={config.yDomain}