Files
cable-latency-survey/penguins/template.html
T

469 lines
34 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>The Penguin Test</title>
<meta name="description" content="{{N_TRACKS}} satellite-tracked penguins on the globe and three flat maps. No track needs more than a penguin's speed on the globe; on the North-pole AE map {{AE_BEYOND}} of {{N_TESTED}} do.">
<meta property="og:type" content="website">
<meta property="og:title" content="The Penguin Test">
<meta property="og:description" content="{{N_TRACKS}} tracked penguins drawn to scale on four maps. On the globe every track fits a penguin's speed; on the North-pole AE map {{AE_BEYOND}} of {{N_TESTED}} need more.">
<meta property="og:url" content="https://penguins.aethercosmology.com/">
<meta property="og:image" content="https://penguins.aethercosmology.com/og.png">
<meta name="twitter:card" content="summary_large_image">
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='13' fill='%23081120' stroke='%233ee6ff' stroke-width='2'/%3E%3Cpath d='M7 20c4-6 9-9 18-8' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round'/%3E%3Ccircle cx='25' cy='12' r='2.6' fill='%23ff4d5e'/%3E%3C/svg%3E">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap">
<style>
/* Layout: four synchronised map panels in a row on wide screens (2 / 1 columns below), readouts under each; text in a ~74ch column above and below. Same system as The Sync Test. */
:root{
--bg:#02050c; --panel:#07101e; --panel2:#0b182b; --line:rgba(120,180,255,.14); --line2:rgba(120,180,255,.28);
--ink:#e8f0fb; --dim:#9badc6; --faint:#65789a;
--track:#3ee6ff; --ok:#3dffa0; --warn:#ffc94a; --bad:#ff4d5e;
--disp:"Space Grotesk","Inter",system-ui,sans-serif;
--sans:"Inter",system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
--mono:"JetBrains Mono",ui-monospace,Menlo,Consolas,monospace;
color-scheme:dark;
}
*{box-sizing:border-box}
html{background:var(--bg)}
body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.6 var(--sans);-webkit-font-smoothing:antialiased;
padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}
body::before{content:"";position:fixed;inset:0 0 auto;height:env(safe-area-inset-top,0px);z-index:20;background:var(--bg)}
a{color:var(--track);text-decoration-color:rgba(62,230,255,.35);text-underline-offset:2px}
a:hover{text-decoration-color:var(--track)}
:focus-visible{outline:2px solid var(--track);outline-offset:2px}
.wrap{max-width:1720px;margin:0 auto;padding-left:max(16px,env(safe-area-inset-left,0px));padding-right:max(16px,env(safe-area-inset-right,0px))}
.top{padding-block:28px 6px}
h1{font:700 clamp(28px,3.2vw,40px)/1.1 var(--disp);margin:0;letter-spacing:-.01em;text-wrap:balance}
.sub{margin:6px 0 0;color:var(--dim);font-size:15px}
.intro{display:grid;gap:10px 40px;padding-block:14px 18px}
@media (min-width:1100px){.intro{grid-template-columns:repeat(3,minmax(0,52ch))}}
.intro p{margin:0;max-width:74ch;color:var(--ink)}
.intro b{font-family:var(--disp);font-weight:600;color:var(--dim);letter-spacing:.01em}
.k-tr{color:var(--track);font-weight:600}.k-bad{color:var(--bad);font-weight:600}
.bar{position:sticky;top:env(safe-area-inset-top,0px);z-index:10;background:rgba(2,5,12,.9);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);border-block:1px solid var(--line)}
.barin{display:flex;flex-wrap:wrap;align-items:center;gap:10px 14px;padding-block:9px}
.row2{padding-block:0 9px;gap:8px 22px}
.rowlab{font:500 10.5px var(--sans);letter-spacing:.07em;text-transform:uppercase;color:var(--faint)}
@media (max-width:620px){.bar{position:static}}
button,select{font:inherit;color:inherit}
#grp{min-width:0;max-width:100%;flex:0 1 430px;background:var(--panel2);border:1px solid var(--line2);border-radius:8px;padding:6px 10px;font:500 13px var(--sans);color:var(--ink)}
#play{width:38px;height:34px;border-radius:8px;border:1px solid var(--line2);background:var(--panel2);cursor:pointer;display:grid;place-items:center;flex:none}
#play svg{width:14px;height:14px;fill:var(--ink)}
.seg{display:flex;border:1px solid var(--line2);border-radius:8px;overflow:hidden}
.seg button{border:0;background:transparent;padding:6px 10px;font:500 12.5px var(--sans);color:var(--dim);cursor:pointer}
.seg.mono button{font-family:var(--mono)}
.seg button+button{border-left:1px solid var(--line)}
.seg button[aria-pressed="true"]{background:var(--panel2);color:var(--ink)}
#day{flex:1 1 200px;min-width:140px;accent-color:var(--track)}
.clock{display:flex;gap:12px;font:500 13px var(--mono);color:var(--dim);font-variant-numeric:tabular-nums;white-space:nowrap}
.clock b{color:var(--ink);font-weight:500}
.lim{display:flex;align-items:center;gap:8px;font-size:12.5px;color:var(--dim)}
#lim{width:140px;accent-color:var(--bad)}
#limv{font:500 12.5px var(--mono);color:var(--ink);min-width:6.5em}
.legend{display:flex;flex-wrap:wrap;gap:6px 18px;padding-block:12px 0;margin-block:0;list-style:none;color:var(--dim);font-size:13px}
.legend li{display:flex;align-items:center;gap:7px}
.legend svg{width:22px;height:14px;flex:none}
.grid{display:grid;gap:12px;grid-template-columns:repeat(4,minmax(0,1fr));padding-block:12px 8px}
@media (max-width:1199px){.grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media (max-width:620px){.grid{grid-template-columns:minmax(0,1fr)}}
.panel{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:10px 10px 8px;display:flex;flex-direction:column;gap:8px;min-width:0}
.ph{display:flex;align-items:baseline;justify-content:space-between;gap:10px;min-width:0}
.ph h2{font:600 16px/1.2 var(--disp);margin:0}
.ph p{margin:0;color:var(--faint);font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.map{position:relative;aspect-ratio:1;width:100%;max-width:100%}
.map canvas{position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:pan-y}
.ro{display:grid;grid-template-columns:1fr 1fr;gap:6px 10px;margin:0}
.ro div{min-width:0}
.ro .w{grid-column:1/-1}
.ro .w dd{white-space:normal;overflow:visible}
.ro dt{font:500 10.5px/1.3 var(--sans);letter-spacing:.07em;text-transform:uppercase;color:var(--faint)}
.ro dd{margin:1px 0 0;font:500 13px/1.35 var(--mono);font-variant-numeric:tabular-nums;color:var(--ink);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.pill{display:inline-block;margin-left:6px;padding:0 6px;border-radius:999px;font-size:11.5px;line-height:18px;border:1px solid currentColor}
.pill.ok{color:var(--ok)}.pill.bad{color:var(--bad)}
.after{padding-block:22px 10px;display:grid;gap:10px}
.after h2{font:600 19px/1.25 var(--disp);margin:14px 0 2px}
.after p b{color:var(--ink);font-weight:600}
.after p{margin:0;max-width:74ch;color:var(--dim)}
.tw{overflow:auto;border:1px solid var(--line);border-radius:10px;max-width:1180px}
.tw.scroll{max-height:420px}
table{border-collapse:collapse;width:100%;min-width:640px;font-size:13.5px}
th,td{padding:7px 12px;text-align:right;border-bottom:1px solid var(--line);white-space:nowrap}
tr:last-child td,tr:last-child th{border-bottom:0}
thead th{font:600 12.5px var(--disp);color:var(--dim);background:var(--panel);position:sticky;top:0;z-index:1}
tbody th{text-align:left;font-weight:500;color:var(--dim)}
td{font-family:var(--mono);font-variant-numeric:tabular-nums;color:var(--ink)}
td.bad{color:var(--bad)}td.na{color:var(--faint)}
td.l{text-align:left;font-family:var(--sans)}
.method{display:grid;grid-template-columns:max-content minmax(0,74ch);gap:8px 20px;margin:0;color:var(--dim)}
.method dt{font:600 13.5px var(--disp);color:var(--ink);padding-top:1px}
.method dd{margin:0}
@media (max-width:620px){.method{grid-template-columns:minmax(0,1fr);gap:2px}.method dd{margin-bottom:10px}}
.refs{margin:0;padding-left:1.2em;color:var(--dim);max-width:92ch;display:grid;gap:4px}
#dl{justify-self:start;border:1px solid var(--line2);background:var(--panel2);border-radius:8px;padding:7px 14px;cursor:pointer;font-size:13.5px}
footer{padding-block:18px 30px;color:var(--faint);font-size:13px}
#tip{position:fixed;z-index:30;pointer-events:none;background:rgba(6,12,24,.96);border:1px solid var(--line2);border-radius:8px;padding:6px 9px;font-size:12.5px;line-height:1.4;max-width:270px}
#tip b{font-weight:600}
#tip span{display:block;color:var(--dim)}
@media (prefers-reduced-motion:reduce){*{scroll-behavior:auto}}
</style>
</head>
<body>
<header class="wrap top">
<h1>The Penguin Test</h1>
<p class="sub">{{N_TRACKS}} tracked penguins on the globe and three flat maps</p>
</header>
<section class="wrap intro">
<p><b>Data.</b> {{N_TRACKS}} penguins of {{N_SPECIES}} species tracked from {{N_COLONIES}} colonies around Antarctica and the sub-Antarctic islands, {{Y0}}–{{Y1}}: {{N_FIXES}} positions from satellite tags and GPS loggers, compiled by SCAR's Retrospective Analysis of Antarctic Tracking Data. The first selection is the emperor colony at Pointe Géologie, Terre Adélie, where <i>March of the Penguins</i> was filmed, tracked in 2005.</p>
<p><b>Test.</b> Each track is drawn to scale on every map and measured there. In {{WINDOW}} days a penguin can travel no farther than {{V_SWIM}} m/s of swimming, the fastest mean speed measured in any penguin species, plus {{V_CURRENT}} m/s of current, about twice the strongest jets of the Antarctic Circumpolar Current, with no time spent diving or resting, plus {{ERR}} km for position error: {{LIMIT}} km/h. A track turns <span class="k-bad">red</span> on a map where some {{WINDOW}}-day stretch needs more.</p>
<p><b>Positions.</b> The positions are those computed by the tags' location systems, Argos and GPS, which work on a globe. The test asks whether the same positions, drawn to scale on each map, describe journeys a penguin can make.</p>
</section>
<div class="bar">
<div class="wrap barin">
<label class="rowlab" for="grp">Colony</label>
<select id="grp" aria-label="Colony and season"></select>
<button id="play" type="button" aria-label="Play"><svg viewBox="0 0 14 14" aria-hidden="true"><path id="playicon" d="M3 1.5v11l9-5.5z"/></svg></button>
<div class="seg mono" role="group" aria-label="Playback speed" id="rates">
<button type="button" data-rate="1" aria-pressed="false">1 d/s</button>
<button type="button" data-rate="4" aria-pressed="true">4 d/s</button>
<button type="button" data-rate="15" aria-pressed="false">15 d/s</button>
</div>
<input id="day" type="range" min="0" max="1" step="0.05" value="1" aria-label="Days since tagging">
<div class="clock"><b id="clock">—</b><span id="span">—</span></div>
</div>
<div class="wrap barin row2">
<span class="rowlab">View</span>
<div class="seg" role="group" aria-label="View" id="view">
<button type="button" data-v="fit" aria-pressed="true">Tracks</button>
<button type="button" data-v="all" aria-pressed="false">Whole map</button>
</div>
<label class="lim" for="lim"><span class="rowlab">Speed limit</span><input id="lim" type="range" min="6" max="24" step="0.1" value="{{LIMIT}}"><output id="limv">{{LIMIT}} km/h</output></label>
</div>
</div>
<ul class="wrap legend">
<li><svg viewBox="0 0 22 14" aria-hidden="true"><path d="M1 7h20" stroke="#3ee6ff" stroke-width="1.6"/></svg>Track within the speed limit on that map</li>
<li><svg viewBox="0 0 22 14" aria-hidden="true"><path d="M1 7h20" stroke="#ff4d5e" stroke-width="1.6"/></svg>Track beyond it</li>
<li><svg viewBox="0 0 22 14" aria-hidden="true"><path d="M1 7h20" stroke="#ff4d5e" stroke-width="3.6"/></svg>Its fastest {{WINDOW}}-day stretch</li>
<li><svg viewBox="0 0 22 14" aria-hidden="true"><circle cx="11" cy="7" r="3.2" fill="#fff"/></svg>Penguin on the day shown</li>
<li><svg viewBox="0 0 22 14" aria-hidden="true"><circle cx="11" cy="7" r="4.5" fill="none" stroke="#ffc94a" stroke-width="1.6"/></svg>Colony</li>
</ul>
<main class="wrap grid">
<article class="panel" data-key="globe">
<header class="ph"><h2>Globe</h2><p>Sphere, radius 6,371 km</p></header>
<div class="map"><canvas aria-label="Globe: penguin tracks"></canvas></div>
<dl class="ro">
<div><dt>Track length, median</dt><dd data-f="len">—</dd></div>
<div><dt>Beyond the limit</dt><dd data-f="n">—</dd></div>
<div class="w"><dt>Fastest {{WINDOW}}-day stretch</dt><dd data-f="v">—</dd></div>
</dl>
</article>
<article class="panel" data-key="ae">
<header class="ph"><h2>North-pole AE</h2><p>Centered on the North Pole</p></header>
<div class="map"><canvas aria-label="North-pole AE map: penguin tracks"></canvas></div>
<dl class="ro">
<div><dt>Track length, median</dt><dd data-f="len">—</dd></div>
<div><dt>Beyond the limit</dt><dd data-f="n">—</dd></div>
<div class="w"><dt>Fastest {{WINDOW}}-day stretch</dt><dd data-f="v">—</dd></div>
</dl>
</article>
<article class="panel" data-key="dualpole">
<header class="ph"><h2>Dual-pole AE</h2><p>Centered on 0°N 0°E</p></header>
<div class="map"><canvas aria-label="Dual-pole AE map: penguin tracks"></canvas></div>
<dl class="ro">
<div><dt>Track length, median</dt><dd data-f="len">—</dd></div>
<div><dt>Beyond the limit</dt><dd data-f="n">—</dd></div>
<div class="w"><dt>Fastest {{WINDOW}}-day stretch</dt><dd data-f="v">—</dd></div>
</dl>
</article>
<article class="panel" data-key="mercator">
<header class="ph"><h2>Mercator</h2><p>True on the equator, edges joined</p></header>
<div class="map"><canvas aria-label="Mercator map: penguin tracks"></canvas></div>
<dl class="ro">
<div><dt>Track length, median</dt><dd data-f="len">—</dd></div>
<div><dt>Beyond the limit</dt><dd data-f="n">—</dd></div>
<div class="w"><dt>Fastest {{WINDOW}}-day stretch</dt><dd data-f="v">—</dd></div>
</dl>
</article>
</main>
<section class="wrap after">
<h2 id="seltitle">Selected penguins</h2>
<div class="tw scroll"><table id="animals"><thead></thead><tbody></tbody></table></div>
<h2>Result</h2>
<p>Of the {{N_TESTED}} tracks long enough to contain a {{WINDOW}}-day stretch, <b>none needs more than {{LIMIT}} km/h on the globe</b>. On the North-pole AE map <b>{{AE_BEYOND}} ({{AE_PCT}}) do</b>, on Mercator {{ME_BEYOND}} and on the dual-pole AE map {{DP_BEYOND}}. At Pointe Géologie, {{FILM_AE}} of the {{FILM_N}} emperors tagged in 2005 need more than the limit on the North-pole map and {{FILM_G}} on the globe.</p>
<p>The North-pole map keeps north–south distances true and stretches east–west ones more the farther they lie from its center: by a factor of about 7 at the latitude of the Antarctic coast. A median track is {{RATIO_AE}} times as long there as on the globe. Mercator stretches distances by the secant of the latitude, 2.5 at 66°S. The dual-pole map, centered on the equator, stretches the far south by up to about 2 in one direction, and these tracks alone do not rule it out. The flight times in <a href="https://fe-map.aethercosmology.com/">The Best Flat Map</a> rule out every flat map, this one included.</p>
<div class="tw"><table id="species"><thead></thead><tbody></tbody></table></div>
<h2>Method</h2>
<dl class="method">
<dt>Data</dt><dd>SCAR Retrospective Analysis of Antarctic Tracking Data, standardized tracking data version 1.5: penguin species only ({{N_TRACKS}} tracks: {{DEVICES}}). Each track is one tagged bird, from the capture record to its last position.</dd>
<dt>Positions</dt><dd>As published. Argos positions are computed from the Doppler shift of the tag's transmissions as recorded by polar-orbiting satellites; GPS positions from satellite ranging; both are expressed as latitude and longitude on the WGS 84 ellipsoid. No position is filtered on speed or on any map.</dd>
<dt>Daily positions</dt><dd>One per UTC day: the median time, latitude and longitude of that day's fixes ({{N_DAYS}} daily positions in all), to damp the error of single Argos fixes. Longitudes are unwrapped around the day's first fix before the median.</dd>
<dt>Lengths</dt><dd>On each map, the sum of straight steps between consecutive daily positions: great-circle steps on the globe, straight lines across the plane on the flat maps.</dd>
<dt>Stretches</dt><dd>Every pair of daily positions {{WINDOW}} days apart, with the elapsed time taken from their median times (at least {{MIN_H}} h). The speed a stretch needs is its distance on the map, less {{ERR}} km for position error at its two ends, divided by the elapsed time. A track is beyond the limit on a map if any of its stretches needs more than the limit there; tracks shorter than {{WINDOW}} days are drawn but not tested.</dd>
<dt>Limit</dt><dd>{{LIMIT}} km/h: {{V_SWIM}} m/s, the highest mean swimming speed measured with speed loggers in any penguin species (gentoo and chinstrap penguins; emperor 1.7, Adélie 2.0, king 2.1 m/s), plus {{V_CURRENT}} m/s of current flowing with the bird for the whole stretch. Surface currents in the Antarctic Circumpolar Current are typically about 0.1 m/s and reach 0.5–0.6 m/s in its frontal jets. Each term favors the flat maps; the bird is also assumed to swim without diving, resting or walking. The slider above changes the limit.</dd>
<dt>Maps</dt><dd>As in the <a href="https://pingstats.aethercosmology.com">Cable Latency Survey</a> and <a href="https://iss-spoofing.aethercosmology.com">The Sync Test</a>: the North-pole and dual-pole maps are azimuthal equidistant, true in distance from their centers; Mercator is true on the equator, with its east and west edges joined so that a track can cross 180°. Lengths are map kilometers at that scale. <i>Tracks</i> fits each map to the selected tracks; the scale bar gives map kilometers.</dd>
</dl>
<h2>Sources</h2>
<ol class="refs">
<li>Ropert-Coudert Y, Van de Putte AP, Reisinger RR, et al. (2020). The retrospective analysis of Antarctic tracking data project. <i>Scientific Data</i> 7, 94. <a href="https://doi.org/10.1038/s41597-020-0406-x">doi:10.1038/s41597-020-0406-x</a>. Data: The Retrospective Analysis of Antarctic Tracking (Standardised) Data from the Scientific Committee on Antarctic Research, v1.5, SCAR AntOBIS, <a href="https://doi.org/10.15468/uzmdpm">doi:10.15468/uzmdpm</a>, CC BY 4.0.</li>
<li>Sato K, Watanuki Y, Takahashi A, et al. (2007). Stroke frequency, but not swimming speed, is related to body size in free-ranging seabirds, pinnipeds and cetaceans. <i>Proceedings of the Royal Society B</i> 274, 471–477. <a href="https://doi.org/10.1098/rspb.2006.0005">doi:10.1098/rspb.2006.0005</a>.</li>
<li>Antarctic Circumpolar Current speeds: <a href="https://glossary.ametsoc.org/wiki/antarctic-circumpolar-current/">AMS Glossary of Meteorology</a>; Stewart RH, <a href="https://geo.libretexts.org/Bookshelves/Oceanography/Introduction_to_Physical_Oceanography_(Stewart)/13%3A_Deep_Circulation_in_the_Ocean/13.5%3A_Antarctic_Circumpolar_Current"><i>Introduction to Physical Oceanography</i>, §13.5</a>.</li>
<li><a href="https://www.naturalearthdata.com/">Natural Earth</a> land, 1:50m south of 35°S and 1:110m elsewhere · <a href="https://d3js.org/">D3</a>.</li>
</ol>
<button id="dl" type="button">Download the data (JSON)</button>
</section>
<footer class="wrap">Built {{BUILT}}. <a href="https://git.aethercosmology.com/toby/cable-latency-survey">Code and data</a> (MIT; tracking data CC BY 4.0, SCAR) · <a href="https://git.aethercosmology.com/toby/cable-latency-survey/src/branch/main/CONTRIBUTING.md">Contribute</a> · Related: <a href="https://pingstats.aethercosmology.com">Cable Latency Survey</a> · <a href="https://fe-map.aethercosmology.com">The Best Flat Map</a> · <a href="https://iss-spoofing.aethercosmology.com">The Sync Test</a> · <a href="https://distance.aethercosmology.com">The Shape of Distance</a></footer>
<div id="tip" hidden></div>
<script>/*D3*/</script>
<script>
(() => {
"use strict";
const D = /*DATA*/null;
const RAD = Math.PI / 180, RE = 6371, MAPS = ["globe", "ae", "dualpole", "mercator"];
const MAPNAME = { globe: "Globe", ae: "North-pole AE", dualpole: "Dual-pole AE", mercator: "Mercator" };
const nf = new Intl.NumberFormat("en-US");
const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
const C = { track: "#3ee6ff", bad: "#ff4d5e", colony: "#ffc94a", ocean: "#06101e", land: "#13243b", coast: "rgba(150,200,255,.24)",
grat: "rgba(120,180,255,.08)", rim: "rgba(120,180,255,.3)", ink: "#e8f0fb", faint: "#65789a" };
const $ = s => document.querySelector(s);
const colony = c => D.colony_fix[c] || c;
const spName = s => D.names[s] || s;
// selection
const S = { key: D.default, day: 0, playing: false, rate: 4, view: "fit", lim: D.limit.kmh, last: 0 };
let G = [], GMAX = 1;
const beyond = (t, m) => t.st[m].need !== null && t.st[m].need > S.lim;
function select(key) {
S.key = key;
const [sp, col, yr] = key.split("|");
G = D.tracks.filter(t => t.sp === sp && colony(t.colony) === colony(col) && t.year === yr);
GMAX = Math.max(1, ...G.map(t => t.d[t.d.length - 1]));
$("#day").max = GMAX; S.day = GMAX; $("#day").value = GMAX;
const t0 = G.map(t => t.start).sort()[0], t1 = G.map(t => t.end).sort().pop();
$("#span").textContent = `${t0} – ${t1}`;
$("#seltitle").textContent = `${spName(sp)}s · ${colony(col)} · ${yr}`;
fitAll(); table(); stop(); dirty = true;
}
// group menu: species, then colony and season
(function menu() {
const sel = $("#grp"), bySp = new Map();
for (const [k, g] of Object.entries(D.groups)) { if (!bySp.has(g.sp)) bySp.set(g.sp, []); bySp.get(g.sp).push([k, g]); }
for (const sp of Object.keys(D.species)) {
const og = document.createElement("optgroup"); og.label = spName(sp);
for (const [k, g] of (bySp.get(sp) || []).sort((a, b) => a[1].colony.localeCompare(b[1].colony) || a[1].year.localeCompare(b[1].year))) {
const o = document.createElement("option"); o.value = k; o.textContent = `${g.colony}, ${g.year} (${g.n})`; og.appendChild(o);
}
sel.appendChild(og);
}
sel.value = D.default;
sel.onchange = () => select(sel.value);
})();
// panels
const LAND = { type: "MultiPolygon", coordinates: D.land };
const GRAT = d3.geoGraticule().step([30, 30])(), SPH = { type: "Sphere" };
const panels = [...document.querySelectorAll(".panel")].map(el => {
const key = el.dataset.key;
const proj = key === "globe" ? d3.geoOrthographic().clipAngle(90)
: key === "ae" ? d3.geoAzimuthalEquidistant().rotate([0, -90]).clipAngle(180 - 1e-3)
: key === "dualpole" ? d3.geoAzimuthalEquidistant().rotate([0, 0]).clipAngle(180 - 1e-3)
: d3.geoMercator();
proj.precision(0.3);
const cv = el.querySelector("canvas"), f = {};
el.querySelectorAll("[data-f]").forEach(d => (f[d.dataset.f] = d));
return { el, key, proj, cv, ctx: cv.getContext("2d"), f, W: 0, bg: null, xy: null };
});
let dpr = 1, dirty = true;
function center() { // mean direction of the selected positions
let x = 0, y = 0, z = 0;
for (const t of G) for (let i = 0; i < t.lat.length; i++) { const p = t.lat[i] * RAD, l = t.lon[i] * RAD; x += Math.cos(p) * Math.cos(l); y += Math.cos(p) * Math.sin(l); z += Math.sin(p); }
return [Math.atan2(y, x) / RAD, Math.atan2(z, Math.hypot(x, y)) / RAD];
}
function fit(p) {
const W = p.W, c = center(), pad = Math.max(18, W * 0.08);
if (p.key === "globe") p.proj.rotate([-c[0], -c[1]]);
if (p.key === "mercator") p.proj.rotate([-c[0], 0]);
if (S.view === "fit" && G.length) {
const pts = { type: "MultiPoint", coordinates: G.flatMap(t => t.lat.map((la, i) => [t.lon[i], la])) };
p.proj.fitExtent([[pad, pad], [W - pad, W - pad - 14]], pts);
if (p.key === "globe") p.proj.scale(Math.min(p.proj.scale(), W * 40));
} else {
const s = W / 2 - 3;
if (p.key === "globe") p.proj.scale(s).translate([W / 2, W / 2]);
else if (p.key === "mercator") p.proj.scale(W / (2 * Math.PI)).translate([W / 2, W / 2]);
else p.proj.scale(s / Math.PI).translate([W / 2, W / 2]);
}
p.bg = document.createElement("canvas"); p.bg.width = p.cv.width; p.bg.height = p.cv.height;
const g = p.bg.getContext("2d"); g.setTransform(dpr, 0, 0, dpr, 0, 0);
const path = d3.geoPath(p.proj, g);
g.save(); g.beginPath(); g.rect(0, 0, W, W); g.clip();
g.beginPath(); path(SPH); g.fillStyle = C.ocean; g.fill();
g.beginPath(); path(GRAT); g.strokeStyle = C.grat; g.lineWidth = 0.7; g.stroke();
g.beginPath(); path(LAND); g.fillStyle = C.land; g.fill(); g.strokeStyle = C.coast; g.lineWidth = 0.6; g.stroke();
g.beginPath(); path(SPH); g.strokeStyle = C.rim; g.lineWidth = 1; g.stroke();
g.restore();
scaleBar(g, p);
// projected daily positions; on the globe, the far side is hidden
const vis = p.key === "globe" ? ll => d3.geoDistance(ll, [c[0], c[1]]) < Math.PI / 2 - 1e-3 : () => true;
p.xy = G.map(t => t.lat.map((la, i) => { const ll = [t.lon[i], la]; return vis(ll) ? p.proj(ll) : null; }));
}
function scaleBar(g, p) { // map kilometers at the map's own scale (at the center for the globe)
const kmpx = RE / p.proj.scale(), want = p.W * 0.22 * kmpx;
const pow = Math.pow(10, Math.floor(Math.log10(want))), km = [1, 2, 5, 10].map(m => m * pow).filter(v => v <= want).pop() || pow;
const w = km / kmpx, x = 10, y = p.W - 12;
g.strokeStyle = "rgba(232,240,251,.75)"; g.lineWidth = 1.2;
g.beginPath(); g.moveTo(x, y - 4); g.lineTo(x, y); g.lineTo(x + w, y); g.lineTo(x + w, y - 4); g.stroke();
g.font = "500 11px JetBrains Mono, monospace"; g.fillStyle = "rgba(232,240,251,.8)"; g.textBaseline = "bottom";
g.fillText(`${nf.format(km)} km${p.key === "globe" ? "" : " (map)"}`, x + w + 6, y + 1);
}
function fitAll() { for (const p of panels) if (p.W) fit(p); }
function layout() {
dpr = Math.min(2, window.devicePixelRatio || 1);
for (const p of panels) {
const W = p.cv.clientWidth; if (!W) continue;
p.W = W; p.cv.width = Math.round(W * dpr); p.cv.height = Math.round(W * dpr);
}
fitAll(); dirty = true;
}
// drawing
function drawPanel(p) {
if (!p.W || !p.bg) return;
const g = p.ctx, W = p.W;
g.setTransform(1, 0, 0, 1, 0, 0); g.clearRect(0, 0, p.cv.width, p.cv.height); g.drawImage(p.bg, 0, 0);
g.setTransform(dpr, 0, 0, dpr, 0, 0);
g.save(); g.beginPath(); g.rect(0, 0, W, W); g.clip();
g.lineJoin = "round"; g.lineCap = "round";
const day = S.day, heads = [];
// colonies
const seen = new Set();
for (let k = 0; k < G.length; k++) {
const q = p.xy[k][0]; if (!q) continue; const id = Math.round(q[0] / 4) + "," + Math.round(q[1] / 4);
if (seen.has(id)) continue; seen.add(id);
g.beginPath(); g.arc(q[0], q[1], 4.5, 0, 7); g.strokeStyle = C.colony; g.lineWidth = 1.6; g.stroke();
}
for (let k = 0; k < G.length; k++) {
const t = G[k], xy = p.xy[k], bad = beyond(t, p.key), s = t.st[p.key];
g.strokeStyle = bad ? C.bad : C.track; g.globalAlpha = 0.75; g.lineWidth = 1.3;
g.beginPath(); let pen = false, last = null;
for (let i = 0; i < t.d.length; i++) {
let q = xy[i];
if (t.d[i] > day) { // partial step up to the day shown
if (i > 0 && xy[i - 1] && q && t.d[i - 1] <= day) { const f = (day - t.d[i - 1]) / (t.d[i] - t.d[i - 1]); q = [xy[i - 1][0] + f * (q[0] - xy[i - 1][0]), xy[i - 1][1] + f * (q[1] - xy[i - 1][1])]; if (pen) g.lineTo(q[0], q[1]); last = q; }
break;
}
if (!q) { pen = false; continue; }
pen ? g.lineTo(q[0], q[1]) : g.moveTo(q[0], q[1]); pen = true; last = q;
}
g.stroke();
if (bad && s.i !== null && t.d[s.j] <= day && xy[s.i] && xy[s.j]) { // the fastest stretch, straight across the map
g.globalAlpha = 0.95; g.lineWidth = 3.4;
g.beginPath(); g.moveTo(xy[s.i][0], xy[s.i][1]); for (let i = s.i + 1; i <= s.j; i++) if (xy[i]) g.lineTo(xy[i][0], xy[i][1]); g.stroke();
}
if (last) heads.push([last, t.d[t.d.length - 1] <= day]);
}
g.globalAlpha = 1;
for (const [q, done] of heads) {
g.beginPath(); g.arc(q[0], q[1], done ? 2 : 3, 0, 7);
if (done) { g.strokeStyle = "rgba(255,255,255,.7)"; g.lineWidth = 1; g.stroke(); } else { g.fillStyle = "#fff"; g.fill(); }
}
g.restore();
}
function readouts() {
for (const p of panels) {
const v = G.filter(t => t.st[p.key].need !== null), lens = G.map(t => t.st[p.key].len).sort((a, b) => a - b);
const med = lens.length ? lens[lens.length >> 1] : 0;
p.f.len.textContent = `${nf.format(Math.round(med))} km`;
const k = v.filter(t => beyond(t, p.key)).length;
p.f.n.innerHTML = v.length ? `${k} of ${v.length}<span class="pill ${k ? "bad" : "ok"}">${k ? "beyond" : "within"}</span>` : "—";
const top = v.reduce((a, t) => (t.st[p.key].need > (a ? a.st[p.key].need : -1) ? t : a), null);
if (top) { const s = top.st[p.key], r = s.need / S.lim;
p.f.v.innerHTML = `${s.need.toFixed(1)} km/h · ${nf.format(Math.round(s.km))} km in ${Math.round(s.h)} h<span class="pill ${r > 1 ? "bad" : "ok"}">×${r.toFixed(Math.abs(r - 1) < 0.005 ? 3 : 2)} limit</span>`; }
else p.f.v.textContent = "no 3-day stretch";
}
const d = Math.min(GMAX, Math.floor(S.day));
$("#clock").textContent = `Day ${d} of ${GMAX}`;
}
// tables
function table() {
const th = `<tr><th scope="col" style="text-align:left">Penguin</th><th scope="col" style="text-align:left">Tag</th><th scope="col">Tracked</th><th scope="col">Days</th><th scope="col">Length on the globe</th>${MAPS.map(m => `<th scope="col">${MAPNAME[m]}, km/h</th>`).join("")}</tr>`;
$("#animals thead").innerHTML = `<tr><th scope="col" colspan="5"></th><th scope="col" colspan="4" style="text-align:center">Fastest ${D.limit.window}-day stretch</th></tr>` + th;
$("#animals tbody").innerHTML = G.map(t => {
const cell = m => { const s = t.st[m]; return s.need === null ? `<td class="na">—</td>` : `<td class="${s.need > S.lim ? "bad" : ""}">${s.need.toFixed(1)}</td>`; };
const who = [{ M: "male", F: "female" }[t.sex], t.stage && t.stage.toLowerCase()].filter(Boolean).join(", ");
return `<tr><td class="l">${t.id}${who ? ` <span style="color:var(--faint)">${who}</span>` : ""}</td><td class="l">${t.dev || "—"}</td><td>${t.start}</td><td>${t.d[t.d.length - 1]}</td><td>${nf.format(Math.round(t.st.globe.len))} km</td>${MAPS.map(cell).join("")}</tr>`;
}).join("");
}
function speciesTable() {
const rows = Object.entries(D.species);
const all = D.tracks.filter(t => t.st.globe.need !== null);
const cnt = (v, m) => v.filter(t => beyond(t, m)).length;
$("#species thead").innerHTML = `<tr><th scope="col" style="text-align:left">Species</th><th scope="col">Tracks</th><th scope="col">Tested</th>${MAPS.map(m => `<th scope="col">${MAPNAME[m]}</th>`).join("")}</tr><tr><th scope="col" colspan="3"></th><th scope="col" colspan="4" style="text-align:center">Beyond ${S.lim.toFixed(1)} km/h · median fastest stretch, km/h</th></tr>`;
const line = (name, v, n) => `<tr><th scope="row">${name}</th><td>${nf.format(n)}</td><td>${nf.format(v.length)}</td>${MAPS.map(m => { const k = cnt(v, m), s = v.map(t => t.st[m].need).sort((a, b) => a - b); return `<td class="${k ? "bad" : ""}">${k} · ${s.length ? s[s.length >> 1].toFixed(1) : "—"}</td>`; }).join("")}</tr>`;
$("#species tbody").innerHTML = rows.map(([sp, s]) => line(s.name, all.filter(t => t.sp === sp), s.tracks)).join("") + line("All", all, D.tracks.length);
}
// tooltip: nearest daily position
const tip = $("#tip");
for (const p of panels) {
p.cv.addEventListener("pointermove", e => {
if (!p.xy) return;
const r = p.cv.getBoundingClientRect(), mx = e.clientX - r.left, my = e.clientY - r.top;
let best = null, bd = 12 * 12;
for (let k = 0; k < G.length; k++) for (let i = 0; i < p.xy[k].length; i++) { const q = p.xy[k][i]; if (!q || G[k].d[i] > S.day) continue; const d = (q[0] - mx) ** 2 + (q[1] - my) ** 2; if (d < bd) { bd = d; best = [k, i]; } }
if (!best) { tip.hidden = true; return; }
const t = G[best[0]], s = t.st[p.key];
tip.innerHTML = `<b>${spName(t.sp)} ${t.id}</b><span>${colony(t.colony)} · ${t.dev || "tag"} · ${t.start} to ${t.end}</span><span>Day ${t.d[best[1]]}: ${t.lat[best[1]].toFixed(2)}°, ${t.lon[best[1]].toFixed(2)}°</span><span>${MAPNAME[p.key]}: ${nf.format(Math.round(s.len))} km tracked${s.need !== null ? `; fastest ${D.limit.window}-day stretch ${s.need.toFixed(1)} km/h` : ""}</span>`;
tip.hidden = false; const tw = tip.getBoundingClientRect();
tip.style.left = Math.min(innerWidth - tw.width - 8, e.clientX + 14) + "px"; tip.style.top = Math.min(innerHeight - tw.height - 8, e.clientY + 14) + "px";
});
p.cv.addEventListener("pointerleave", () => (tip.hidden = true));
}
// controls
const playBtn = $("#play"), icon = $("#playicon");
function setPlay(on) { S.playing = on; icon.setAttribute("d", on ? "M2 1h3.5v12H2zM8.5 1H12v12H8.5z" : "M3 1.5v11l9-5.5z"); playBtn.setAttribute("aria-label", on ? "Pause" : "Play"); S.last = performance.now(); }
function stop() { setPlay(false); }
playBtn.onclick = () => { if (!S.playing && S.day >= GMAX) S.day = 0; setPlay(!S.playing); };
$("#rates").addEventListener("click", e => { const b = e.target.closest("button"); if (!b) return; S.rate = +b.dataset.rate; for (const x of $("#rates").children) x.setAttribute("aria-pressed", String(x === b)); });
$("#view").addEventListener("click", e => { const b = e.target.closest("button"); if (!b) return; S.view = b.dataset.v; for (const x of $("#view").children) x.setAttribute("aria-pressed", String(x === b)); fitAll(); dirty = true; });
$("#day").addEventListener("input", e => { S.day = +e.target.value; stop(); dirty = true; });
$("#lim").addEventListener("input", e => { S.lim = +e.target.value; $("#limv").textContent = `${S.lim.toFixed(1)} km/h`; table(); speciesTable(); dirty = true; });
$("#dl").addEventListener("click", () => {
const blob = new Blob([JSON.stringify({ tracks: D.tracks, species: D.species, total: D.total, limit: D.limit, source: "SCAR RAATD v1.5, doi:10.15468/uzmdpm, CC BY 4.0" })], { type: "application/json" });
const a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = "penguin_test_data.json"; document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(a.href), 2000);
});
function frame(now) {
if (S.playing) {
S.day = Math.min(GMAX, S.day + (now - S.last) / 1000 * S.rate); S.last = now;
$("#day").value = S.day; if (S.day >= GMAX) stop(); dirty = true;
}
if (dirty) { for (const p of panels) drawPanel(p); readouts(); dirty = false; }
requestAnimationFrame(frame);
}
new ResizeObserver(() => layout()).observe($(".grid"));
select(D.default); speciesTable(); layout();
requestAnimationFrame(frame);
})();
</script>
</body>
</html>