From b5497ffc1f551ae6b184f8fbb3571d083aa787e4 Mon Sep 17 00:00:00 2001 From: fraxle Date: Thu, 28 May 2026 14:06:50 +0100 Subject: [PATCH] 2.0.6 Soil moisture shades --- assets/js/app.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/assets/js/app.js b/assets/js/app.js index a6c5fad..f61b076 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -656,6 +656,29 @@ ${(isPro ? (activeProfile === 'custom' || activeProfile === 'showall' || activeC const a = 0.035 + x * maxAlpha; return `rgba(${rgb},${a.toFixed(3)})`; }; + const soilMoistureBg = (v) => { + if (v == null || isNaN(v)) return { bg: 'transparent', fg: '#555' }; + const pct = v * 100; + // stops: [pct, r, g, b] + const stops = [ + [0, 212, 180, 131], // sandy tan – bone dry + [10, 160, 120, 64], // mid brown – dry + [22, 138, 122, 80], // olive-brown – damp/firm + [32, 200, 160, 64], // amber – soft, caution + [38, 58, 138, 92], // green – wet + [50, 42, 106, 144], // blue – saturated + ]; + let s0 = stops[0], s1 = stops[stops.length - 1]; + for (let i = 0; i < stops.length - 1; i++) { + if (pct >= stops[i][0] && pct <= stops[i+1][0]) { s0 = stops[i]; s1 = stops[i+1]; break; } + } + const t = s1[0] === s0[0] ? 1 : Math.max(0, Math.min(1, (pct - s0[0]) / (s1[0] - s0[0]))); + const r = Math.round(s0[1] + t * (s1[1] - s0[1])); + const g = Math.round(s0[2] + t * (s1[2] - s0[2])); + const b = Math.round(s0[3] + t * (s1[3] - s0[3])); + const lum = 0.299*r + 0.587*g + 0.114*b; + return { bg: `rgba(${r},${g},${b},0.18)`, fg: '#3a2a10' }; + }; const deltaBg = (v) => { if (v == null || isNaN(v)) return 'transparent'; if (Math.abs(v) < 1) return 'transparent'; @@ -734,7 +757,7 @@ ${(isPro ? (activeProfile === 'custom' || activeProfile === 'showall' || activeC ${visibleCols.soilT6 && html` ${fmt(r.soilT6)}${u('°C')}`} ${visibleCols.soilM && html` - ${r.soilM != null ? fmt(r.soilM * 100, 1) + u('%') : '—'}`} + { const sm = soilMoistureBg(r.soilM); return { color: sm.fg, background: sm.bg }; })()}>${r.soilM != null ? fmt(r.soilM * 100, 1) + u('%') : '—'}`} ${visibleCols.air && html`${fmt(r.Ta)}${u('°C')}`} ${visibleCols.rh && html`${Math.round(r.RH)}${u('%')}`} ${visibleCols.dew && html`${fmt(r.dew)}${u('°C')}`}