next try
This commit is contained in:
@@ -55,37 +55,39 @@ data:
|
|||||||
span = g_max - g_min
|
span = g_max - g_min
|
||||||
if span <= 0: span = 1.0
|
if span <= 0: span = 1.0
|
||||||
|
|
||||||
# 2. Calculate percentages for key colors relative to this week's range
|
# 2. Helper to get percentage
|
||||||
# -10 (White), 0 (Blue), 15 (Purple), 25 (Pink), 35 (Red)
|
|
||||||
def get_pct(t): return (t - g_min) / span * 100.0
|
def get_pct(t): return (t - g_min) / span * 100.0
|
||||||
|
|
||||||
|
# 3. Calculate stops (floats)
|
||||||
s_wht = get_pct(-10)
|
s_wht = get_pct(-10)
|
||||||
s_blu = get_pct(0)
|
s_blu = get_pct(0)
|
||||||
s_pur = get_pct(15)
|
s_pur = get_pct(15)
|
||||||
s_pnk = get_pct(25)
|
s_pnk = get_pct(25)
|
||||||
s_red = get_pct(35)
|
s_red = get_pct(35)
|
||||||
|
|
||||||
# 3. Generate CSS Variables for each row
|
# 4. Inject individual floats into the dictionary
|
||||||
for d in daily_items:
|
for d in daily_items:
|
||||||
tmin, tmax = d["tmin_c"], d["tmax_c"]
|
tmin, tmax = d["tmin_c"], d["tmax_c"]
|
||||||
if tmin is None or tmax is None: continue
|
if tmin is None or tmax is None: continue
|
||||||
|
|
||||||
# Bar Geometry
|
|
||||||
w_pct = (tmax - tmin) / span * 100.0
|
w_pct = (tmax - tmin) / span * 100.0
|
||||||
if w_pct < 2: w_pct = 2
|
if w_pct < 2: w_pct = 2
|
||||||
l_pct = (tmin - g_min) / span * 100.0
|
l_pct = (tmin - g_min) / span * 100.0
|
||||||
|
|
||||||
# Gradient Compensation (Zoom & Shift)
|
|
||||||
inner_w = (100.0 / w_pct) * 100.0
|
inner_w = (100.0 / w_pct) * 100.0
|
||||||
inner_ml = -(l_pct / w_pct) * 100.0
|
inner_ml = -(l_pct / w_pct) * 100.0
|
||||||
|
|
||||||
# We pass ONLY variables to avoid HTML sanitization issues
|
# STORE AS FLOATS (No "%" symbol here)
|
||||||
d["css_vars"] = (
|
d["c_l"] = l_pct
|
||||||
f"--l: {l_pct:.1f}%; --w: {w_pct:.1f}%; "
|
d["c_w"] = w_pct
|
||||||
f"--gw: {inner_w:.1f}%; --ml: {inner_ml:.1f}%; "
|
d["c_gw"] = inner_w
|
||||||
f"--s-wht: {s_wht:.1f}%; --s-blu: {s_blu:.1f}%; "
|
d["c_ml"] = inner_ml
|
||||||
f"--s-pur: {s_pur:.1f}%; --s-pnk: {s_pnk:.1f}%; --s-red: {s_red:.1f}%;"
|
|
||||||
)
|
d["c_s1"] = s_wht # White
|
||||||
|
d["c_s2"] = s_blu # Blue
|
||||||
|
d["c_s3"] = s_pur # Purple
|
||||||
|
d["c_s4"] = s_pnk # Pink
|
||||||
|
d["c_s5"] = s_red # Red
|
||||||
|
|
||||||
return daily_items
|
return daily_items
|
||||||
|
|
||||||
|
|||||||
@@ -737,8 +737,19 @@ data:
|
|||||||
|
|
||||||
<div class="idokep-bar">
|
<div class="idokep-bar">
|
||||||
<div class="idokep-bar-track"></div>
|
<div class="idokep-bar-track"></div>
|
||||||
{{/* Inject safe CSS Variables only */}}
|
|
||||||
<div class="idokep-bar-fill" style="{{ .String "css_vars" }}">
|
{{/* We construct the style manually to bypass Go security sanitization */}}
|
||||||
|
<div class="idokep-bar-fill" style="
|
||||||
|
--l: {{ printf "%.1f" (.Float "c_l") }}%;
|
||||||
|
--w: {{ printf "%.1f" (.Float "c_w") }}%;
|
||||||
|
--gw: {{ printf "%.1f" (.Float "c_gw") }}%;
|
||||||
|
--ml: {{ printf "%.1f" (.Float "c_ml") }}%;
|
||||||
|
--s-wht: {{ printf "%.1f" (.Float "c_s1") }}%;
|
||||||
|
--s-blu: {{ printf "%.1f" (.Float "c_s2") }}%;
|
||||||
|
--s-pur: {{ printf "%.1f" (.Float "c_s3") }}%;
|
||||||
|
--s-pnk: {{ printf "%.1f" (.Float "c_s4") }}%;
|
||||||
|
--s-red: {{ printf "%.1f" (.Float "c_s5") }}%;
|
||||||
|
">
|
||||||
<div class="idokep-bar-gradient"></div>
|
<div class="idokep-bar-gradient"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user