From 94bd3de12d08929d542502f5334f4bafe6abd5ef Mon Sep 17 00:00:00 2001 From: bendtherules Date: Mon, 22 Jun 2026 18:56:07 +0530 Subject: [PATCH] =?UTF-8?q?Extract=20raw=20value=20in=20data.js,=20use=20f?= =?UTF-8?q?ixed=20200=C2=B0C=20max=20for=20bar=20height,=20add=20hover=20t?= =?UTF-8?q?ooltip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chart.js | 17 ++++++----------- src/data.js | 5 ++--- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/chart.js b/src/chart.js index 4ad008b..566e4a7 100644 --- a/src/chart.js +++ b/src/chart.js @@ -7,12 +7,10 @@ export function createChartForZone(zoneId) { return d.toLocaleTimeString('en-US', { hour12: false }); } - function maxValue() { - let m = 0; - for (const h of history) { - if (h.value > m) m = h.value; - } - return m || 100; + const MAX_TEMP = 200; + + function barHeight(value) { + return Math.max(4, (value / MAX_TEMP) * 100); } function render() { @@ -29,11 +27,9 @@ export function createChartForZone(zoneId) { `; - const max = maxValue(); let html = ''; for (const h of history) { - const pct = Math.max(4, (h.value / max) * 100); - html += `
${formatTime(h.time)}
`; + html += `
${formatTime(h.time)}
`; } chartEl.innerHTML = html; } @@ -56,8 +52,7 @@ export function createChartForZone(zoneId) { return { element: card, - update(val) { - const value = typeof val === 'object' && val !== null ? val.value : val; + update(value) { history.push({ value, time: new Date() }); if (history.length > MAX_HISTORY) history.shift(); render(); diff --git a/src/data.js b/src/data.js index f8ae084..bd00037 100644 --- a/src/data.js +++ b/src/data.js @@ -5,7 +5,6 @@ async function fetchTemperature(zoneId) { // Don't change this function signature export async function attachChart(chartInstance, zoneId) { - await fetchTemperature(zoneId).then(temp => { - chartInstance.update(temp); - }); + const temp = await fetchTemperature(zoneId); + chartInstance.update(temp.value); }