From a0df63b1d9b017e6b3ac3e0e8826f1fe2fedb3e9 Mon Sep 17 00:00:00 2001 From: Harwinder Sekhon Date: Sat, 15 Aug 2026 11:34:19 -0400 Subject: [PATCH] Replace score bars with Google Gauge visualization --- static/dashboard.html | 2 ++ static/dashboard.js | 6 +---- static/gauge.js | 52 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 static/gauge.js diff --git a/static/dashboard.html b/static/dashboard.html index debf646..86fc783 100644 --- a/static/dashboard.html +++ b/static/dashboard.html @@ -11,6 +11,7 @@ + + diff --git a/static/dashboard.js b/static/dashboard.js index 9b866e9..3666d24 100644 --- a/static/dashboard.js +++ b/static/dashboard.js @@ -174,13 +174,9 @@ function renderContext() { /* ── timeframe cards ──────────────────────────────────────────── */ function scoreBar(label, score) { const v = Math.max(-100, Math.min(100, score ?? 0)); - const pct = Math.abs(v) / 2; - const cls = v >= 0 ? "pos" : "neg"; return `
${label} - +
${v >= 0 ? "+" : ""}${v.toFixed(1)}
`; } diff --git a/static/gauge.js b/static/gauge.js new file mode 100644 index 0000000..abf108c --- /dev/null +++ b/static/gauge.js @@ -0,0 +1,52 @@ +document.addEventListener('DOMContentLoaded', function() { + // Load Google Charts + google.charts.load('current', {'packages':['gauge']}); + google.charts.setOnLoadCallback(drawGauges); + + // Draw all gauges on the page + function drawGauges() { + const gaugeContainers = document.querySelectorAll('.gauge-container'); + + gaugeContainers.forEach(container => { + const label = container.dataset.label; + const score = parseFloat(container.dataset.score); + + // Create data table + const data = google.visualization.arrayToDataTable([ + ['Label', 'Value'], + [label, score] + ]); + + // Configure gauge options + const options = { + width: 200, + height: 160, + redFrom: -100, + redTo: -50, + yellowFrom: -50, + yellowTo: 0, + greenFrom: 0, + greenTo: 50, + minorTicks: 5, + min: -100, + max: 100, + majorTicks: [-100, -50, 0, 50, 100], + animation: { + duration: 500, + easing: 'out' + } + }; + + // Create and draw the gauge + const chart = new google.visualization.Gauge(container); + chart.draw(data, options); + }); + } + + // Re-draw gauges when window is resized + window.addEventListener('resize', function() { + if (typeof google !== 'undefined' && google.visualization) { + drawGauges(); + } + }); +}); \ No newline at end of file