diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-12 19:07:11 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-12 19:07:11 +0100 |
| commit | 7ac7a0326387012b1aad6ebc692c26b5620289b4 (patch) | |
| tree | ea6dc5b7ac0b0396540a0282cfb0bd091713b50a /static | |
| parent | 53c4a434a8587a531c288e98875ab76c180d376a (diff) | |
| download | deck-it-7ac7a0326387012b1aad6ebc692c26b5620289b4.tar.gz deck-it-7ac7a0326387012b1aad6ebc692c26b5620289b4.zip | |
fix(dashboard): stroke only the top of the chip graphs
The CPU, GPU and network graphs stroked their closed area path, so the
outline also ran along the bottom edge and up the left side while the
history filled. Each series is now a filled area and an open line
through the samples, and only the line is stroked.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'static')
| -rw-r--r-- | static/dashboard.js | 38 | ||||
| -rw-r--r-- | static/deck.css | 7 |
2 files changed, 30 insertions, 15 deletions
diff --git a/static/dashboard.js b/static/dashboard.js index adf690e..c6eab3c 100644 --- a/static/dashboard.js +++ b/static/dashboard.js @@ -53,15 +53,27 @@ export function push(list, v, n = HISTORY) { return list; } -// A filled area over a 120x100 viewBox, the newest sample at the right edge; -// the largest value reaches 12% from the top. -export function area(samples, max, n = HISTORY) { - if (!samples.length) return ""; +// The trend over a 120x100 viewBox, the newest sample at the right edge; the +// largest value reaches 12% from the top. +export function line(samples, max, n = HISTORY) { const x = (i) => ((n - samples.length + i) * 120) / (n - 1); const y = (v) => 100 - Math.min(1, v / (max || 1)) * 88; - return `M${x(0)},100 ` + samples.map((v, i) => `L${x(i)},${y(v)}`).join(" ") + " L120,100 Z"; + return samples.map((v, i) => `${i ? "L" : "M"}${x(i)},${y(v)}`).join(" "); +} + +// The area under line(), closed along the bottom edge. It is filled only: +// stroking it would also draw the bottom and side edges. +export function area(samples, max, n = HISTORY) { + const l = line(samples, max, n); + return l && `M${l.slice(1, l.indexOf(","))},100 L${l.slice(1)} L120,100 Z`; } +// A graph's two paths: the filled area, then the stroked line over it. +const graph = ([fill, stroke], samples, max) => { + fill.setAttribute("d", area(samples, max)); + stroke.setAttribute("d", line(samples, max)); +}; + // The top 3 paid models (llm.py sorts them by cost), then the rest as "other". export function spendParts(models) { const paid = (models ?? []).filter((m) => m.cost > 0); @@ -114,12 +126,12 @@ const SKELETON = ` <span class="sep">|</span><span><i class="nf">${G.clock}</i><span class="up"></span></span> <span class="sep upd">|</span><span class="upd n-upd"></span></div> <div class="chips sys"> - <div class="chip c-cpu"><svg viewBox="0 0 120 100" preserveAspectRatio="none"><path class="hy"/></svg> + <div class="chip c-cpu"><svg viewBox="0 0 120 100" preserveAspectRatio="none"><path class="hy"/><path class="hy ln"/></svg> <i class="nf ic">${G.cpu}</i><span class="col"><span class="n"></span><span class="v num"></span></span><span class="s"></span></div> <div class="chip c-mem"><i class="fill"></i><i class="nf ic">${G.mem}</i><span class="v num"></span><span class="s"></span></div> - <div class="chip c-gpu"><svg viewBox="0 0 120 100" preserveAspectRatio="none"><path class="hy"/></svg> + <div class="chip c-gpu"><svg viewBox="0 0 120 100" preserveAspectRatio="none"><path class="hy"/><path class="hy ln"/></svg> <i class="nf ic">${G.gpu}</i><span class="col"><span class="n"></span><span class="v num"></span></span><span class="s"></span></div> - <div class="chip c-net"><svg viewBox="0 0 120 100" preserveAspectRatio="none"><path class="hy"/><path class="up"/></svg> + <div class="chip c-net"><svg viewBox="0 0 120 100" preserveAspectRatio="none"><path class="hy"/><path class="hy ln"/><path class="up"/><path class="up ln"/></svg> <i class="nf ic">${G.net}</i><span class="v num"></span></div> </div> <div class="chips aux"> @@ -174,7 +186,7 @@ export default { $(".n-upd").textContent = `${st.updates} update${st.updates === 1 ? "" : "s"} available`; push(hist.cpu, st.cpu); push(hist.down, st.net.down); push(hist.up, st.net.up); $(".c-cpu .n").textContent = st.cpuName ?? ""; - $(".c-cpu path").setAttribute("d", area(hist.cpu, Math.max(25, ...hist.cpu))); + graph($(".c-cpu").querySelectorAll("path"), hist.cpu, Math.max(25, ...hist.cpu)); chip(".c-cpu", `${st.cpu}%`, st.cpuTemp != null ? `${st.cpuTemp}°C` : "", null, st.cpuTemp >= 85); chip(".c-mem", gib(st.memUsed * 1024), `/ ${Math.round(st.memTotal / 1048576)} GiB`, (100 * st.memUsed) / st.memTotal); @@ -187,15 +199,15 @@ export default { // older kernel) the temperature takes the big value. if (g.util != null) { push(hist.gpu, g.util); - $(".c-gpu path").setAttribute("d", area(hist.gpu, Math.max(25, ...hist.gpu))); + graph($(".c-gpu").querySelectorAll("path"), hist.gpu, Math.max(25, ...hist.gpu)); } const t = g.temp != null ? `${g.temp}°C` : "—"; chip(".c-gpu", g.util != null ? `${g.util}%` : t, g.util != null ? t : "", null, g.temp >= 85); } const max = Math.max(1, ...hist.down, ...hist.up); - const [down, up] = $(".c-net").querySelectorAll("path"); - down.setAttribute("d", area(hist.down, max)); - up.setAttribute("d", area(hist.up, max)); + const net = [...$(".c-net").querySelectorAll("path")]; + graph(net.slice(0, 2), hist.down, max); + graph(net.slice(2), hist.up, max); chip(".c-net", `↓${rate(st.net.down)} ↑${rate(st.net.up)}`); }); diff --git a/static/deck.css b/static/deck.css index 74cf147..b6d2202 100644 --- a/static/deck.css +++ b/static/deck.css @@ -672,8 +672,11 @@ select { .dash .chip svg, .dash .chip .fill { position: absolute; inset: 0; pointer-events: none; } .dash .chip svg { width: 100%; height: 100%; } .dash .chip svg path { stroke-width: 1.5; vector-effect: non-scaling-stroke; } -.dash .chip svg path.hy { fill: url(#hyfill); stroke: url(#hyline); } -.dash .chip svg path.up { fill: color-mix(in srgb, var(--udt-text) 8%, transparent); stroke: color-mix(in srgb, var(--udt-text) 30%, transparent); } +.dash .chip svg path.hy { fill: url(#hyfill); } +.dash .chip svg path.up { fill: color-mix(in srgb, var(--udt-text) 8%, transparent); } +.dash .chip svg path.ln { fill: none; } +.dash .chip svg path.hy.ln { stroke: url(#hyline); } +.dash .chip svg path.up.ln { stroke: color-mix(in srgb, var(--udt-text) 30%, transparent); } .dash .chip .fill { right: auto; width: 0; background: color-mix(in srgb, var(--udt-accent) 20%, transparent); transition: width .4s; } /* Charging: streaks rain right to left into the fill's edge. The strip sits past the fill and the chip's overflow clips it; each layer moves a whole tile per |
