import { BaseChart } from "@/components/monitors/Chart";
import { BaseBox } from "@/components/design-elements";
import { Clock } from "lucide-react";
import { normalizeResponseTimes } from "@/utils/DataUtils";
import {
AreaChart,
Area,
XAxis,
Tooltip,
CartesianGrid,
ResponsiveContainer,
Text,
} from "recharts";
import Typography from "@mui/material/Typography";
import {
formatDateWithTz,
tickDateFormatLookup,
tooltipDateFormatLookup,
} from "@/utils/TimeUtils";
import { useTheme } from "@mui/material/styles";
import type { GroupedCheck } from "@/types/check";
import { useAppSelector } from "@/hooks/AppHooks";
type XTickProps = {
x: number;
y: number;
payload: { value: any };
range: string;
};
export const XTick = ({ x, y, payload, range }: XTickProps) => {
const format = tickDateFormatLookup(range);
const theme = useTheme();
const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
console.log(payload);
return (
{formatDateWithTz(payload?.value, format, uiTimezone)}
);
};
type ResponseTimeToolTipProps = {
active?: boolean | undefined;
payload?: any[];
label?: string | number;
range: string;
theme: any;
uiTimezone: string;
};
const ResponseTimeToolTip = ({
active,
payload,
label,
range,
theme,
uiTimezone,
}: ResponseTimeToolTipProps) => {
if (!label) return null;
if (!payload) return null;
if (!active) return null;
const format = tooltipDateFormatLookup(range);
const responseTime = Math.floor(payload?.[0]?.payload?.avgResponseTime || 0);
return (
{formatDateWithTz(String(label), format, uiTimezone)}
Response time: {responseTime} ms
);
};
export const ChartResponseTime = ({
checks,
range,
}: {
checks: GroupedCheck[];
range: string;
}) => {
const theme = useTheme();
const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
const normalized = normalizeResponseTimes(
checks,
"avgResponseTime"
);
return (
}
title="Response times"
>
}
/>
(
)}
/>
);
};