From 08e34736703b79cad9d1b36b5b54d3bb08430e75 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Wed, 11 Jun 2025 14:14:55 +0200 Subject: [PATCH] Finalisation jauge alcool --- static/stocks.html | 211 ++++++++++++++++++++++++--------------------- 1 file changed, 115 insertions(+), 96 deletions(-) diff --git a/static/stocks.html b/static/stocks.html index 06120e7..6499367 100644 --- a/static/stocks.html +++ b/static/stocks.html @@ -1,118 +1,137 @@ - - - Stock alcool - - - - + + + -
- -
Chargement…
-
+
+ +
Chargement…
+
- + async function updateGauge() { + try { + const res = await fetch(DATA_URL, { cache: 'no-store' }); + if (!res.ok) throw new Error(res.status); + const text = await res.text(); + const pct = Math.min(100, Math.max(0, parseFloat(text))); + updateGaugeColor(pct); + gauge.set(pct); + document.getElementById('value').textContent = pct.toFixed(1) + ' %'; + } catch (e) { + document.getElementById('value').textContent = 'Erreur de chargement'; + console.error(e); + } + } - + window.addEventListener('load', () => { + initGauge(); + updateGauge(); + setInterval(updateGauge, 30_000); + }); + + window.addEventListener('resize', () => { + const last = gauge ? gauge.value : 0; + initGauge(); + if (gauge && last !== undefined) { + updateGaugeColor(last); + gauge.set(last); + } + }); + + + -