diff --git a/Client/src/Components/Charts/AreaChart/index.jsx b/Client/src/Components/Charts/AreaChart/index.jsx index e69de29bb..ce4da9830 100644 --- a/Client/src/Components/Charts/AreaChart/index.jsx +++ b/Client/src/Components/Charts/AreaChart/index.jsx @@ -0,0 +1,144 @@ +import { + AreaChart, + Area, + XAxis, + YAxis, + CartesianGrid, + Tooltip, + ResponsiveContainer, +} from "recharts"; +import { createGradient } from "../Utils/gradientUtils"; +import PropTypes from "prop-types"; +import { useTheme } from "@mui/material"; + +/** + * CustomAreaChart component for rendering an area chart with optional gradient and custom ticks. + * + * @param {Object} props - The properties object. + * @param {Array} props.data - The data array for the chart. + * @param {string} props.xKey - The key for the x-axis data. + * @param {string} props.yKey - The key for the y-axis data. + * @param {Object} [props.xTick] - Custom tick component for the x-axis. + * @param {Object} [props.yTick] - Custom tick component for the y-axis. + * @param {string} [props.strokeColor] - The stroke color for the area. + * @param {string} [props.fillColor] - The fill color for the area. + * @param {boolean} [props.gradient=false] - Whether to apply a gradient fill. + * @param {string} [props.gradientDirection="vertical"] - The direction of the gradient. + * @param {string} [props.gradientStartColor] - The start color of the gradient. + * @param {string} [props.gradientEndColor] - The end color of the gradient. + * @param {Object} [props.customTooltip] - Custom tooltip component. + * @returns {JSX.Element} The rendered area chart component. + * + * @example + * // Example usage of CustomAreaChart + * import React from 'react'; + * import CustomAreaChart from './CustomAreaChart'; + * import { TzTick, PercentTick, InfrastructureTooltip } from './chartUtils'; + * + * const data = [ + * { createdAt: '2023-01-01T00:00:00Z', cpu: { usage_percent: 0.5 } }, + * { createdAt: '2023-01-01T01:00:00Z', cpu: { usage_percent: 0.6 } }, + * // more data points... + * ]; + * + * const MyChartComponent = () => { + * return ( + * + * ); + * }; + * + * export default MyChartComponent; + */ +const CustomAreaChart = ({ + data, + dataKey, + xKey, + yKey, + xTick, + yTick, + strokeColor, + fillColor, + gradient = false, + gradientDirection = "vertical", + gradientStartColor, + gradientEndColor, + customTooltip, +}) => { + const theme = useTheme(); + return ( + + + + + {gradient === true && + createGradient({ + startColor: gradientStartColor, + endColor: gradientEndColor, + direction: gradientDirection, + })} + + + + {customTooltip ? ( + + ) : ( + + )} + + + ); +}; + +CustomAreaChart.propTypes = { + data: PropTypes.array.isRequired, + dataKey: PropTypes.string.isRequired, + 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 + xKey: PropTypes.string.isRequired, + yKey: PropTypes.string.isRequired, + fillColor: PropTypes.string, + strokeColor: PropTypes.string, + gradient: PropTypes.bool, + gradientDirection: PropTypes.string, + gradientStartColor: PropTypes.string, + gradientEndColor: PropTypes.string, + customTooltip: PropTypes.object, +}; + +export default CustomAreaChart;