精修 WebUI 第九轮:overview 福袋卡迷你 sparkline

- 福袋处理卡片底部加入 22px 高 sparkline,合成 fudai_open_detail + fudai_attend_ok 两条序列为一条折线
- 渐变填充 + 折线双层;用 currentColor 保证主题切换自动跟随;数据少于 2 点时隐藏
- pollStats 触发渲染,与主时间轴同源数据
- cache-bust v11 → v12
This commit is contained in:
Codex committed 2026-05-21 09:29:38 +08:00
1 parent d1f153b373
commit 0a2d67afb4
3 files changed
+75 -2

No files matched your search

+58
View File
@@ -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 = `<stop offset="0%" stop-color="currentColor" stop-opacity="0.28"/><stop offset="100%" stop-color="currentColor" stop-opacity="0"/>`;
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 || {});
+3 -2
View File
@@ -15,7 +15,7 @@
} catch (e) {}
})();
</script>
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v11" />
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v12" />
</head>
<body>
<div class="app">
@@ -116,6 +116,7 @@
<div class="overviewLabel">福袋处理</div>
<div class="overviewValue" id="topFudaiState">0 / 0</div>
<div class="overviewMeta" id="topFudaiMeta">打开详情 / 成功参与</div>
<svg id="topFudaiSparkline" class="overviewSpark" viewBox="0 0 100 24" preserveAspectRatio="none" aria-hidden="true"></svg>
</article>
<article class="overviewCard">
<div class="overviewLabel">日志缓存</div>
@@ -1248,6 +1249,6 @@
</footer>
</div>
<script src="app.js?v=console-20260520-theme-v11"></script>
<script src="app.js?v=console-20260520-theme-v12"></script>
</body>
</html>
+14
View File
@@ -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;