From ac366d04cd54869c9a2b090aae24a276c32a85a6 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Sat, 14 Feb 2026 01:35:54 +0100 Subject: feat: Implemen experimental bus stop usage display --- .../app/components/stop/StopUsageModal.tsx | 151 +++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/frontend/app/components/stop/StopUsageModal.tsx (limited to 'src/frontend/app/components/stop') diff --git a/src/frontend/app/components/stop/StopUsageModal.tsx b/src/frontend/app/components/stop/StopUsageModal.tsx new file mode 100644 index 0000000..41db64a --- /dev/null +++ b/src/frontend/app/components/stop/StopUsageModal.tsx @@ -0,0 +1,151 @@ +import { useMemo, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { Sheet } from "react-modal-sheet"; +import type { BusStopUsagePoint } from "~/api/schema"; + +interface StopUsageModalProps { + isOpen: boolean; + onClose: () => void; + usage: BusStopUsagePoint[]; +} + +export const StopUsageModal = ({ + isOpen, + onClose, + usage, +}: StopUsageModalProps) => { + const { t } = useTranslation(); + + // Get current day of week (1=Monday, 7=Sunday) + // JS getDay(): 0=Sunday, 1=Monday ... 6=Saturday + const currentJsDay = new Date().getDay(); + const initialDay = currentJsDay === 0 ? 7 : currentJsDay; + + const [selectedDay, setSelectedDay] = useState(initialDay); + + const days = [ + { id: 1, label: t("days.monday") }, + { id: 2, label: t("days.tuesday") }, + { id: 3, label: t("days.wednesday") }, + { id: 4, label: t("days.thursday") }, + { id: 5, label: t("days.friday") }, + { id: 6, label: t("days.saturday") }, + { id: 7, label: t("days.sunday") }, + ]; + + const filteredData = useMemo(() => { + const data = usage.filter((u) => u.d === selectedDay); + // Ensure all 24 hours are represented + const fullDay = Array.from({ length: 24 }, (_, h) => { + const match = data.find((u) => u.h === h); + return { h, t: match?.t ?? 0 }; + }); + return fullDay; + }, [usage, selectedDay]); + + const maxUsage = useMemo(() => { + const max = Math.max(...filteredData.map((d) => d.t)); + return max === 0 ? 1 : max; + }, [filteredData]); + + // Use a square root scale to make smaller values more visible + const getScaledHeight = (value: number) => { + if (value <= 0) return 0; + const scaledValue = Math.sqrt(value); + const scaledMax = Math.sqrt(maxUsage); + return (scaledValue / scaledMax) * 100; + }; + + return ( + + + + +
+
+

+ {t("stop.usage_title", "Ocupación por horas")} +

+
+ {days.map((day) => ( + + ))} +
+
+ +
+
+ {/* Horizontal grid lines */} +
+
+
+
+
+ + {filteredData.map((data) => { + const height = getScaledHeight(data.t); + const isServiceHour = data.h >= 7 && data.h < 23; + + return ( +
+
+ {data.t > 0 && ( +
+ {data.t} {t("stop.usage_passengers", "pas.")} +
+ )} +
+ {data.h % 4 === 0 && ( + + {data.h}h + + )} +
+ ); + })} +
+
{/* Spacer for hour labels */} +
+ +
+

+ {t( + "stop.usage_scale_info", + "Escala no lineal para resaltar valores bajos" + )} +

+

+ {t( + "stop.usage_disclaimer", + "Datos históricos aproximados de ocupación." + )} +

+
+
+
+
+ +
+ ); +}; -- cgit v1.3