ASP.NET Core 10 API and React client that visualize the canton of Thurgau's hourly traffic counts by vehicle class (data.tg.ch, CC0). - Background refresh from data.tg.ch every 6 h into a per-day JSON cache, so history grows beyond the source's two-week window - Road geometry per station direction from swisstopo swissTLM3D, oriented by geocoding the direction's target town; roundabout arms follow the road outward only - Leaflet map with canvas animation: dots drive along the road in both directions, density by hourly count, colour by vehicle class, right-hand traffic; play/pause, time slider and day selection - Station panel with per-class counts and Chart.js charts (hourly, weekday/weekend profile, daily totals, class mix) - swisstopo base map switcher (grey, colour, aerial) - Dockerfile and docker-compose with a data volume - xUnit tests for mapping, cache, geometry, geocoding and analysis Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
2.4 KiB
TypeScript
99 lines
2.4 KiB
TypeScript
import { formatClock, formatDate } from '../traffic/format';
|
||
|
||
export const SPEEDS = [
|
||
{ label: '1 h = 10 s', hoursPerSecond: 0.1 },
|
||
{ label: '1 h = 4 s', hoursPerSecond: 0.25 },
|
||
{ label: '1 h = 1 s', hoursPerSecond: 1 },
|
||
];
|
||
|
||
interface TimeControlsProps {
|
||
dates: string[];
|
||
date: string;
|
||
time: number;
|
||
playing: boolean;
|
||
hoursPerSecond: number;
|
||
onDateChange: (date: string) => void;
|
||
onTimeChange: (time: number) => void;
|
||
onPlayingChange: (playing: boolean) => void;
|
||
onSpeedChange: (hoursPerSecond: number) => void;
|
||
}
|
||
|
||
export function TimeControls({
|
||
dates,
|
||
date,
|
||
time,
|
||
playing,
|
||
hoursPerSecond,
|
||
onDateChange,
|
||
onTimeChange,
|
||
onPlayingChange,
|
||
onSpeedChange,
|
||
}: TimeControlsProps) {
|
||
const index = dates.indexOf(date);
|
||
|
||
return (
|
||
<div className="time-controls">
|
||
<button
|
||
type="button"
|
||
className="play-button"
|
||
onClick={() => onPlayingChange(!playing)}
|
||
aria-label={playing ? 'Pause' : 'Abspielen'}
|
||
title={playing ? 'Pause' : 'Abspielen'}
|
||
>
|
||
{playing ? '❚❚' : '▶'}
|
||
</button>
|
||
|
||
<div className="date-picker">
|
||
<button
|
||
type="button"
|
||
disabled={index <= 0}
|
||
onClick={() => onDateChange(dates[index - 1])}
|
||
aria-label="Vorheriger Tag"
|
||
>
|
||
‹
|
||
</button>
|
||
<select value={date} onChange={(e) => onDateChange(e.target.value)}>
|
||
{dates.map((d) => (
|
||
<option key={d} value={d}>
|
||
{formatDate(d)}
|
||
</option>
|
||
))}
|
||
</select>
|
||
<button
|
||
type="button"
|
||
disabled={index < 0 || index >= dates.length - 1}
|
||
onClick={() => onDateChange(dates[index + 1])}
|
||
aria-label="Nächster Tag"
|
||
>
|
||
›
|
||
</button>
|
||
</div>
|
||
|
||
<div className="clock">{formatClock(time)}</div>
|
||
|
||
<input
|
||
className="time-slider"
|
||
type="range"
|
||
min={0}
|
||
max={23.99}
|
||
step={0.05}
|
||
value={time}
|
||
onChange={(e) => onTimeChange(Number(e.target.value))}
|
||
aria-label="Uhrzeit"
|
||
/>
|
||
|
||
<select
|
||
className="speed-select"
|
||
value={hoursPerSecond}
|
||
onChange={(e) => onSpeedChange(Number(e.target.value))}
|
||
aria-label="Geschwindigkeit"
|
||
>
|
||
{SPEEDS.map((speed) => (
|
||
<option key={speed.hoursPerSecond} value={speed.hoursPerSecond}>
|
||
{speed.label}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</div>
|
||
);
|
||
}
|