import { useMemo } from "react"; import Tooltip from "@mui/material/Tooltip"; import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import type { SxProps, Theme } from "@mui/material/styles"; import { useTranslation } from "react-i18next"; import { formatMs } from "@/Utils/TimeUtils"; import type { BarKind, ChartCell, } from "@/Pages/StatusPage/Status/themes/shared/ChartCells"; interface Props { cells: ChartCell[]; containerSx: SxProps; barSx: (kind: BarKind, heightPct: number) => SxProps; statsSx: SxProps; statsGap?: number; } export const ThemedHistogram = ({ cells, containerSx, barSx, statsSx, statsGap = 1, }: Props) => { const { t } = useTranslation(); const { avg, peak } = useMemo(() => { const valid = cells.filter((cell) => cell.responseTime > 0); const maxRt = valid.length ? Math.max(...valid.map((cell) => cell.responseTime)) : 0; const avgRt = valid.length ? valid.reduce((sum, cell) => sum + cell.responseTime, 0) / valid.length : 0; return { avg: formatMs(avgRt), peak: formatMs(maxRt) }; }, [cells]); return ( {cells.map((cell) => { if (cell.barKind === "empty") { return ( ); } return ( ); })} {t("pages.statusPages.monitorsList.chart.avg", { value: avg })} {t("pages.statusPages.monitorsList.chart.max", { value: peak })} ); };