From 505b952973bffe6c43a6d4b9dc20e76432e8b84b Mon Sep 17 00:00:00 2001 From: luen Date: Wed, 11 Nov 2026 09:11:43 +1000 Subject: [PATCH 01/15] Charts: season slider on the nurseries map (#172) The map can step through the 13 seasons, or play them in turn, with circles on one catch-rate scale so frames are comparable. Nurseries not sampled with timed sets that season show as dashed rings. InteractiveMap now redraws its layers when they change, keeping the view and any layers the reader switched off. Co-Authored-By: Claude Opus 5.5 --- src/lib/components/InteractiveMap.svelte | 98 +++++++++++++------ src/routes/nurseries/+page.server.ts | 10 +- src/routes/nurseries/+page.svelte | 116 ++++++++++++++++++++--- 3 files changed, 181 insertions(+), 43 deletions(-) diff --git a/src/lib/components/InteractiveMap.svelte b/src/lib/components/InteractiveMap.svelte index 90177b6..2fdeb6f 100644 --- a/src/lib/components/InteractiveMap.svelte +++ b/src/lib/components/InteractiveMap.svelte @@ -10,6 +10,8 @@ sized?: boolean; /** Fixed radius in px when not sized (default 5). */ radius?: number; + /** Value that gets the largest circle; fix it to keep sizes comparable as points change. */ + max?: number; } /** Base maps (#29). Hosts must match img-src in vite.config.ts. */ @@ -84,8 +86,15 @@ return box; } + let map = $state.raw(); + let leaflet: typeof import('leaflet') | undefined; + let drawn: { + groups: import('leaflet').LayerGroup[]; + control: import('leaflet').Control.Layers; + }[] = []; + let bases: Record = {}; + onMount(() => { - let map: import('leaflet').Map | undefined; let cancelled = false; (async () => { const mod = await import('leaflet'); @@ -94,48 +103,28 @@ ready = true; await tick(); if (!el || cancelled) return; + leaflet = L; // Reduced motion (#32): jump instead of animating zooms and fades. const still = matchMedia('(prefers-reduced-motion: reduce)').matches; - map = L.map(el, { + const m = L.map(el, { scrollWheelZoom: false, zoomSnap: 0.5, zoomAnimation: !still, fadeAnimation: !still, markerZoomAnimation: !still }); - const bases = Object.fromEntries( + bases = Object.fromEntries( BASEMAPS.map((b) => [ b.name, L.tileLayer(b.url, { attribution: b.attribution, maxZoom: b.maxZoom }) ]) ); - bases[BASEMAPS[0].name].addTo(map); - const overlays: Record = {}; - const all: [number, number][] = []; - layers.forEach((layer, i) => { - const max = Math.max(1e-9, ...layer.points.map((p) => p.value ?? 0)); - const group = L.layerGroup(); - for (const p of layer.points) { - const r = layer.sized - ? 5 + 13 * Math.sqrt(Math.max(0, p.value ?? 0) / max) - : (layer.radius ?? 5); - const tooltip = document.createElement('span'); - tooltip.textContent = p.label; - L.circleMarker([p.lat, p.lon], { radius: r, className: `ps-layer ps-layer-${i}` }) - .bindTooltip(tooltip) - .bindPopup(() => popup(p)) - .addTo(group); - all.push([p.lat, p.lon]); - } - group.addTo(map!); - overlays[`${layer.name}`] = group; - }); - L.control - .layers(bases, layers.length > 1 ? overlays : {}, { collapsed: el.clientWidth < 560 }) - .addTo(map); - if (focus) map.setView([focus.lat, focus.lon], focus.zoom ?? 14); - else if (all.length) map.fitBounds(L.latLngBounds(all), { padding: [24, 24], maxZoom: 14 }); - else map.setView([-17.53, -149.83], 12); + bases[BASEMAPS[0].name].addTo(m); + const all = layers.flatMap((l) => l.points.map((p) => [p.lat, p.lon] as [number, number])); + if (focus) m.setView([focus.lat, focus.lon], focus.zoom ?? 14); + else if (all.length) m.fitBounds(L.latLngBounds(all), { padding: [24, 24], maxZoom: 14 }); + else m.setView([-17.53, -149.83], 12); + map = m; })(); return () => { cancelled = true; @@ -143,6 +132,50 @@ }; }); + // Redraw the overlays whenever the layers change (e.g. a season slider), keeping the view. + $effect(() => { + const m = map; + const L = leaflet; + const current = layers; + if (!m || !L || !el) return; + const hidden = new Set( + drawn.length + ? current.map((l, i) => (drawn[0].groups[i] && !m.hasLayer(drawn[0].groups[i]) ? i : -1)) + : [] + ); + for (const d of drawn) { + d.groups.forEach((g) => g.remove()); + d.control.remove(); + } + const overlays: Record = {}; + const groups = current.map((layer, i) => { + const max = layer.max ?? Math.max(1e-9, ...layer.points.map((p) => p.value ?? 0)); + const group = L.layerGroup(); + for (const p of layer.points) { + const empty = layer.sized && p.value == null; + const r = empty + ? 5 + : layer.sized + ? 5 + 13 * Math.sqrt(Math.min(1, Math.max(0, p.value ?? 0) / max)) + : (layer.radius ?? 5); + L.circleMarker([p.lat, p.lon], { + radius: r, + className: `ps-layer ps-layer-${i}${empty ? ' ps-empty' : ''}` + }) + .bindTooltip(p.label) + .bindPopup(() => popup(p)) + .addTo(group); + } + if (!hidden.has(i)) group.addTo(m); + overlays[`${layer.name}`] = group; + return group; + }); + const control = L.control + .layers(bases, current.length > 1 ? overlays : {}, { collapsed: el.clientWidth < 560 }) + .addTo(m); + drawn = [{ groups, control }]; + }); + const style = $derived(layers.map((l, i) => `--ps-layer-${i}: ${l.color}`).join('; ')); @@ -189,6 +222,11 @@ font-size: 0.8rem; color: #13213a; } + .map :global(.leaflet-interactive.ps-layer.ps-empty) { + fill: transparent; + stroke: var(--muted); + stroke-dasharray: 2 2; + } .map :global(.ps-key) { display: inline-block; width: 10px; diff --git a/src/routes/nurseries/+page.server.ts b/src/routes/nurseries/+page.server.ts index ab9b1c5..cf08636 100644 --- a/src/routes/nurseries/+page.server.ts +++ b/src/routes/nurseries/+page.server.ts @@ -53,6 +53,14 @@ export const load: PageServerLoad = () => round(cpueOf(eff.filter((s) => s.siteId === id && s.season === season))) ) ); + // Per-season counts for the map's season slider (#172). + const perSeason = ids.map((id) => + d.seasons.map((season) => ({ + sets: d.sets.filter((x) => x.siteId === id && x.season === season && x.gear === 'Gillnet') + .length, + captures: caps.filter((c) => c.siteId === id && c.season === season).length + })) + ); // Adult blacktips caught on hook and line, where the datasheet has both coordinates. const adults = d.adults .filter((a) => a.lat != null && a.lon != null && a.lon < 0) @@ -79,5 +87,5 @@ export const load: PageServerLoad = () => ) ) }; - return { rows, seasons: d.seasons, heat, adults, stats }; + return { rows, seasons: d.seasons, heat, perSeason, adults, stats }; }); diff --git a/src/routes/nurseries/+page.svelte b/src/routes/nurseries/+page.svelte index fe554fb..f4850bb 100644 --- a/src/routes/nurseries/+page.svelte +++ b/src/routes/nurseries/+page.svelte @@ -9,7 +9,57 @@ import type { PageProps } from './$types'; let { data }: PageProps = $props(); - const mapped = $derived(data.rows.filter((r) => r.lat != null && r.lon != null)); + + // Season slider (#172): the last stop shows every season pooled. + let idx = $state(Number.MAX_SAFE_INTEGER); + const all = $derived(data.seasons.length); + const at = $derived(Math.min(idx, all)); + const seasonLabel = $derived(at === all ? 'All seasons' : season(data.seasons[at])); + // One scale for every frame so circle sizes stay comparable between seasons. + const scaleMax = $derived( + Math.max(1e-9, ...data.heat.flat().map((v) => v ?? 0), ...data.rows.map((r) => r.cpue ?? 0)) + ); + const points = $derived( + data.rows.flatMap((r, i) => { + if (r.lat == null || r.lon == null) return []; + const s = at === all ? null : data.perSeason[i][at]; + const value = at === all ? r.cpue : data.heat[i][at]; + return [ + { + id: r.id, + label: r.name, + lat: r.lat, + lon: r.lon, + value, + href: r.href, + sub: s + ? value == null + ? s.sets + ? `${num(s.sets)} sets, none timed` + : 'Not sampled this season' + : `${num(s.captures)} captures, ${num(s.sets)} sets` + : `${num(r.captures)} captures, ${num(r.sets)} sets` + } + ]; + }) + ); + + let timer: ReturnType | undefined; + let playing = $state(false); + function stop() { + clearInterval(timer); + playing = false; + } + function play() { + if (playing) return stop(); + if (at >= all - 1) idx = 0; + playing = true; + timer = setInterval(() => { + if (idx >= all - 1) stop(); + else idx = Math.min(idx, all) + 1; + }, 1200); + } + $effect(() => stop);
@@ -26,26 +76,39 @@ +
+ + + { + stop(); + idx = Number(e.currentTarget.value); + }} + aria-valuetext={seasonLabel} + /> + {seasonLabel} +
num(v, 2)} layers={[ { - name: 'Nurseries', + name: at === all ? 'Nurseries' : `Nurseries, ${seasonLabel}`, color: 'var(--series-1)', sized: true, - points: mapped.map((r) => ({ - id: r.id, - label: r.name, - lat: r.lat!, - lon: r.lon!, - value: r.cpue, - href: r.href, - sub: `${num(r.captures)} captures, ${num(r.sets)} sets` - })) + max: scaleMax, + points }, ...(data.adults.length ? [{ name: 'Adult blacktip captures', color: 'var(--series-4)', points: data.adults }] @@ -138,3 +201,32 @@

+ + From 02a15dc6555fea54baa5eea94601433f4887a768 Mon Sep 17 00:00:00 2001 From: luen Date: Wed, 11 Nov 2026 09:16:47 +1000 Subject: [PATCH 02/15] Charts: map shark moves between nurseries (#173) /recaptures gets a map with one line per nursery pair and species (width = moves, both directions pooled) over circles sized by same-nursery recaptures; sharks with identity conflicts are left out. Each shark's page joins consecutive captures at different nurseries and lists capture numbers per site. Copy says the lines join capture sites, not the route swum. InteractiveMap gains toggleable line layers and MooreaMap draws lines in the server-rendered fallback; both offer them as CSV. Co-Authored-By: Claude Opus 5.5 --- src/lib/components/InteractiveMap.svelte | 107 +++++++++++++++++++---- src/lib/components/MooreaMap.svelte | 52 +++++++++++ src/routes/recaptures/+page.server.ts | 58 ++++++++++++ src/routes/recaptures/+page.svelte | 30 +++++++ src/routes/sharks/[id]/+page.server.ts | 20 ++++- src/routes/sharks/[id]/+page.svelte | 14 ++- 6 files changed, 262 insertions(+), 19 deletions(-) diff --git a/src/lib/components/InteractiveMap.svelte b/src/lib/components/InteractiveMap.svelte index 2fdeb6f..78aca48 100644 --- a/src/lib/components/InteractiveMap.svelte +++ b/src/lib/components/InteractiveMap.svelte @@ -1,5 +1,12 @@ {#if ready} @@ -189,7 +241,14 @@ >

Drag to pan, use + / − to zoom. Select a circle for details.

{:else} - + g.lines.map((l) => ({ ...l, color: g.color })))} + {lineLabel} + {valueLabel} + {format} + csv={false} + /> {/if}