refactor: 提取 hex_to_rgba 函数规范颜色透明度处理
将图表 fill 颜色的硬编码十六进制拼接替换为 hex_to_rgba 辅助函数调用,使颜色转换逻辑更清晰、可维护。
This commit is contained in:
11
app.py
11
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",
|
||||
))
|
||||
# 添加生育期标记
|
||||
|
||||
Reference in New Issue
Block a user