import { BaseChart } from "@/Components/design-elements"; import { AreaChart, Area, XAxis, YAxis, CartesianGrid, ResponsiveContainer, } from "recharts"; import { Fragment, useId } from "react"; import { XTick } from "@/Components/monitors/charts/XTick"; import { useTheme } from "@mui/material/styles"; import type { HardwareCheckStats } from "@/Types/Monitor"; 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 ]; const createGradient = ({ id, startColor, endColor, startOpacity = 0.8, endOpacity = 0, direction = "vertical", }: { id: string; startColor: string; endColor: string; startOpacity?: number; endOpacity?: number; direction?: "vertical" | "horizontal"; }) => ( ); export const HistogramInfrastructure = ({ dateRange, title, type, idx: _idx, checks, xKey, yDomain, dataKeys, gradient = false, gradientDirection = "vertical", gradientStartColor, gradientEndColor, strokeColor, fillColor, yAxisFormatter, }: { dateRange: string; title: string; type: string; idx: number | null; checks: HardwareCheckStats[]; xKey: string; yDomain?: number[]; dataKeys: string[]; gradient?: boolean; gradientDirection?: "vertical" | "horizontal"; gradientStartColor?: string; gradientEndColor?: string; strokeColor: string; fillColor?: string; yAxisFormatter?: (value: number) => string; }) => { const theme = useTheme(); const uniqueId = useId(); const data = checks; let avgTemps: { bucketDate: string; avg_temp: number | null }[] = []; let tempYDomain: number[] = []; if (type === "temp") { avgTemps = data.map((check) => { const temps = check.avgTemperature || []; if (temps.length === 0) return { bucketDate: check.bucketDate, avg_temp: null }; const totalTemp = temps.reduce((sum, temp) => sum + (temp || 0), 0); const avgTemp = totalTemp / temps.length; return { bucketDate: check.bucketDate, avg_temp: avgTemp }; }); const maxTemp: number = avgTemps.reduce((max, item) => { return item.avg_temp && item.avg_temp > max ? item.avg_temp : max; }, 0); tempYDomain = [0, Math.ceil((maxTemp * 1.3) / 10) * 10]; } return ( ( )} /> {dataKeys?.map((dataKey, index) => { const gradientId = `gradient-${uniqueId}-${index}`; return ( {gradient === true && createGradient({ id: gradientId, startColor: gradientStartColor || AREA_COLORS[index], endColor: gradientEndColor || "transparent", direction: gradientDirection, })} ); })} ); };