From 129b23cd2b0ee2e4d677429fc7063c56b9ce62d8 Mon Sep 17 00:00:00 2001
From: wait4xx
Date: Wed, 4 Nov 2026 23:04:14 +0800
Subject: [PATCH] =?UTF-8?q?fix(heatmap):=20=E4=BF=AE=E8=9B=87=E5=A4=B4?=
=?UTF-8?q?=E5=9D=90=E6=A0=87=E8=BD=B4=E5=8F=8D=E4=BA=86=E8=B7=91=E5=87=BA?=
=?UTF-8?q?=E8=BE=B9=E7=95=8C=EF=BC=9BP1=20=E6=99=BA=E8=83=BD=E5=AF=BB?=
=?UTF-8?q?=E9=A3=9F=E8=9B=87=E8=90=BD=E8=BF=9B=E6=AD=A3=E5=BC=8F=E5=BC=80?=
=?UTF-8?q?=E6=BA=90=E9=A1=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
用户选定 P1,同时报障「贪吃蛇跑到了窗口之外」。
根因:网格是**列优先**索引(idx → 列=floor(idx/7)、行=idx%7),P1 引擎的 posOf
把 x/y 写反——蛇头 y 会到 676px(网格仅 91px 高),一路走出下边界。
预览页坐标已修正;正式热力图按 P1 落地时直接用正确坐标系。
P1 落进正式开源页(Heatmap.astro):
- 头(accent 圆点)+ 8 节渐隐拖尾,沿「最近邻路径」只在有贡献的格子间滑行,
空格不染色(371 格仅 51 天活跃,全网扫描会让蛇 86% 行程空转)
- 吃到的格子点亮 accent;月柱随蛇头所在月份递增点亮
- 路径首尾相接实现无缝循环;离开视口即停;reduced-motion 下头/拖尾隐藏、
柱子以终态呈现;无 JS 兜底同款(noscript 样式)
- 清理死分支:P1 路径只访问活跃格子,walked 分支永不触发
验证: 构建 51 页 exit 0;E2E 56/56;
Playwright 实测蛇头 transform 始终在网格包围盒内(x≤676、y≤83 含居中偏移)、
eaten 递增至 51、月柱 13/13 点亮、reduced-motion 头隐藏柱立起、无 JS 柱立起
Spec: none (P1 为用户已选定方案的落地 + 坐标 bug 修复)
Co-authored-by: GLM-5.3
---
src/components/geek/Heatmap.astro | 178 +++++++++++++++++++++++++++++-
src/pages/heatmap-preview.astro | 4 +-
2 files changed, 180 insertions(+), 2 deletions(-)
diff --git a/src/components/geek/Heatmap.astro b/src/components/geek/Heatmap.astro
index f24f1a9..777804a 100644
--- a/src/components/geek/Heatmap.astro
+++ b/src/components/geek/Heatmap.astro
@@ -29,6 +29,17 @@ try {
const streak = streakStats(weeks.flat());
const updatedOn = new Date().toISOString().slice(0, 10);
const summary = labels.summary.replace('{n}', String(total));
+
+// 月度聚合(P1 蛇 + 月柱联动):柱子给"哪个月最忙"的粗粒度答案
+const byMonth = new Map();
+for (const week of weeks) {
+ for (const day of week) {
+ const key = day.date.slice(0, 7);
+ byMonth.set(key, (byMonth.get(key) ?? 0) + day.count);
+ }
+}
+const months = [...byMonth.entries()].sort(([a], [b]) => a.localeCompare(b)).filter(([m]) => m);
+const maxMonth = Math.max(...months.map(([, v]) => v), 1);
---
@@ -40,19 +51,34 @@ const summary = labels.summary.replace('{n}', String(total));
{streak.total}{locale === 'en' ? 'total' : '总贡献'}
数据更新于 {updatedOn}
-