2023-06-15 12:52:46 +03:00
|
|
|
/* eslint-disable */
|
2023-06-06 18:32:48 +03:00
|
|
|
"use client";
|
2023-06-05 18:58:59 +03:00
|
|
|
import { format, subDays } from "date-fns";
|
|
|
|
import {
|
|
|
|
VictoryAxis,
|
|
|
|
VictoryChart,
|
2023-06-06 18:32:48 +03:00
|
|
|
VictoryChartProps,
|
2023-06-05 18:58:59 +03:00
|
|
|
VictoryContainer,
|
|
|
|
VictoryLine,
|
|
|
|
VictoryTheme,
|
|
|
|
} from "victory";
|
|
|
|
|
|
|
|
type RequestStat = {
|
|
|
|
date: string;
|
2023-08-21 15:05:13 +03:00
|
|
|
daily_requests_count: number;
|
2023-06-05 18:58:59 +03:00
|
|
|
user_id: string;
|
|
|
|
};
|
|
|
|
|
2023-06-06 18:32:48 +03:00
|
|
|
interface RequestsPerDayChartProps extends VictoryChartProps {
|
2023-06-05 18:58:59 +03:00
|
|
|
requests_stats: RequestStat[];
|
2023-06-06 18:32:48 +03:00
|
|
|
}
|
2023-06-05 18:58:59 +03:00
|
|
|
|
2023-06-15 12:52:46 +03:00
|
|
|
export const RequestsPerDayChart = ({
|
2023-06-05 18:58:59 +03:00
|
|
|
requests_stats,
|
2023-06-06 18:32:48 +03:00
|
|
|
...props
|
2023-06-15 12:52:46 +03:00
|
|
|
}: RequestsPerDayChartProps): JSX.Element => {
|
2023-06-05 18:58:59 +03:00
|
|
|
const data = Array.from({ length: 7 }, (_, i) => subDays(new Date(), i))
|
|
|
|
.map((date) => {
|
|
|
|
const dateString = format(date, "yyyyMMdd");
|
|
|
|
const stat = requests_stats.find((s) => s.date === dateString);
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2023-06-05 18:58:59 +03:00
|
|
|
return {
|
|
|
|
date: format(date, "MM/dd/yyyy"),
|
2023-08-21 15:05:13 +03:00
|
|
|
daily_requests_count: stat ? stat.daily_requests_count : 0,
|
2023-06-05 18:58:59 +03:00
|
|
|
};
|
|
|
|
})
|
|
|
|
.reverse();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<VictoryChart
|
|
|
|
theme={VictoryTheme.material}
|
2023-06-06 18:32:48 +03:00
|
|
|
containerComponent={
|
|
|
|
<VictoryContainer
|
2023-10-05 18:50:02 +03:00
|
|
|
className="bg-white dark:bg-black rounded-md w-full h-full"
|
2023-06-06 18:32:48 +03:00
|
|
|
responsive={true}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
animate={{
|
|
|
|
duration: 1000,
|
|
|
|
onLoad: { duration: 1000 },
|
|
|
|
}}
|
|
|
|
{...props}
|
2023-06-05 18:58:59 +03:00
|
|
|
>
|
|
|
|
<VictoryAxis
|
|
|
|
tickFormat={(tick) => {
|
|
|
|
return `${tick.split("/")[0]}/${tick.split("/")[1]}`;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<VictoryAxis dependentAxis />
|
2023-08-21 15:05:13 +03:00
|
|
|
<VictoryLine data={data} x="date" y="daily_requests_count" />
|
2023-06-05 18:58:59 +03:00
|
|
|
</VictoryChart>
|
|
|
|
);
|
|
|
|
};
|