: asapien/superpulse

commit fe84180173e0a723d113638fc9f2019d673b1aaa
parent beb70eea3e80cee4b54d7f679b27d98a8d9e921c
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Wed, 7 Oct 2026 17:23:21 +0530

Finish ponytail cleanup
2 files changed, 201 insertions(+), 75 deletions(-)
M
tva-control.css
|
150
+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
M
tva-control.js
|
126
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
diff --git a/tva-control.css b/tva-control.css
@@ -1,4 +1,34 @@
 /* Standalone TVA control styles. Pair with tva-control.js. */
+
+:root {
+  --tva-light-bg: #f1f5f4;
+  --tva-light-border: #dde7e5;
+  --tva-light-plot-glow: rgba(255, 0, 85, 0.06);
+  --tva-light-control-active-bg: rgba(0, 128, 112, 0.1);
+  --tva-light-control-border-muted: rgba(0, 128, 112, 0.3);
+  --tva-light-double-red-shadow: rgba(255, 0, 0, 0.34);
+  --tva-light-control-bg: rgba(255, 255, 255, 0.86);
+  --tva-light-control-border: rgba(0, 128, 112, 0.34);
+  --tva-light-control-border-active: rgba(0, 128, 112, 0.82);
+  --tva-light-control-text: #173f3a;
+  --tva-light-title: #006f62;
+  --tva-light-alert-amber: #8a5c00;
+  --tva-light-alert-red: #c00045;
+  --tva-light-alert-double-red: #b00000;
+  --tva-light-fullscreen-border: rgba(208, 0, 75, 0.5);
+  --tva-light-fullscreen-shadow: rgba(208, 0, 75, 0.16);
+  --tva-light-fullscreen-inset: rgba(0, 128, 112, 0.04);
+  --tva-light-chart-grid: rgba(0, 48, 87, 0.055);
+  --tva-light-axis-text: #173f3a;
+  --tva-light-detail-axis-text: #49615e;
+  --tva-light-plot-icon: #111827;
+  --tva-light-stale-text: #4f646e;
+  --tva-light-stale-label-fill: rgba(255, 255, 255, 0.88);
+  --tva-light-normal-label-fill: rgba(255, 255, 255, 0.82);
+  --tva-light-normal-label-stroke: rgba(23, 63, 58, 0.24);
+  --tva-light-normal-line: #90a4ae;
+  --tva-light-border-alert-color: #c40000;
+}
 .tva-control-container,
 .action-chart-container {
   color-scheme: dark;

@@ -38,74 +68,74 @@
 .tva-control-container[data-tva-theme="light"],
 .action-chart-container[data-tva-theme="light"] {
   color-scheme: light;
-  --tva-bg: #f1f5f4;
-  --tva-border: #dde7e5;
-  --tva-plot-glow: rgba(255, 0, 85, 0.06);
+  --tva-bg: var(--tva-light-bg);
+  --tva-border: var(--tva-light-border);
+  --tva-plot-glow: var(--tva-light-plot-glow);
   --tva-white: #ffffff;
-  --tva-control-active-bg: rgba(0, 128, 112, 0.1);
-  --tva-control-border-muted: rgba(0, 128, 112, 0.3);
-  --tva-double-red-shadow: rgba(255, 0, 0, 0.34);
-  --tva-control-bg: rgba(255, 255, 255, 0.86);
-  --tva-control-border: rgba(0, 128, 112, 0.34);
-  --tva-control-border-active: rgba(0, 128, 112, 0.82);
-  --tva-control-text: #173f3a;
-  --tva-title: #006f62;
-  --tva-alert-amber: #8a5c00;
-  --tva-alert-red: #c00045;
-  --tva-alert-double-red: #b00000;
-  --tva-icon-cutout: #f1f5f4;
-  --tva-fullscreen-border: rgba(208, 0, 75, 0.5);
-  --tva-fullscreen-shadow: rgba(208, 0, 75, 0.16);
-  --tva-fullscreen-inset: rgba(0, 128, 112, 0.04);
-  --tva-chart-grid: rgba(0, 48, 87, 0.055);
-  --tva-chart-detail-grid: rgba(0, 48, 87, 0.055);
-  --tva-axis-text: #173f3a;
-  --tva-detail-axis-text: #49615e;
-  --tva-plot-icon: #111827;
-  --tva-stale-text: #4f646e;
-  --tva-stale-label-fill: rgba(255, 255, 255, 0.88);
-  --tva-normal-label-fill: rgba(255, 255, 255, 0.82);
-  --tva-normal-label-stroke: rgba(23, 63, 58, 0.24);
-  --tva-normal-line: #90a4ae;
-  --tva-stale-line: #90a4ae;
-  --tva-border-alert-color: #c40000;
+  --tva-control-active-bg: var(--tva-light-control-active-bg);
+  --tva-control-border-muted: var(--tva-light-control-border-muted);
+  --tva-double-red-shadow: var(--tva-light-double-red-shadow);
+  --tva-control-bg: var(--tva-light-control-bg);
+  --tva-control-border: var(--tva-light-control-border);
+  --tva-control-border-active: var(--tva-light-control-border-active);
+  --tva-control-text: var(--tva-light-control-text);
+  --tva-title: var(--tva-light-title);
+  --tva-alert-amber: var(--tva-light-alert-amber);
+  --tva-alert-red: var(--tva-light-alert-red);
+  --tva-alert-double-red: var(--tva-light-alert-double-red);
+  --tva-icon-cutout: var(--tva-light-bg);
+  --tva-fullscreen-border: var(--tva-light-fullscreen-border);
+  --tva-fullscreen-shadow: var(--tva-light-fullscreen-shadow);
+  --tva-fullscreen-inset: var(--tva-light-fullscreen-inset);
+  --tva-chart-grid: var(--tva-light-chart-grid);
+  --tva-chart-detail-grid: var(--tva-light-chart-grid);
+  --tva-axis-text: var(--tva-light-axis-text);
+  --tva-detail-axis-text: var(--tva-light-detail-axis-text);
+  --tva-plot-icon: var(--tva-light-plot-icon);
+  --tva-stale-text: var(--tva-light-stale-text);
+  --tva-stale-label-fill: var(--tva-light-stale-label-fill);
+  --tva-normal-label-fill: var(--tva-light-normal-label-fill);
+  --tva-normal-label-stroke: var(--tva-light-normal-label-stroke);
+  --tva-normal-line: var(--tva-light-normal-line);
+  --tva-stale-line: var(--tva-light-normal-line);
+  --tva-border-alert-color: var(--tva-light-border-alert-color);
 }
 
 @media (prefers-color-scheme: light) {
   .tva-control-container:not([data-tva-theme="dark"]),
   .action-chart-container:not([data-tva-theme="dark"]) {
     color-scheme: light;
-    --tva-bg: #f1f5f4;
-    --tva-border: #dde7e5;
-    --tva-plot-glow: rgba(255, 0, 85, 0.06);
+    --tva-bg: var(--tva-light-bg);
+    --tva-border: var(--tva-light-border);
+    --tva-plot-glow: var(--tva-light-plot-glow);
     --tva-white: #ffffff;
-    --tva-control-active-bg: rgba(0, 128, 112, 0.1);
-    --tva-control-border-muted: rgba(0, 128, 112, 0.3);
-    --tva-double-red-shadow: rgba(255, 0, 0, 0.34);
-    --tva-control-bg: rgba(255, 255, 255, 0.86);
-    --tva-control-border: rgba(0, 128, 112, 0.34);
-    --tva-control-border-active: rgba(0, 128, 112, 0.82);
-    --tva-control-text: #173f3a;
-    --tva-title: #006f62;
-    --tva-alert-amber: #8a5c00;
-    --tva-alert-red: #c00045;
-    --tva-alert-double-red: #b00000;
-    --tva-icon-cutout: #f1f5f4;
-    --tva-fullscreen-border: rgba(208, 0, 75, 0.5);
-    --tva-fullscreen-shadow: rgba(208, 0, 75, 0.16);
-    --tva-fullscreen-inset: rgba(0, 128, 112, 0.04);
-    --tva-chart-grid: rgba(0, 48, 87, 0.055);
-    --tva-chart-detail-grid: rgba(0, 48, 87, 0.055);
-    --tva-axis-text: #173f3a;
-    --tva-detail-axis-text: #49615e;
-    --tva-plot-icon: #111827;
-    --tva-stale-text: #4f646e;
-    --tva-stale-label-fill: rgba(255, 255, 255, 0.88);
-    --tva-normal-label-fill: rgba(255, 255, 255, 0.82);
-    --tva-normal-label-stroke: rgba(23, 63, 58, 0.24);
-    --tva-normal-line: #90a4ae;
-    --tva-stale-line: #90a4ae;
-    --tva-border-alert-color: #c40000;
+    --tva-control-active-bg: var(--tva-light-control-active-bg);
+    --tva-control-border-muted: var(--tva-light-control-border-muted);
+    --tva-double-red-shadow: var(--tva-light-double-red-shadow);
+    --tva-control-bg: var(--tva-light-control-bg);
+    --tva-control-border: var(--tva-light-control-border);
+    --tva-control-border-active: var(--tva-light-control-border-active);
+    --tva-control-text: var(--tva-light-control-text);
+    --tva-title: var(--tva-light-title);
+    --tva-alert-amber: var(--tva-light-alert-amber);
+    --tva-alert-red: var(--tva-light-alert-red);
+    --tva-alert-double-red: var(--tva-light-alert-double-red);
+    --tva-icon-cutout: var(--tva-light-bg);
+    --tva-fullscreen-border: var(--tva-light-fullscreen-border);
+    --tva-fullscreen-shadow: var(--tva-light-fullscreen-shadow);
+    --tva-fullscreen-inset: var(--tva-light-fullscreen-inset);
+    --tva-chart-grid: var(--tva-light-chart-grid);
+    --tva-chart-detail-grid: var(--tva-light-chart-grid);
+    --tva-axis-text: var(--tva-light-axis-text);
+    --tva-detail-axis-text: var(--tva-light-detail-axis-text);
+    --tva-plot-icon: var(--tva-light-plot-icon);
+    --tva-stale-text: var(--tva-light-stale-text);
+    --tva-stale-label-fill: var(--tva-light-stale-label-fill);
+    --tva-normal-label-fill: var(--tva-light-normal-label-fill);
+    --tva-normal-label-stroke: var(--tva-light-normal-label-stroke);
+    --tva-normal-line: var(--tva-light-normal-line);
+    --tva-stale-line: var(--tva-light-normal-line);
+    --tva-border-alert-color: var(--tva-light-border-alert-color);
   }
 }
 
diff --git a/tva-control.js b/tva-control.js
@@ -152,15 +152,31 @@
     let updatedAtByKey = Object.fromEntries(metricKeys.map(k => [k, Date.now()]));
     if (data.updatedAt) Object.entries(data.updatedAt).forEach(([k, v]) => { const ts = typeof v === 'string' ? Date.parse(v) : number(v, NaN); if (Number.isFinite(ts)) updatedAtByKey[k] = ts; });
 
-    const controls = document.createElement('div'); controls.className = 'tva-chart-controls';
-    const modeOptions = [{ key: 'timeline', label: init.title || 'Timeline' }, ...parameters.filter(p => p.detailMode).map(p => ({ key: p.detailMode, label: p.detailTitle || `${p.label} Area Scan` }))];
-    controls.innerHTML = `<button type="button" class="tva-chart-back" hidden>←</button><label class="tva-chart-heading"><span class="sr-only">Chart type</span><select class="tva-chart-mode-select">${modeOptions.map(o => `<option value="${escapeAttr(o.key)}">${escapeAttr(o.label)}</option>`).join('')}</select></label><button type="button" class="tva-chart-fullscreen" title="Fullscreen chart" aria-label="Fullscreen chart"><span class="tva-fullscreen-icon" aria-hidden="true"></span></button>`;
-    const alertBadge = document.createElement('div'); alertBadge.className = 'tva-alert-badge'; alertBadge.hidden = true;
+    const controls = document.createElement('div');
+    controls.className = 'tva-chart-controls';
+    const modeOptions = [
+      { key: 'timeline', label: init.title || 'Timeline' },
+      ...parameters.filter(p => p.detailMode).map(p => ({ key: p.detailMode, label: p.detailTitle || `${p.label} Area Scan` }))
+    ];
+    const modeOptionHtml = modeOptions.map(o => `<option value="${escapeAttr(o.key)}">${escapeAttr(o.label)}</option>`).join('');
+    controls.innerHTML = `
+      <button type="button" class="tva-chart-back" hidden>←</button>
+      <label class="tva-chart-heading"><span class="sr-only">Chart type</span><select class="tva-chart-mode-select">${modeOptionHtml}</select></label>
+      <button type="button" class="tva-chart-fullscreen" title="Fullscreen chart" aria-label="Fullscreen chart"><span class="tva-fullscreen-icon" aria-hidden="true"></span></button>
+    `;
+    const alertBadge = document.createElement('div');
+    alertBadge.className = 'tva-alert-badge';
+    alertBadge.hidden = true;
     if (!container.querySelector('.tva-chart-controls')) container.prepend(controls);
     if (!container.querySelector('.tva-alert-badge')) container.prepend(alertBadge);
     controls.querySelector('.tva-chart-back').onclick = () => switchMode('timeline');
     controls.querySelector('.tva-chart-mode-select').onchange = e => switchMode(e.target.value);
-    controls.querySelector('.tva-chart-fullscreen').onclick = () => { container.classList.toggle('tva-chart-fullscreen-mode'); syncControls(); chart && chart.resize(); chart && chart.update('none'); };
+    controls.querySelector('.tva-chart-fullscreen').onclick = () => {
+      container.classList.toggle('tva-chart-fullscreen-mode');
+      syncControls();
+      chart && chart.resize();
+      chart && chart.update('none');
+    };
 
     function getValue(p) { return number(state[p.key], number(p.defaultValue)); }
     function limit(p, level, side, fallback) { return number(p.thresholds && p.thresholds[`${camel(level.key)}${side}`], fallback); }

@@ -177,9 +193,24 @@
     function breachedLevel(i, v) { let hit = null; levels.forEach(l => { if (v > limit(parameters[i], l, 'Upper', Infinity) || v < limit(parameters[i], l, 'Lower', -Infinity)) hit = l; }); return hit; }
     function staleColor(full = false) { return full ? state.colors.stale : colorWithAlpha(state.colors.stale, number(state.staleAlpha, 0.35)); }
     function metricColor(i, v) { if (isMetricStale(i)) return staleColor(false); const l = breachedLevel(i, v); return l ? levelColor(l) : state.colors.normal; }
-    function formatPoint(p) { const v = getValue(p), d = p.display || {}, dec = Number.isInteger(d.decimals) ? d.decimals : 0; const s = Number.isInteger(v) || dec === 0 ? String(Math.round(v)) : v.toFixed(dec); return `${d.prefix || ''}${s}${d.suffix || ''}`; }
-    function trend(i) { const v = values(); return getTrend(previousMetricValues && previousMetricValues[i], v[i], number(state.trendThreshold, 15)); }
-    function zoomBounds(vs) { let min = Math.min(0, ...vs), max = Math.max(0, ...vs); if (min === max) { min -= 10; max += 10; } const pad = Math.max(8, (max - min) * .24); return { min: Math.floor(min - pad), max: Math.ceil(max + pad) }; }
+    function formatPoint(p) {
+      const v = getValue(p);
+      const d = p.display || {};
+      const decimals = Number.isInteger(d.decimals) ? d.decimals : 0;
+      const text = Number.isInteger(v) || decimals === 0 ? String(Math.round(v)) : v.toFixed(decimals);
+      return `${d.prefix || ''}${text}${d.suffix || ''}`;
+    }
+    function trend(i) {
+      const v = values();
+      return getTrend(previousMetricValues && previousMetricValues[i], v[i], number(state.trendThreshold, 15));
+    }
+    function zoomBounds(vs) {
+      let min = Math.min(0, ...vs);
+      let max = Math.max(0, ...vs);
+      if (min === max) { min -= 10; max += 10; }
+      const pad = Math.max(8, (max - min) * .24);
+      return { min: Math.floor(min - pad), max: Math.ceil(max + pad) };
+    }
     function gradient(ctx) {
       const v = values();
       const c0 = metricColor(ctx.p0DataIndex, v[ctx.p0DataIndex]);

@@ -250,8 +281,56 @@
       ctx.restore();
     }
     const ambientGlowPlugin = { id: 'tvaAmbientGlow', beforeDraw: drawAmbientGlow };
-    const zeroAxisPlugin = { id: 'tvaZeroAxis', beforeDatasetsDraw(c) { if (mode !== 'timeline') return; const y = c.scales.y; if (!y) return; const py = y.getPixelForValue(0), ctx = c.ctx; ctx.save(); ctx.strokeStyle = colorWithAlpha(state.colors.normal, .48); ctx.lineWidth = 1.5; ctx.beginPath(); ctx.moveTo(0, py); ctx.lineTo(c.width, py); ctx.stroke(); ctx.restore(); } };
-    const labelPlugin = { id: 'tvaLabels', afterDatasetsDraw(c) { if (mode !== 'timeline') return; const meta = c.getDatasetMeta(metricDatasetIndex); if (!meta) return; const vs = values(); meta.data.forEach((pt, i) => { const p = parameters[i], stale = isMetricStale(i), lvl = !stale && breachedLevel(i, vs[i]), critical = lvl && lvl.blink !== false && lvl.key !== levels[0].key; const { x, y } = pt.getProps(['x', 'y'], true), gy = y - c.chartArea.top < 52 ? y + 18 : y - 43, text = stale ? 'STALE' : formatPoint(p), ctx = c.ctx; ctx.save(); ctx.globalAlpha = stale ? .72 : critical ? (criticalBlink ? 1 : .38) : 1; ctx.font = 'bold 9px monospace'; const w = Math.max(28, ctx.measureText(text).width + 10), gx = Math.min(Math.max(x - w / 2, c.chartArea.left + 2), c.chartArea.right - w - 2); ctx.fillStyle = stale ? state.uiColors.staleLabelFill : lvl ? colorWithAlpha(levelColor(lvl), .18) : state.uiColors.normalLabelFill; ctx.strokeStyle = stale ? staleColor(false) : lvl ? levelColor(lvl) : state.uiColors.normalLabelStroke; ctx.beginPath(); ctx.rect(gx, gy, w, 31); ctx.fill(); ctx.stroke(); drawIcon(ctx, p.icon || 'warning', gx + w / 2, gy + 3, stale ? state.uiColors.staleText : state.uiColors.plotIcon); ctx.fillStyle = stale ? state.uiColors.staleText : state.uiColors.plotIcon; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(text, gx + w / 2, gy + 24); ctx.restore(); }); } };
+    const zeroAxisPlugin = { id: 'tvaZeroAxis', beforeDatasetsDraw(c) {
+      if (mode !== 'timeline') return;
+      const y = c.scales.y;
+      if (!y) return;
+      const py = y.getPixelForValue(0);
+      const ctx = c.ctx;
+      ctx.save();
+      ctx.strokeStyle = colorWithAlpha(state.colors.normal, .48);
+      ctx.lineWidth = 1.5;
+      ctx.beginPath();
+      ctx.moveTo(0, py);
+      ctx.lineTo(c.width, py);
+      ctx.stroke();
+      ctx.restore();
+    } };
+    function drawLabel(c, pt, i, vs) {
+      const p = parameters[i];
+      const stale = isMetricStale(i);
+      const lvl = !stale && breachedLevel(i, vs[i]);
+      const critical = lvl && lvl.blink !== false && lvl.key !== levels[0].key;
+      const { x, y } = pt.getProps(['x', 'y'], true);
+      const text = stale ? 'STALE' : formatPoint(p);
+      const ctx = c.ctx;
+      const gy = y - c.chartArea.top < 52 ? y + 18 : y - 43;
+
+      ctx.save();
+      ctx.globalAlpha = stale ? .72 : critical ? (criticalBlink ? 1 : .38) : 1;
+      ctx.font = 'bold 9px monospace';
+      const w = Math.max(28, ctx.measureText(text).width + 10);
+      const gx = Math.min(Math.max(x - w / 2, c.chartArea.left + 2), c.chartArea.right - w - 2);
+      ctx.fillStyle = stale ? state.uiColors.staleLabelFill : lvl ? colorWithAlpha(levelColor(lvl), .18) : state.uiColors.normalLabelFill;
+      ctx.strokeStyle = stale ? staleColor(false) : lvl ? levelColor(lvl) : state.uiColors.normalLabelStroke;
+      ctx.beginPath();
+      ctx.rect(gx, gy, w, 31);
+      ctx.fill();
+      ctx.stroke();
+      drawIcon(ctx, p.icon || 'warning', gx + w / 2, gy + 3, stale ? state.uiColors.staleText : state.uiColors.plotIcon);
+      ctx.fillStyle = stale ? state.uiColors.staleText : state.uiColors.plotIcon;
+      ctx.textAlign = 'center';
+      ctx.textBaseline = 'middle';
+      ctx.fillText(text, gx + w / 2, gy + 24);
+      ctx.restore();
+    }
+    const labelPlugin = { id: 'tvaLabels', afterDatasetsDraw(c) {
+      if (mode !== 'timeline') return;
+      const meta = c.getDatasetMeta(metricDatasetIndex);
+      if (!meta) return;
+      const vs = values();
+      meta.data.forEach((pt, i) => drawLabel(c, pt, i, vs));
+    } };
 
     function thresholdDataset(level, side) { return parameters.map(p => limit(p, level, side, side === 'Upper' ? Infinity : -Infinity)); }
     function thresholdDatasets() {

@@ -293,6 +372,26 @@
         pointHoverRadius: 8
       };
     }
+    function openDetailFromClick(_e, els) {
+      const hit = els[0];
+      if (hit && hit.datasetIndex === metricDatasetIndex && parameters[hit.index].detailMode) switchMode(parameters[hit.index].detailMode);
+    }
+    function timelineScales(vs) {
+      return {
+        x: {
+          offset: false,
+          border: { display: false },
+          grid: { color: state.uiColors.grid },
+          ticks: { color: state.uiColors.tick, font: { weight: 'bold', size: 10 }, callback: (_v, i) => container.classList.contains('tva-chart-fullscreen-mode') ? labels[i] : '' }
+        },
+        y: {
+          ...zoomBounds(vs),
+          border: { display: false },
+          grid: { color: c => c.tick.value === 0 ? state.uiColors.transparent : state.uiColors.grid },
+          ticks: { display: false }
+        }
+      };
+    }
     function timelineConfig() {
       const vs = values();
       return {

@@ -302,12 +401,9 @@
           responsive: true,
           maintainAspectRatio: false,
           layout: { padding: { left: 2, right: 6, top: number(init.topPadding, 34), bottom: 4 } },
-          onClick: (_e, els) => { const hit = els[0]; if (hit && hit.datasetIndex === metricDatasetIndex && parameters[hit.index].detailMode) switchMode(parameters[hit.index].detailMode); },
+          onClick: openDetailFromClick,
           plugins: { title: { display: false }, legend: { display: false }, tooltip: { callbacks: { title: items => items.length ? labels[items[0].dataIndex] : '', label: c => c.datasetIndex === metricDatasetIndex ? formatPoint(parameters[c.dataIndex]) : null } } },
-          scales: {
-            x: { offset: false, border: { display: false }, grid: { color: state.uiColors.grid }, ticks: { color: state.uiColors.tick, font: { weight: 'bold', size: 10 }, callback: (_v, i) => container.classList.contains('tva-chart-fullscreen-mode') ? labels[i] : '' } },
-            y: { ...zoomBounds(vs), border: { display: false }, grid: { color: c => c.tick.value === 0 ? state.uiColors.transparent : state.uiColors.grid }, ticks: { display: false } }
-          }
+          scales: timelineScales(vs)
         },
         plugins: [ambientGlowPlugin, zeroAxisPlugin, labelPlugin]
       };