Update gauge macro again to remove depdency on cos

This commit is contained in:
Peter Stockings
2025-12-22 13:39:59 +11:00
parent 28fd88121b
commit 2171b73b5f

View File

@@ -2,54 +2,42 @@
{% set p = pct if pct is not none else 0 %} {% set p = pct if pct is not none else 0 %}
{% if p < 0 %}{% set p=0 %}{% endif %} {% if p> 100 %}{% set p = 100 %}{% endif %} {% if p < 0 %}{% set p=0 %}{% endif %} {% if p> 100 %}{% set p = 100 %}{% endif %}
{# severity color #} {% if p < 60 %} {% set col="#16a34a" %} {% elif p < 85 %} {% set col="#f59e0b" %} {% else %} {% set col="#ef4444" %}
{% if p < 60 %} {% set col="#16a34a" %} {# green #} {% elif p < 85 %} {% set col="#f59e0b" %} {# amber #} {% else %} {% endif %} {% set r=24 %} {% set stroke=10 %} {% set c=2 * 3.1415926 * r %} {% set dash=(p / 100.0) * c %} {%
{% set col="#ef4444" %} {# red #} {% endif %} {% set r=24 %} {% set stroke=10 %} {% set c=2 * 3.1415926 * r %} set txt=value_text if value_text else (p|round(0) ~ "%" ) %} <div style="
{% set dash=(p / 100.0) * c %} {% set txt=value_text if value_text else (p|round(0) ~ "%" ) %} <div style="
border:1px solid rgba(0,0,0,.08); border:1px solid rgba(0,0,0,.08);
border-radius: 16px; border-radius: 16px;
padding: 14px 14px; padding: 14px;
background: linear-gradient(180deg, rgba(255,255,255,.9), rgba(255,255,255,.75)); background: linear-gradient(180deg, rgba(255,255,255,.95), rgba(255,255,255,.80));
box-shadow: 0 8px 24px rgba(0,0,0,.06); box-shadow: 0 8px 24px rgba(0,0,0,.06);
display:flex; display:flex;
align-items:center; align-items:center;
gap: 14px; gap: 14px;
min-height: 92px; min-height: 92px;
"> ">
<div style="position:relative; width:72px; height:72px; flex: 0 0 auto;"> <svg width="72" height="72" viewBox="0 0 72 72" style="flex: 0 0 auto;">
<svg width="72" height="72" viewBox="0 0 72 72"> <defs>
<defs> <filter id="softShadow" x="-50%" y="-50%" width="200%" height="200%">
<filter id="softShadow" x="-50%" y="-50%" width="200%" height="200%"> <feDropShadow dx="0" dy="2" stdDeviation="2" flood-opacity="0.18" />
<feDropShadow dx="0" dy="2" stdDeviation="2" flood-opacity="0.18" /> </filter>
</filter> </defs>
</defs>
{# track #} <!-- track -->
<circle cx="36" cy="36" r="{{ r }}" fill="none" stroke="rgba(0,0,0,.08)" stroke-width="{{ stroke }}" <circle cx="36" cy="36" r="{{ r }}" fill="none" stroke="rgba(0,0,0,.08)" stroke-width="{{ stroke }}"
stroke-linecap="round" /> stroke-linecap="round" />
{# progress ring #} <!-- progress -->
<circle cx="36" cy="36" r="{{ r }}" fill="none" stroke="{{ col }}" stroke-width="{{ stroke }}" <circle cx="36" cy="36" r="{{ r }}" fill="none" stroke="{{ col }}" stroke-width="{{ stroke }}"
stroke-linecap="round" stroke-dasharray="{{ dash }} {{ c - dash }}" transform="rotate(-90 36 36)" stroke-linecap="round" stroke-dasharray="{{ dash }} {{ c - dash }}" transform="rotate(-90 36 36)"
filter="url(#softShadow)" /> filter="url(#softShadow)" />
{# center text #} <!-- center -->
<text x="36" y="40" text-anchor="middle" font-size="14" font-weight="700" <text x="36" y="40" text-anchor="middle" font-size="14" font-weight="800"
font-family="system-ui, -apple-system, Segoe UI, Roboto" fill="rgba(0,0,0,.82)">{{ txt }}</text> font-family="system-ui, -apple-system, Segoe UI, Roboto" fill="rgba(0,0,0,.82)">{{ txt }}</text>
</svg> </svg>
{# small dot marker at end (nice touch) #} <div style="min-width: 0; width: 100%;">
{% set angle = (p/100.0) * 2 * 3.1415926 - (3.1415926/2) %} <div style="display:flex; align-items:center; justify-content:space-between; gap: 10px;">
{% set cx = 36 + r * (angle|float|cos) %}
{% set cy = 36 + r * (angle|float|sin) %}
</div>
<div style="min-width: 0;">
<div style="
display:flex;
align-items:center;
justify-content:space-between;
gap: 10px;">
<div style="font-weight:800; letter-spacing:-0.2px;">{{ label }}</div> <div style="font-weight:800; letter-spacing:-0.2px;">{{ label }}</div>
<div style=" <div style="
font-size:12px; font-size:12px;
@@ -62,12 +50,11 @@
</div> </div>
</div> </div>
<div class="muted" <div
style="margin-top:4px; font-size:12.5px; color: rgba(0,0,0,.62); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;"> style="margin-top:4px; font-size:12.5px; color: rgba(0,0,0,.62); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
{{ subtitle }} {{ subtitle }}
</div> </div>
{# bar meter for quick scan #}
<div <div
style="margin-top:10px; height:8px; border-radius:999px; background: rgba(0,0,0,.07); overflow:hidden;"> style="margin-top:10px; height:8px; border-radius:999px; background: rgba(0,0,0,.07); overflow:hidden;">
<div style="height:100%; width: {{ p }}%; background: {{ col }}; border-radius:999px;"></div> <div style="height:100%; width: {{ p }}%; background: {{ col }}; border-radius:999px;"></div>