YeCanming
feat: presentation
4dcd117
import streamlit as st
import plotly.graph_objects as go
import plotly.express as px
import time
def render_metrics_charts(current_study, current_trial):
"""把原来在 tab_charts 里的 DataFrame 可视化代码都搬进来,只依赖 current_trial 和 st.session_state."""
if not current_trial.metrics_data:
st.info("当前 Trial 没有可显示的指标数据。")
return
# 全局步骤控制、st.session_state.shared_selected_global_step 等逻辑照搬
# …(省略,直接粘进去原来 streamlit_app.py 中的控制器和自动播放部分)…
# 然后就是那段循环绘图和 st.metric + st.plotly_chart + st.dataframe
metric_names = sorted(current_trial.metrics_data.keys())
cols_per_row = st.slider(
"每行图表数量",
1,
4,
2,
key=f"cols_slider_{current_study.name}_{current_trial.name}",
)
for i in range(0, len(metric_names), cols_per_row):
chunk = metric_names[i : i + cols_per_row]
cols = st.columns(len(chunk))
for j, m in enumerate(chunk):
with cols[j]:
df = current_trial.get_metric_dataframe(m)
if df is None or df.empty:
st.warning(f"指标 '{m}' 无数据")
continue
st.subheader(m)
# …Metric 计算 + Plotly 绘制 + 高亮 + 点击同步…
fig = go.Figure()
# …省略:完全同原来逻辑…
st.plotly_chart(fig, use_container_width=True, key=f"chart_{m}")
st.dataframe(df)