From 8251308f72c1b45b814993f91e1e16480259e546 Mon Sep 17 00:00:00 2001 From: zhenghu <1831829219@qq.com> Date: Tue, 14 Apr 2026 15:16:31 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8F=90=E5=8F=96=20hex=5Fto=5Frgb?= =?UTF-8?q?a=20=E5=87=BD=E6=95=B0=E8=A7=84=E8=8C=83=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E9=80=8F=E6=98=8E=E5=BA=A6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将图表 fill 颜色的硬编码十六进制拼接替换为 hex_to_rgba 辅助函数调用,使颜色转换逻辑更清晰、可维护。 --- app.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index bad2ff6..7ed69f8 100644 --- a/app.py +++ b/app.py @@ -8,6 +8,15 @@ from plotly.subplots import make_subplots from simulator import run_wofost, run_multi_crop, list_available_crops, CROP_META + +def hex_to_rgba(hex_color: str, alpha: float = 0.1) -> str: + hex_color = hex_color.lstrip("#") + r = int(hex_color[0:2], 16) + g = int(hex_color[2:4], 16) + b = int(hex_color[4:6], 16) + return f"rgba({r}, {g}, {b}, {alpha})" + + # ─── Page Config ──────────────────────────────────────────────────────────── st.set_page_config( page_title="麦麦智农", @@ -274,7 +283,7 @@ with chart_left: mode="lines", line=dict(color=crop_info["color"], width=2.5), fill="tozeroy", - fillcolor=crop_info["color"] + "1A", + fillcolor=hex_to_rgba(crop_info["color"], 0.1), name="LAI", )) # 添加生育期标记