Add the Diagnosis tab: camera image at T and sensor-by-time grid, linked (D-053)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-10-16 14:53:52 +02:00
1 parent e1d9f78679
commit 13697e094a
1 file changed
+100
@@ -54,6 +54,13 @@
.pane.active { display: block; } .pane.active { display: block; }
.pane > img { display: block; width: 100%; margin-bottom: 8px; border: 1px solid var(--line); } .pane > img { display: block; width: 100%; margin-bottom: 8px; border: 1px solid var(--line); }
.empty { padding: 30px 0; color: var(--muted); } .empty { padding: 30px 0; color: var(--muted); }
/* Onglet Diagnosis (spec §1 à §3). */
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--text); font-size: 14px; }
.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); }
</style> </style>
</head> </head>
<body> <body>
@@ -125,6 +132,99 @@ for (const [tab, srcs] of Object.entries(D.captures)) {
if (!srcs.length) pane.innerHTML = '<p class="empty">No capture of this page.</p>'; 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="">`); for (const src of srcs) pane.insertAdjacentHTML("beforeend", `<img src="${src}" alt="">`);
} }
// Onglet Diagnosis (spec §1 à §3) : image à l'instant T et grille capteurs × temps, reliées.
const S = D.sensors, NAMES = S.map(s => s.name);
const COLUMNS = ["corr_x", "corr_y", "error_value"]; // grandeurs de la grille (spec §2)
const CAP = 10; // plafond de l'échelle de couleur, ±10 pas : choix d'affichage, pas un seuil (spec §2)
const TOL = 10 * 60e3; // image la plus proche de T, à 10 min près (spec §1)
const SCALE = [[0, "#2166ac"], [0.5, "#ffffff"], [1, "#b2182b"]]; // linéaire : négatif en bleu, positif en rouge,
// blanc au niveau des 24 premières heures, distinct du gris
const GAP = "#c8c8c8"; // case sans valeur, ligne sans niveau (spec §2)
const CONFIG = { responsive: true, scrollZoom: true, displaylogo: false };
const ASKED = new URLSearchParams(location.hash.slice(1)); // état de départ lu dans l'adresse (spec §3)
let col = COLUMNS.includes(ASKED.get("col")) ? ASKED.get("col") : "corr_y";
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
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 } });
function nearestImage() {
const t = Date.parse(D.times[T]);
let best = null, gap = Infinity;
for (const im of D.images) {
const g = Math.abs(Date.parse(im.t) - t);
if (g < gap) { gap = g; best = im; }
}
return gap <= TOL ? best : null;
}
function drawGrid() {
return Plotly.react("grid", [{
type: "heatmap", x: D.times, y: NAMES, z: S.map(s => s.dev[col]), customdata: S.map(s => s.values[col]),
zmin: -CAP, zmax: CAP, colorscale: SCALE, hoverongaps: false, colorbar: { title: { text: "steps" }, thickness: 12 },
hovertemplate: `%{y} · %{x|%d %b %H:%M} UTC<br>${col} %{customdata:.4g} · %{z:.1f} steps<extra></extra>`,
}], {
height: 80 + 18 * S.length, margin: { l: 60, r: 10, t: 10, b: 40 }, plot_bgcolor: GAP, uirevision: "grid",
xaxis: { type: "date" }, yaxis: { autorange: "reversed", fixedrange: true, dtick: 1 }, shapes: [tLine()],
}, CONFIG);
}
function drawImage() {
const im = nearestImage();
const seen = S.map((s, i) => i).filter(i => S[i].x[T] !== null && S[i].y[T] !== null);
const markers = (ids, marker) => ({
type: "scatter", mode: "markers+text", x: ids.map(i => S[i].x[T]), y: ids.map(i => S[i].y[T]),
text: ids.map(i => NAMES[i]), customdata: ids, textposition: "top center", textfont: { color: "#fff", size: 11 },
marker: { size: 13, line: { color: "#fff", width: 1 }, ...marker }, hovertemplate: "%{text}<extra></extra>",
showlegend: false,
});
const valued = seen.filter(i => S[i].dev[col][T] !== null), blank = seen.filter(i => S[i].dev[col][T] === null);
const v = D.view || { x: [0, W || 1], y: [0, H || 1] };
return Plotly.react("image", [
markers(valued, { color: valued.map(i => S[i].dev[col][T]), cmin: -CAP, cmax: CAP, colorscale: SCALE }),
markers(blank, { color: GAP }),
], {
height: 520, margin: { l: 10, r: 10, t: 34, b: 10 }, plot_bgcolor: "#000", uirevision: "image",
title: { text: im ? `Image ${utc(im.t)}` : "", font: { size: 13 } },
xaxis: { range: v.x, showgrid: false, zeroline: false, showticklabels: false },
yaxis: { range: [v.y[1], v.y[0]], showgrid: false, zeroline: false, showticklabels: false, scaleanchor: "x" },
images: im && W ? [{ source: im.src, xref: "x", yref: "y", x: 0, y: 0, sizex: W, sizey: H,
xanchor: "left", yanchor: "top", sizing: "stretch", layer: "below" }] : [],
annotations: im ? [] : [{ text: "No image at this time", xref: "paper", yref: "paper", x: 0.5, y: 0.97,
showarrow: false, font: { color: "#fff", size: 15 } }],
}, CONFIG);
}
function setT(j) {
T = j;
document.getElementById("instant").textContent = `T = ${utc(D.times[T])}`;
Plotly.relayout("grid", { shapes: [tLine()] });
drawImage();
}
const columns = document.getElementById("columns");
columns.innerHTML = COLUMNS.map(c => `<button type="button" data-col="${c}">${c}</button>`).join("");
const markColumn = () => columns.querySelectorAll("button").forEach(b => b.classList.toggle("active", b.dataset.col === col));
columns.addEventListener("click", ev => {
if (!ev.target.dataset.col) return;
col = ev.target.dataset.col;
markColumn();
drawGrid();
drawImage();
});
markColumn();
document.getElementById("instant").textContent = `T = ${utc(D.times[T])}`;
Promise.all([drawGrid(), drawImage()]).then(() => {
document.getElementById("grid").on("plotly_click", ev => setT(ev.points[0].pointNumber[1]));
});
if (D.images.length) { // la taille de l'image, lue sur la première, place la photo sous les marqueurs
const probe = new Image();
probe.onload = () => { W = probe.naturalWidth; H = probe.naturalHeight; drawImage(); };
probe.src = D.images[0].src;
}
</script> </script>
</body> </body>
</html> </html>