Files
Support-Agent/vues-deplacements/maquette/explore_template.html
T
maximeandClaude Opus 5.5 d07edace60 Detect every jump and the trends in the Displacements page (D-055)
Jumps: a sudden change within 2 h (8 times the target's usual 2-hour
change) that lasts 24 h (at least 1.4 times its daily swing); every
jump of the range, returns included, so PR17's return on 12/10 now
shows. Trends: Theil-Sen slope and Kendall tau of the daily levels,
jumps set aside, kept when the drift over the period reaches the daily
swing and goes steadily one way. Provisional thresholds; method and
results in vues-deplacements/contexte/detection-d-anomalies.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 18:22:54 +02:00

827 lines
47 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">
<title><!--PLATFORM--> · Explore</title>
<script src="https://cdn.plot.ly/plotly-4.1.1.min.js"></script>
<style>
/* Maquette de la page Explore avec l'onglet Diagnosis (D-053, vues-deplacements/maquette/spec.md). Données injectées
par explore.py. Habillage repris de maquettes/user/summary_template.html. */
:root {
--sidebar: #2a3f54; --topbar: #ededed; --page: #f7f7f7; --panel-border: #e6e9ed;
--muted: #73879c; --text: #333; --line: #dee2e6; --blue: #2a78d6;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--muted);
font: 13px/1.47 "Helvetica Neue", Roboto, Arial, "Droid Sans", sans-serif; }
svg.i { width: 15px; height: 15px; fill: currentColor; vertical-align: -2px; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 230px; background: var(--sidebar); color: #fff; }
.brand { height: 57px; padding: 0 10px; display: flex; align-items: center; font-size: 22px; }
.profile { display: flex; align-items: center; gap: 22px; padding: 18px 12px 24px; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: #9b59b6; border: 3px solid #fff;
display: grid; place-items: center; font-size: 19px; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.profile small { display: block; color: #bab8b8; font-size: 13px; }
.profile span { font-size: 14px; }
.section { padding: 0 23px 18px; font-size: 11px; font-weight: bold; letter-spacing: .3px; }
.nav a { display: flex; align-items: center; gap: 4px; padding: 13px 15px; color: #e7e7e7;
text-decoration: none; font-weight: bold; }
.nav a .chev { margin-left: auto; }
.nav a[data-page] { cursor: pointer; }
.nav a.active { background: #3e5367; }
.topbar { margin-left: 230px; height: 52px; background: var(--topbar); border-bottom: 1px solid #d9dee4;
display: flex; align-items: center; justify-content: space-between; padding: 0 15px; }
.topbar .burger { color: #5a738e; width: 26px; height: 26px; }
.user { display: flex; align-items: center; gap: 10px; color: #515356; }
.user .avatar { width: 29px; height: 29px; border-width: 0; font-size: 11px; box-shadow: none; }
main { margin-left: 230px; padding: 10px 28px; }
.panel { background: #fff; border: 1px solid var(--panel-border); padding: 10px 17px 20px; }
.panel-title { display: flex; align-items: center; border-bottom: 2px solid var(--panel-border); padding: 4px 6px 12px; }
.panel-title h2 { margin: 0; font-size: 18px; font-weight: 400; }
.panel-title h2 small { font-size: 14px; margin-left: 10px; }
.panel-title .tools { margin-left: auto; color: #c5c7cb; }
/* Période (inerte) et onglets, comme la page Explore de la plateforme. */
.period { display: flex; margin: 22px 22px 0; }
.period span { border: 1px solid #ced4da; border-radius: 4px 0 0 4px; padding: 7px 12px; color: var(--text); font-size: 15px; }
.period b { background: #6c757d; color: #fff; padding: 7px 12px; font-weight: normal; font-size: 15px; border-radius: 0 4px 4px 0; }
.tabs { display: flex; margin: 18px 22px 0; border-bottom: 1px solid var(--line); }
.tabs button { border: 1px solid transparent; border-bottom: 0; background: none; padding: 7px 16px; margin-bottom: -1px;
font: inherit; font-size: 15px; color: var(--blue); cursor: pointer; border-radius: 4px 4px 0 0; }
.tabs button.active { color: var(--text); background: #fff; border-color: var(--line); }
.pane { display: none; margin: 0 22px; padding-top: 14px; }
.pane.active { display: block; }
.pane > img { display: block; width: 100%; margin-bottom: 8px; border: 1px solid var(--line); }
.empty { padding: 30px 0; color: var(--muted); }
/* Onglet Diagnosis (spec §1 à §3). */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--text); font-size: 14px;
white-space: nowrap; }
.toolbar button { border: 1px solid var(--line); background: #fff; border-radius: 4px; padding: 4px 10px;
font: inherit; cursor: pointer; }
.toolbar button.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.toolbar .meta { margin-left: auto; color: var(--muted); }
/* Onglet View (spec « L'onglet View ») : images au glisseur, film, comparaison à ±24 h, zoom commun. */
.viewer { margin: 0 auto; width: min(100%, calc((100vh - 370px) * 1.5 * var(--n, 1))); }
.frames { display: flex; gap: 8px; }
.frame { flex: 1; position: relative; margin: 0; aspect-ratio: 3 / 2; overflow: hidden; background: #000;
cursor: grab; touch-action: none; user-select: none; }
.layer { position: absolute; inset: 0; transform-origin: 0 0; } /* l'image et ses repères, zoomés ensemble */
.layer > * { position: absolute; inset: 0; width: 100%; height: 100%; }
/* Cercle et nom de chaque capteur ; le nom garde sa taille à l'écran quel que soit le zoom (font-size, voir zoom()). */
.marks { overflow: visible; pointer-events: none; font-family: sans-serif; }
.marks circle { fill: none; stroke: currentColor; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.marks text { fill: currentColor; text-anchor: middle; paint-order: stroke; stroke: rgba(0,0,0,.85); stroke-width: .25em;
stroke-linejoin: round; }
.marks .target { color: #ffd400; }
.marks .global_ref { color: #3cc8ff; }
.marks .ref { color: #ff9f1c; }
.marks .sel text { font-weight: bold; text-decoration: underline; }
.marks .sel circle { stroke-width: 3; }
.marks .over circle { stroke-width: 3; stroke-dasharray: 5 3; } /* error_value au-dessus du seuil : mesure rejetée */
.strip figcaption.over { color: #d0021b; }
.legend b { font-weight: normal; padding: 0 4px; border-radius: 3px; background: #333; }
.frame figcaption { position: absolute; left: 8px; top: 6px; padding: 2px 8px; border-radius: 3px;
background: rgba(0,0,0,.6); color: #fff; font-size: 13px; pointer-events: none; }
#v-slider { width: 100%; margin: 10px 0 0; }
/* Bandes d'error_value (système, puis cible du gros plan) : une colonne par image, alignées sur le glisseur (8 px :
demi-curseur). */
#v-band { display: block; width: calc(100% - 16px); height: 19px; margin: 2px 8px 0; image-rendering: pixelated; cursor: pointer; }
.days { position: relative; height: 18px; font-size: 11px; }
.days span { position: absolute; transform: translateX(-50%); }
/* Gros plan d'une cible, avec les images d'avant et d'après (spec « L'onglet View »). */
.sub { margin: 22px 0 8px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 15px; color: var(--text); }
.toolbar input, .toolbar select { font: inherit; }
.note { margin: 0 0 10px; color: var(--text); }
.strip { display: flex; justify-content: safe center; align-items: flex-end; gap: 6px; overflow-x: auto; margin-bottom: 14px; }
.strip figure { flex: none; margin: 0; color: var(--text); font-size: 12px; white-space: pre-line; line-height: 1.3; }
.strip canvas { display: block; cursor: pointer; }
.strip .now canvas { outline: 2px solid var(--blue); cursor: default; }
#t-also { flex: 1; white-space: normal; }
/* Demande à l'agent (Diagnosis). */
#d-targets, #d-question { flex: 1; white-space: normal; }
#d-question { min-width: 300px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 4px; }
#d-request textarea { width: 100%; font: 13px/1.4 monospace; padding: 6px 8px; border: 1px solid var(--line); }
#d-request p { margin: 4px 0; color: var(--text); }
/* Page Displacements (D-055) : un événement par groupe de sauts, ses sauts en tableau, puis les courbes en mm. */
#p-displacements .note { margin: 0 6px 10px; }
#p-displacements .sub { margin: 18px 6px 6px; }
#r-trends { margin: 0 6px 12px; }
#r-events details { margin: 0 6px 12px; color: var(--text); }
#r-events summary { font-size: 15px; cursor: pointer; padding: 4px 0; }
.rtable { border-collapse: collapse; width: 100%; margin-top: 4px; color: var(--text); }
.rtable th, .rtable td { padding: 5px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.rtable th { color: var(--muted); font-weight: normal; }
.rtable tbody tr { cursor: pointer; }
.rtable tbody tr:hover { background: #f2f5f8; }
.rtable i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
</style>
</head>
<body>
<svg style="display:none">
<symbol id="home" viewBox="0 0 20 20"><path d="M10 2 1 10h3v8h5v-5h2v5h5v-8h3z"/></symbol>
<symbol id="list" viewBox="0 0 20 20"><path d="M1 3h3v3H1zm5 0h13v3H6zM1 8.5h3v3H1zm5 0h13v3H6zM1 14h3v3H1zm5 0h13v3H6z"/></symbol>
<symbol id="cog" viewBox="0 0 20 20"><circle cx="10" cy="10" r="6" fill="none" stroke="currentColor" stroke-width="4" stroke-dasharray="2.4 2.3"/><circle cx="10" cy="10" r="5" fill="none" stroke="currentColor" stroke-width="3"/></symbol>
<symbol id="chev" viewBox="0 0 20 20"><path d="M4 7l6 6 6-6" fill="none" stroke="currentColor" stroke-width="2.2"/></symbol>
<symbol id="burger" viewBox="0 0 20 20"><path d="M2 4h16v2.4H2zm0 4.8h16v2.4H2zm0 4.8h16V16H2z"/></symbol>
<symbol id="trend" viewBox="0 0 20 20"><path d="M2 15l5-5 4 3 7-8" fill="none" stroke="currentColor" stroke-width="2.2"/></symbol>
<symbol id="wrench" viewBox="0 0 20 20"><path d="M13.5 1.5a5 5 0 0 0-4.6 6.9L2 15.3 4.7 18l6.9-6.9a5 5 0 0 0 6.9-4.6l-3 3-2.8-.6-.6-2.8z"/></symbol>
</svg>
<aside class="sidebar">
<div class="brand">AIMsight monitoring</div>
<div class="profile"><div class="avatar">MP</div><div><small>Welcome,</small><span>Maxime Pasquier</span></div></div>
<div class="section">GENERAL</div>
<nav class="nav">
<a><svg class="i"><use href="#home"/></svg>Home</a>
<a data-page="explore"><svg class="i"><use href="#list"/></svg>Explore<svg class="i chev"><use href="#chev"/></svg></a>
<a data-page="displacements"><svg class="i"><use href="#trend"/></svg>Displacements</a>
<a><svg class="i"><use href="#cog"/></svg>Settings<svg class="i chev"><use href="#chev"/></svg></a>
</nav>
</aside>
<header class="topbar">
<svg class="burger"><use href="#burger"/></svg>
<div class="user"><div class="avatar">MP</div>Maxime Pasquier ▾</div>
</header>
<main>
<section class="panel" id="p-displacements" hidden>
<div class="panel-title"><h2><!--PLATFORM--><small>Displacements</small></h2></div>
<h3 class="sub">Jumps</h3>
<p class="note" id="r-note"></p>
<div id="r-events"></div>
<h3 class="sub">Trends</h3>
<p class="note" id="r-trend-note"></p>
<div id="r-trends"></div>
<div id="r-curves"></div>
</section>
<section class="panel" id="p-explore">
<div class="panel-title">
<h2><!--PLATFORM--><small>Explore</small></h2>
<span class="tools"><svg class="i"><use href="#wrench"/></svg> ▾</span>
</div>
<div class="period"><span id="period"></span><b>Apply</b></div>
<nav class="tabs">
<button type="button" data-pane="time_series">Time Series</button>
<button type="button" data-pane="advanced">Advanced</button>
<button type="button" data-pane="view" class="active">View</button>
<button type="button" data-pane="diagnosis">Diagnosis</button>
</nav>
<div class="pane" id="time_series"></div>
<div class="pane" id="advanced"></div>
<div class="pane active" id="view">
<div class="toolbar">
<button type="button" id="v-prev" title="Previous image (←)">◀</button>
<button type="button" id="v-play" title="Play / pause (Space)">▶ Play</button>
<button type="button" id="v-next" title="Next image (→)">▶</button>
<select id="v-speed" title="Images per second"><option>2</option><option selected>4</option><option>8</option></select> img/s
&nbsp; Compare <span id="v-cmp"><button type="button" data-cmp="0">Off</button><button type="button" data-cmp="-1">−24 h</button><button type="button" data-cmp="1">+24 h</button></span>
&nbsp; Zoom <button type="button" id="v-targets">Targets</button><button type="button" id="v-full">Full image</button>
&nbsp; <label><input type="checkbox" id="v-marks" checked> Sensors</label>
colored by <select id="v-color"><option value="error">error_value</option><option value="type">type</option></select>
<span class="legend" id="v-legend"></span>
<span class="meta">← → image · Shift ← → ±24 h · Space play · wheel zoom, drag to pan</span>
</div>
<div class="viewer">
<div class="frames">
<figure class="frame"><div class="layer"><img alt="" draggable="false"><svg class="marks"></svg></div><figcaption></figcaption></figure>
<figure class="frame" hidden><div class="layer"><img alt="" draggable="false"><svg class="marks"></svg></div><figcaption></figcaption></figure>
</div>
<input type="range" id="v-slider" min="0" value="0">
<canvas id="v-band" height="3"></canvas>
<div class="days" id="v-days"></div>
<div class="toolbar">
<button type="button" id="v-prev-rej">◀ Previous rejection</button><button type="button" id="v-next-rej">Next rejection ▶</button>
<span id="v-rej"></span>
<span class="meta">bands: top all sensors (mean of error_value / threshold), bottom close-up target ·
green low, orange near threshold, red above · grey no value</span>
</div>
</div>
<h3 class="sub">Target close-up</h3>
<div class="toolbar">
Target <select id="t-name"></select>
&nbsp; Crop ± <select id="t-r"><option>15</option><option selected>30</option><option>75</option><option>150</option><option>300</option></select> px
&nbsp; Step <select id="t-step"><option value="15">15 min</option><option value="60" selected>1 h</option><option value="180">3 h</option>
<option value="360">6 h</option><option value="1440">1 day</option></select>
&nbsp; Images on each side <select id="t-side"><option>2</option><option selected>3</option><option>4</option><option>6</option></select>
</div>
<div class="toolbar">Also show <span id="t-also"></span><button type="button" id="t-data">Data →</button>
<span class="meta">before and after images appear when the film is paused</span>
</div>
<p class="note">Each image is centered on the target's raw position (x, y) measured at that image's time, not on corr.
The large image is the image above; the others are the images before and after it.</p>
<div id="t-strips"></div>
</div>
<div class="pane" id="diagnosis">
<div class="toolbar">Targets <span id="d-targets"></span></div>
<div id="curves"></div>
<div class="toolbar">
<b id="d-range"></b> <span id="instant"></span>
<span class="meta">zoom the curves to choose the range · click a button to add or remove a target</span>
</div>
<div class="toolbar">
<input type="text" id="d-question" placeholder="Question for the agent (optional)">
<button type="button" id="d-ai">Analyze by AI</button><button type="button" id="d-images">Images →</button>
</div>
<div id="d-request" hidden>
<textarea rows="3" readonly></textarea>
<p>Not run from this page yet: paste this request into Claude Code. <button type="button" id="d-copy">Copy</button></p>
</div>
</div>
</section>
</main>
<script>
const D = /*DATA*/null;
const day = t => `${+t.slice(8, 10)}/${+t.slice(5, 7)}/${t.slice(0, 4)}`;
document.getElementById("period").textContent = `${day(D.times[0])} → ${day(D.times[D.times.length - 1])}`;
// Onglets : un seul volet visible ; Plotly recalcule la taille des graphiques du volet qui s'affiche. Entre View et
// Diagnosis, l'instant et les cibles passent d'un onglet à l'autre (syncTabs).
function activate(b, sync = true) {
const prev = document.querySelector(".pane.active").id;
document.querySelectorAll(".tabs button, .pane").forEach(e => e.classList.remove("active"));
b.classList.add("active");
const pane = document.getElementById(b.dataset.pane);
pane.classList.add("active");
if (sync) syncTabs(prev, b.dataset.pane);
pane.querySelectorAll(".js-plotly-plot").forEach(p => Plotly.Plots.resize(p));
}
for (const b of document.querySelectorAll(".tabs button")) b.addEventListener("click", () => activate(b));
const tabButton = pane => document.querySelector(`.tabs button[data-pane="${pane}"]`);
// Time Series et Advanced : les captures de la plateforme, telles quelles (décor, spec « La page »).
for (const [tab, srcs] of Object.entries(D.captures)) {
const pane = document.getElementById(tab);
if (!srcs.length) pane.innerHTML = '<p class="empty">No capture of this page.</p>';
for (const src of srcs) pane.insertAdjacentHTML("beforeend", `<img src="${src}" alt="">`);
}
// Onglet Diagnosis (spec « L'onglet Diagnosis ») : ce que disent les données. Courbes des cibles choisies sur une
// plage, et la demande à l'agent de diagnostic pour cette plage et ces cibles.
const S = D.sensors, NAMES = S.map(s => s.name);
const TOL = 10 * 60e3; // image ou mesure la plus proche d'un instant, à 10 min près
const CONFIG = { responsive: true, scrollZoom: true, displaylogo: false };
const ASKED = new URLSearchParams(location.hash.slice(1)); // état de départ lu dans l'adresse
let T = D.times.includes(ASKED.get("t")) ? D.times.indexOf(ASKED.get("t")) : D.times.length - 1;
let W = 0, H = 0; // taille des images de la caméra, lue sur la première
if (tabButton(ASKED.get("tab"))) activate(tabButton(ASKED.get("tab")), false); // onglet de départ (#tab=diagnosis), View sinon
const utc = t => t.replace("T", " ").replace("Z", " UTC");
const tLine = () => ({ type: "line", xref: "x", yref: "paper", x0: D.times[T], x1: D.times[T], y0: 0, y1: 1,
line: { color: "#111", width: 1.5 } });
const IMS = D.images.map(im => Date.parse(im.t)), TMS = D.times.map(t => Date.parse(t)); // instants en ms
function nearestIndex(ms, list = IMS) { // index de l'image (ou de la mesure) la plus proche de ms, à TOL près ; -1 sinon
let best = -1, gap = Infinity;
list.forEach((t, k) => {
const g = Math.abs(t - ms);
if (g < gap) { gap = g; best = k; }
});
return gap <= TOL ? best : -1;
}
function setT(j) {
T = j;
document.getElementById("instant").textContent = `· T = ${utc(D.times[T])}`;
const gd = document.getElementById("curves");
if (gd.layout) Plotly.relayout(gd, { shapes: [tLine()] }); // seulement s'il est déjà tracé
}
// Cibles choisies (SEL, dans l'ordre du choix) et plage (RANGE, la fenêtre visible des courbes et de la grille).
const PALETTE = ["#2a78d6", "#d03b3b", "#2ca02c", "#9467bd", "#ff7f0e", "#17becf", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22"];
const FULL = [D.times[0], D.times[D.times.length - 1]];
let SEL = (ASKED.get("open") || "PR17").split(",").filter(n => NAMES.includes(n)).map(n => NAMES.indexOf(n));
let RANGE = [...FULL];
const chips = document.getElementById("d-targets");
chips.innerHTML = S.map((s, i) => `<button type="button" data-i="${i}">${s.name}</button>`).join("");
function markTargets() {
chips.querySelectorAll("button").forEach(b => {
const at = SEL.indexOf(+b.dataset.i);
b.classList.toggle("active", at >= 0);
b.style.background = at >= 0 ? PALETTE[at % PALETTE.length] : ""; // la couleur de ses courbes
});
}
chips.addEventListener("click", ev => { // un clic ajoute la cible, un second la retire
const b = ev.target.closest("button");
if (!b) return;
b.blur();
const i = +b.dataset.i;
SEL = SEL.includes(i) ? SEL.filter(k => k !== i) : [...SEL, i];
markTargets();
drawCurves();
});
function autoscale(plotId) { // ordonnées recalées sur la plage visible (D-013)
/*AUTOSCALE*/
}
function drawCurves() { // une rangée par grandeur, une courbe par cible choisie ; seuils en tirets ; T marqué
Plotly.purge("curves");
const box = document.getElementById("curves");
if (!SEL.length) {
box.innerHTML = '<p class="empty">Choose targets: click a button above.</p>';
return;
}
box.innerHTML = "";
const traces = [], HR = D.hourly;
SEL.forEach((i, n) => {
const s = S[i], color = PALETTE[n % PALETTE.length], mm = HR.sensors[s.name];
if (mm) [["h", "horizontal"], ["v", "vertical"]].forEach(([k, label], r) => traces.push({ // export horaire, en mm
type: "scatter", mode: "lines", x: HR.times, y: mm[k], name: s.name, legendgroup: s.name, showlegend: false,
yaxis: `y${r ? 2 : ""}`, line: { color, width: 1.3 },
hovertemplate: `${s.name} · %{x|%d %b %H:%M} UTC (hour start)<br>${label} %{y:.2f} mm<extra></extra>` }));
traces.push({ type: "scatter", mode: "lines", x: D.times, y: s.values.error_value, yaxis: "y3", line: { color, width: 1.3 },
name: mm ? s.name : `${s.name} (no mm: not in the hourly export)`, legendgroup: s.name,
hovertemplate: `${s.name} · %{x|%d %b %H:%M} UTC<br>error_value %{y:.3f}<extra></extra>` });
traces.push({ type: "scatter", mode: "lines", x: FULL, y: [s.threshold, s.threshold], name: `${s.name} threshold`,
legendgroup: s.name, showlegend: false, yaxis: "y3", line: { color, width: 1, dash: "dash" }, hoverinfo: "skip" });
});
Plotly.newPlot("curves", traces, {
height: 620, margin: { l: 70, r: 10, t: 30, b: 40 }, legend: { orientation: "h", x: 0, y: 1.06 },
xaxis: { type: "date", anchor: "y3", range: RANGE },
yaxis: { domain: [0.70, 1], fixedrange: true, title: { text: "horizontal (mm)" } },
yaxis2: { domain: [0.36, 0.66], fixedrange: true, title: { text: "vertical (mm)" } },
yaxis3: { domain: [0, 0.32], fixedrange: true, title: { text: "error_value" } },
annotations: [{ text: "Displacement: hourly export, in mm, one point per hour (hour start, UTC) · error_value: every measurement",
xref: "paper", yref: "paper", x: 1, y: 1.06, xanchor: "right", showarrow: false, font: { size: 11, color: "#73879c" } }],
shapes: [tLine()],
}, CONFIG).then(() => {
autoscale("curves");
Plotly.relayout("curves", { "xaxis.range": RANGE }); // recale les ordonnées sur la plage dès l'ouverture
const gd = document.getElementById("curves");
gd.on("plotly_relayout", ev => onZoom(gd, ev));
gd.on("plotly_click", ev => { // un point d'une courbe : T devient son instant
const j = D.times.indexOf(minute(ev.points[0].x));
if (j >= 0) setT(j);
});
});
}
// La plage : la fenêtre visible des courbes ; un double-clic revient à toute la période.
const minute = v => String(v).replace(" ", "T").slice(0, 16) + "Z"; // borne d'axe Plotly -> instant UTC à la minute
function onZoom(gd, ev) {
if (!Object.keys(ev).some(k => k.startsWith("xaxis"))) return;
const r = ev["xaxis.autorange"] ? FULL : gd.layout.xaxis.range.map(minute);
RANGE = r;
document.getElementById("d-range").textContent = `Range: ${utc(RANGE[0])} → ${utc(RANGE[1])}`;
}
// Demande à l'agent de diagnostic : composée et affichée, pas encore lancée depuis la page.
function request() {
const q = document.getElementById("d-question").value.trim() || "Qu'est-ce qui explique le comportement de ces cibles sur cette plage ?";
return `@agent-diagnostic ${D.folder}/ Cibles : ${SEL.map(i => NAMES[i]).join(", ") || "aucune"}. ` +
`Plage : du ${RANGE[0]} au ${RANGE[1]} (UTC). Question : ${q}`;
}
document.getElementById("d-ai").addEventListener("click", ev => {
ev.currentTarget.blur();
const box = document.getElementById("d-request");
box.hidden = false;
box.querySelector("textarea").value = request();
});
document.getElementById("d-copy").addEventListener("click", ev => {
ev.currentTarget.blur();
const text = document.querySelector("#d-request textarea");
text.select();
navigator.clipboard.writeText(text.value).catch(() => document.execCommand("copy"));
});
document.getElementById("d-images").addEventListener("click", () => activate(tabButton("view")));
markTargets();
document.getElementById("instant").textContent = `· T = ${utc(D.times[T])}`;
document.getElementById("d-range").textContent = `Range: ${utc(RANGE[0])} → ${utc(RANGE[1])}`;
drawCurves();
if (D.images.length) { // la taille des images de la caméra, lue sur la première
const probe = new Image();
probe.onload = () => {
W = probe.naturalWidth; H = probe.naturalHeight;
frames.forEach(f => (f.style.aspectRatio = `${W} / ${H}`));
fit(D.view);
redrawMarks();
};
probe.src = D.images[0].src;
}
// Passage d'un onglet à l'autre : View -> Diagnosis emporte l'instant de l'image et les cibles du gros plan ;
// Diagnosis -> View emporte T et les cibles choisies (la première devient la cible du gros plan).
function syncTabs(from, to) {
if (from === "view" && to === "diagnosis") {
const j = nearestIndex(IMS[V], TMS);
SEL = [+tName.value, ...[...ALSO].filter(i => i !== +tName.value)];
markTargets();
drawCurves();
if (j >= 0) setT(j);
} else if (from === "diagnosis" && to === "view") {
if (SEL.length && S[SEL[0]].home) {
tName.value = SEL[0];
ALSO.clear();
SEL.slice(1).forEach(i => ALSO.add(i));
markAlso();
drawBand();
}
const k = nearestIndex(TMS[T]);
show(k >= 0 ? k : V);
}
}
// Onglet View : une image à la fois, au glisseur, au clavier ou en film ; à côté, si demandée, l'image la plus proche
// de la même heure la veille ou le lendemain. Les deux images partagent le zoom : échelle k, décalage x, y en fraction
// du cadre (les deux cadres ont la même taille).
const IM = D.images, DAY = 24 * 3600e3;
const frames = [...document.querySelectorAll("#view .frame")];
const slider = document.getElementById("v-slider"), playBtn = document.getElementById("v-play");
let V = IM.length - 1, cmp = { "-24": -1, "24": 1 }[ASKED.get("cmp")] || 0; // image affichée, décalage en jours
let Z = { k: 1, x: 0, y: 0 }, run = 0, playing = false;
function paint(frame, im, label) {
const img = frame.querySelector("img");
img.hidden = !im;
if (im && img.getAttribute("src") !== im.src) img.src = im.src;
img.dataset.t = im ? im.t : "";
frame.querySelector("figcaption").textContent = `${label}${im ? utc(im.t) : "No image at this time"}`;
drawMarks(frame);
}
const RING = 22; // rayon du cercle autour d'un capteur, en px de l'image (une tache de nuit fait une quinzaine de px)
const LEGENDS = { // légende des cercles, selon leur couleur (type de capteur ou error_value)
type: '<b style="color:#ffd400">target</b> <b style="color:#3cc8ff">reference</b> <b style="color:#ff9f1c">local reference</b>',
error: '<b style="color:hsl(120,90%,55%)">low</b> <b style="color:hsl(30,90%,55%)">near threshold</b> ' +
'<b style="color:#ff3b3b">- - above threshold (rejected)</b> <b style="color:#aaa">no value</b>',
};
function errorColor(e, threshold) { // vert loin du seuil, orange à son approche, rouge au-dessus
if (e === null) return "#aaa";
return e > threshold ? "#ff3b3b" : `hsl(${120 - 90 * Math.max(0, e / threshold)}, 90%, 55%)`;
}
function errorText(s, t) { // error_value du capteur s à l'heure t, face à son seuil ; null sans mesure
const j = nearestIndex(Date.parse(t), TMS), e = j < 0 ? null : s.values.error_value[j];
return e === null ? null : { text: `error ${e.toFixed(2)} ${e > s.threshold ? ">" : "≤"} ${s.threshold}`, over: e > s.threshold };
}
function drawMarks(frame) { // un cercle et le nom de chaque capteur, à x, y mesurés à l'heure de l'image ; le capteur
// du gros plan en gras souligné
const img = frame.querySelector("img"), svg = frame.querySelector("svg"), mode = document.getElementById("v-color").value;
svg.innerHTML = "";
if (img.hidden || !W || !document.getElementById("v-marks").checked) return;
svg.setAttribute("viewBox", `0 0 ${W} ${H}`);
const j = nearestIndex(Date.parse(img.dataset.t), TMS), sel = +document.getElementById("t-name").value;
if (j < 0) return;
svg.innerHTML = S.map((s, i) => {
if (s.x[j] === null) return "";
const e = s.values.error_value[j], byError = mode === "error";
const cls = [byError ? "" : s.kind, byError && e !== null && e > s.threshold ? "over" : "", i === sel ? "sel" : ""].join(" ");
const label = byError ? `${s.name} ${e === null ? "–" : e.toFixed(2)}` : s.name;
return `<g class="${cls}"${byError ? ` style="color:${errorColor(e, s.threshold)}"` : ""}>` +
`<circle cx="${s.x[j]}" cy="${s.y[j]}" r="${RING}"/><text x="${s.x[j]}" y="${s.y[j] - RING - 6}">${label}</text></g>`;
}).join("");
document.getElementById("v-legend").innerHTML = LEGENDS[mode] + " · <u><b style='color:#fff'>close-up target</b></u>";
}
const redrawMarks = () => frames.forEach(drawMarks);
function show(k) {
V = Math.max(0, Math.min(IM.length - 1, k));
slider.value = V;
const other = cmp ? nearestIndex(Date.parse(IM[V].t) + cmp * DAY) : -1;
paint(frames[0], IM[V], "");
paint(frames[1], IM[other], cmp > 0 ? "+24 h · " : "−24 h · ");
for (const n of [V + 1, other + 1]) if (n > 0 && IM[n]) new Image().src = IM[n].src; // la suivante, en cache
drawStrips();
}
function setCompare(c) {
cmp = c;
frames[1].hidden = !cmp;
document.querySelector("#view .viewer").style.setProperty("--n", cmp ? 2 : 1);
document.querySelectorAll("#v-cmp button").forEach(b => b.classList.toggle("active", +b.dataset.cmp === cmp));
show(V);
zoom(); // la largeur des cadres a changé : taille des noms à recalculer
}
function zoom() {
const px = W ? frames[0].clientWidth * Z.k / W : 0; // px d'écran par px de l'image
for (const f of frames) {
f.querySelector(".layer").style.transform = `translate(${Z.x * 100}%, ${Z.y * 100}%) scale(${Z.k})`;
if (px) f.querySelector("svg").style.fontSize = `${12 / px}px`; // les noms restent à 12 px à l'écran
}
}
function fit(box) { // cadre en pixels de l'image ({x: [x0, x1], y: [y0, y1]}), ou rien pour l'image entière
if (!box || !W) Z = { k: 1, x: 0, y: 0 };
else {
const [u0, u1] = box.x.map(x => x / W), [v0, v1] = box.y.map(y => y / H), k = Math.min(1 / (u1 - u0), 1 / (v1 - v0));
Z = { k, x: 0.5 - k * (u0 + u1) / 2, y: 0.5 - k * (v0 + v1) / 2 };
}
zoom();
}
function play(on) { // film : l'image suivante une fois les images décodées, au rythme choisi ; arrêt à la dernière
playing = on;
const me = ++run;
playBtn.textContent = on ? "❚❚ Pause" : "▶ Play";
if (!on) return drawStrips(); // à l'arrêt, les images d'avant et d'après reviennent
if (V === IM.length - 1) show(0);
const step = () => {
if (me !== run) return;
if (V === IM.length - 1) return play(false);
show(V + 1);
Promise.all(frames.map(f => f.querySelector("img").decode().catch(() => {})))
.then(() => setTimeout(step, 1000 / document.getElementById("v-speed").value));
};
setTimeout(step, 1000 / document.getElementById("v-speed").value);
}
for (const f of frames) {
f.addEventListener("wheel", ev => { // zoom autour du pointeur
ev.preventDefault();
const r = f.getBoundingClientRect(), u = (ev.clientX - r.left) / r.width, v = (ev.clientY - r.top) / r.height;
const k = Math.min(40, Math.max(1, Z.k * Math.exp(-ev.deltaY / 500)));
Z = { k, x: u - k * (u - Z.x) / Z.k, y: v - k * (v - Z.y) / Z.k };
zoom();
}, { passive: false });
f.addEventListener("pointerdown", ev => { // déplacement à la souris
f.setPointerCapture(ev.pointerId);
const r = f.getBoundingClientRect(), from = { ...Z, cx: ev.clientX, cy: ev.clientY };
f.onpointermove = e => { Z.x = from.x + (e.clientX - from.cx) / r.width; Z.y = from.y + (e.clientY - from.cy) / r.height; zoom(); };
f.onpointerup = () => (f.onpointermove = null);
});
f.addEventListener("dblclick", () => fit(D.view));
}
// Gros plan d'une cible, pour son aspect d'une heure ou d'un jour à l'autre (perte de visibilité, obstacle…), pas pour
// son déplacement : chaque vignette est centrée sur x, y mesurés à sa propre heure (la position médiane du capteur
// s'il n'y a pas de mesure), pixels non lissés. Une rangée par image du haut (T, et sa comparaison à ±24 h) : au centre,
// en grand, l'image du haut ; de part et d'autre, les images d'avant et d'après, au pas choisi.
const tName = document.getElementById("t-name"), tR = document.getElementById("t-r");
const tStep = document.getElementById("t-step"), tSide = document.getElementById("t-side");
const ALSO = new Set(), also = document.getElementById("t-also"); // capteurs montrés en plus de la cible du gros plan
const short = t => `${+t.slice(8, 10)}/${+t.slice(5, 7)} ${t.slice(11, 16)}`;
const BIG = 300, SMALL = 140; // côté des vignettes à l'écran, en px
let stripTimer = null, loading = [];
function crop(canvas, img, s, t) { // gros plan de s dans img (heure t) ; false s'il n'y a pas de x, y à cette heure
const r = +tR.value, j = t ? nearestIndex(Date.parse(t), TMS) : -1, measured = j >= 0 && s.x[j] !== null;
const [cx, cy] = measured ? [s.x[j], s.y[j]] : s.home;
const ctx = canvas.getContext("2d"), n = canvas.width;
ctx.imageSmoothingEnabled = n < 2 * r;
ctx.fillStyle = "#000";
ctx.fillRect(0, 0, n, n);
if (img) ctx.drawImage(img, Math.round(cx) - r, Math.round(cy) - r, 2 * r, 2 * r, 0, 0, n, n);
return measured;
}
function shift(min) { // décalage en texte : −2 h, +1 d, +15 min
const a = Math.abs(min);
return (min < 0 ? "−" : "+") + (a % 1440 === 0 ? `${a / 1440} d` : a % 60 === 0 ? `${a / 60} h` : `${a} min`);
}
function drawStrips() { // un peu après le dernier changement, pour ne pas charger chaque pas du glisseur
clearTimeout(stripTimer);
stripTimer = setTimeout(() => {
loading.forEach(im => (im.src = "")); // abandonne les images encore en chargement
loading = [];
const box = document.getElementById("t-strips"), primary = +tName.value;
const shown = [primary, ...[...ALSO].filter(i => i !== primary)].filter(i => S[i]); // la cible d'abord
const step = +tStep.value, side = playing ? 0 : +tSide.value, big = shown.length > 1 ? 200 : BIG; // en film : l'image du haut seule
const todo = new Map(); // image -> vignettes à y découper : chaque image n'est chargée qu'une fois
box.innerHTML = "";
for (const n of cmp ? [0, cmp] : [0]) for (const i of shown) { // groupées par heure : les capteurs l'un sous l'autre
const s = S[i], row = document.createElement("div"), base = IMS[V] + n * DAY;
row.className = "strip";
box.append(row);
for (let k = -side; k <= side; k++) {
const idx = nearestIndex(base + k * step * 60e3), size = k ? SMALL : big;
const label = k ? shift(k * step) : `${s.name} · ${n ? (n > 0 ? "+24 h" : "−24 h") : "T"}`;
const fig = document.createElement("figure");
if (!k) fig.className = "now";
fig.innerHTML = `<canvas width="${size}" height="${size}"></canvas><figcaption></figcaption>`;
row.append(fig);
const canvas = fig.querySelector("canvas"), cap = fig.querySelector("figcaption");
crop(canvas, null, s, null);
if (idx < 0) {
cap.textContent = `${label}\nno image`;
continue;
}
const err = errorText(s, IM[idx].t);
cap.textContent = `${label} · ${short(IM[idx].t)}\n${err ? err.text : "no error_value"}`;
cap.classList.toggle("over", !!err && err.over);
if (k) {
canvas.title = "Show this image above";
canvas.addEventListener("click", () => show(idx));
}
if (!todo.has(idx)) todo.set(idx, []);
todo.get(idx).push({ canvas, cap, s });
}
}
for (const [idx, tiles] of todo) {
const img = new Image();
img.onload = () => tiles.forEach(({ canvas, cap, s }) => {
if (!crop(canvas, img, s, IM[idx].t)) cap.textContent += "\nno x, y: median position";
});
img.src = IM[idx].src;
loading.push(img);
}
}, 120);
}
S.forEach((s, i) => { if (s.home) tName.add(new Option(`${s.name} · ${s.kind}`, i)); });
also.innerHTML = S.map((s, i) => (s.home ? `<button type="button" data-i="${i}">${s.name}</button>` : "")).join("");
const markAlso = () => also.querySelectorAll("button").forEach(b => b.classList.toggle("active", ALSO.has(+b.dataset.i)));
also.addEventListener("click", ev => { // un clic ajoute le capteur aux rangées, un second le retire
const b = ev.target.closest("button");
if (!b) return;
b.blur();
ALSO.has(+b.dataset.i) ? ALSO.delete(+b.dataset.i) : ALSO.add(+b.dataset.i);
markAlso();
drawStrips();
});
for (const name of (ASKED.get("also") || "").split(",")) if (NAMES.includes(name)) ALSO.add(NAMES.indexOf(name));
document.getElementById("t-data").addEventListener("click", () => activate(tabButton("diagnosis"))); // vers les données
markAlso();
const wanted = NAMES.indexOf(ASKED.get("target") || "PR17");
if (wanted >= 0 && S[wanted].home) tName.value = wanted;
for (const sel of [tName, tR, tStep, tSide]) sel.addEventListener("change", () => {
sel.blur(); // les flèches reviennent aux images
drawStrips();
if (sel === tName) { // la cible du gros plan : soulignée sur les grandes images, et ses rejets sous le glisseur
redrawMarks();
drawBand();
}
});
// Deux bandes sous le glisseur, une colonne par image, couleur des cercles (errorColor) : en haut, le système entier,
// moyenne sur les capteurs mesurés de error_value / seuil du capteur (rouge si la moyenne dépasse 1) ; en bas, la cible
// du gros plan, error_value face à son seuil. Les boutons mènent au début de l'épisode de rejet (de la cible) précédent
// ou suivant ; le survol donne le détail.
const IMJ = IMS.map(t => nearestIndex(t, TMS)); // mesure de chaque image, -1 sans mesure à 10 min près
const SYSTEM = IMJ.map(j => { // par image : moyenne des error_value / seuil, et nombre de capteurs rejetés / mesurés
const r = j < 0 ? [] : S.filter(s => s.values.error_value[j] !== null && s.threshold > 0)
.map(s => s.values.error_value[j] / s.threshold);
return r.length ? { mean: r.reduce((a, b) => a + b) / r.length, over: r.filter(v => v > 1).length, n: r.length } : null;
});
const band = document.getElementById("v-band");
let over = []; // par image : true si la cible dépasse son seuil, false en dessous, null sans valeur
function drawBand() {
const s = S[+tName.value];
if (!s) return;
const errs = IMJ.map(j => (j < 0 ? null : s.values.error_value[j]));
over = errs.map(e => (e === null ? null : e > s.threshold));
band.width = Math.max(1, IM.length);
const ctx = band.getContext("2d"); // ligne 0 : système ; ligne 1 : vide ; ligne 2 : cible
ctx.clearRect(0, 0, band.width, band.height);
errs.forEach((e, k) => {
ctx.fillStyle = errorColor(SYSTEM[k] && SYSTEM[k].mean, 1);
ctx.fillRect(k, 0, 1, 1);
ctx.fillStyle = errorColor(e, s.threshold);
ctx.fillRect(k, 2, 1, 1);
});
document.getElementById("v-rej").textContent =
`${s.name} above its threshold (${s.threshold}): ${over.filter(o => o).length} images in ${episodes().length} episodes`;
}
const episodes = () => over.map((o, k) => (o && !over[k - 1] ? k : -1)).filter(k => k >= 0); // début de chaque épisode
document.getElementById("v-prev-rej").addEventListener("click", ev => {
ev.currentTarget.blur();
const k = episodes().filter(k => k < V).pop();
if (k !== undefined) show(k);
});
document.getElementById("v-next-rej").addEventListener("click", ev => {
ev.currentTarget.blur();
const k = episodes().find(k => k > V);
if (k !== undefined) show(k);
});
const bandIndex = ev => {
const r = band.getBoundingClientRect();
return Math.max(0, Math.min(IM.length - 1, Math.round((ev.clientX - r.left) / r.width * (IM.length - 1))));
};
band.addEventListener("click", ev => show(bandIndex(ev)));
band.addEventListener("mousemove", ev => { // détail de l'image sous le pointeur
const k = bandIndex(ev), sys = SYSTEM[k], s = S[+tName.value], e = IMJ[k] < 0 ? null : s.values.error_value[IMJ[k]];
band.title = `${utc(IM[k].t)}\nAll sensors: ${sys ? `mean error_value / threshold ${sys.mean.toFixed(2)}, ` +
`${sys.over} of ${sys.n} above threshold` : "no value"}\n${s.name}: ${e === null ? "no value" :
`error_value ${e.toFixed(2)} ${e > s.threshold ? ">" : "≤"} ${s.threshold}`}`;
});
if (IM.length) drawBand();
for (const id of ["v-marks", "v-color"]) document.getElementById(id).addEventListener("change", ev => {
ev.target.blur();
redrawMarks();
});
const jumpDay = d => { const k = nearestIndex(Date.parse(IM[V].t) + d * DAY); if (k >= 0) show(k); };
document.addEventListener("keydown", ev => {
if (document.getElementById("p-explore").hidden || !document.getElementById("view").classList.contains("active")) return;
if (ev.target.matches("select, input:not([type=range])")) return; // les flèches restent au champ qui a le focus
const d = { ArrowLeft: -1, ArrowRight: 1 }[ev.key];
if (ev.key === " ") play(!playing);
else if (d) ev.shiftKey ? jumpDay(d) : show(V + d);
else return;
ev.preventDefault(); // ni défilement de la page, ni second pas du glisseur s'il a le focus
});
document.querySelector("#view .toolbar").addEventListener("click", ev => {
const b = ev.target.closest("button");
if (!b) return;
b.blur(); // la barre d'espace reste au film, sans recliquer le bouton
if (b.dataset.cmp !== undefined) setCompare(+b.dataset.cmp);
else if (b.id === "v-prev") show(V - 1);
else if (b.id === "v-next") show(V + 1);
else if (b.id === "v-play") play(!playing);
else if (b.id === "v-targets") fit(D.view);
else if (b.id === "v-full") fit(null);
});
slider.max = Math.max(0, IM.length - 1);
slider.addEventListener("input", () => show(+slider.value));
const daysBar = document.getElementById("v-days");
IM.forEach((im, k) => { // une étiquette sous le glisseur au début de chaque jour UTC
if (k && im.t.slice(0, 10) === IM[k - 1].t.slice(0, 10)) return;
daysBar.insertAdjacentHTML("beforeend",
`<span style="left:${100 * k / Math.max(1, IM.length - 1)}%">${+im.t.slice(8, 10)}/${+im.t.slice(5, 7)}</span>`);
});
if (ASKED.get("img")) { const k = nearestIndex(Date.parse(ASKED.get("img"))); if (k >= 0) V = k; }
if (IM.length) setCompare(cmp);
else document.querySelector("#view .viewer").innerHTML = '<p class="empty">No image in this folder.</p>';
// Page Displacements (D-055) : sauts brutaux qui durent et tendances, calculés par explore.py (regime_changes) ; les sauts
// groupés en événements, dans l'ordre du temps ; puis toutes les courbes en mm, en gris, celles qui ont sauté ou dérivé
// en couleur. Un clic sur une ligne ouvre Explore, onglet Diagnosis, sur cette cible à cette heure. Données inchangées.
const REG = D.regime, TRENDS = D.trends, RCOL = {}, RULES = D.rules;
[...REG.flatMap(e => e.targets), ...TRENDS.map(f => f.target)]
.forEach(n => { if (!(n in RCOL)) RCOL[n] = PALETTE[Object.keys(RCOL).length % PALETTE.length]; });
const signed = (v, d = 1) => `${v > 0 ? "+" : v < 0 ? "−" : ""}${Math.abs(v).toFixed(d)} mm`;
const dot = n => `<i style="background:${RCOL[n]}"></i>${n}`;
document.getElementById("r-note").textContent = `A sudden change that stays: within 2 h, the target moves at least ` +
`${RULES.abrupt} × as much as it usually does in 2 h, and its level over the next 24 h differs from the previous 24 h ` +
`by at least ${RULES.size} × its usual daily swing (median of max − min per UTC day). Daily and weather cycles are slow ` +
`and come back; these do not. Jumps within 6 h of each other form one event. Hourly export in mm, unchanged.`;
document.getElementById("r-trend-note").textContent = `A slow, steady drift: the daily level (median of each UTC day, ` +
`jumps above set aside) keeps moving the same way, and drifts over the period by at least ${RULES.trend_size} × the ` +
`usual daily swing. Needs ${RULES.trend_days} full days or more.`;
document.getElementById("r-events").innerHTML = REG.length ? REG.map(e => `
<details${e.jumps.length <= 4 ? " open" : ""}><summary><b>${e.start === e.end ? utc(e.start) : `${utc(e.start)} → ${utc(e.end)}`}</b>
· ${e.targets.length === 1 ? `${e.targets[0]} alone` : `${e.targets.length} targets together`}</summary>
<table class="rtable"><thead><tr><th>Target</th><th>Axis</th><th>When</th><th>Jump</th><th>Usual daily swing</th>
<th>Left at end of data</th></tr></thead><tbody>${e.jumps.map(f => `
<tr data-target="${f.target}" data-t="${f.t2}" title="Open in Explore · Diagnosis"><td>${dot(f.target)}</td>
<td>${f.axis}</td><td>${utc(f.t)} → ${f.t2.slice(11, 16)}</td><td>${signed(f.jump)}</td><td>${f.swing.toFixed(1)} mm</td>
<td>${signed(f.left)}</td></tr>`).join("")}
</tbody></table></details>`).join("")
: '<p class="empty">No jump: no target changed suddenly and stayed there.</p>';
document.getElementById("r-trends").innerHTML = TRENDS.length ? `<table class="rtable"><thead><tr><th>Target</th><th>Axis</th>
<th>Drift over the period</th><th>Per day</th><th>Usual daily swing</th><th>Days</th><th>Jumps set aside</th></tr></thead>
<tbody>${TRENDS.map(f => `<tr data-target="${f.target}" data-t="${f.t}" title="Open in Explore · Diagnosis">
<td>${dot(f.target)}</td><td>${f.axis}</td><td>${signed(f.drift)}</td><td>${signed(f.slope, 2)}</td>
<td>${f.swing.toFixed(1)} mm</td><td>${f.days + 1}</td><td>${f.jumps || ""}</td></tr>`).join("")}</tbody></table>`
: '<p class="empty">No trend: no daily level drifted steadily by more than its daily swing.</p>';
document.getElementById("p-displacements").addEventListener("click", ev => { // une ligne : Explore, Diagnosis, cette cible
const tr = ev.target.closest("tr[data-target]");
if (!tr) return;
goPage("explore");
activate(tabButton("diagnosis"), false);
const i = NAMES.indexOf(tr.dataset.target), j = nearestIndex(Date.parse(tr.dataset.t), TMS);
if (i >= 0) SEL = [i];
if (j >= 0) setT(j);
markTargets();
drawCurves();
});
function drawRegime() { // toutes les cibles en gris fin, celles qui ont sauté ou dérivé en couleur par-dessus
const grey = [], lit = [];
for (const [name, mm] of Object.entries(D.hourly.sensors)) [["h", "horizontal"], ["v", "vertical"]].forEach(([k, label], r) => {
const c = RCOL[name];
(c ? lit : grey).push({ type: "scatter", mode: "lines", x: D.hourly.times, y: mm[k], name, legendgroup: name,
showlegend: !!c && !r, yaxis: `y${r ? 2 : ""}`, line: { color: c || "#d3d8de", width: c ? 2 : 1 },
hovertemplate: `${name} · %{x|%d %b %H:%M} UTC (hour start)<br>${label} %{y:.2f} mm<extra></extra>` });
});
if (!grey.length && !lit.length) {
document.getElementById("r-curves").innerHTML = '<p class="empty">No hourly export: no displacement in mm.</p>';
return;
}
Plotly.newPlot("r-curves", [...grey, ...lit], {
height: 600, margin: { l: 70, r: 10, t: 40, b: 40 }, legend: { orientation: "h", x: 0, y: 1.07 },
xaxis: { type: "date", anchor: "y2" },
yaxis: { domain: [0.53, 1], fixedrange: true, title: { text: "horizontal (mm)" } },
yaxis2: { domain: [0, 0.47], fixedrange: true, title: { text: "vertical (mm)" } },
annotations: [{ text: "grey: the other targets · hourly export, in mm, hour start in UTC", xref: "paper", yref: "paper",
x: 1, y: 1.07, xanchor: "right", showarrow: false, font: { size: 11, color: "#73879c" } }],
}, CONFIG).then(() => autoscale("r-curves"));
}
// Pages : Explore ou Displacements, depuis la barre latérale. Départ : Displacements, sauf adresse d'Explore (#tab=…,
// #img=…) ou #page=explore.
function goPage(p) {
document.querySelectorAll("main > .panel").forEach(e => (e.hidden = e.id !== `p-${p}`));
document.querySelectorAll(".nav a[data-page]").forEach(a => a.classList.toggle("active", a.dataset.page === p));
const plots = p === "explore" ? "#p-explore .pane.active .js-plotly-plot" : "#p-displacements .js-plotly-plot";
document.querySelectorAll(plots).forEach(g => Plotly.Plots.resize(g));
if (p === "explore") zoom(); // la taille des noms sur les images se calcule sur un cadre visible
}
document.querySelectorAll(".nav a[data-page]").forEach(a => a.addEventListener("click", () => goPage(a.dataset.page)));
goPage(ASKED.get("page") || (location.hash.length > 1 ? "explore" : "displacements"));
drawRegime();
</script>
</body>
</html>