OpenDataVisualizer/client/src/components/watercraft/CategoryLegend.tsx
Claudio Schaad a082eafdad Add Thurgau watercraft map
New Schaad.OpenData.Watercraft library that discovers the yearly
"immatrikulierte Wasserfahrzeuge" datasets (2021–2025) on data.tg.ch,
caches them and aggregates boats per harbour location by type,
propulsion, fuel, emission group and use, with length/power bins.

API under /api/watercraft, new page /schifffahrt/thurgau with donut
markers per location, year playback, toggleable categories and a
location/canton panel. Swisstopo base layers moved to map/baseLayers.ts
for both maps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 21:49:32 +01:00

68 lines
2 KiB
TypeScript

import type { Dimension, DimensionKey } from '../../api/watercraft';
import { formatNumber } from '../../traffic/format';
import type { CategoryGroup } from '../../watercraft/categories';
interface CategoryLegendProps {
dimensions: Dimension[];
dimension: Dimension;
groups: CategoryGroup[];
counts: number[];
hidden: Set<string>;
onDimensionChange: (key: DimensionKey) => void;
onToggle: (label: string) => void;
onShowAll: () => void;
}
export function CategoryLegend({
dimensions,
dimension,
groups,
counts,
hidden,
onDimensionChange,
onToggle,
onShowAll,
}: CategoryLegendProps) {
return (
<div className="legend category-legend">
<div className="dimension-tabs" role="tablist" aria-label="Färben nach">
{dimensions.map((d) => (
<button
key={d.key}
type="button"
role="tab"
aria-selected={d.key === dimension.key}
className={d.key === dimension.key ? 'active' : ''}
onClick={() => onDimensionChange(d.key)}
>
{d.label}
</button>
))}
</div>
<div className="category-chips">
{groups.map((group, i) => {
const off = hidden.has(group.label);
return (
<button
key={group.label}
type="button"
className={`category-chip ${off ? 'off' : ''}`}
aria-pressed={!off}
title={off ? 'Einblenden' : 'Ausblenden'}
onClick={() => onToggle(group.label)}
>
<span className="legend-dot small" style={{ background: group.color }} />
{group.label}
<span className="chip-count">{formatNumber(counts[i] ?? 0)}</span>
</button>
);
})}
{hidden.size > 0 && (
<button type="button" className="link-button" onClick={onShowAll}>
Alle zeigen
</button>
)}
</div>
</div>
);
}