fix: 修复调用趋势统计与图表渲染,柱状图改为平滑折线图

- 趋势窗口 off-by-one:窗口不含当天,当天调用永远不进图表;
  改为以 UTC 日界、包含今天的 N 天窗口
- BarChart 容器 items-end 导致列高塌缩,柱子百分比高度恒为 0,
  图表自组件抽取以来从未渲染;重写为 LineChart(单调三次样条
  平滑曲线 + 面积填充 + 十字线 tooltip + 键盘导航)
- nginx 为 index.html 增加 no-cache、/assets/ 增加 immutable
  缓存,避免发版后浏览器沿用旧 bundle

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-03 11:59:27 +08:00
parent 95198e6a07
commit 65e4e6778d
6 changed files with 158 additions and 55 deletions

View File

@@ -8,10 +8,15 @@ export type TrendRow = {
tokens: bigint;
};
/**
* UTC midnight `days - 1` days ago, so a window of `days` buckets ends on
* (and includes) today. UTC is used because `calledAt` is stored as naive
* UTC and the SQL groups by its date part.
*/
export function daysWindowStart(days: number): Date {
const since = new Date();
since.setDate(since.getDate() - days);
since.setHours(0, 0, 0, 0);
const now = new Date();
const since = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
since.setUTCDate(since.getUTCDate() - (days - 1));
return since;
}
@@ -43,7 +48,7 @@ export async function getDailyTrends(opts: { since: Date; days: number; projectI
const filled = [];
for (let i = 0; i < days; i++) {
const d = new Date(since);
d.setDate(d.getDate() + i);
d.setUTCDate(d.getUTCDate() + i);
const key = d.toISOString().slice(0, 10);
const row = map.get(key);
const total = row ? Number(row.total) : 0;