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
@@ -1,63 +1,147 @@
|
||||
"use client";
|
||||
|
||||
import { X } from "lucide-react";
|
||||
import { X, PlayCircle } from "lucide-react";
|
||||
|
||||
interface Props {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
onStartTutorial?: () => void;
|
||||
}
|
||||
|
||||
export default function AboutModal({ isOpen, onClose }: Props) {
|
||||
function Section({ title, children }: { title: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<section className="space-y-1">
|
||||
<h3 className="font-semibold text-gray-900">{title}</h3>
|
||||
<div className="text-gray-700 space-y-1">{children}</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default function AboutModal({ isOpen, onClose, onStartTutorial }: Props) {
|
||||
if (!isOpen) return null;
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4" onClick={onClose}>
|
||||
<div
|
||||
className="bg-white rounded-lg shadow-xl max-w-lg w-full max-h-[85vh] overflow-y-auto"
|
||||
className="bg-white rounded-lg shadow-xl max-w-2xl w-full max-h-[88vh] overflow-y-auto"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="flex items-center justify-between p-4 border-b">
|
||||
<h2 className="text-lg font-semibold">Over Laadpalenviewer</h2>
|
||||
<div className="flex items-center justify-between p-4 border-b sticky top-0 bg-white z-10">
|
||||
<h2 className="text-lg font-semibold">Over Laadpalenviewer — uitleg & methodologie</h2>
|
||||
<button onClick={onClose} className="p-1 hover:bg-gray-100 rounded">
|
||||
<X className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="p-4 space-y-4 text-sm text-gray-700">
|
||||
<p>
|
||||
Laadpalenviewer toont laadpunten in Nederland op een interactieve kaart, opgesplitst in twee lagen:
|
||||
<strong> personenauto's</strong> en <strong>logistiek/vracht</strong> (zware voertuigen en
|
||||
megawatt charging).
|
||||
</p>
|
||||
<div>
|
||||
<h3 className="font-medium text-gray-900 mb-1">Databronnen</h3>
|
||||
<ul className="list-disc list-inside space-y-1">
|
||||
|
||||
<div className="p-4 space-y-4 text-sm">
|
||||
{onStartTutorial && (
|
||||
<button
|
||||
onClick={() => {
|
||||
onClose();
|
||||
onStartTutorial();
|
||||
}}
|
||||
className="flex items-center gap-2 px-3 py-2 text-sm font-medium text-blue-700 bg-blue-50 rounded-lg hover:bg-blue-100"
|
||||
>
|
||||
<PlayCircle className="h-4 w-4" /> Start de rondleiding
|
||||
</button>
|
||||
)}
|
||||
|
||||
<Section title="Wat toont deze app?">
|
||||
<p>
|
||||
Alle publiek toegankelijke laadpunten in Nederland in twee lagen — <strong>personenauto</strong> en
|
||||
<strong> logistiek/vracht</strong> — plus een analyse-laag per gemeente (vraag, plaatsing, bezetting,
|
||||
netimpact).
|
||||
</p>
|
||||
</Section>
|
||||
|
||||
<Section title="Databronnen">
|
||||
<ul className="space-y-1">
|
||||
<li>
|
||||
<strong>NDW DOT-NL (OCPI)</strong> — alle publiek toegankelijke laadpunten in Nederland.
|
||||
<strong>NDW DOT-NL (OCPI 2.2.1)</strong> — laadlocaties, connectoren, tarieven en status.
|
||||
Open data via opendata.ndw.nu.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Vracht/logistiek</strong> — classificatie van NDW-data op zeer hoog vermogen
|
||||
(DC ≥ 350 kW), megawatt/MCS-standaard en exploitant, aangevuld met bekende truckhubs
|
||||
(Milence, WattHub) en Open Charge Map. Reguliere snelladers (150–350 kW) voor
|
||||
personenauto's blijven in de personenauto-laag.
|
||||
<strong>NDW uurlijkse momentopname</strong> — wij downloaden de OCPI-export elk uur en leiden er
|
||||
bezetting/status-historie uit af.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Gemeente- en provinciegrenzen</strong> — PDOK CBS Gebiedsindelingen (WFS).
|
||||
<strong>CBS Kerncijfers wijken en buurten (85984NED)</strong> — inwoners, huishoudens, inkomen,
|
||||
stedelijkheid, autobezit. Licentie CC-BY 4.0 (© CBS).
|
||||
</li>
|
||||
<li>
|
||||
<strong>Adres zoeken</strong> — PDOK Locatieserver.
|
||||
<strong>PDOK CBS Gebiedsindelingen</strong> — gemeente- en provinciegrenzen. <strong>PDOK Locatieserver</strong> — adres zoeken.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Open Charge Map</strong> + handmatig samengestelde truck-hubs (Milence, WattHub) — extra
|
||||
vrachtlocaties.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-medium text-gray-900 mb-1">Detailniveau</h3>
|
||||
</Section>
|
||||
|
||||
<Section title="Personenauto vs. logistiek/vracht">
|
||||
<p>
|
||||
Op landelijk niveau worden alle laadpunten getoond zonder details (snel). Bij het kiezen van
|
||||
een gemeente worden alle details (laadpunten, connectoren, tarieven) direct geladen, zodat
|
||||
klikken op een marker meteen volledige informatie toont.
|
||||
Een laadpunt is <strong>vracht</strong> bij: een truck-exploitant (Milence/WattHub…), de MCS/megawatt-standaard,
|
||||
of een DC-connector ≥ 350 kW. Daardoor blijven gewone snelladers (150–350 kW) in de personenauto-laag.
|
||||
Megawatt-locaties (≥ 1 MW) krijgen een aparte kleur.
|
||||
</p>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">
|
||||
Classificatie en deduplicatie zijn heuristisch; controleer voor operationeel gebruik altijd de bron.
|
||||
</Section>
|
||||
|
||||
<Section title="Status & gebruik">
|
||||
<p>
|
||||
Markerkleuren tonen de OCPI-status (beschikbaar/bezet/niet beschikbaar/onbekend) uit de laatste
|
||||
uurlijkse snapshot. <strong>Bezetting</strong> = aandeel connectoren (EVSE's) met status “laden”. De
|
||||
grafiek “Gebruik over de tijd” bouwt deze bezetting per uur op (24u/7d/30d/1j).
|
||||
</p>
|
||||
</Section>
|
||||
|
||||
<Section title="Berekeningen (analyse-laag)">
|
||||
<ul className="space-y-1">
|
||||
<li>
|
||||
<strong>Verwachte vraag (peer-model)</strong> — een random-forest die het verwachte aantal
|
||||
laadpunten voorspelt uit demografie (inwoners, huishoudens, auto's, inkomen, stedelijkheid,
|
||||
adresdichtheid). Out-of-fold gevalideerd.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Tekort/overschot</strong> = werkelijk − verwacht. <strong>Plaatsingsprioriteit (0-100)</strong>{" "}
|
||||
combineert relatief + absoluut tekort en bezetting.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Belasting nu (live)</strong> = (EVSE's die nú laden, uit de snapshot) × ~11 kW.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Potentiële piek (planning)</strong> = (alle EVSE's) × ~11 kW × 30% gelijktijdigheid.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Congestie-index</strong> = relatieve percentielrang van de piekbelasting per inwoner.
|
||||
<strong> Netimpact-scenario</strong> herschaalt de piek met EV-groei en slim-laden.
|
||||
</li>
|
||||
</ul>
|
||||
</Section>
|
||||
|
||||
<Section title="Belangrijke nuances / beperkingen">
|
||||
<ul className="list-disc list-inside space-y-1 text-gray-600">
|
||||
<li>
|
||||
<strong>Vermogen wordt aangenomen</strong> (~11 kW/laadpunt): NDW publiceert <em>max_electric_power</em>
|
||||
voor ±90% van de connectoren niet. Absolute kW zijn dus schattingen.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Congestie is gemodelleerd</strong> — er is geen DSO-capaciteit ingelezen (de Capaciteitskaart
|
||||
is alleen een viewer). De index is relatief, geen knelpuntvoorspelling.
|
||||
</li>
|
||||
<li>
|
||||
<strong>EV-aantallen</strong> zijn nog niet per gemeente meegenomen (RDW heeft geen locatie; CBS-EV per
|
||||
regio volgt). Vraag is nu op autobezit/demografie gebaseerd.
|
||||
</li>
|
||||
<li>
|
||||
Analyse is op <strong>gemeente-niveau</strong> (buurt/PC4 volgt). “Laadpunten” = OCPI-locaties; één
|
||||
locatie kan meerdere sockets (EVSE's) hebben.
|
||||
</li>
|
||||
<li>NDW-dekking kan per gemeente verschillen (sommige CPO's ontbreken), wat aanbod kan onderschatten.</li>
|
||||
</ul>
|
||||
</Section>
|
||||
|
||||
<p className="text-xs text-gray-400 pt-2 border-t">
|
||||
Attributie: data © CBS (CC-BY 4.0), PDOK (CC0), NDW (open data), Open Charge Map. Voor operationeel
|
||||
gebruik altijd de bron raadplegen.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import type { Filters } from "@/types/charging";
|
||||
import { LEGEND } from "@/lib/colors";
|
||||
import InfoTip from "@/components/InfoTip";
|
||||
|
||||
interface FilterPanelProps {
|
||||
filters: Filters;
|
||||
@@ -16,8 +17,14 @@ export default function FilterPanel({ filters, onChange, passengerCount, freight
|
||||
const set = (patch: Partial<Filters>) => onChange({ ...filters, ...patch });
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-lg shadow-sm p-4 space-y-4">
|
||||
<h3 className="text-sm font-semibold text-gray-900">Kaartlagen</h3>
|
||||
<div className="bg-white rounded-lg shadow-sm p-4 space-y-4" data-tour="layers">
|
||||
<h3 className="text-sm font-semibold text-gray-900 flex items-center gap-1">
|
||||
Kaartlagen
|
||||
<InfoTip title="Kaartlagen">
|
||||
Zet de twee laadpunt-lagen (personenauto / vracht) en de gemeente-/provinciegrenzen aan of uit, en
|
||||
filter op minimaal laadvermogen. De tellingen rechts tonen het aantal in de huidige weergave.
|
||||
</InfoTip>
|
||||
</h3>
|
||||
|
||||
{/* Layer toggles */}
|
||||
<div className="space-y-2">
|
||||
@@ -64,7 +71,13 @@ export default function FilterPanel({ filters, onChange, passengerCount, freight
|
||||
{/* Power filter */}
|
||||
<div className="pt-2 border-t border-gray-100">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<span className="text-sm font-medium text-gray-700">Min. vermogen</span>
|
||||
<span className="text-sm font-medium text-gray-700 flex items-center gap-1">
|
||||
Min. vermogen
|
||||
<InfoTip title="Minimaal vermogen">
|
||||
Toon alleen laadpunten met een gerapporteerd maximaal connectorvermogen ≥ de gekozen kW. Let op:
|
||||
NDW publiceert voor veel AC-laders géén vermogen (telt als 0), dus een hoge drempel verbergt die.
|
||||
</InfoTip>
|
||||
</span>
|
||||
<span className="text-xs text-gray-500">
|
||||
{filters.minPowerKw === 0 ? "alle" : `≥ ${filters.minPowerKw} kW`}
|
||||
</span>
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { X, ArrowRight } from "lucide-react";
|
||||
import type { AreaProps } from "@/types/analysis";
|
||||
import InfoTip from "@/components/InfoTip";
|
||||
|
||||
interface Props {
|
||||
area: AreaProps | null;
|
||||
onClose: () => void;
|
||||
onOpenGemeente?: (slug: string) => void;
|
||||
}
|
||||
|
||||
const num = (v: unknown): number | null => (typeof v === "number" && Number.isFinite(v) ? v : null);
|
||||
const fmt = (v: number | null, d = 0) =>
|
||||
v === null ? "–" : v.toLocaleString("nl-NL", { minimumFractionDigits: d, maximumFractionDigits: d });
|
||||
|
||||
function Bar({ pct, color }: { pct: number | null; color: string }) {
|
||||
return (
|
||||
<div className="h-1.5 bg-gray-100 rounded overflow-hidden">
|
||||
<div className="h-full rounded" style={{ width: `${pct ?? 0}%`, background: color }} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Row({ label, value, pct, color = "#3b82f6" }: { label: string; value: string; pct?: number | null; color?: string }) {
|
||||
return (
|
||||
<div className="space-y-0.5">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-gray-600">{label}</span>
|
||||
<span className="font-medium text-gray-900">{value}</span>
|
||||
</div>
|
||||
{pct !== undefined && <Bar pct={pct} color={color} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function GemeenteScorecard({ area, onClose, onOpenGemeente }: Props) {
|
||||
const [growth, setGrowth] = useState(50); // % EV growth
|
||||
const [smart, setSmart] = useState(20); // % peak reduction via smart charging
|
||||
if (!area) return null;
|
||||
|
||||
const basePeak = num(area.est_peak_load_kw) ?? 0; // = potential peak (planning)
|
||||
const projected = basePeak * (1 + growth / 100) * (1 - smart / 100);
|
||||
const inw = num(area.inwoners) ?? 0;
|
||||
const projPer1000 = inw ? (projected / inw) * 1000 : null;
|
||||
const livePeak = num(area.live_peak_load_kw);
|
||||
const occNow = num(area.occupancy_now);
|
||||
const evse = num(area.evse_total);
|
||||
const chargingNow = num(area.charging_now);
|
||||
|
||||
const gap = num(area.supply_gap);
|
||||
const slug = typeof area.slug === "string" ? area.slug : null;
|
||||
|
||||
return (
|
||||
<div
|
||||
data-tour="scorecard"
|
||||
className="absolute top-4 right-14 w-96 max-w-[calc(100vw-5rem)] max-h-[calc(100%-2rem)] bg-white rounded-lg shadow-lg overflow-hidden flex flex-col z-10"
|
||||
>
|
||||
<div className="p-4 border-b bg-gray-50 flex justify-between items-start">
|
||||
<div>
|
||||
<h3 className="font-semibold text-lg">{area.gemeente}</h3>
|
||||
<p className="text-xs text-gray-500">Gemeente-scorecard (laadinfra)</p>
|
||||
</div>
|
||||
<button onClick={onClose} className="p-1 hover:bg-gray-200 rounded">
|
||||
<X className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="overflow-y-auto flex-1 p-4 space-y-4">
|
||||
{/* Aanbod */}
|
||||
<section className="space-y-2">
|
||||
<h4 className="text-sm font-medium text-gray-700">Aanbod</h4>
|
||||
<Row label="Laadlocaties (personen)" value={fmt(num(area.chargers_passenger))} />
|
||||
<Row label="Vracht-laadpunten" value={fmt(num(area.chargers_freight))} />
|
||||
{evse !== null && <Row label="Laadpunten (sockets/EVSEs)" value={fmt(evse)} />}
|
||||
<Row label="Per 1.000 inwoners" value={fmt(num(area.chargers_per_1000_inw), 1)} pct={num(area.supply_pct)} color="#22c55e" />
|
||||
<Row label="Gem. bezetting" value={num(area.avg_occupancy) === null ? "–" : `${fmt(num(area.avg_occupancy), 1)}%`} pct={num(area.occupancy_pct)} color="#3b82f6" />
|
||||
</section>
|
||||
|
||||
{/* Live load now */}
|
||||
{livePeak !== null && (
|
||||
<section className="space-y-1 pt-2 border-t border-gray-100">
|
||||
<h4 className="text-sm font-medium text-gray-700 flex items-center gap-1">
|
||||
Belasting nu (live)
|
||||
<InfoTip title="Belasting nu (live)">
|
||||
= aantal laadpunten dat op dit moment laadt (uit de uurlijkse OCPI-snapshot) × ~11 kW per
|
||||
laadpunt. Het vermogen is aangenomen omdat NDW het voor ±90% van de connectoren niet publiceert.
|
||||
Dit is een live momentopname, geen gemeten kW.
|
||||
</InfoTip>
|
||||
</h4>
|
||||
<div className="bg-green-50 rounded p-2">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-green-900">Geschatte belasting nu</span>
|
||||
<span className="font-semibold text-green-900">{fmt(livePeak)} kW</span>
|
||||
</div>
|
||||
<div className="text-xs text-green-700">
|
||||
{chargingNow !== null ? `${fmt(chargingNow)} laadpunten aan het laden` : ""}
|
||||
{occNow !== null ? ` · ${fmt(occNow, 1)}% bezet nu` : ""}
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-[10px] text-gray-400">
|
||||
Live uit OCPI-status (uurlijkse snapshot) × {`~11 kW per laadpunt`} — vermogen aangenomen,
|
||||
want NDW publiceert het voor ±90% van de connectoren niet.
|
||||
</p>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{/* Vraag & plaatsing */}
|
||||
<section className="space-y-2 pt-2 border-t border-gray-100">
|
||||
<h4 className="text-sm font-medium text-gray-700 flex items-center gap-1">
|
||||
Vraag & plaatsing
|
||||
<InfoTip title="Vraag & plaatsing (peer-model)">
|
||||
Een random-forest voorspelt het “verwachte” aantal laadpunten uit demografie (inwoners,
|
||||
huishoudens, auto's, inkomen, stedelijkheid, adresdichtheid). Werkelijk − verwacht =
|
||||
tekort/overschot; de plaatsingsprioriteit (0-100) weegt relatief + absoluut tekort en bezetting.
|
||||
</InfoTip>
|
||||
</h4>
|
||||
<Row label="Verwacht (peer-model)" value={fmt(num(area.expected_chargers))} />
|
||||
<Row
|
||||
label="Tekort / overschot"
|
||||
value={gap === null ? "–" : `${gap > 0 ? "+" : ""}${fmt(gap)}`}
|
||||
/>
|
||||
<div className={`text-xs rounded px-2 py-1 ${gap !== null && gap < 0 ? "bg-amber-50 text-amber-800" : "bg-green-50 text-green-800"}`}>
|
||||
{gap !== null && gap < 0
|
||||
? `Ondergemiddeld aanbod t.o.v. vergelijkbare gemeenten — plaatsingsprioriteit ${fmt(num(area.siting_priority))}/100.`
|
||||
: "Aanbod op of boven verwachting voor vergelijkbare gemeenten."}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Netimpact scenario */}
|
||||
<section className="space-y-2 pt-2 border-t border-gray-100">
|
||||
<h4 className="text-sm font-medium text-gray-700 flex items-center gap-1">
|
||||
Netimpact (scenario)
|
||||
<InfoTip title="Netimpact-scenario">
|
||||
Potentiële piek = alle laadpunten (EVSE's) × ~11 kW × 30% gelijktijdigheid. De schuiven
|
||||
herschalen dit met EV-groei (meer laden) en slim laden (piekreductie):
|
||||
piek × (1+groei) × (1−reductie). Gemodelleerd — er is geen netcapaciteit (DSO) ingelezen.
|
||||
</InfoTip>
|
||||
</h4>
|
||||
<Row label="Potentiële piek (planning)" value={`${fmt(basePeak)} kW`} />
|
||||
<div>
|
||||
<div className="flex justify-between text-xs text-gray-600">
|
||||
<span>EV-groei</span>
|
||||
<span>+{growth}%</span>
|
||||
</div>
|
||||
<input type="range" min={0} max={200} value={growth} onChange={(e) => setGrowth(+e.target.value)} className="w-full accent-blue-600" />
|
||||
</div>
|
||||
<div>
|
||||
<div className="flex justify-between text-xs text-gray-600">
|
||||
<span>Slim laden (piekreductie)</span>
|
||||
<span>−{smart}%</span>
|
||||
</div>
|
||||
<input type="range" min={0} max={50} value={smart} onChange={(e) => setSmart(+e.target.value)} className="w-full accent-green-600" />
|
||||
</div>
|
||||
<div className="bg-blue-50 rounded p-2 text-sm">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-blue-900">Projectie piekbelasting</span>
|
||||
<span className="font-semibold text-blue-900">{fmt(projected)} kW</span>
|
||||
</div>
|
||||
{projPer1000 !== null && (
|
||||
<div className="flex justify-between text-xs text-blue-700">
|
||||
<span>per 1.000 inwoners</span>
|
||||
<span>{fmt(projPer1000, 1)} kW</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-[10px] text-gray-400">
|
||||
Potentiële piek = alle laadpunten × ~11 kW × 30% gelijktijdigheid. Gemodelleerd
|
||||
(geen DSO-capaciteit ingelezen); congestie-index is relatief.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
{slug && onOpenGemeente && (
|
||||
<button
|
||||
onClick={() => onOpenGemeente(slug)}
|
||||
className="w-full flex items-center justify-center gap-1 px-3 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700"
|
||||
>
|
||||
Open {area.gemeente} op de kaart <ArrowRight className="h-4 w-4" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useCallback, useRef } from "react";
|
||||
import { X, ChevronLeft, ChevronRight } from "lucide-react";
|
||||
|
||||
export interface TourStep {
|
||||
title: string;
|
||||
body: React.ReactNode;
|
||||
target?: string; // data-tour selector to spotlight; omit for centered
|
||||
action?: () => void; // drives app state on entering the step
|
||||
pad?: number; // spotlight padding
|
||||
}
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
steps: TourStep[];
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
type Rect = { top: number; left: number; width: number; height: number };
|
||||
|
||||
const PAD = 8;
|
||||
|
||||
export default function GuidedTour({ open, steps, onClose }: Props) {
|
||||
const [idx, setIdx] = useState(0);
|
||||
const [rect, setRect] = useState<Rect | null>(null);
|
||||
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
|
||||
const step = steps[idx];
|
||||
|
||||
// Find + measure the target element (polling, since app state/data loads async).
|
||||
const locate = useCallback((selector?: string) => {
|
||||
if (pollRef.current) clearInterval(pollRef.current);
|
||||
if (!selector) {
|
||||
setRect(null);
|
||||
return;
|
||||
}
|
||||
let tries = 0;
|
||||
const tick = () => {
|
||||
const el = document.querySelector(selector) as HTMLElement | null;
|
||||
if (el) {
|
||||
const r = el.getBoundingClientRect();
|
||||
if (r.width > 0 && r.height > 0) {
|
||||
setRect({ top: r.top, left: r.left, width: r.width, height: r.height });
|
||||
if (pollRef.current) clearInterval(pollRef.current);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (++tries > 24) {
|
||||
setRect(null);
|
||||
if (pollRef.current) clearInterval(pollRef.current);
|
||||
}
|
||||
};
|
||||
tick();
|
||||
pollRef.current = setInterval(tick, 150);
|
||||
}, []);
|
||||
|
||||
// On entering a step: run its action, then locate the target.
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
step?.action?.();
|
||||
const t = setTimeout(() => locate(step?.target), 350);
|
||||
return () => clearTimeout(t);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [open, idx]);
|
||||
|
||||
// Keep the spotlight aligned on resize/scroll.
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const on = () => step?.target && locate(step.target);
|
||||
window.addEventListener("resize", on);
|
||||
window.addEventListener("scroll", on, true);
|
||||
return () => {
|
||||
window.removeEventListener("resize", on);
|
||||
window.removeEventListener("scroll", on, true);
|
||||
};
|
||||
}, [open, step, locate]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) setIdx(0);
|
||||
}, [open]);
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (!open) return;
|
||||
if (e.key === "Escape") onClose();
|
||||
if (e.key === "ArrowRight") setIdx((v) => Math.min(steps.length - 1, v + 1));
|
||||
if (e.key === "ArrowLeft") setIdx((v) => Math.max(0, v - 1));
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [open, steps.length, onClose]);
|
||||
|
||||
if (!open) return null;
|
||||
const last = idx === steps.length - 1;
|
||||
const pad = step?.pad ?? PAD;
|
||||
|
||||
// Spotlight hole geometry.
|
||||
const hole = rect
|
||||
? {
|
||||
top: Math.max(0, rect.top - pad),
|
||||
left: Math.max(0, rect.left - pad),
|
||||
width: rect.width + pad * 2,
|
||||
height: rect.height + pad * 2,
|
||||
}
|
||||
: null;
|
||||
|
||||
// Place the card near the hole (or centered).
|
||||
const vw = typeof window !== "undefined" ? window.innerWidth : 1280;
|
||||
const vh = typeof window !== "undefined" ? window.innerHeight : 800;
|
||||
const CARD_W = 340;
|
||||
let cardStyle: React.CSSProperties = {
|
||||
left: vw / 2 - CARD_W / 2,
|
||||
top: vh / 2 - 120,
|
||||
};
|
||||
if (hole) {
|
||||
const spaceRight = vw - (hole.left + hole.width);
|
||||
const spaceLeft = hole.left;
|
||||
let left: number;
|
||||
let top = Math.min(Math.max(12, hole.top), vh - 240);
|
||||
if (spaceRight > CARD_W + 24) left = hole.left + hole.width + 16;
|
||||
else if (spaceLeft > CARD_W + 24) left = hole.left - CARD_W - 16;
|
||||
else {
|
||||
// place below or above, centered horizontally over the hole
|
||||
left = Math.min(Math.max(12, hole.left + hole.width / 2 - CARD_W / 2), vw - CARD_W - 12);
|
||||
top = hole.top + hole.height + 16 < vh - 220 ? hole.top + hole.height + 16 : Math.max(12, hole.top - 230);
|
||||
}
|
||||
cardStyle = { left, top };
|
||||
}
|
||||
|
||||
// Four blurred panes around the hole (everything except the target is dimmed+blurred).
|
||||
const Pane = ({ s }: { s: React.CSSProperties }) => (
|
||||
<div className="fixed bg-slate-900/55 backdrop-blur-[3px] z-[140]" style={s} />
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
{hole ? (
|
||||
<>
|
||||
<Pane s={{ top: 0, left: 0, width: vw, height: hole.top }} />
|
||||
<Pane s={{ top: hole.top + hole.height, left: 0, width: vw, height: vh - (hole.top + hole.height) }} />
|
||||
<Pane s={{ top: hole.top, left: 0, width: hole.left, height: hole.height }} />
|
||||
<Pane s={{ top: hole.top, left: hole.left + hole.width, width: vw - (hole.left + hole.width), height: hole.height }} />
|
||||
<div
|
||||
className="fixed z-[142] rounded-lg ring-2 ring-blue-500 pointer-events-none"
|
||||
style={{ top: hole.top, left: hole.left, width: hole.width, height: hole.height }}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<div className="fixed inset-0 bg-slate-900/55 backdrop-blur-[3px] z-[140]" />
|
||||
)}
|
||||
|
||||
{/* Card */}
|
||||
<div
|
||||
className="fixed z-[150] bg-white rounded-xl shadow-2xl w-[340px] max-w-[calc(100vw-24px)]"
|
||||
style={cardStyle}
|
||||
>
|
||||
<div className="flex items-center justify-between px-4 py-2.5 border-b">
|
||||
<span className="text-xs font-medium text-gray-400">
|
||||
Rondleiding · {idx + 1}/{steps.length}
|
||||
</span>
|
||||
<button onClick={onClose} className="p-1 hover:bg-gray-100 rounded" aria-label="Sluiten">
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="p-4">
|
||||
<h2 className="text-base font-semibold mb-1.5">{step.title}</h2>
|
||||
<div className="text-sm text-gray-700 space-y-2">{step.body}</div>
|
||||
</div>
|
||||
<div className="flex items-center justify-between px-4 py-2.5 border-t bg-gray-50">
|
||||
<button
|
||||
onClick={() => setIdx((v) => Math.max(0, v - 1))}
|
||||
disabled={idx === 0}
|
||||
className="flex items-center gap-1 px-2.5 py-1.5 text-sm rounded-lg disabled:opacity-40 hover:bg-gray-200"
|
||||
>
|
||||
<ChevronLeft className="h-4 w-4" /> Vorige
|
||||
</button>
|
||||
<div className="flex gap-1">
|
||||
{steps.map((_, i) => (
|
||||
<span key={i} className={`w-1.5 h-1.5 rounded-full ${i === idx ? "bg-blue-600" : "bg-gray-300"}`} />
|
||||
))}
|
||||
</div>
|
||||
{last ? (
|
||||
<button onClick={onClose} className="px-3 py-1.5 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700">
|
||||
Klaar
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => setIdx((v) => Math.min(steps.length - 1, v + 1))}
|
||||
className="flex items-center gap-1 px-3 py-1.5 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700"
|
||||
>
|
||||
Volgende <ChevronRight className="h-4 w-4" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useRef, useLayoutEffect, useEffect, useCallback } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { Info } from "lucide-react";
|
||||
|
||||
interface Props {
|
||||
title?: string;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
// Small "?" info icon that shows a portal popover (so it never clips inside
|
||||
// scrollable panels). Opens on hover and on click (touch-friendly).
|
||||
export default function InfoTip({ title, children, className }: Props) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [pos, setPos] = useState<{ top: number; left: number } | null>(null);
|
||||
const btnRef = useRef<HTMLButtonElement>(null);
|
||||
const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
const WIDTH = 270;
|
||||
|
||||
const place = useCallback(() => {
|
||||
const r = btnRef.current?.getBoundingClientRect();
|
||||
if (!r) return;
|
||||
let left = r.left + r.width / 2 - WIDTH / 2;
|
||||
left = Math.max(8, Math.min(left, window.innerWidth - WIDTH - 8));
|
||||
setPos({ top: r.bottom + 6, left });
|
||||
}, []);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (open) place();
|
||||
}, [open, place]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKey = (e: KeyboardEvent) => e.key === "Escape" && setOpen(false);
|
||||
const onScroll = () => setOpen(false);
|
||||
window.addEventListener("keydown", onKey);
|
||||
window.addEventListener("scroll", onScroll, true);
|
||||
window.addEventListener("resize", onScroll);
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onKey);
|
||||
window.removeEventListener("scroll", onScroll, true);
|
||||
window.removeEventListener("resize", onScroll);
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
const show = () => {
|
||||
if (closeTimer.current) clearTimeout(closeTimer.current);
|
||||
setOpen(true);
|
||||
};
|
||||
const hide = () => {
|
||||
if (closeTimer.current) clearTimeout(closeTimer.current);
|
||||
closeTimer.current = setTimeout(() => setOpen(false), 120);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
ref={btnRef}
|
||||
type="button"
|
||||
aria-label={title || "Uitleg"}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setOpen((o) => !o);
|
||||
}}
|
||||
onMouseEnter={show}
|
||||
onMouseLeave={hide}
|
||||
className={`inline-flex items-center justify-center align-middle text-gray-400 hover:text-blue-600 ${className ?? ""}`}
|
||||
>
|
||||
<Info className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
{open &&
|
||||
pos &&
|
||||
createPortal(
|
||||
<div
|
||||
style={{ position: "fixed", top: pos.top, left: pos.left, width: WIDTH }}
|
||||
className="z-[200] bg-gray-900 text-white text-xs rounded-lg shadow-xl p-3 leading-relaxed"
|
||||
onMouseEnter={show}
|
||||
onMouseLeave={hide}
|
||||
>
|
||||
{title && <div className="font-semibold mb-1">{title}</div>}
|
||||
<div className="text-gray-200 space-y-1">{children}</div>
|
||||
</div>,
|
||||
document.body,
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import type { MetricMeta } from "@/types/analysis";
|
||||
import InfoTip from "@/components/InfoTip";
|
||||
|
||||
interface Props {
|
||||
metrics: MetricMeta[];
|
||||
active: string | null;
|
||||
onChange: (key: string | null) => void;
|
||||
}
|
||||
|
||||
export default function LayerSwitcher({ metrics, active, onChange }: Props) {
|
||||
const groups = useMemo(() => {
|
||||
const m = new Map<string, MetricMeta[]>();
|
||||
for (const metric of metrics) {
|
||||
const cat = metric.category ?? "Overig";
|
||||
if (!m.has(cat)) m.set(cat, []);
|
||||
m.get(cat)!.push(metric);
|
||||
}
|
||||
return [...m.entries()];
|
||||
}, [metrics]);
|
||||
|
||||
const activeMeta = metrics.find((m) => m.key === active);
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-lg shadow-sm p-4 space-y-2" data-tour="analyse">
|
||||
<h3 className="text-sm font-semibold text-gray-900 flex items-center gap-1">
|
||||
Analyse (per gemeente)
|
||||
<InfoTip title="Analyse-laag">
|
||||
Toont een indicator als kleurvlak (choropleth) over alle gemeenten. Donker = hoge waarde. Klik een
|
||||
gemeente voor de scorecard met onderliggende cijfers en berekeningen. Alleen beschikbaar in de
|
||||
“Nederland (totaal)”-weergave.
|
||||
</InfoTip>
|
||||
</h3>
|
||||
<p className="text-xs text-gray-500">Kies een indicator. Klik een gemeente voor de scorecard.</p>
|
||||
<select
|
||||
value={active ?? ""}
|
||||
onChange={(e) => onChange(e.target.value || null)}
|
||||
className="w-full text-sm border border-gray-300 rounded-lg px-2 py-2 bg-white"
|
||||
>
|
||||
<option value="">Geen (laadpunten tonen)</option>
|
||||
{groups.map(([cat, items]) => (
|
||||
<optgroup key={cat} label={cat}>
|
||||
{items.map((m) => (
|
||||
<option key={m.key} value={m.key}>
|
||||
{m.label}
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
))}
|
||||
</select>
|
||||
{activeMeta?.desc && (
|
||||
<p className="text-xs text-gray-600 bg-gray-50 rounded p-2 leading-relaxed">{activeMeta.desc}</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,22 +3,27 @@
|
||||
import { X, ExternalLink, Clock, Zap, MapPin, Building2, Truck } from "lucide-react";
|
||||
import type { ChargeFeature, EnrichedLocation } from "@/types/charging";
|
||||
import { formatConnectorStandard, formatPowerType, statusColorClass, statusLabel } from "@/lib/connectorLabels";
|
||||
import UsageChart from "@/components/UsageChart";
|
||||
|
||||
interface Props {
|
||||
selected: ChargeFeature | null;
|
||||
detail: EnrichedLocation | null;
|
||||
loading: boolean;
|
||||
slug?: string; // gemeente slug for usage history (undefined / 'nederland' = no chart)
|
||||
onClose: () => void;
|
||||
onJumpToGemeente?: () => void;
|
||||
}
|
||||
|
||||
export default function LocationDetailPanel({ selected, detail, loading, onClose, onJumpToGemeente }: Props) {
|
||||
export default function LocationDetailPanel({ selected, detail, loading, slug, onClose, onJumpToGemeente }: Props) {
|
||||
if (!selected) return null;
|
||||
const p = selected.properties;
|
||||
const isFreight = p.layer === "freight";
|
||||
|
||||
return (
|
||||
<div className="absolute top-4 right-14 w-96 max-w-[calc(100vw-5rem)] max-h-[calc(100%-2rem)] bg-white rounded-lg shadow-lg overflow-hidden flex flex-col z-10">
|
||||
<div
|
||||
data-tour="detail"
|
||||
className="absolute top-4 right-14 w-96 max-w-[calc(100vw-5rem)] max-h-[calc(100%-2rem)] bg-white rounded-lg shadow-lg overflow-hidden flex flex-col z-10"
|
||||
>
|
||||
<div className="p-4 border-b bg-gray-50 flex-shrink-0">
|
||||
<div className="flex justify-between items-start">
|
||||
<div className="flex-1 min-w-0">
|
||||
@@ -76,6 +81,9 @@ export default function LocationDetailPanel({ selected, detail, loading, onClose
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Usage over time (gemeente view only; per-gemeente snapshot history) */}
|
||||
{slug && slug !== "nederland" && <UsageChart slug={slug} locationId={p.locationId} />}
|
||||
|
||||
{loading && (
|
||||
<div className="text-sm text-gray-500 italic flex items-center gap-2">
|
||||
<span className="animate-spin h-4 w-4 border-2 border-gray-300 border-t-gray-600 rounded-full" />
|
||||
|
||||
@@ -7,7 +7,9 @@ import { ScatterplotLayer, GeoJsonLayer } from "@deck.gl/layers";
|
||||
import type { PickingInfo } from "@deck.gl/core";
|
||||
import "maplibre-gl/dist/maplibre-gl.css";
|
||||
import type { ChargeFeature, BoundaryFeature, Filters } from "@/types/charging";
|
||||
import type { ChoroplethData, MetricMeta } from "@/types/analysis";
|
||||
import { statusColor, freightColor, BOUNDARY_LINE, LEGEND, type RGBA } from "@/lib/colors";
|
||||
import { rampColor, rampCss, robustDomain, NODATA } from "@/lib/ramp";
|
||||
|
||||
interface MapDeckProps {
|
||||
chargeFeatures: ChargeFeature[];
|
||||
@@ -16,6 +18,17 @@ interface MapDeckProps {
|
||||
filters: Filters;
|
||||
selectedLocationId: string | null;
|
||||
onSelect: (feature: ChargeFeature | null) => void;
|
||||
choropleth?: ChoroplethData | null;
|
||||
analysisMetric?: string | null;
|
||||
metricMeta?: MetricMeta | null;
|
||||
onAreaSelect?: (props: Record<string, unknown>) => void;
|
||||
}
|
||||
|
||||
interface AreaHover {
|
||||
gemeente: string;
|
||||
value: number | null;
|
||||
lng: number;
|
||||
lat: number;
|
||||
}
|
||||
|
||||
const NL_BOUNDS: [[number, number], [number, number]] = [
|
||||
@@ -36,10 +49,29 @@ export default function MapDeck({
|
||||
filters,
|
||||
selectedLocationId,
|
||||
onSelect,
|
||||
choropleth,
|
||||
analysisMetric,
|
||||
metricMeta,
|
||||
onAreaSelect,
|
||||
}: MapDeckProps) {
|
||||
const mapRef = useRef<MapRef>(null);
|
||||
const [deckOverlay, setDeckOverlay] = useState<MapboxOverlay | null>(null);
|
||||
const [hovered, setHovered] = useState<ChargeFeature | null>(null);
|
||||
const [areaHover, setAreaHover] = useState<AreaHover | null>(null);
|
||||
|
||||
const choroActive = !!(choropleth && analysisMetric);
|
||||
const metricDomain = useMemo<[number, number] | null>(() => {
|
||||
if (!choroActive) return null;
|
||||
const vals = choropleth!.features
|
||||
.map((f) => f.properties[analysisMetric!])
|
||||
.filter((v): v is number => typeof v === "number");
|
||||
return robustDomain(vals);
|
||||
}, [choropleth, analysisMetric, choroActive]);
|
||||
|
||||
const fmt = (v: number) => {
|
||||
const d = metricMeta?.decimals ?? 1;
|
||||
return v.toLocaleString("nl-NL", { minimumFractionDigits: d, maximumFractionDigits: d });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const overlay = new MapboxOverlay({ interleaved: true, layers: [] });
|
||||
@@ -73,6 +105,46 @@ export default function MapDeck({
|
||||
const layers = useMemo(() => {
|
||||
const result: unknown[] = [];
|
||||
|
||||
// Choropleth (analysis) underneath everything else.
|
||||
if (choroActive && metricDomain) {
|
||||
const [lo, hi] = metricDomain;
|
||||
result.push(
|
||||
new GeoJsonLayer({
|
||||
id: "choropleth",
|
||||
data: choropleth as never,
|
||||
stroked: true,
|
||||
filled: true,
|
||||
getFillColor: (f: { properties: Record<string, unknown> }) => {
|
||||
const v = f.properties[analysisMetric!];
|
||||
if (typeof v !== "number") return NODATA as RGBA;
|
||||
return rampColor(hi > lo ? (v - lo) / (hi - lo) : 0.5);
|
||||
},
|
||||
getLineColor: [255, 255, 255, 180] as RGBA,
|
||||
lineWidthMinPixels: 0.5,
|
||||
pickable: true,
|
||||
onClick: (info: PickingInfo) => {
|
||||
const o = info.object as { properties?: Record<string, unknown> } | null;
|
||||
if (o?.properties && onAreaSelect) onAreaSelect(o.properties);
|
||||
},
|
||||
onHover: (info: PickingInfo) => {
|
||||
const o = info.object as { properties?: Record<string, unknown> } | null;
|
||||
if (o?.properties && info.coordinate) {
|
||||
const v = o.properties[analysisMetric!];
|
||||
setAreaHover({
|
||||
gemeente: String(o.properties.gemeente ?? ""),
|
||||
value: typeof v === "number" ? v : null,
|
||||
lng: info.coordinate[0],
|
||||
lat: info.coordinate[1],
|
||||
});
|
||||
} else {
|
||||
setAreaHover(null);
|
||||
}
|
||||
},
|
||||
updateTriggers: { getFillColor: [analysisMetric, lo, hi] },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (filters.showBoundary && boundaryFeatures.length) {
|
||||
result.push(
|
||||
new GeoJsonLayer({
|
||||
@@ -147,6 +219,11 @@ export default function MapDeck({
|
||||
selectedLocationId,
|
||||
handleHover,
|
||||
handleClick,
|
||||
choroActive,
|
||||
choropleth,
|
||||
analysisMetric,
|
||||
metricDomain,
|
||||
onAreaSelect,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -174,7 +251,7 @@ export default function MapDeck({
|
||||
|
||||
return (
|
||||
<div className="h-full w-full relative">
|
||||
<style>{cursorStyle(!!hovered)}</style>
|
||||
<style>{cursorStyle(!!hovered || !!areaHover)}</style>
|
||||
<Map
|
||||
ref={mapRef}
|
||||
initialViewState={{ longitude: 5.2913, latitude: 52.1326, zoom: 7 }}
|
||||
@@ -230,10 +307,52 @@ export default function MapDeck({
|
||||
</div>
|
||||
</Popup>
|
||||
)}
|
||||
|
||||
{/* Choropleth area hover */}
|
||||
{choroActive && areaHover && (
|
||||
<Popup
|
||||
longitude={areaHover.lng}
|
||||
latitude={areaHover.lat}
|
||||
closeButton={false}
|
||||
closeOnClick={false}
|
||||
anchor="bottom"
|
||||
offset={8}
|
||||
>
|
||||
<div className="p-2">
|
||||
<div className="font-semibold text-sm text-gray-900">{areaHover.gemeente}</div>
|
||||
<div className="text-xs text-gray-600">
|
||||
{metricMeta?.label}:{" "}
|
||||
<span className="font-medium">
|
||||
{areaHover.value === null ? "geen data" : `${fmt(areaHover.value)}${metricMeta?.unit ? " " + metricMeta.unit : ""}`}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Popup>
|
||||
)}
|
||||
</Map>
|
||||
|
||||
{/* Legend */}
|
||||
<div className="absolute bottom-4 left-4 bg-white/90 backdrop-blur-sm rounded-lg p-3 shadow-md text-xs">
|
||||
{/* Choropleth legend */}
|
||||
{choroActive && metricDomain && (
|
||||
<div className="absolute bottom-4 left-4 bg-white/90 backdrop-blur-sm rounded-lg p-3 shadow-md text-xs">
|
||||
<div className="font-semibold mb-1">{metricMeta?.label}</div>
|
||||
<div
|
||||
className="h-2 w-40 rounded"
|
||||
style={{ background: `linear-gradient(to right, ${rampCss(0)}, ${rampCss(0.25)}, ${rampCss(0.5)}, ${rampCss(0.75)}, ${rampCss(1)})` }}
|
||||
/>
|
||||
<div className="flex justify-between w-40 text-gray-500 mt-0.5">
|
||||
<span>{fmt(metricDomain[0])}</span>
|
||||
<span>{fmt(metricDomain[1])}{metricMeta?.unit ? ` ${metricMeta.unit}` : ""}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1 mt-1 text-gray-400">
|
||||
<span className="w-3 h-3 rounded-sm" style={{ background: "rgb(226,232,240)" }} />
|
||||
geen data
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Marker legend */}
|
||||
{!choroActive && (
|
||||
<div data-tour="legend" className="absolute bottom-4 left-4 bg-white/90 backdrop-blur-sm rounded-lg p-3 shadow-md text-xs">
|
||||
<div className="font-semibold mb-1">Personenauto (status)</div>
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -265,6 +384,7 @@ export default function MapDeck({
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { useMemo } from "react";
|
||||
import type { ChargeFeature } from "@/types/charging";
|
||||
import { LEGEND } from "@/lib/colors";
|
||||
import InfoTip from "@/components/InfoTip";
|
||||
|
||||
interface StatsPanelProps {
|
||||
gemeente: string;
|
||||
@@ -50,7 +51,14 @@ export default function StatsPanel({ gemeente, chargeFeatures }: StatsPanelProps
|
||||
<div className="text-xl font-bold text-amber-700 tabular-nums">
|
||||
{stats.freight.toLocaleString("nl-NL")}
|
||||
</div>
|
||||
<div className="text-xs text-amber-900">Logistiek / vracht</div>
|
||||
<div className="text-xs text-amber-900 flex items-center gap-1">
|
||||
Logistiek / vracht
|
||||
<InfoTip title="Logistiek / vracht">
|
||||
Laadpunten geclassificeerd als zware-voertuiglader: een truck-exploitant (Milence, WattHub…),
|
||||
de MCS/megawatt-standaard, of een DC-connector ≥ 350 kW. Gewone snelladers (150–350 kW) blijven
|
||||
personenauto.
|
||||
</InfoTip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -62,7 +70,13 @@ export default function StatsPanel({ gemeente, chargeFeatures }: StatsPanelProps
|
||||
|
||||
{/* OCPI status breakdown */}
|
||||
<div>
|
||||
<div className="text-xs font-medium text-gray-600 mb-1">Status (OCPI-momentopname)</div>
|
||||
<div className="text-xs font-medium text-gray-600 mb-1 flex items-center gap-1">
|
||||
Status (OCPI-momentopname)
|
||||
<InfoTip title="OCPI-status">
|
||||
Beschikbaar/bezet/niet-beschikbaar komt uit de OCPI-status in de laatste uurlijkse momentopname van
|
||||
de NDW-data — een snapshot, geen continue realtime stream. “Bezet” = connector aan het laden.
|
||||
</InfoTip>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-x-3 gap-y-1 text-xs">
|
||||
<StatusChip color={LEGEND.available} label="Beschikbaar" value={stats.available} />
|
||||
<StatusChip color={LEGEND.charging} label="Bezet" value={stats.charging} />
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import InfoTip from "@/components/InfoTip";
|
||||
|
||||
// Per-day snapshot file shape (data/snapshots/<slug>/<date>.json)
|
||||
interface DayFile {
|
||||
date: string;
|
||||
tz: string;
|
||||
locations: Record<string, { n: number; occ: (number | null)[] }>;
|
||||
}
|
||||
// Daily-averages file shape (data/snapshots/<slug>/daily.json)
|
||||
type DailyFile = Record<string, Record<string, number>>;
|
||||
|
||||
type Range = "24h" | "7d" | "30d" | "1y";
|
||||
const RANGES: { key: Range; label: string }[] = [
|
||||
{ key: "24h", label: "24u" },
|
||||
{ key: "7d", label: "7d" },
|
||||
{ key: "30d", label: "30d" },
|
||||
{ key: "1y", label: "1j" },
|
||||
];
|
||||
|
||||
interface Point {
|
||||
label: string; // x tooltip label
|
||||
short: string; // x-axis tick
|
||||
v: number | null; // occupancy %
|
||||
}
|
||||
|
||||
// Europe/Amsterdam local date (YYYY-MM-DD), `offset` days ago.
|
||||
function localDate(offsetDays: number): string {
|
||||
const d = new Date();
|
||||
d.setDate(d.getDate() - offsetDays);
|
||||
return new Intl.DateTimeFormat("en-CA", {
|
||||
timeZone: "Europe/Amsterdam",
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
}).format(d);
|
||||
}
|
||||
|
||||
async function getJson<T>(url: string): Promise<T | null> {
|
||||
try {
|
||||
const r = await fetch(url);
|
||||
return r.ok ? ((await r.json()) as T) : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export default function UsageChart({ slug, locationId }: { slug: string; locationId: string }) {
|
||||
const [range, setRange] = useState<Range>("24h");
|
||||
const [points, setPoints] = useState<Point[] | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [hover, setHover] = useState<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
setLoading(true);
|
||||
setPoints(null);
|
||||
setHover(null);
|
||||
|
||||
const build = async (): Promise<Point[]> => {
|
||||
if (range === "1y") {
|
||||
const daily = await getJson<DailyFile>(`/data/snapshots/${slug}/daily.json`);
|
||||
const series = daily?.[locationId] ?? {};
|
||||
const dates = Object.keys(series).sort();
|
||||
return dates.map((d) => ({ label: d, short: d.slice(5), v: series[d] }));
|
||||
}
|
||||
const days = range === "24h" ? 1 : range === "7d" ? 7 : 30;
|
||||
const dates: string[] = [];
|
||||
for (let i = days - 1; i >= 0; i--) dates.push(localDate(i));
|
||||
const files = await Promise.all(dates.map((d) => getJson<DayFile>(`/data/snapshots/${slug}/${d}.json`)));
|
||||
const out: Point[] = [];
|
||||
files.forEach((f, di) => {
|
||||
const occ = f?.locations?.[locationId]?.occ ?? Array(24).fill(null);
|
||||
for (let h = 0; h < 24; h++) {
|
||||
out.push({
|
||||
label: `${dates[di]} ${String(h).padStart(2, "0")}:00`,
|
||||
short: range === "24h" ? `${h}u` : h === 12 ? dates[di].slice(5) : "",
|
||||
v: occ[h] ?? null,
|
||||
});
|
||||
}
|
||||
});
|
||||
return out;
|
||||
};
|
||||
|
||||
build()
|
||||
.then((p) => {
|
||||
if (!cancelled) setPoints(p);
|
||||
})
|
||||
.finally(() => !cancelled && setLoading(false));
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [slug, locationId, range]);
|
||||
|
||||
const stats = useMemo(() => {
|
||||
if (!points) return null;
|
||||
const vals = points.map((p) => p.v).filter((v): v is number => v !== null);
|
||||
if (vals.length === 0) return { avg: null, hasData: false };
|
||||
return { avg: Math.round(vals.reduce((a, b) => a + b, 0) / vals.length), hasData: true };
|
||||
}, [points]);
|
||||
|
||||
// Build SVG polyline segments (break on nulls).
|
||||
const segments = useMemo(() => {
|
||||
if (!points || points.length === 0) return [];
|
||||
const n = points.length;
|
||||
const segs: string[] = [];
|
||||
let cur: string[] = [];
|
||||
points.forEach((p, i) => {
|
||||
if (p.v === null) {
|
||||
if (cur.length) segs.push(cur.join(" "));
|
||||
cur = [];
|
||||
return;
|
||||
}
|
||||
const x = n === 1 ? 50 : (i / (n - 1)) * 100;
|
||||
const y = 100 - Math.min(100, Math.max(0, p.v));
|
||||
cur.push(`${x.toFixed(2)},${y.toFixed(2)}`);
|
||||
});
|
||||
if (cur.length) segs.push(cur.join(" "));
|
||||
return segs;
|
||||
}, [points]);
|
||||
|
||||
return (
|
||||
<div className="space-y-2" data-tour="usage">
|
||||
<div className="flex items-center justify-between">
|
||||
<h4 className="font-medium text-sm text-gray-700 flex items-center gap-1">
|
||||
Gebruik over de tijd
|
||||
<InfoTip title="Gebruik over de tijd">
|
||||
Per uur: het aandeel connectoren van deze locatie met OCPI-status “laden” (% in gebruik). Opgebouwd
|
||||
uit de uurlijkse NDW-snapshots; 24u/7d/30d tonen uurwaarden, 1j toont daggemiddelden. De historie
|
||||
groeit naarmate de app langer draait.
|
||||
</InfoTip>
|
||||
</h4>
|
||||
<div className="flex gap-1">
|
||||
{RANGES.map((r) => (
|
||||
<button
|
||||
key={r.key}
|
||||
onClick={() => setRange(r.key)}
|
||||
className={`px-1.5 py-0.5 text-[11px] rounded ${
|
||||
range === r.key ? "bg-blue-600 text-white" : "bg-gray-100 text-gray-600 hover:bg-gray-200"
|
||||
}`}
|
||||
>
|
||||
{r.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div className="h-28 bg-gray-100 rounded animate-pulse" />
|
||||
) : !stats?.hasData ? (
|
||||
<p className="text-xs text-gray-400">Nog geen gebruiksdata voor deze locatie.</p>
|
||||
) : (
|
||||
<div className="bg-gray-50 rounded p-2">
|
||||
<div className="flex">
|
||||
<div className="flex flex-col justify-between h-28 pr-1 text-[9px] text-gray-400 text-right">
|
||||
<span>100%</span>
|
||||
<span>50%</span>
|
||||
<span>0%</span>
|
||||
</div>
|
||||
<div
|
||||
className="relative flex-1 h-28"
|
||||
onMouseLeave={() => setHover(null)}
|
||||
onMouseMove={(e) => {
|
||||
const rect = e.currentTarget.getBoundingClientRect();
|
||||
const ratio = (e.clientX - rect.left) / rect.width;
|
||||
const idx = Math.round(ratio * ((points?.length ?? 1) - 1));
|
||||
setHover(Math.max(0, Math.min((points?.length ?? 1) - 1, idx)));
|
||||
}}
|
||||
>
|
||||
{/* grid */}
|
||||
{[0, 50, 100].map((g) => (
|
||||
<div key={g} className="absolute left-0 right-0 border-t border-gray-200" style={{ top: `${g}%` }} />
|
||||
))}
|
||||
{/* average line */}
|
||||
{stats.avg !== null && (
|
||||
<div
|
||||
className="absolute left-0 right-0 border-t border-dashed border-blue-400/70"
|
||||
style={{ top: `${100 - stats.avg}%` }}
|
||||
>
|
||||
<span className="absolute right-0 -top-3 text-[9px] text-blue-500 bg-gray-50 px-0.5">
|
||||
gem. {stats.avg}%
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<svg className="absolute inset-0 w-full h-full" viewBox="0 0 100 100" preserveAspectRatio="none">
|
||||
{segments.map((pts, i) =>
|
||||
pts.includes(" ") ? (
|
||||
<polyline key={i} points={pts} fill="none" stroke="#2563eb" strokeWidth="1.2" vectorEffect="non-scaling-stroke" />
|
||||
) : (
|
||||
<circle key={i} cx={pts.split(",")[0]} cy={pts.split(",")[1]} r="1.5" fill="#2563eb" vectorEffect="non-scaling-stroke" />
|
||||
),
|
||||
)}
|
||||
</svg>
|
||||
{/* hover marker */}
|
||||
{hover !== null && points && points[hover]?.v !== null && (
|
||||
<div
|
||||
className="absolute z-10 -translate-x-1/2 -translate-y-full bg-gray-800 text-white text-[9px] px-1 py-0.5 rounded whitespace-nowrap pointer-events-none"
|
||||
style={{
|
||||
left: `${points.length === 1 ? 50 : (hover / (points.length - 1)) * 100}%`,
|
||||
top: `${100 - (points[hover].v as number)}%`,
|
||||
}}
|
||||
>
|
||||
{points[hover].label} — {points[hover].v}%
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{/* x-axis ticks */}
|
||||
<div className="flex justify-between mt-1 pl-6 text-[8px] text-gray-400">
|
||||
{points &&
|
||||
points
|
||||
.map((p, i) => ({ p, i }))
|
||||
.filter(({ p }) => p.short)
|
||||
.filter((_, idx, arr) => arr.length <= 12 || idx % Math.ceil(arr.length / 12) === 0)
|
||||
.map(({ p, i }) => <span key={i}>{p.short}</span>)}
|
||||
</div>
|
||||
<p className="text-[10px] text-gray-400 mt-1">% connectoren in gebruik (laden), OCPI-momentopname per uur.</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user