From 0a2d67afb4854b21ad69f9663f2ca00c2a463ce5 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 21 May 2026 00:46:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E4=BF=AE=20WebUI=20=E7=AC=AC=E4=B9=9D?= =?UTF-8?q?=E8=BD=AE=EF=BC=9Aoverview=20=E7=A6=8F=E8=A2=8B=E5=8D=A1?= =?UTF-8?q?=E8=BF=B7=E4=BD=A0=20sparkline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 福袋处理卡片底部加入 22px 高 sparkline,合成 fudai_open_detail + fudai_attend_ok 两条序列为一条折线 - 渐变填充 + 折线双层;用 currentColor 保证主题切换自动跟随;数据少于 2 点时隐藏 - pollStats 触发渲染,与主时间轴同源数据 - cache-bust v11 → v12 --- webui/app.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ webui/index.html | 5 +++-- webui/styles.css | 14 ++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/webui/app.js b/webui/app.js index 5c52cd1..3e35bf2 100644 --- a/webui/app.js +++ b/webui/app.js @@ -1118,6 +1118,63 @@ function notifyApiFail() { if (_apiFailStreak >= _apiFailThreshold) setConnState("error"); } +function renderOverviewSparkline(svgId, timeline) { + const svg = document.getElementById(svgId); + if (!svg) return; + // 把 fudai_open_detail + fudai_attend_ok 两个序列合成一条迷你折线 + const series = (timeline && timeline.series) || {}; + const keys = ["fudai_open_detail", "fudai_attend_ok"]; + const arrs = keys.map((k) => Array.isArray(series[k]) ? series[k] : []); + const len = Math.max(...arrs.map((a) => a.length), 0); + if (len < 2) { + svg.innerHTML = ""; + svg.classList.remove("hasData"); + return; + } + const combined = new Array(len).fill(0); + for (const arr of arrs) { + for (let i = 0; i < arr.length; i++) combined[i] += Number(arr[i]) || 0; + } + const maxY = Math.max(1, ...combined); + // 100x24 viewBox:留 1px 边 + const W = 100, H = 24, padY = 1.5; + const xAt = (i) => (W * i) / (len - 1); + const yAt = (v) => H - padY - ((H - padY * 2) * v) / maxY; + let d = ""; + for (let i = 0; i < len; i++) { + const x = xAt(i).toFixed(2), y = yAt(combined[i]).toFixed(2); + d += (i === 0 ? "M" : " L") + x + " " + y; + } + // 渐变填充区 + const dArea = d + ` L ${W} ${H} L 0 ${H} Z`; + const NS = "http://www.w3.org/2000/svg"; + svg.setAttribute("viewBox", `0 0 ${W} ${H}`); + svg.innerHTML = ""; + // gradient defs + const defs = document.createElementNS(NS, "defs"); + const gid = svgId + "Grad"; + const grad = document.createElementNS(NS, "linearGradient"); + grad.setAttribute("id", gid); + grad.setAttribute("x1", "0"); grad.setAttribute("y1", "0"); + grad.setAttribute("x2", "0"); grad.setAttribute("y2", "1"); + grad.innerHTML = ``; + defs.appendChild(grad); + svg.appendChild(defs); + const area = document.createElementNS(NS, "path"); + area.setAttribute("d", dArea); + area.setAttribute("fill", `url(#${gid})`); + svg.appendChild(area); + const line = document.createElementNS(NS, "path"); + line.setAttribute("d", d); + line.setAttribute("fill", "none"); + line.setAttribute("stroke", "currentColor"); + line.setAttribute("stroke-width", "1.25"); + line.setAttribute("stroke-linecap", "round"); + line.setAttribute("stroke-linejoin", "round"); + svg.appendChild(line); + svg.classList.add("hasData"); +} + async function apiGet(path) { try { const res = await fetch(path, { cache: "no-store" }); @@ -1912,6 +1969,7 @@ async function pollStats() { }; renderTimeline("chartTimeline", agg.timeline); + renderOverviewSparkline("topFudaiSparkline", agg.timeline); renderBars("chartSkipReason", agg.skip_reason || {}, reasonName); renderBars("chartSwitchReason", agg.switch_reason || {}, switchName); renderBars("chartValueBuckets", agg.value_buckets || {}); diff --git a/webui/index.html b/webui/index.html index 205822f..9d34664 100644 --- a/webui/index.html +++ b/webui/index.html @@ -15,7 +15,7 @@ } catch (e) {} })(); - +
@@ -116,6 +116,7 @@
福袋处理
0 / 0
打开详情 / 成功参与
+
日志缓存
@@ -1248,6 +1249,6 @@
- + diff --git a/webui/styles.css b/webui/styles.css index e1d8e78..f9dd96a 100644 --- a/webui/styles.css +++ b/webui/styles.css @@ -602,6 +602,20 @@ svg { overflow-wrap: anywhere; } +.overviewSpark { + display: block; + width: 100%; + height: 22px; + margin-top: 8px; + color: var(--primary); + opacity: 0; + transition: opacity var(--motion); +} + +.overviewSpark.hasData { + opacity: 0.8; +} + .statusDot { position: relative; flex: 0 0 8px;