Add hourly usage snapshots, analysis layer, scorecard, tooltips & guided tour
- data-pipeline: hourly NDW snapshot job (occupancy + status) + GitHub Action; per-gemeente day files, current-status, daily-average rollup. - webapp: usage-over-day chart in detail panel; fresh per-gemeente status colours; national analysis choropleth (LayerSwitcher) + gemeente scorecard with demand (peer-model), siting priority, congestion and live/potential net-impact scenario. - analysis/ (Python): golden dataset (CBS Kerncijfers + chargers) -> derived metrics + models (demand, siting, congestion, municipal percentiles). - UX: InfoTip tooltips throughout, expanded methodology modal, interactive guided tour (spotlight + blur) that drives the app to example screens. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
55ecd88b78
commit
800ad823e9
+202
-6
@@ -1,14 +1,18 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { useState, useEffect, useMemo, useRef } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import MunicipalitySelector from "@/components/MunicipalitySelector";
|
||||
import AddressSearchInput from "@/components/AddressSearchInput";
|
||||
import FilterPanel from "@/components/FilterPanel";
|
||||
import StatsPanel from "@/components/StatsPanel";
|
||||
import LocationDetailPanel from "@/components/LocationDetailPanel";
|
||||
import LayerSwitcher from "@/components/LayerSwitcher";
|
||||
import GemeenteScorecard from "@/components/GemeenteScorecard";
|
||||
import AboutModal from "@/components/AboutModal";
|
||||
import ShareModal from "@/components/ShareModal";
|
||||
import GuidedTour, { type TourStep } from "@/components/GuidedTour";
|
||||
import type { ChoroplethData, AreaProps } from "@/types/analysis";
|
||||
import {
|
||||
Municipality,
|
||||
CropoutData,
|
||||
@@ -44,10 +48,156 @@ export default function Home() {
|
||||
const [selected, setSelected] = useState<ChargeFeature | null>(null);
|
||||
const [showAbout, setShowAbout] = useState(false);
|
||||
const [showShare, setShowShare] = useState(false);
|
||||
const [showTutorial, setShowTutorial] = useState(false);
|
||||
const [mobileSidebarOpen, setMobileSidebarOpen] = useState(false);
|
||||
|
||||
// Auto-open the tutorial on first visit.
|
||||
useEffect(() => {
|
||||
if (!localStorage.getItem("tutorialSeen")) {
|
||||
setShowTutorial(true);
|
||||
localStorage.setItem("tutorialSeen", "1");
|
||||
}
|
||||
}, []);
|
||||
const [choropleth, setChoropleth] = useState<ChoroplethData | null>(null);
|
||||
const [analysisMetric, setAnalysisMetric] = useState<string | null>(null);
|
||||
const [selectedArea, setSelectedArea] = useState<AreaProps | null>(null);
|
||||
|
||||
const isNational = selectedMunicipality === "nederland";
|
||||
|
||||
// Load the analysis choropleth dataset once.
|
||||
useEffect(() => {
|
||||
fetch("/data/derived/gemeente-metrics.geojson")
|
||||
.then((r) => (r.ok ? r.json() : null))
|
||||
.then((d: ChoroplethData | null) => d && setChoropleth(d))
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
const metricMeta = useMemo(
|
||||
() => choropleth?.metadata.metrics.find((m) => m.key === analysisMetric) ?? null,
|
||||
[choropleth, analysisMetric],
|
||||
);
|
||||
const choroActive = isNational && !!analysisMetric;
|
||||
|
||||
// Refs so the guided tour can read current data inside its step actions.
|
||||
const chargeFeaturesRef = useRef(chargeFeatures);
|
||||
const choroplethRef = useRef(choropleth);
|
||||
useEffect(() => {
|
||||
chargeFeaturesRef.current = chargeFeatures;
|
||||
}, [chargeFeatures]);
|
||||
useEffect(() => {
|
||||
choroplethRef.current = choropleth;
|
||||
}, [choropleth]);
|
||||
|
||||
// Interactive guided tour: each step drives the app to a real example screen,
|
||||
// lets the existing zoom/fit behaviour kick in, and spotlights the relevant UI.
|
||||
const tourSteps: TourStep[] = useMemo(
|
||||
() => [
|
||||
{
|
||||
title: "Welkom bij Laadpalenviewer",
|
||||
body: (
|
||||
<>
|
||||
<p>Een korte rondleiding stuurt je langs alle onderdelen — de kaart beweegt mee.</p>
|
||||
<p className="text-gray-400">Later opnieuw te openen via de knop “Uitleg”.</p>
|
||||
</>
|
||||
),
|
||||
action: () => {
|
||||
setSelected(null);
|
||||
setSelectedArea(null);
|
||||
setAnalysisMetric(null);
|
||||
setSelectedMunicipality("utrecht");
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Kies een gemeente",
|
||||
target: '[data-tour="municipality"]',
|
||||
body: <p>Selecteer hier een gemeente of zoek een adres. De kaart zoomt naar die gemeente en laadt alle details.</p>,
|
||||
},
|
||||
{
|
||||
title: "Twee kaartlagen + filters",
|
||||
target: '[data-tour="layers"]',
|
||||
body: (
|
||||
<p>
|
||||
Zet de lagen <strong>personenauto</strong> en <strong>logistiek/vracht</strong> aan/uit en filter op
|
||||
vermogen. De ⓘ-iconen geven overal extra uitleg.
|
||||
</p>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "Kleuren = live status",
|
||||
target: '[data-tour="legend"]',
|
||||
body: (
|
||||
<p>
|
||||
Punten zijn gekleurd op OCPI-status uit de uurlijkse momentopname:
|
||||
<span className="text-green-600"> beschikbaar</span>,
|
||||
<span className="text-blue-600"> bezet</span>,
|
||||
<span className="text-red-600"> niet beschikbaar</span>.
|
||||
</p>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "Detail van een laadpunt",
|
||||
target: '[data-tour="detail"]',
|
||||
action: () => {
|
||||
const f = chargeFeaturesRef.current.find((x) => x.properties.layer === "passenger") ?? chargeFeaturesRef.current[0];
|
||||
if (f) setSelected(f);
|
||||
},
|
||||
body: <p>We openden een voorbeeld-laadpunt: exploitant, connectoren (type & kW) en tarieven — direct geladen.</p>,
|
||||
},
|
||||
{
|
||||
title: "Gebruik over de tijd",
|
||||
target: '[data-tour="usage"]',
|
||||
body: <p>Per uur het aandeel connectoren dat laadt (24u/7d/30d/1j), opgebouwd uit de uurlijkse snapshots.</p>,
|
||||
},
|
||||
{
|
||||
title: "Analyse per gemeente",
|
||||
target: '[data-tour="analyse"]',
|
||||
action: () => {
|
||||
setSelected(null);
|
||||
setSelectedMunicipality("nederland");
|
||||
setAnalysisMetric("siting_priority");
|
||||
},
|
||||
body: (
|
||||
<p>
|
||||
In de landelijke weergave kleurt elke indicator de gemeenten (choropleth). Hier:
|
||||
<strong> plaatsingsprioriteit</strong>. Onder de keuze staat steeds een uitleg.
|
||||
</p>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "Gemeente-scorecard",
|
||||
target: '[data-tour="scorecard"]',
|
||||
action: () => {
|
||||
const fc = choroplethRef.current;
|
||||
const f =
|
||||
fc?.features.find((x) => x.properties.gemeente === "Utrecht") ?? fc?.features.find((x) => x.properties.chargers_total != null);
|
||||
if (f) setSelectedArea(f.properties as typeof selectedArea);
|
||||
},
|
||||
body: (
|
||||
<p>
|
||||
Klik een gemeente voor de scorecard: verwachte vraag (peer-model), tekort/overschot, live belasting en
|
||||
een netimpact-scenario met schuiven.
|
||||
</p>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "Bronnen & methodologie",
|
||||
body: (
|
||||
<>
|
||||
<p>
|
||||
Bronnen: NDW DOT-NL, CBS, PDOK, Open Charge Map. Vermogen wordt aangenomen (NDW mist het meestal);
|
||||
congestie is gemodelleerd.
|
||||
</p>
|
||||
<p className="text-gray-400">Volledige uitleg staat onder “Over”.</p>
|
||||
</>
|
||||
),
|
||||
action: () => {
|
||||
setSelectedArea(null);
|
||||
},
|
||||
},
|
||||
],
|
||||
[],
|
||||
);
|
||||
|
||||
// Load municipalities once.
|
||||
useEffect(() => {
|
||||
fetch("/municipalities.json")
|
||||
@@ -105,14 +255,22 @@ export default function Home() {
|
||||
setDetails({});
|
||||
setGemeenteName("Nederland");
|
||||
} else {
|
||||
const [cropRes, detRes] = await Promise.all([
|
||||
const [cropRes, detRes, statusRes] = await Promise.all([
|
||||
fetch(`/data/gemeenten/${selectedMunicipality}.geojson`),
|
||||
fetch(`/data/gemeenten/${selectedMunicipality}.details.json`),
|
||||
fetch(`/data/status/${selectedMunicipality}.json`),
|
||||
]);
|
||||
const crop = (await cropRes.json()) as CropoutData;
|
||||
const bundle = (await detRes.json()) as DetailBundle;
|
||||
// Fresh hourly status (may not exist yet); overrides build-time status on the map.
|
||||
const freshStatus = statusRes.ok
|
||||
? ((await statusRes.json()) as Record<string, ChargeFeature["properties"]["status"]>)
|
||||
: {};
|
||||
if (cancelled) return;
|
||||
const charges = crop.features.filter((f) => f.properties.type === "charge") as ChargeFeature[];
|
||||
const charges = (crop.features.filter((f) => f.properties.type === "charge") as ChargeFeature[]).map((f) => {
|
||||
const s = freshStatus[f.properties.locationId];
|
||||
return s ? { ...f, properties: { ...f.properties, status: s } } : f;
|
||||
});
|
||||
const boundaries = crop.features.filter((f) => f.properties.type === "boundary") as BoundaryFeature[];
|
||||
setChargeFeatures(charges);
|
||||
setBoundaryFeatures(boundaries);
|
||||
@@ -156,7 +314,7 @@ export default function Home() {
|
||||
<h1 className="text-lg md:text-xl font-bold text-gray-900 flex-shrink-0">
|
||||
🔌 <span className="hidden sm:inline">Laadpalenviewer</span>
|
||||
</h1>
|
||||
<div className="flex-1 min-w-0 max-w-[200px] sm:max-w-xs md:max-w-md">
|
||||
<div className="flex-1 min-w-0 max-w-[200px] sm:max-w-xs md:max-w-md" data-tour="municipality">
|
||||
<MunicipalitySelector
|
||||
municipalities={municipalities}
|
||||
selected={selectedMunicipality}
|
||||
@@ -179,6 +337,12 @@ export default function Home() {
|
||||
</div>
|
||||
)}
|
||||
<div className="hidden lg:flex gap-2 ml-auto">
|
||||
<button
|
||||
onClick={() => setShowTutorial(true)}
|
||||
className="px-3 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 transition"
|
||||
>
|
||||
Uitleg
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setShowShare(true)}
|
||||
className="px-3 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 transition"
|
||||
@@ -207,6 +371,16 @@ export default function Home() {
|
||||
${mobileSidebarOpen ? "translate-x-0" : "-translate-x-full md:translate-x-0"} shadow-xl md:shadow-none`}
|
||||
>
|
||||
<StatsPanel gemeente={gemeenteName} chargeFeatures={chargeFeatures} />
|
||||
{isNational && choropleth && (
|
||||
<LayerSwitcher
|
||||
metrics={choropleth.metadata.metrics}
|
||||
active={analysisMetric}
|
||||
onChange={(k) => {
|
||||
setAnalysisMetric(k);
|
||||
setSelectedArea(null);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<FilterPanel
|
||||
filters={filters}
|
||||
onChange={setFilters}
|
||||
@@ -226,15 +400,32 @@ export default function Home() {
|
||||
chargeFeatures={chargeFeatures}
|
||||
boundaryFeatures={boundaryFeatures}
|
||||
bounds={bounds}
|
||||
filters={filters}
|
||||
filters={choroActive ? { ...filters, showPassenger: false, showFreight: false } : filters}
|
||||
selectedLocationId={selected?.properties.locationId ?? null}
|
||||
onSelect={setSelected}
|
||||
choropleth={choroActive ? choropleth : null}
|
||||
analysisMetric={choroActive ? analysisMetric : null}
|
||||
metricMeta={metricMeta}
|
||||
onAreaSelect={(p) => setSelectedArea(p as AreaProps)}
|
||||
/>
|
||||
|
||||
{choroActive && selectedArea && (
|
||||
<GemeenteScorecard
|
||||
area={selectedArea}
|
||||
onClose={() => setSelectedArea(null)}
|
||||
onOpenGemeente={(slug) => {
|
||||
setSelectedArea(null);
|
||||
setAnalysisMetric(null);
|
||||
setSelectedMunicipality(slug);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<LocationDetailPanel
|
||||
selected={selected}
|
||||
detail={selectedDetail}
|
||||
loading={false}
|
||||
slug={selectedMunicipality}
|
||||
onClose={() => setSelected(null)}
|
||||
/>
|
||||
|
||||
@@ -258,7 +449,12 @@ export default function Home() {
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<AboutModal isOpen={showAbout} onClose={() => setShowAbout(false)} />
|
||||
<AboutModal
|
||||
isOpen={showAbout}
|
||||
onClose={() => setShowAbout(false)}
|
||||
onStartTutorial={() => setShowTutorial(true)}
|
||||
/>
|
||||
<GuidedTour open={showTutorial} steps={tourSteps} onClose={() => setShowTutorial(false)} />
|
||||
<ShareModal
|
||||
isOpen={showShare}
|
||||
onClose={() => setShowShare(false)}
|
||||
|
||||
Reference in New Issue
Block a user