import Stack from "@mui/material/Stack"; import Typography from "@mui/material/Typography"; import { BaseChart } from "@/Components/design-elements"; import { useTheme } from "@mui/material/styles"; import { useSelector } from "react-redux"; import { formatDateWithTz } from "@/Utils/TimeUtils"; import { useTranslation } from "react-i18next"; import { ResponsiveContainer, BarChart, XAxis, Bar, Cell, Tooltip } from "recharts"; import { getResponseTimeColor } from "@/Utils/MonitorUtils"; import type { GroupedCheck } from "@/Types/Check"; import type { RootState } from "@/Types/state"; interface XLabelProps { p1: GroupedCheck; p2: GroupedCheck; range: string; } const XLabel = ({ p1, p2, range }: XLabelProps) => { const theme = useTheme(); const uiTimezone = useSelector((state: RootState) => state.ui.timezone); const dateFormat = range === "day" ? "MMM D, h:mm A" : "MMM D"; return ( <> {formatDateWithTz(p1.bucketDate, dateFormat, uiTimezone)} {formatDateWithTz(p2.bucketDate, dateFormat, uiTimezone)} ); }; interface HistogramStatusProps { title: string; icon: React.ReactNode; checks?: GroupedCheck[]; range: string; } export const HistogramStatus = ({ title, icon, checks = [], range, }: HistogramStatusProps) => { const { t } = useTranslation(); const theme = useTheme(); const CustomTooltip = ({ active, payload, }: { active?: boolean; payload?: Array<{ payload: GroupedCheck }>; }) => { const uiTimezone = useSelector((state: RootState) => state.ui.timezone); if (!active || !payload?.length) return null; const d = payload[0]?.payload; const avg = d?.avgResponseTime ?? 0; const titleText = t("common.charts.labels.averageResponseTime"); const fmt = range === "30d" ? "MMM D, YYYY" : "ddd, MMM D, YYYY, h:mm A"; let dateLabel = ""; if (d?.bucketDate) { const base = new Date(d.bucketDate); const midBucket = range === "30d" ? new Date(base.getTime() + 12 * 60 * 60 * 1000) : base; dateLabel = formatDateWithTz(midBucket.toISOString(), fmt, uiTimezone); } return ( {dateLabel ? ( {dateLabel} ) : null} {titleText} {Math.floor(avg)} ms ); }; const totalChecks = checks.reduce((acc, check) => acc + (check.totalChecks || 0), 0); return ( Total checks: {totalChecks} } /> } /> {checks?.map((groupedCheck, index) => { const fillColor = getResponseTimeColor(groupedCheck.avgResponseTime); return ( ); })} ); };