[feat](trx-frontend-http): replace header graph with adaptive strip

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
2026-02-28 00:04:17 +01:00
parent fffc4c6b90
commit c010073e0c
3 changed files with 189 additions and 105 deletions
@@ -313,7 +313,9 @@ const rigSubtitle = document.getElementById("rig-subtitle");
const ownerSubtitle = document.getElementById("owner-subtitle");
const loadingTitle = document.getElementById("loading-title");
const loadingSub = document.getElementById("loading-sub");
const headerSigCanvas = document.getElementById("header-sig-canvas");
const overviewCanvas = document.getElementById("overview-canvas");
const overviewLabel = document.getElementById("overview-label");
const overviewPeakHoldEl = document.getElementById("overview-peak-hold");
const themeToggleBtn = document.getElementById("theme-toggle");
const rigSwitchSelect = document.getElementById("rig-switch-select");
const rigSwitchBtn = document.getElementById("rig-switch-btn");
@@ -364,6 +366,18 @@ function setTheme(theme) {
}
}
if (overviewPeakHoldEl) {
if (!Number.isFinite(overviewPeakHoldMs) || overviewPeakHoldMs <= 0) {
overviewPeakHoldMs = 2000;
}
overviewPeakHoldEl.value = String(overviewPeakHoldMs);
overviewPeakHoldEl.addEventListener("change", () => {
overviewPeakHoldMs = Math.max(0, Number(overviewPeakHoldEl.value) || 0);
saveSetting("overviewPeakHoldMs", overviewPeakHoldMs);
scheduleOverviewDraw();
});
}
if (savedTheme === "light" || savedTheme === "dark") {
setTheme(savedTheme);
} else {
@@ -375,6 +389,7 @@ if (themeToggleBtn) {
themeToggleBtn.addEventListener("click", () => {
setTheme(currentTheme() === "dark" ? "light" : "dark");
updateMapBaseLayerForTheme(currentTheme());
scheduleOverviewDraw();
});
}
@@ -464,139 +479,170 @@ let lastEventAt = Date.now();
let es;
let esHeartbeat;
let reconnectTimer = null;
let headerSigSamples = [];
let headerSigTimer = null;
let overviewSignalSamples = [];
let overviewSignalTimer = null;
let overviewWaterfallRows = [];
let overviewDrawPending = false;
const HEADER_SIG_WINDOW_MS = 10_000;
let overviewPeakHoldMs = Number(loadSetting("overviewPeakHoldMs", 2000));
function resizeHeaderSignalCanvas() {
if (!headerSigCanvas) return;
const cssW = Math.floor(headerSigCanvas.clientWidth);
const cssH = Math.floor(headerSigCanvas.clientHeight);
if (!overviewCanvas) return;
const cssW = Math.floor(overviewCanvas.clientWidth);
const cssH = Math.floor(overviewCanvas.clientHeight);
if (cssW <= 0 || cssH <= 0) return;
const dpr = window.devicePixelRatio || 1;
const nextW = Math.floor(cssW * dpr);
const nextH = Math.floor(cssH * dpr);
if (headerSigCanvas.width !== nextW || headerSigCanvas.height !== nextH) {
headerSigCanvas.width = nextW;
headerSigCanvas.height = nextH;
if (overviewCanvas.width !== nextW || overviewCanvas.height !== nextH) {
overviewCanvas.width = nextW;
overviewCanvas.height = nextH;
trimOverviewWaterfallRows();
}
drawHeaderSignalGraph();
}
function scheduleOverviewDraw() {
if (!overviewCanvas || overviewDrawPending) return;
overviewDrawPending = true;
requestAnimationFrame(() => {
overviewDrawPending = false;
drawHeaderSignalGraph();
});
}
function pushHeaderSignalSample(sUnits) {
if (!headerSigCanvas) return;
if (!overviewCanvas) return;
const now = Date.now();
const sample = Number.isFinite(sUnits) ? Math.max(0, Math.min(20, sUnits)) : 0;
headerSigSamples.push({ t: now, v: sample });
while (headerSigSamples.length && now - headerSigSamples[0].t > HEADER_SIG_WINDOW_MS) {
headerSigSamples.shift();
overviewSignalSamples.push({ t: now, v: sample });
while (overviewSignalSamples.length && now - overviewSignalSamples[0].t > HEADER_SIG_WINDOW_MS) {
overviewSignalSamples.shift();
}
drawHeaderSignalGraph();
scheduleOverviewDraw();
}
function trimOverviewWaterfallRows() {
if (!overviewCanvas) return;
const dpr = window.devicePixelRatio || 1;
const maxRows = Math.max(1, Math.floor(overviewCanvas.height / dpr));
while (overviewWaterfallRows.length > maxRows) {
overviewWaterfallRows.shift();
}
}
function pushOverviewWaterfallFrame(data) {
if (!overviewCanvas || !data || !Array.isArray(data.bins) || data.bins.length === 0) return;
overviewWaterfallRows.push(data.bins.slice());
trimOverviewWaterfallRows();
scheduleOverviewDraw();
}
function startHeaderSignalSampling() {
if (!headerSigCanvas || headerSigTimer) return;
headerSigTimer = setInterval(() => {
if (!overviewCanvas || overviewSignalTimer) return;
overviewSignalTimer = setInterval(() => {
pushHeaderSignalSample(Number.isFinite(sigLastSUnits) ? sigLastSUnits : 0);
}, 120);
}
function drawHeaderSignalGraph() {
if (!headerSigCanvas) return;
const ctx = headerSigCanvas.getContext("2d");
if (!overviewCanvas) return;
const ctx = overviewCanvas.getContext("2d");
if (!ctx) return;
const isLight = currentTheme() === "light";
const dpr = window.devicePixelRatio || 1;
const w = headerSigCanvas.width / dpr;
const h = headerSigCanvas.height / dpr;
const w = overviewCanvas.width / dpr;
const h = overviewCanvas.height / dpr;
if (w <= 0 || h <= 0) return;
ctx.save();
ctx.scale(dpr, dpr);
ctx.clearRect(0, 0, w, h);
if (lastSpectrumData && overviewWaterfallRows.length > 0) {
if (overviewLabel) overviewLabel.textContent = "Waterfall";
drawOverviewWaterfall(ctx, w, h, isLight);
} else {
if (overviewLabel) overviewLabel.textContent = "Signal History";
drawOverviewSignalHistory(ctx, w, h, isLight);
}
ctx.restore();
}
// Soft horizontal guides for readability.
ctx.strokeStyle = isLight ? "rgba(71, 85, 105, 0.26)" : "rgba(148, 163, 184, 0.16)";
function drawOverviewWaterfall(ctx, w, h, isLight) {
const rows = overviewWaterfallRows.slice(-Math.max(1, Math.floor(h)));
if (rows.length === 0) return;
const rowH = h / rows.length;
for (let rowIdx = 0; rowIdx < rows.length; rowIdx++) {
const bins = rows[rowIdx];
if (!Array.isArray(bins) || bins.length === 0) continue;
const y = h - (rows.length - rowIdx) * rowH;
for (let x = 0; x < w; x++) {
const binIdx = Math.floor((x / Math.max(1, w - 1)) * (bins.length - 1));
ctx.fillStyle = waterfallColor(bins[binIdx], isLight);
ctx.fillRect(x, y, 1.25, rowH + 1);
}
}
}
function drawOverviewSignalHistory(ctx, w, h, isLight) {
const now = Date.now();
const samples = overviewSignalSamples.filter((sample) => now - sample.t <= HEADER_SIG_WINDOW_MS);
if (samples.length === 0) return;
const maxVal = 20;
const windowStart = now - HEADER_SIG_WINDOW_MS;
const toX = (t) => ((t - windowStart) / HEADER_SIG_WINDOW_MS) * w;
const toY = (v) => h - (Math.max(0, Math.min(maxVal, v)) / maxVal) * (h - 3) - 1.5;
ctx.strokeStyle = isLight ? "rgba(71, 85, 105, 0.14)" : "rgba(148, 163, 184, 0.12)";
ctx.lineWidth = 1;
for (let i = 1; i <= 3; i++) {
const y = Math.round((h * i) / 4) + 0.5;
for (const val of [0, 9, 18]) {
const y = toY(val);
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(w, y);
ctx.stroke();
}
// Minimal S-unit scale markers.
const yFor = (v) => h - (Math.max(0, Math.min(20, v)) / 20) * (h - 2) - 1;
ctx.fillStyle = isLight ? "rgba(30, 41, 59, 0.62)" : "rgba(154, 164, 181, 0.55)";
ctx.font = "10px sans-serif";
ctx.textAlign = "right";
ctx.textBaseline = "middle";
[["S9+", 18], ["S9", 9], ["S0", 0]].forEach(([label, val]) => {
const y = yFor(val);
ctx.fillText(label, w - 4, y);
ctx.strokeStyle = isLight ? "rgba(51, 65, 85, 0.22)" : "rgba(154, 164, 181, 0.22)";
ctx.beginPath();
ctx.moveTo(2, y + 0.5);
ctx.lineTo(w - 36, y + 0.5);
ctx.stroke();
});
if (headerSigSamples.length > 1) {
const maxVal = 20; // includes S9+ scale overshoot.
const toY = (v) => h - (Math.max(0, Math.min(maxVal, v)) / maxVal) * (h - 2) - 1;
const now = Date.now();
const windowStart = now - HEADER_SIG_WINDOW_MS;
const toX = (t) => ((t - windowStart) / HEADER_SIG_WINDOW_MS) * w;
const strengthGrad = ctx.createLinearGradient(0, h, 0, 0);
const fillGrad = ctx.createLinearGradient(0, h, 0, 0);
if (isLight) {
// Higher-contrast palette for bright backgrounds.
strengthGrad.addColorStop(0.0, "rgba(0, 86, 255, 0.95)"); // weak: deep blue
strengthGrad.addColorStop(0.5, "rgba(0, 179, 255, 0.95)");
strengthGrad.addColorStop(0.8, "rgba(255, 133, 0, 0.97)");
strengthGrad.addColorStop(1.0, "rgba(224, 36, 36, 0.98)"); // strong: red
fillGrad.addColorStop(0.0, "rgba(0, 86, 255, 0.18)");
fillGrad.addColorStop(0.5, "rgba(0, 179, 255, 0.20)");
fillGrad.addColorStop(0.8, "rgba(255, 133, 0, 0.22)");
fillGrad.addColorStop(1.0, "rgba(224, 36, 36, 0.24)");
} else {
strengthGrad.addColorStop(0.0, "rgba(64, 120, 255, 0.88)"); // weak: blue
strengthGrad.addColorStop(0.5, "rgba(106, 186, 255, 0.9)");
strengthGrad.addColorStop(0.8, "rgba(255, 166, 77, 0.9)");
strengthGrad.addColorStop(1.0, "rgba(255, 78, 78, 0.92)"); // strong: red
fillGrad.addColorStop(0.0, "rgba(64, 120, 255, 0.12)");
fillGrad.addColorStop(0.5, "rgba(106, 186, 255, 0.16)");
fillGrad.addColorStop(0.8, "rgba(255, 166, 77, 0.18)");
fillGrad.addColorStop(1.0, "rgba(255, 78, 78, 0.2)");
}
ctx.beginPath();
headerSigSamples.forEach((sample, i) => {
samples.forEach((sample, idx) => {
const x = toX(sample.t);
const y = toY(sample.v);
if (i === 0) ctx.moveTo(x, y);
if (idx === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
});
ctx.lineTo(w, h);
ctx.lineTo(0, h);
ctx.closePath();
ctx.fillStyle = fillGrad;
ctx.fill();
ctx.strokeStyle = isLight ? "rgba(17, 94, 89, 0.95)" : "rgba(94, 234, 212, 0.92)";
ctx.lineWidth = 1.6;
ctx.stroke();
const holdMs = Math.max(0, Number.isFinite(overviewPeakHoldMs) ? overviewPeakHoldMs : 0);
if (holdMs > 0) {
ctx.beginPath();
headerSigSamples.forEach((sample, i) => {
const x = toX(sample.t);
const y = toY(sample.v);
for (let i = 0; i < samples.length; i++) {
let peak = samples[i].v;
for (let j = i; j >= 0; j--) {
if (samples[i].t - samples[j].t > holdMs) break;
if (samples[j].v > peak) peak = samples[j].v;
}
const x = toX(samples[i].t);
const y = toY(peak);
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
});
ctx.strokeStyle = strengthGrad;
ctx.lineWidth = 1.25;
}
ctx.strokeStyle = isLight ? "rgba(217, 119, 6, 0.9)" : "rgba(251, 191, 36, 0.88)";
ctx.lineWidth = 1;
ctx.stroke();
}
}
ctx.restore();
function waterfallColor(db, isLight) {
const clamped = Math.max(-120, Math.min(-10, Number.isFinite(db) ? db : -120));
const t = (clamped + 120) / 110;
const hue = isLight ? 210 - t * 175 : 225 - t * 195;
const sat = isLight ? 82 : 88;
const light = isLight ? 92 - t * 52 : 16 + t * 52;
const alpha = isLight ? 0.42 + t * 0.38 : 0.28 + t * 0.58;
return `hsla(${hue}, ${sat}%, ${light}%, ${alpha})`;
}
function formatFreq(hz) {
@@ -2578,11 +2624,14 @@ function startSpectrumStreaming() {
spectrumSource.onmessage = (evt) => {
if (evt.data === "null") {
lastSpectrumData = null;
overviewWaterfallRows = [];
scheduleOverviewDraw();
clearSpectrumCanvas();
return;
}
try {
lastSpectrumData = JSON.parse(evt.data);
pushOverviewWaterfallFrame(lastSpectrumData);
refreshCenterFreqDisplay();
scheduleSpectrumDraw();
} catch (_) {}
@@ -2607,6 +2656,8 @@ function stopSpectrumStreaming() {
}
spectrumDrawPending = false;
lastSpectrumData = null;
overviewWaterfallRows = [];
scheduleOverviewDraw();
clearSpectrumCanvas();
}
@@ -18,9 +18,6 @@
<div class="subtitle" id="rig-subtitle" style="font-weight: 700;">Rig: --</div>
<div class="subtitle" id="owner-subtitle">Owner: --</div>
</div>
<div class="header-signal-wrap" aria-hidden="true">
<canvas id="header-sig-canvas"></canvas>
</div>
<div class="header-right">
<img id="logo" class="header-logo" src="/logo.png?v=1" alt="trx logo" onerror="this.style.display='none'" />
<div class="header-rig-switch">
@@ -33,6 +30,20 @@
</div>
</div>
</div>
<div class="overview-strip">
<div class="overview-toolbar">
<span class="overview-label" id="overview-label">Signal History</span>
<label class="overview-control">Peak Hold
<select id="overview-peak-hold" class="status-input">
<option value="500">0.5 s</option>
<option value="1000">1 s</option>
<option value="2000" selected>2 s</option>
<option value="5000">5 s</option>
</select>
</label>
</div>
<canvas id="overview-canvas" aria-hidden="true"></canvas>
</div>
<!-- Auth gate (hidden by default, shown if auth is required) -->
<div id="auth-gate" style="display:none; padding: 3rem 2rem; text-align: center;">
<div style="margin-bottom: 1.5rem;">
@@ -332,7 +332,7 @@ button:disabled { opacity: 0.6; cursor: not-allowed; }
small { color: var(--text-muted); }
.header {
display: grid;
grid-template-columns: 16em 1fr auto;
grid-template-columns: minmax(0, 1fr) auto;
align-items: center;
column-gap: 1.5em;
margin-bottom: 0.25rem;
@@ -343,20 +343,42 @@ small { color: var(--text-muted); }
flex: 0 0 16em;
}
.title { font-size: 1.4rem; font-weight: 700; display: inline-flex; align-items: center; gap: 0.35rem; }
.header-signal-wrap {
.overview-strip {
width: 100%;
min-width: 160px;
height: clamp(2.6rem, 8vh, 4.5rem);
margin: 0;
border: 1px solid color-mix(in srgb, var(--border-light) 55%, transparent);
border-radius: 8px;
background: color-mix(in srgb, var(--input-bg) 72%, transparent);
opacity: 0.45;
overflow: hidden;
margin: 0.35rem 0 0.95rem;
}
#header-sig-canvas {
.overview-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.75rem;
margin-bottom: 0.25rem;
}
.overview-label {
color: var(--text-heading);
font-size: 0.82rem;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.overview-control {
display: inline-flex;
align-items: center;
gap: 0.4rem;
color: var(--text-muted);
font-size: 0.8rem;
white-space: nowrap;
}
.overview-control .status-input {
width: auto;
min-width: 4.6rem;
padding-top: 0.22rem;
padding-bottom: 0.22rem;
font-size: 0.85rem;
}
#overview-canvas {
width: 100%;
height: 100%;
height: clamp(4.2rem, 11vh, 6.25rem);
display: block;
}
.header-right {
@@ -598,10 +620,10 @@ button:focus-visible, input:focus-visible, select:focus-visible {
.freq-inline { gap: 0.5rem; }
.freq-inline { flex-wrap: wrap; }
.header-text { width: auto; min-width: 0; flex: 0 1 auto; }
.header-signal-wrap { display: none; }
.header-right { align-items: flex-end; }
.header-rig-switch { width: 100%; justify-content: flex-end; }
.header-rig-switch select { min-width: 6.5rem; }
.overview-toolbar { flex-wrap: wrap; }
.controls-row { grid-template-columns: 1fr auto; }
.controls-col-wfm { grid-column: 1 / -1; }
.controls-col-power { grid-column: 1 / -1; }