Commit 3443f7c7 authored by 郭阔's avatar 郭阔

ui(dashboard): 趋势图重绘为 SVG——柔和配色/圆角柱/坐标轴/悬浮高亮

替换 flex 拼柱:细柱大缝、刻度挤、数字悬空等问题。SVG viewBox 坐标系内
预算几何,5 条基线+刻度右对齐,柱顶总量标签,日期标签随柱,悬浮整组高亮
并显示站点明细;配色降饱和;图例移至标题行右侧带 7 天合计。
parent 984f70d2
......@@ -1310,8 +1310,8 @@ def guide():
return render_template("guide.html", body=body, raw=text)
SITE_COLORS = {"reuters": "#e05555", "nikkei": "#6b9ef1", "wsj": "#4ec9b0", "ft": "#e8c34a",
"bloomberg": "#c586c0", "digitimes": "#8badd4", "wccftech": "#8a8f98"}
SITE_COLORS = {"reuters": "#ef8a8a", "nikkei": "#8ab4f8", "wsj": "#6fd3be", "ft": "#e6c86e",
"bloomberg": "#c9a2e0", "digitimes": "#9db8d9", "wccftech": "#9aa0a6"}
@app.route("/dashboard")
......@@ -1367,23 +1367,33 @@ def dashboard():
sites = sorted({r["site"] for r in rows if r["d7"] > 0},
key=lambda s: -sum(per_day[d].get(s, 0) for d in days))
chart_max = max([sum(v.values()) for v in per_day.values()] or [1]) or 1
chart_axis_max = int(math.ceil(chart_max / 20.0) * 20)
chart_axis_max = int(math.ceil(chart_max / 20.0) * 20) or 20
# SVG 坐标系(viewBox 760x260)内预算好柱体几何
CW, CH, PL, PT, PR, PB = 760, 260, 46, 28, 10, 30
plot_h = CH - PT - PB
slot = (CW - PL - PR) / max(len(days), 1)
bar_w = min(58.0, slot * 0.56)
bars = []
for d in days:
segs, y = [], 100.0
for i, d in enumerate(days):
x = PL + i * slot + (slot - bar_w) / 2
cum, segs = 0.0, []
total = sum(per_day[d].values())
for s in sites:
v = per_day[d].get(s, 0)
for site in sites:
v = per_day[d].get(site, 0)
if not v:
continue
h = v / chart_axis_max * 100
y -= h
segs.append({"site": s, "v": v, "y": round(y, 1), "h": round(h, 1),
"color": SITE_COLORS.get(s, "#8a8f98")})
bars.append({"day": d, "total": total, "segs": segs})
h = plot_h * v / chart_axis_max
segs.append({"site": site, "v": v, "x": round(x, 1), "h": round(h, 1),
"y": round(PT + plot_h - cum - h, 1),
"color": SITE_COLORS.get(site, "#9aa0a6")})
cum += h
bars.append({"day": d, "label": f"{int(d[5:7])}/{int(d[8:10])}",
"total": total, "x": round(x, 1), "w": round(bar_w, 1), "segs": segs})
grid = [{"y": round(PT + plot_h * (1 - g / 100), 1), "val": int(chart_axis_max * g / 100)}
for g in (0, 25, 50, 75, 100)]
rows.sort(key=lambda r: (-r["today"], -r["d7"]))
active = _active_harvests()
return render_template("dashboard.html", rows=rows, bars=bars, days=days, chart_axis_max=chart_axis_max,
return render_template("dashboard.html", rows=rows, bars=bars, days=days, grid=grid, chart_axis_max=chart_axis_max,
sites=[(s, SITE_COLORS.get(s, "#8a8f98"),
sum(per_day[d].get(s, 0) for d in days)) for s in sites],
tot=tot, today=today, active=active,
......
......@@ -7,16 +7,17 @@
.kpi .card { padding:14px 16px; }
.kpi .num { font-size:26px; font-weight:700; line-height:1.2; }
.kpi .sub { color:#888; font-size:12px; margin-top:2px; }
.chart { display:flex; align-items:stretch; gap:6px; height:200px; margin:10px 0 4px; position:relative; padding-left:44px; }
.chart .grid { position:absolute; left:44px; right:0; border-top:1px dashed #2a2d37; }
.chart .grid span { position:absolute; left:-42px; top:-7px; width:36px; text-align:right; font-size:11px; color:#666; }
.chart .bar { flex:1; display:flex; flex-direction:column-reverse; position:relative; min-width:0; }
.chart .seg { width:100%; }
.chart .bar .total { position:absolute; top:-20px; width:100%; text-align:center; font-size:12px; color:#aaa; }
.chart-labels { display:flex; gap:6px; margin-top:22px; }
.chart-labels span { flex:1; text-align:center; font-size:11px; color:#666; }
.legend { display:flex; gap:14px; flex-wrap:wrap; margin:8px 0 0; font-size:12px; color:#aaa; }
.legend i { display:inline-block; width:10px; height:10px; border-radius:2px; margin-right:5px; vertical-align:-1px; }
.chart-svg { width:100%; height:auto; display:block; }
.chart-svg .barg rect { opacity:.82; transition:opacity .15s; }
.chart-svg .barg:hover rect { opacity:1; }
.chart-svg .axis { font-size:11px; fill:#6a7080; }
.chart-svg .gline { stroke:#232633; stroke-width:1; }
.chart-svg .dlabel { font-size:11px; fill:#7a8090; }
.chart-svg .tlabel { font-size:12px; fill:#aab2c0; font-weight:600; }
.chart-head { display:flex; align-items:baseline; gap:14px; flex-wrap:wrap; margin-top:18px; }
.chart-head h2 { margin:0; }
.legend { display:flex; gap:12px; flex-wrap:wrap; margin-left:auto; font-size:12px; color:#aab2c0; }
.legend i { display:inline-block; width:9px; height:9px; border-radius:50%; margin-right:5px; vertical-align:-1px; }
</style>
{% endblock %}
{% block content %}
......@@ -36,22 +37,28 @@
</div>
</div>
<h2>每日产出(按站点堆叠)</h2>
<div class="chart">
{% for g in [100, 75, 50, 25] %}
<div class="grid" style="bottom:{{ g }}%"><span>{{ (chart_axis_max * g / 100)|int }}</span></div>
<div class="chart-head">
<h2>每日产出</h2>
<div class="legend">
{% for s, color, n in sites %}<span><i style="background:{{ color }}"></i>{{ s }} <b style="color:#d4d4d4">{{ n }}</b></span>{% endfor %}
</div>
</div>
<svg class="chart-svg" viewBox="0 0 760 260" role="img">
{% for g in grid %}
<line class="gline" x1="46" x2="750" y1="{{ g.y }}" y2="{{ g.y }}"></line>
<text class="axis" x="40" y="{{ g.y + 4 }}" text-anchor="end">{{ g.val }}</text>
{% endfor %}
{% for b in bars %}
<div class="bar" title="{{ b.day }} 共 {{ b.total }} 篇{% for s in b.segs %}&#10;{{ s.site }}: {{ s.v }}{% endfor %}">
{% if b.total %}<div class="total">{{ b.total }}</div>{% endif %}
{% for s in b.segs %}<div class="seg" style="height:{{ s.h }}%;background:{{ s.color }}"></div>{% endfor %}
</div>
<g class="barg">
<title>{{ b.day }} · 共 {{ b.total }} 篇
{% for sg in b.segs %}{{ sg.site }}: {{ sg.v }}
{% endfor %}</title>
{% if b.total %}<text class="tlabel" x="{{ b.x + b.w / 2 }}" y="{{ b.segs[0].y - 7 }}" text-anchor="middle">{{ b.total }}</text>{% endif %}
{% for sg in b.segs %}<rect x="{{ sg.x }}" y="{{ sg.y }}" width="{{ b.w }}" height="{{ sg.h }}" rx="2.5" fill="{{ sg.color }}"></rect>{% endfor %}
<text class="dlabel" x="{{ b.x + b.w / 2 }}" y="252" text-anchor="middle">{{ b.label }}</text>
</g>
{% endfor %}
</div>
<div class="chart-labels">{% for b in bars %}<span>{{ b.day[5:] }}</span>{% endfor %}</div>
<div class="legend">
{% for s, color, n in sites %}<span><i style="background:{{ color }}"></i>{{ s }} {{ n }} 篇</span>{% endfor %}
</div>
</svg>
<div style="display:flex;gap:24px;flex-wrap:wrap;margin-top:22px;align-items:flex-start">
<div style="flex:3 1 420px;min-width:340px">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment