: asapien/superpulse

commit bb2182ba2f0be1f82e5d2b2f841b47a497a7bd40
parent 0844574d85440c2f3f849087fb594612b98d8296
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Wed, 7 Oct 2026 17:20:21 +0530

Make TVA detail chart config readable
1 file changed, 40 insertions(+), 1 deletion(-)
M
tva-control.js
|
41
++++++++++++++++++++++++++++++++++++++++-
diff --git a/tva-control.js b/tva-control.js
@@ -253,8 +253,47 @@
       };
     }
     function detailParam() { return parameters.find(p => p.detailMode === mode); }
-    function barConfig() { const p = detailParam(), rows = normalizeAreas(state[p.areaKey]), days = rows.map(r => r.days), dl = p.detailLevels || []; return { type: 'bar', data: { labels: rows.map(r => r.name), datasets: [{ data: days, borderWidth: 1.2, borderRadius: 8, backgroundColor: c => { const lvl = dl.findLast(l => (c.raw || 0) > number(l.above, Infinity)); return lvl ? colorWithAlpha(colorForDetail(lvl), .38) : colorWithAlpha(state.colors.normal, .3); }, borderColor: c => { const lvl = dl.findLast(l => (c.raw || 0) > number(l.above, Infinity)); return lvl ? colorForDetail(lvl) : state.colors.normal; } }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { title: { display: false }, subtitle: { display: true, text: p.detailSubtitle || '', color: state.colors[dl[0] && dl[0].level] || state.colors.normal, font: { size: 10, weight: 'bold' } }, legend: { display: false } }, scales: { x: { grid: { color: state.uiColors.detailGrid }, ticks: { color: state.uiColors.tick, font: { weight: 'bold', size: 10 } } }, y: { min: 0, max: Math.max(...days, ...dl.map(l => number(l.above, 0))) + 1.5, ticks: { color: state.uiColors.detailTick, callback: v => `${v}d` } } } } }; }
     function colorForDetail(l) { return state.colors[l.level] || state.colors[camel(l.level)] || state.colors.normal; }
+    function detailLevelFor(value, levels) { return levels.findLast(l => (value || 0) > number(l.above, Infinity)); }
+    function barConfig() {
+      const p = detailParam();
+      const rows = normalizeAreas(state[p.areaKey]);
+      const days = rows.map(r => r.days);
+      const detailLevels = p.detailLevels || [];
+
+      return {
+        type: 'bar',
+        data: {
+          labels: rows.map(r => r.name),
+          datasets: [{
+            data: days,
+            borderWidth: 1.2,
+            borderRadius: 8,
+            backgroundColor: c => {
+              const lvl = detailLevelFor(c.raw, detailLevels);
+              return colorWithAlpha(lvl ? colorForDetail(lvl) : state.colors.normal, lvl ? .38 : .3);
+            },
+            borderColor: c => {
+              const lvl = detailLevelFor(c.raw, detailLevels);
+              return lvl ? colorForDetail(lvl) : state.colors.normal;
+            }
+          }]
+        },
+        options: {
+          responsive: true,
+          maintainAspectRatio: false,
+          plugins: {
+            title: { display: false },
+            subtitle: { display: true, text: p.detailSubtitle || '', color: state.colors[detailLevels[0] && detailLevels[0].level] || state.colors.normal, font: { size: 10, weight: 'bold' } },
+            legend: { display: false }
+          },
+          scales: {
+            x: { grid: { color: state.uiColors.detailGrid }, ticks: { color: state.uiColors.tick, font: { weight: 'bold', size: 10 } } },
+            y: { min: 0, max: Math.max(...days, ...detailLevels.map(l => number(l.above, 0))) + 1.5, ticks: { color: state.uiColors.detailTick, callback: v => `${v}d` } }
+          }
+        }
+      };
+    }
     function syncControls() { const select = controls.querySelector('.tva-chart-mode-select'), back = controls.querySelector('.tva-chart-back'), fs = controls.querySelector('.tva-chart-fullscreen'); if (select) select.value = mode; back.hidden = mode === 'timeline'; fs.classList.toggle('is-restore', container.classList.contains('tva-chart-fullscreen-mode')); const vs = values(), active = vs.map((v, i) => isMetricStale(i) ? null : breachedLevel(i, v)).filter(Boolean).sort((a, b) => number(b.priority, 0) - number(a.priority, 0))[0], borderAlert = active && (active.borderBlink || active.blinkBorder || active.borderAlert); alertBadge.hidden = mode !== 'timeline' || !active; alertBadge.innerHTML = active ? `<span class="tva-alert-icon" aria-hidden="true"></span>${active.label || active.key.toUpperCase()}` : ''; alertBadge.style.color = active ? levelColor(active) : ''; container.classList.toggle('tva-border-alert', !!borderAlert); if (borderAlert) container.style.setProperty('--tva-border-alert-color', levelColor(active)); else container.style.removeProperty('--tva-border-alert-color'); }
     function render() { if (chart) chart.destroy(); chart = new Chart(canvas.getContext('2d'), mode === 'timeline' ? timelineConfig() : barConfig()); syncControls(); }
     let blinkId = null;