mirror of
https://github.com/hotyue/IP-Sentinel.git
synced 2026-09-09 09:27:16 +08:00
style: 升级星标图表渲染引擎,适配暗黑模式可视化
This commit is contained in:
@@ -2,8 +2,8 @@ name: Generate Star History
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * *' # 每天 UTC 零点自动触发执行
|
- cron: '0 0 * * *'
|
||||||
workflow_dispatch: # 允许您在 GitHub 网页上手动点击运行
|
workflow_dispatch:
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@@ -19,12 +19,10 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
echo "🚀 初始化 Python 虚拟环境与画图引擎..."
|
|
||||||
python3 -m venv venv
|
python3 -m venv venv
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
pip install matplotlib requests
|
pip install matplotlib requests
|
||||||
|
|
||||||
echo "📊 正在从 GitHub 官方接口拉取星标数据并渲染 SVG..."
|
|
||||||
python3 - <<'PYEOF'
|
python3 - <<'PYEOF'
|
||||||
import requests, os
|
import requests, os
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@@ -40,7 +38,6 @@ jobs:
|
|||||||
while url:
|
while url:
|
||||||
r = requests.get(url, headers=headers)
|
r = requests.get(url, headers=headers)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
print(f"API Error: {r.status_code} - {r.text}")
|
|
||||||
break
|
break
|
||||||
data = r.json()
|
data = r.json()
|
||||||
if not data:
|
if not data:
|
||||||
@@ -53,25 +50,47 @@ jobs:
|
|||||||
if dates:
|
if dates:
|
||||||
dates.sort()
|
dates.sort()
|
||||||
counts = list(range(1, len(dates) + 1))
|
counts = list(range(1, len(dates) + 1))
|
||||||
# 延长折线到当前时间
|
|
||||||
dates.append(datetime.utcnow())
|
dates.append(datetime.utcnow())
|
||||||
counts.append(counts[-1])
|
counts.append(counts[-1])
|
||||||
|
|
||||||
plt.figure(figsize=(10, 5))
|
# ==========================================
|
||||||
plt.plot(dates, counts, color='#2ea44f', linewidth=2)
|
# [视觉升级] 注入 GitHub 官方暗黑模式 UI 规范
|
||||||
plt.fill_between(dates, counts, color='#2ea44f', alpha=0.1)
|
# ==========================================
|
||||||
plt.title(f'{repo} Star History', fontsize=16)
|
bg_color = '#0d1117' # GitHub 暗黑底色
|
||||||
plt.ylabel('Stars', fontsize=12)
|
text_color = '#c9d1d9' # GitHub 亮灰字体
|
||||||
plt.grid(True, linestyle='--', alpha=0.6)
|
grid_color = '#30363d' # GitHub 边框网格色
|
||||||
|
line_color = '#2ea44f' # GitHub 经典成功绿
|
||||||
|
|
||||||
|
fig, ax = plt.subplots(figsize=(10, 5), facecolor=bg_color)
|
||||||
|
ax.set_facecolor(bg_color)
|
||||||
|
|
||||||
|
# 设置字体颜色与坐标轴颜色
|
||||||
|
ax.tick_params(colors=text_color)
|
||||||
|
ax.xaxis.label.set_color(text_color)
|
||||||
|
ax.yaxis.label.set_color(text_color)
|
||||||
|
ax.title.set_color(text_color)
|
||||||
|
|
||||||
|
# 设置边框颜色
|
||||||
|
for spine in ax.spines.values():
|
||||||
|
spine.set_edgecolor(grid_color)
|
||||||
|
|
||||||
|
# 绘制核心趋势线与阴影填充
|
||||||
|
plt.plot(dates, counts, color=line_color, linewidth=2)
|
||||||
|
plt.fill_between(dates, counts, color=line_color, alpha=0.1)
|
||||||
|
|
||||||
|
plt.title(f'{repo} Star History', fontsize=16, color=text_color, pad=15)
|
||||||
|
plt.ylabel('Stars', fontsize=12, color=text_color)
|
||||||
|
|
||||||
|
# 设置网格虚线
|
||||||
|
plt.grid(True, linestyle='--', alpha=0.5, color=grid_color)
|
||||||
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
|
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
|
||||||
plt.gcf().autofmt_xdate()
|
plt.gcf().autofmt_xdate()
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
|
|
||||||
os.makedirs('data', exist_ok=True)
|
os.makedirs('data', exist_ok=True)
|
||||||
plt.savefig('data/star_history.svg', format='svg', transparent=True)
|
# 强制应用背景色,关闭透明度,打破隐形诅咒
|
||||||
print("✅ [Success] 原生 SVG 图表渲染完毕!")
|
plt.savefig('data/star_history.svg', format='svg', facecolor=bg_color, transparent=False)
|
||||||
else:
|
print("✅ [Success] 极客暗黑风 SVG 渲染完毕!")
|
||||||
print("⚠️ [Warning] 暂无 Star 数据或获取失败。")
|
|
||||||
PYEOF
|
PYEOF
|
||||||
|
|
||||||
- name: Commit & Push Changes
|
- name: Commit & Push Changes
|
||||||
@@ -79,5 +98,5 @@ jobs:
|
|||||||
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
git config --local user.name "github-actions[bot]"
|
git config --local user.name "github-actions[bot]"
|
||||||
git add data/star_history.svg
|
git add data/star_history.svg
|
||||||
git commit -m "chore: 部署纯本地 Python 渲染引擎,彻底摆脱 502 梦魇" || exit 0
|
git commit -m "style: 修复暗黑模式下坐标轴隐形问题,采用 GitHub 原生深色主题渲染图表" || exit 0
|
||||||
git push origin main
|
git push origin main
|
||||||
|
|||||||
Reference in New Issue
Block a user