diff --git a/src/app/globals.css b/src/app/globals.css index ed3e984..1971b63 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -125,6 +125,30 @@ html { animation: fade-in 2s; } +.custom-tooltip { + z-index: 9999; + background-color: #fff; + border: 1px solid #000; + border-radius: 0.5rem; + padding: 0.5rem; + box-shadow: 0 0 0.5rem rgba(0, 0, 0, 0.1); + animation: fade-in 0.5s; +} + +.dark .custom-tooltip { + background-color: #000; + color: #fff; + box-shadow: 0 0 0.5rem rgba(255, 255, 255, 0.1); +} + +.custom-tooltip > .label { + font-weight: bold; +} + +.recharts-dot { + opacity: 0.3; +} + @keyframes fade-in { 0%, 50% { diff --git a/src/components/stats/stats-page.tsx b/src/components/stats/stats-page.tsx index 192baae..2fb4030 100644 --- a/src/components/stats/stats-page.tsx +++ b/src/components/stats/stats-page.tsx @@ -31,9 +31,99 @@ interface StatsPageProps { stats: GlobalStats; } +interface TooltipPayload { + color: string; + value: number | string; + dataKey: string; +} + +interface CustomTooltipProps { + locale: "en" | "fr"; + tooltipMapping: Record; + active: boolean; + payload?: TooltipPayload[]; + label: string | number; +} + +interface DotProps { + cx: any; + cy: any; + stroke: any; + payload: any; + value: any; +} + +const CustomTooltip: React.FC = ({ + locale, + tooltipMapping, + active, + payload, + label, +}) => { + const formattedLabel = + locale === "fr" + ? new Date(label).toLocaleDateString("fr-FR", { + day: "2-digit", + month: "long", + year: "numeric", + }) + : new Date(label).toLocaleDateString("en-GB", { + day: "2-digit", + month: "long", + year: "numeric", + }); + + let localeString = "fr-FR"; + if (locale === "en") { + localeString = "en-GB"; + } + + if (active && payload && payload.length) { + return ( +
+

{formattedLabel}

+
    + {payload.map((entry, index) => ( +
  • + {`${(entry.value).toLocaleString(localeString)} ${tooltipMapping[entry.dataKey] || entry.dataKey}`} +
  • + ))} +
+
+ ); + } + + return null; +}; + +const CustomDot = (props: { cx: any; cy: any; stroke: any; payload: any; value: any; }) => { + const { cx, cy, stroke, payload, value } = props; + + return ( + + + + ); +}; + export default function StatsPage({ taches, stats }: StatsPageProps) { const t = useTranslations("StatsPage"); + const locale = useLocale(); + let localeString = "fr-FR"; + if (locale === "en") { + localeString = "en-GB"; + } + return (
@@ -44,43 +134,43 @@ export default function StatsPage({ taches, stats }: StatsPageProps) { {t("stats.menus")} - {(stats?.menus ?? 0).toLocaleString("fr")} + {(stats?.menus ?? 0).toLocaleString(localeString)} {t("stats.compositions")} - {(stats?.compositions ?? 0).toLocaleString("fr")} + {(stats?.compositions ?? 0).toLocaleString(localeString)} {t("stats.categories")} - {(stats?.categories ?? 0).toLocaleString("fr")} + {(stats?.categories ?? 0).toLocaleString(localeString)} {t("stats.repas")} - {(stats?.repas ?? 0).toLocaleString("fr")} + {(stats?.repas ?? 0).toLocaleString(localeString)} {t("stats.plats")} - {(stats?.plats ?? 0).toLocaleString("fr")} + {(stats?.plats ?? 0).toLocaleString(localeString)} {t("stats.restaurants")} - {(stats?.restaurants ?? 0).toLocaleString("fr")} + {(stats?.restaurants ?? 0).toLocaleString(localeString)} {t("stats.regions")} - {(stats?.regions ?? 0).toLocaleString("fr")} + {(stats?.regions ?? 0).toLocaleString(localeString)}
@@ -89,26 +179,7 @@ export default function StatsPage({ taches, stats }: StatsPageProps) { ); } -const chartConfig = { - menuAdded: { - label: "Menus Added", - }, - compositionAdded: { - label: "Compositions Added", - }, - categoryAdded: { - label: "Categories Added", - }, - repasAdded: { - label: "Repas Added", - }, - platAdded: { - label: "Plats Added", - }, - requests: { - label: "Requests", - }, -} satisfies ChartConfig; +const chartConfig = {} satisfies ChartConfig; const TacheCharts = ({ data }: { data: Tache[] }) => { const processedData = useMemo(() => { @@ -138,6 +209,15 @@ const TacheCharts = ({ data }: { data: Tache[] }) => { const t = useTranslations("StatsPage"); + const tooltipMapping = { + deltaMenus: t("charts.labels.menus"), + deltaRepas: t("charts.labels.repas"), + deltaCategories: t("charts.labels.categories"), + deltaPlats: t("charts.labels.plats"), + deltaCompositions: t("charts.labels.compositions"), + requetes: t("charts.labels.requetes"), + }; + return (
{/* Chart for the menus added over time */} @@ -180,7 +260,7 @@ const TacheCharts = ({ data }: { data: Tache[] }) => { }} /> - + } /> { }} /> - + } /> } /> } /> } /> } /> @@ -305,13 +389,14 @@ const TacheCharts = ({ data }: { data: Tache[] }) => { }} /> - + } /> } />