Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ src/lib/server/analytics common.ts (CPUE, Fulton's K, recapture pairs…) · env
src/lib/server/astro.ts sunset/twilight/moon (local formulas) · tides.ts (extrema, interpolation)
src/lib/server/holidays.ts French Polynesia public holidays (Easter-based too) + festive window
src/lib/stats.ts regression, Spearman, Welch, Wilson, binomial, histograms, box stats
src/lib/components/ ChartCard, StatTile, DataTable, FindingCard, MooreaMap, charts/*
src/lib/components/ ChartCard, StatTile, DataTable, FindingCard, MooreaMap (SSR SVG),
InteractiveMap (Leaflet, lazy; MooreaMap is its fallback), charts/*
src/routes/ one folder per page (+page.server.ts computes, +page.svelte renders)
scripts/ fetch-external.mjs · make-fixture.mjs · server.mjs · nightlyRelease.mjs
external/ public environmental snapshots (committed)
Expand Down Expand Up @@ -117,7 +118,7 @@ REAL_DATA_DIR=data pnpm vitest run src/lib/server/import/realData.test.ts # op
## What not to do

- Don't edit, rename, re-save or "clean" the spreadsheets. Don't commit them, fixtures derived from them, or SQLite caches.
- Don't add a chart library or third-party scripts/fonts/tiles without updating the CSP in `vite.config.ts` and this file.
- Don't add a chart library or third-party scripts/fonts without updating the CSP in `vite.config.ts` and this file. Map tiles (Esri World Imagery, OpenStreetMap) are the only allowed external images (`img-src`); a new tile host needs the CSP, the e2e tile stub in `e2e/pages.spec.ts` and the attribution.
- Don't hard-code numbers in page copy; compute them in the load function.
- Don't claim causation from the correlations; don't overstate the human-pressure results (the source paper found no significant effect).
- Don't reintroduce dual-axis charts or per-point value labels.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ Read [AGENTS.md](AGENTS.md) before changing the importer, charts or release proc

## Credits

Survey data © the Physioshark project. Environmental data: Open-Meteo (CC BY 4.0, ERA5 © Copernicus/ECMWF), NOAA OISST v2.1, NOAA Coral Reef Watch (via PacIOOS), University of Hawaii Sea Level Center, NOAA Climate Prediction Center. Coastline © OpenStreetMap contributors (ODbL).
Survey data © the Physioshark project. Environmental data: Open-Meteo (CC BY 4.0, ERA5 © Copernicus/ECMWF), NOAA OISST v2.1, NOAA Coral Reef Watch (via PacIOOS), University of Hawaii Sea Level Center, NOAA Climate Prediction Center. Coastline and street map tiles © OpenStreetMap contributors (ODbL). Satellite imagery © Esri, Maxar, Earthstar Geographics.
11 changes: 11 additions & 0 deletions e2e/pages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ const ROUTES = [
'/nurseries/haapiti'
];

// Map tiles come from third-party hosts: serve a blank tile so tests don't depend on them.
const BLANK_PNG = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=',
'base64'
);
test.beforeEach(async ({ page }) => {
await page.route(/server\.arcgisonline\.com|tile\.openstreetmap\.org/, (route) =>
route.fulfill({ contentType: 'image/png', body: BLANK_PNG })
);
});

async function axe(page: Page) {
const result = await new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa']).analyze();
return result.violations.filter((v) => v.impact === 'serious' || v.impact === 'critical');
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
"@sveltejs/vite-plugin-svelte": "^7.3.1",
"@tailwindcss/vite": "^4.3.3",
"@types/better-sqlite3": "^9.6.0",
"@types/leaflet": "^1.9.22",
"@types/node": "^26.6.6",
"drizzle-kit": "^0.31.11",
"eslint": "^10.14.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-svelte": "^3.23.1",
"globals": "^17.13.0",
"leaflet": "^1.9.4",
"prettier": "^3.9.10",
"prettier-plugin-svelte": "^4.1.1",
"svelte": "^5.57.3",
Expand Down
23 changes: 23 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

213 changes: 213 additions & 0 deletions src/lib/components/InteractiveMap.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
<script lang="ts" module>
import type { MapPoint } from './MooreaMap.svelte';

export interface MapLayer {
name: string;
/** CSS colour, e.g. var(--series-1); applied through CSS so it follows the theme. */
color: string;
points: MapPoint[];
/** Size circles by `value` (area-proportional) or use a fixed radius. */
sized?: boolean;
/** Fixed radius in px when not sized (default 5). */
radius?: number;
}

/** Base maps (#29). Hosts must match img-src in vite.config.ts. */
const BASEMAPS = [
{
name: 'Satellite',
url: 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
attribution:
'Imagery © <a href="https://www.esri.com/">Esri</a>, Maxar, Earthstar Geographics',
maxZoom: 18
},
{
name: 'Map',
url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
attribution:
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
maxZoom: 19
}
];
</script>

<script lang="ts">
import 'leaflet/dist/leaflet.css';
import { onMount, tick } from 'svelte';
import MooreaMap from './MooreaMap.svelte';
import { registerCsv } from './charts/csv';

let {
layers,
label,
valueLabel = '',
format = (v: number) => String(Math.round(v)),
focus,
height = 440,
fallback
}: {
layers: MapLayer[];
/** Accessible name of the map region. */
label: string;
valueLabel?: string;
format?: (v: number) => string;
/** Open zoomed on this point instead of fitting all points. */
focus?: { lat: number; lon: number; zoom?: number };
height?: number;
/** Points for the server-rendered SVG map shown before Leaflet loads (default: first layer). */
fallback?: MapPoint[];
} = $props();

registerCsv(() => ({
columns: ['layer', 'name', 'lat', 'lon', valueLabel || 'value'],
rows: layers.flatMap((l) => l.points.map((p) => [l.name, p.label, p.lat, p.lon, p.value]))
}));

let el = $state<HTMLDivElement>();
let ready = $state(false);

function popup(p: MapPoint) {
const box = document.createElement('div');
const title = document.createElement(p.href ? 'a' : 'strong');
title.textContent = p.label;
if (p.href) (title as HTMLAnchorElement).href = p.href;
box.append(title);
for (const line of [
p.value != null && valueLabel ? `${valueLabel}: ${format(p.value)}` : null,
p.sub ?? null
]) {
if (!line) continue;
const div = document.createElement('div');
div.textContent = line;
box.append(div);
}
return box;
}

onMount(() => {
let map: import('leaflet').Map | undefined;
let cancelled = false;
(async () => {
const mod = await import('leaflet');
const L = (mod as unknown as { default?: typeof mod }).default ?? mod;
if (cancelled) return;
ready = true;
await tick();
if (!el || cancelled) return;
map = L.map(el, { scrollWheelZoom: false, zoomSnap: 0.5 });
const 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<string, import('leaflet').LayerGroup> = {};
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);
L.circleMarker([p.lat, p.lon], { radius: r, className: `ps-layer ps-layer-${i}` })
.bindTooltip(p.label)
.bindPopup(() => popup(p))
.addTo(group);
all.push([p.lat, p.lon]);
}
group.addTo(map!);
overlays[`<span class="ps-key ps-layer-${i}"></span>${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);
})();
return () => {
cancelled = true;
map?.remove();
};
});

const style = $derived(layers.map((l, i) => `--ps-layer-${i}: ${l.color}`).join('; '));
</script>

{#if ready}
<div
class="map"
bind:this={el}
role="region"
aria-label={label}
style={`${style}; height: ${height}px`}
></div>
<p class="hint">Drag to pan, use + / − to zoom. Select a circle for details.</p>
{:else}
<MooreaMap points={fallback ?? layers[0]?.points ?? []} {valueLabel} {format} csv={false} />
{/if}

<style>
.map {
width: 100%;
border-radius: 10px;
overflow: hidden;
border: 1px solid var(--hairline);
background: var(--surface-2);
font: inherit;
z-index: 0;
}
.hint {
margin: 6px 0 0;
font-size: 0.78rem;
color: var(--muted);
}
@media (max-width: 640px) {
.map {
height: 340px !important;
}
}
.map :global(.leaflet-interactive.ps-layer) {
stroke: #fff;
stroke-width: 1.5px;
fill-opacity: 0.85;
}
.map :global(.leaflet-control-layers) {
font: inherit;
font-size: 0.8rem;
color: #13213a;
}
.map :global(.ps-key) {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
margin: 0 6px 0 2px;
vertical-align: -1px;
}
.map :global(.leaflet-popup-content) {
font: inherit;
font-size: 0.85rem;
color: #13213a;
display: grid;
gap: 2px;
}
.map :global(.leaflet-popup-content a) {
font-weight: 650;
color: #1d5fb8;
}
.map :global(.ps-layer-0) {
fill: var(--ps-layer-0);
background: var(--ps-layer-0);
}
.map :global(.ps-layer-1) {
fill: var(--ps-layer-1);
background: var(--ps-layer-1);
}
.map :global(.ps-layer-2) {
fill: var(--ps-layer-2);
background: var(--ps-layer-2);
}
</style>
11 changes: 10 additions & 1 deletion src/lib/components/MooreaMap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,30 @@
<script lang="ts">
import outline from '#lib/moorea-outline.json';
import Tip, { type TipState } from './charts/Tip.svelte';
import { registerCsv } from './charts/csv';

let {
points,
valueLabel = '',
format = (v: number) => String(Math.round(v)),
showLabels = true,
maxR = 20
maxR = 20,
csv = true
}: {
points: MapPoint[];
valueLabel?: string;
format?: (v: number) => string;
showLabels?: boolean;
maxR?: number;
/** Offer the points as CSV to the enclosing ChartCard. */
csv?: boolean;
} = $props();

registerCsv(() => ({
columns: ['name', 'lat', 'lon', valueLabel || 'value'],
rows: csv ? points.map((p) => [p.label, p.lat, p.lon, p.value]) : []
}));

let width = $state(640);
const lat0 = -17.53;
const k = Math.cos((lat0 * Math.PI) / 180);
Expand Down
4 changes: 4 additions & 0 deletions src/routes/about/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
formulas.
</li>
<li><b>Coastline:</b> © OpenStreetMap contributors (ODbL), simplified.</li>
<li>
<b>Interactive maps:</b> street tiles © OpenStreetMap contributors; satellite imagery © Esri,
Maxar, Earthstar Geographics. Tiles load from those servers in your browser.
</li>
</ul>
<p class="small muted">
Last import {date(data.importedAt)}. Environmental data to {date(data.external.weather)} (weather),
Expand Down
Loading
Loading