Add x and y domain as optional values to AreaChart

This commit is contained in:
Alex Holliday committed 2024-11-25 10:48:43 +08:00
1 parent bf79dde960
commit 56e1aee525
1 file changed
+8
@@ -46,7 +46,9 @@ import { useId } from "react";
* <CustomAreaChart * <CustomAreaChart
* data={data} * data={data}
* xKey="createdAt" * xKey="createdAt"
* xDomain={["2023-01-01T00:00:00Z", "2023-01-01T02:00:00Z"]}
* yKey="cpu.usage_percent" * yKey="cpu.usage_percent"
* yDomain={[0, 1]}
* xTick={<TzTick />} * xTick={<TzTick />}
* yTick={<PercentTick />} * yTick={<PercentTick />}
* strokeColor="#8884d8" * strokeColor="#8884d8"
@@ -73,7 +75,9 @@ const CustomAreaChart = ({
data, data,
dataKey, dataKey,
xKey, xKey,
xDomain,
yKey, yKey,
yDomain,
xTick, xTick,
yTick, yTick,
strokeColor, strokeColor,
@@ -97,9 +101,11 @@ const CustomAreaChart = ({
<AreaChart data={data}> <AreaChart data={data}>
<XAxis <XAxis
dataKey={xKey} dataKey={xKey}
{...(xDomain && { domain: xDomain })}
{...(xTick && { tick: xTick })} {...(xTick && { tick: xTick })}
/> />
<YAxis <YAxis
{...(yDomain && { domain: yDomain })}
dataKey={yKey} dataKey={yKey}
{...(yTick && { tick: yTick })} {...(yTick && { tick: yTick })}
/> />
@@ -143,7 +149,9 @@ CustomAreaChart.propTypes = {
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,
xDomain: PropTypes.array,
yKey: PropTypes.string.isRequired, yKey: PropTypes.string.isRequired,
yDomain: PropTypes.array,
fillColor: PropTypes.string, fillColor: PropTypes.string,
strokeColor: PropTypes.string, strokeColor: PropTypes.string,
gradient: PropTypes.bool, gradient: PropTypes.bool,