commit ebd94bd7e825acf8a861c151d6aafc26a21d75d9
parent de9c482875652ec8cf28abc82d1e677d48ab8fdd
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Wed, 7 Oct 2026 17:19:30 +0530
parent de9c482875652ec8cf28abc82d1e677d48ab8fdd
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Wed, 7 Oct 2026 17:19:30 +0530
Make TVA ambient glow readable
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/tva-control.js b/tva-control.js @@ -154,7 +154,42 @@ const ambientGlow = init.ambientGlow || {}; function ambientGlowEnabled() { return ambientGlow.enabled !== false && ambientGlow.enabled !== 0; } function levelGlowEnabled(level) { return level && level.ambientGlow !== false && level.glow !== false; } - const ambientGlowPlugin = { id: 'tvaAmbientGlow', beforeDraw(c) { if (mode !== 'timeline' || !ambientGlowEnabled()) return; const meta = c.getDatasetMeta(metricDatasetIndex), area = c.chartArea; if (!meta || !area) return; const vs = values(), ctx = c.ctx; ctx.save(); ctx.beginPath(); ctx.rect(0, 0, c.width, c.height); ctx.clip(); meta.data.forEach((pt, i) => { if (isMetricStale(i)) return; const lvl = breachedLevel(i, vs[i]); if (!levelGlowEnabled(lvl)) return; const { x, y } = pt.getProps(['x', 'y'], true), color = lvl.glowColor || levelColor(lvl), radius = number(lvl.glowRadius, number(ambientGlow.radius, 72)), blur = number(lvl.glowBlur, number(ambientGlow.blur, 36)), alpha = number(lvl.glowAlpha, number(ambientGlow.alpha, .16)), spread = radius + blur; const g = ctx.createRadialGradient(x, y, 0, x, y, spread); g.addColorStop(0, colorWithAlpha(color, alpha)); g.addColorStop(.34, colorWithAlpha(color, alpha * .42)); g.addColorStop(.72, colorWithAlpha(color, alpha * .12)); g.addColorStop(1, colorWithAlpha(color, 0)); ctx.fillStyle = g; ctx.fillRect(x - spread, y - spread, spread * 2, spread * 2); }); ctx.restore(); } }; + function drawAmbientGlow(chart) { + if (mode !== 'timeline' || !ambientGlowEnabled()) return; + const meta = chart.getDatasetMeta(metricDatasetIndex); + if (!meta || !chart.chartArea) return; + + const vs = values(); + const ctx = chart.ctx; + ctx.save(); + ctx.beginPath(); + ctx.rect(0, 0, chart.width, chart.height); + ctx.clip(); + + meta.data.forEach((pt, i) => { + if (isMetricStale(i)) return; + const lvl = breachedLevel(i, vs[i]); + if (!levelGlowEnabled(lvl)) return; + + const { x, y } = pt.getProps(['x', 'y'], true); + const color = lvl.glowColor || levelColor(lvl); + const radius = number(lvl.glowRadius, number(ambientGlow.radius, 72)); + const blur = number(lvl.glowBlur, number(ambientGlow.blur, 36)); + const alpha = number(lvl.glowAlpha, number(ambientGlow.alpha, .16)); + const spread = radius + blur; + const g = ctx.createRadialGradient(x, y, 0, x, y, spread); + + g.addColorStop(0, colorWithAlpha(color, alpha)); + g.addColorStop(.34, colorWithAlpha(color, alpha * .42)); + g.addColorStop(.72, colorWithAlpha(color, alpha * .12)); + g.addColorStop(1, colorWithAlpha(color, 0)); + ctx.fillStyle = g; + ctx.fillRect(x - spread, y - spread, spread * 2, spread * 2); + }); + + 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(); }); } };
: asapien/superpulse