Skip to content

Commit 0feca91

Browse files
committed
fix(MOC-54): 活跃度图单点态渲染 marker+grid,不再空荡
下载量趋势图刚上线(每日 cron 累积 1 点,GitHub 不暴露下载历史无法回填), 当前只有 1 个数据点 → 触发 <2 点占位分支,只在空卡片中央飘一行文字,观感 像"曲线没显示 / 文字过大"(实际 ≥2 点的曲线渲染完全正常,本次未动)。 <2 点态改为:画 grid + 单点 marker + 简短 caption(0 点画 grid + 提示), 读起来是"已开始追踪、趋势线每日填充"而非坏图。grid/坐标系上提复用, ≥2 点输出字节不变。
1 parent 31ed52c commit 0feca91

1 file changed

Lines changed: 31 additions & 13 deletions

File tree

tools/download-stats/gen_chart.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,43 @@ def render_svg(series: list[dict]) -> str:
8181
f'font-size="20" font-weight="800">{esc(fmt(latest))}</text>'
8282
)
8383

84+
x0, x1 = PAD_L, W - PAD_R
85+
y0, y1 = PAD_T, H - PAD_B
86+
grid = "".join(
87+
f'<line x1="{x0}" y1="{y0 + (y1-y0)*k/3:.1f}" x2="{x1}" '
88+
f'y2="{y0 + (y1-y0)*k/3:.1f}" stroke="rgba(27,31,36,0.06)"/>'
89+
for k in range(4)
90+
)
91+
92+
# Fewer than two points: a trend line needs at least two, and GitHub exposes only the
93+
# current cumulative count (no history) so earlier points can't be backfilled — the
94+
# line draws itself once the daily cron lands a 2nd point. Render the grid (so the card
95+
# reads as a chart that has started) plus, for the single point, a centred marker and
96+
# caption, instead of an empty card with one floating line of text.
8497
if len(series) < 2:
85-
sub = (
86-
f'<text x="{W/2}" y="{H/2+8}" text-anchor="middle" fill="#57606a" font-size="13">'
87-
+ (f"tracking since {esc(series[0]['date'])} — chart fills in over time"
88-
if series else "no release downloads yet")
89-
+ "</text>"
98+
if not series:
99+
body = (
100+
grid
101+
+ f'<text x="{(x0+x1)/2:.1f}" y="{(y0+y1)/2:.1f}" text-anchor="middle" '
102+
'dominant-baseline="middle" fill="#57606a" font-size="13">'
103+
"no release downloads yet</text>"
104+
)
105+
return head + big + body + "</svg>"
106+
cx, cy = (x0 + x1) / 2, (y0 + y1) / 2
107+
d0 = esc(series[0]["date"])
108+
body = (
109+
grid
110+
+ f'<circle cx="{cx:.1f}" cy="{cy:.1f}" r="8" fill="{accent}" opacity="0.25"/>'
111+
+ f'<circle cx="{cx:.1f}" cy="{cy:.1f}" r="4.5" fill="{accent}"/>'
112+
+ f'<text x="{cx:.1f}" y="{cy+26:.1f}" text-anchor="middle" fill="#57606a" '
113+
f'font-size="12">tracking since {d0} · trend line fills in daily</text>'
114+
+ f'<text x="{x0}" y="{H-12}" fill="#8b949e" font-size="11">{d0}</text>'
90115
)
91-
return head + big + sub + "</svg>"
116+
return head + big + body + "</svg>"
92117

93118
totals = [p["total"] for p in series]
94119
lo, hi = min(totals), max(totals)
95120
span = (hi - lo) or 1
96-
x0, x1 = PAD_L, W - PAD_R
97-
y0, y1 = PAD_T, H - PAD_B
98121
n = len(series)
99122

100123
def px(i: int) -> float:
@@ -111,11 +134,6 @@ def py(v: int) -> float:
111134
+ f" L{pts[-1][0]:.1f},{y1:.1f} Z"
112135
)
113136

114-
grid = "".join(
115-
f'<line x1="{x0}" y1="{y0 + (y1-y0)*k/3:.1f}" x2="{x1}" '
116-
f'y2="{y0 + (y1-y0)*k/3:.1f}" stroke="rgba(27,31,36,0.06)"/>'
117-
for k in range(4)
118-
)
119137
lx, ly = pts[-1]
120138
body = (
121139
grid

0 commit comments

Comments
 (0)