aboutsummaryrefslogtreecommitdiffstats
path: root/static/dashboard.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/dashboard.js')
-rw-r--r--static/dashboard.js38
1 files changed, 25 insertions, 13 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)}`);
});