From 70ff4c31fbcb01d81e526b5584b26bfbb2c1c57f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 25 Nov 2024 16:14:37 +0800 Subject: [PATCH] refactor area char to take an array of areas and data keys --- .../src/Components/Charts/AreaChart/index.jsx | 91 +++++++++++++++---- 1 file changed, 71 insertions(+), 20 deletions(-) diff --git a/Client/src/Components/Charts/AreaChart/index.jsx b/Client/src/Components/Charts/AreaChart/index.jsx index e3c231ebc..d99ab6eb4 100644 --- a/Client/src/Components/Charts/AreaChart/index.jsx +++ b/Client/src/Components/Charts/AreaChart/index.jsx @@ -11,6 +11,7 @@ import { createGradient } from "../Utils/gradientUtils"; import PropTypes from "prop-types"; import { useTheme } from "@mui/material"; import { useId } from "react"; +import { Fragment } from "react"; /** * CustomAreaChart component for rendering an area chart with optional gradient and custom ticks. * @@ -92,7 +93,49 @@ const CustomAreaChart = ({ }) => { const theme = useTheme(); const uniqueId = useId(); - const gradientId = `gradient-${uniqueId}`; + + const AREA_COLORS = [ + // Blues + "#3182bd", // Deep blue + "#6baed6", // Medium blue + "#9ecae1", // Light blue + + // Greens + "#74c476", // Soft green + "#a1d99b", // Light green + "#c7e9c0", // Pale green + + // Oranges + "#fdae6b", // Warm orange + "#fdd0a2", // Light orange + "#feedde", // Pale orange + + // Purples + "#9467bd", // Lavender + "#a55194", // Deep magenta + "#c994c7", // Soft magenta + + // Reds + "#ff9896", // Soft red + "#de2d26", // Deep red + "#fc9272", // Medium red + + // Cyans/Teals + "#17becf", // Cyan + "#7fcdbb", // Teal + "#a1dab4", // Light teal + + // Yellows + "#fec44f", // Mustard + "#fee391", // Light yellow + "#ffffd4", // Pale yellow + + // Additional colors + "#e377c2", // Soft pink + "#bcbd22", // Olive + "#2ca02c", // Vibrant green + ]; + return ( - {gradient === true && - createGradient({ - id: gradientId, - startColor: gradientStartColor, - endColor: gradientEndColor, - direction: gradientDirection, - })} + - {dataKeys.map((dataKey) => ( - - ))} + {dataKeys.map((dataKey, index) => { + const gradientId = `gradient-${uniqueId}-${index}`; + + return ( + + {gradient === true && + createGradient({ + id: gradientId, + startColor: gradientStartColor || AREA_COLORS[index], + endColor: gradientEndColor, + direction: gradientDirection, + })} + + + ); + })} {customTooltip ? (