Commit ·
82db717
1
Parent(s): a83d1a4
fix(app): placer la légende de la météo 7 jours sous le graphique
Browse filesLa légende verticale par défaut chevauchait l'axe de droite
(température). Elle est désormais horizontale, centrée sous le
graphique, avec une marge basse dédiée (rendu vérifié en PNG).
- utils_simple.create_forecast_chart() : construction du graphique
déplacée hors de app.py pour être testable
- Test : légende horizontale sous la zone de tracé, axe droit conservé
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- streamlit_app/app.py +2 -25
- streamlit_app/utils_simple.py +32 -0
- tests/test_messages.py +22 -0
streamlit_app/app.py
CHANGED
|
@@ -27,6 +27,7 @@ from streamlit_app.utils_simple import (
|
|
| 27 |
format_risk,
|
| 28 |
sync_conso_default,
|
| 29 |
risk_message,
|
|
|
|
| 30 |
NO_TRANSLATE_JS,
|
| 31 |
)
|
| 32 |
from src.config import QUARTIERS_DAKAR, classify_risk, RISK_THRESHOLDS, SLIDER_CONFIG, TRAINING_RANGES
|
|
@@ -304,31 +305,7 @@ with tab4:
|
|
| 304 |
st.subheader("🌤️ Prévisions Météo 7 Jours")
|
| 305 |
forecast = get_weather_forecast_7days()
|
| 306 |
if forecast:
|
| 307 |
-
|
| 308 |
-
fig_fc = go.Figure()
|
| 309 |
-
fig_fc.add_trace(go.Bar(
|
| 310 |
-
x=df_fc['date'], y=df_fc['precipitation'],
|
| 311 |
-
name='Précipitations (mm)', marker_color='#3498db', opacity=0.6,
|
| 312 |
-
))
|
| 313 |
-
fig_fc.add_trace(go.Scatter(
|
| 314 |
-
x=df_fc['date'], y=df_fc['temp_max'],
|
| 315 |
-
mode='lines+markers', name='Temp max (°C)',
|
| 316 |
-
line=dict(color='#e74c3c', width=2), yaxis='y2',
|
| 317 |
-
))
|
| 318 |
-
fig_fc.add_trace(go.Scatter(
|
| 319 |
-
x=df_fc['date'], y=df_fc['temp_min'],
|
| 320 |
-
mode='lines+markers', name='Temp min (°C)',
|
| 321 |
-
line=dict(color='#2ecc71', width=2, dash='dot'), yaxis='y2',
|
| 322 |
-
))
|
| 323 |
-
fig_fc.update_layout(
|
| 324 |
-
title="Prévisions Météo Dakar — 7 prochains jours",
|
| 325 |
-
xaxis_title="Date",
|
| 326 |
-
yaxis=dict(title="Précipitations (mm)", range=[0, 20]),
|
| 327 |
-
yaxis2=dict(title="Température (°C)", overlaying='y', side='right', range=[20, 45]),
|
| 328 |
-
hovermode='x unified',
|
| 329 |
-
height=400,
|
| 330 |
-
)
|
| 331 |
-
st.plotly_chart(fig_fc, use_container_width=True)
|
| 332 |
else:
|
| 333 |
st.info("🌐 Prévisions indisponibles (API météo)")
|
| 334 |
|
|
|
|
| 27 |
format_risk,
|
| 28 |
sync_conso_default,
|
| 29 |
risk_message,
|
| 30 |
+
create_forecast_chart,
|
| 31 |
NO_TRANSLATE_JS,
|
| 32 |
)
|
| 33 |
from src.config import QUARTIERS_DAKAR, classify_risk, RISK_THRESHOLDS, SLIDER_CONFIG, TRAINING_RANGES
|
|
|
|
| 305 |
st.subheader("🌤️ Prévisions Météo 7 Jours")
|
| 306 |
forecast = get_weather_forecast_7days()
|
| 307 |
if forecast:
|
| 308 |
+
st.plotly_chart(create_forecast_chart(forecast), use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
else:
|
| 310 |
st.info("🌐 Prévisions indisponibles (API météo)")
|
| 311 |
|
streamlit_app/utils_simple.py
CHANGED
|
@@ -358,6 +358,38 @@ def create_temporal_chart(df_hist, quartier_filter):
|
|
| 358 |
logger.warning(f"create_temporal_chart failed: {e}")
|
| 359 |
return None
|
| 360 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
def create_risk_trend_chart(df_hist, quartier_filter):
|
| 362 |
if df_hist is None or len(df_hist) == 0 or 'coupure' not in df_hist.columns:
|
| 363 |
return None
|
|
|
|
| 358 |
logger.warning(f"create_temporal_chart failed: {e}")
|
| 359 |
return None
|
| 360 |
|
| 361 |
+
def create_forecast_chart(forecast):
|
| 362 |
+
"""Prévisions météo 7 jours : précipitations (axe gauche), températures (axe droit).
|
| 363 |
+
Légende horizontale sous le graphique pour ne pas chevaucher l'axe de droite."""
|
| 364 |
+
df_fc = pd.DataFrame(forecast)
|
| 365 |
+
fig = go.Figure()
|
| 366 |
+
fig.add_trace(go.Bar(
|
| 367 |
+
x=df_fc['date'], y=df_fc['precipitation'],
|
| 368 |
+
name='Précipitations (mm)', marker_color='#3498db', opacity=0.6,
|
| 369 |
+
))
|
| 370 |
+
fig.add_trace(go.Scatter(
|
| 371 |
+
x=df_fc['date'], y=df_fc['temp_max'],
|
| 372 |
+
mode='lines+markers', name='Temp max (°C)',
|
| 373 |
+
line=dict(color='#e74c3c', width=2), yaxis='y2',
|
| 374 |
+
))
|
| 375 |
+
fig.add_trace(go.Scatter(
|
| 376 |
+
x=df_fc['date'], y=df_fc['temp_min'],
|
| 377 |
+
mode='lines+markers', name='Temp min (°C)',
|
| 378 |
+
line=dict(color='#2ecc71', width=2, dash='dot'), yaxis='y2',
|
| 379 |
+
))
|
| 380 |
+
fig.update_layout(
|
| 381 |
+
title="Prévisions Météo Dakar — 7 prochains jours",
|
| 382 |
+
xaxis_title="Date",
|
| 383 |
+
yaxis=dict(title="Précipitations (mm)", range=[0, 20]),
|
| 384 |
+
yaxis2=dict(title="Température (°C)", overlaying='y', side='right', range=[20, 45]),
|
| 385 |
+
legend=dict(orientation='h', yanchor='top', y=-0.25, xanchor='center', x=0.5),
|
| 386 |
+
margin=dict(b=110),
|
| 387 |
+
hovermode='x unified',
|
| 388 |
+
height=450,
|
| 389 |
+
)
|
| 390 |
+
return fig
|
| 391 |
+
|
| 392 |
+
|
| 393 |
def create_risk_trend_chart(df_hist, quartier_filter):
|
| 394 |
if df_hist is None or len(df_hist) == 0 or 'coupure' not in df_hist.columns:
|
| 395 |
return None
|
tests/test_messages.py
CHANGED
|
@@ -54,3 +54,25 @@ def test_dockerfile_desactive_la_traduction():
|
|
| 54 |
dockerfile = (ROOT / 'Dockerfile').read_text(encoding='utf-8')
|
| 55 |
assert '<html lang="fr" translate="no">' in dockerfile
|
| 56 |
assert 'content="notranslate"' in dockerfile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
dockerfile = (ROOT / 'Dockerfile').read_text(encoding='utf-8')
|
| 55 |
assert '<html lang="fr" translate="no">' in dockerfile
|
| 56 |
assert 'content="notranslate"' in dockerfile
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# ---------------------------------------------------------------------------
|
| 60 |
+
# Graphique météo 7 jours : légende sous le graphique
|
| 61 |
+
# ---------------------------------------------------------------------------
|
| 62 |
+
|
| 63 |
+
from streamlit_app.utils_simple import create_forecast_chart
|
| 64 |
+
|
| 65 |
+
FORECAST = [
|
| 66 |
+
{'date': f'2026-11-{17 + i}', 'temp_max': 30 + i, 'temp_min': 22, 'precipitation': 0.0, 'wind_max': 15}
|
| 67 |
+
for i in range(7)
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def test_legende_meteo_horizontale_sous_le_graphique():
|
| 72 |
+
fig = create_forecast_chart(FORECAST)
|
| 73 |
+
legend = fig.layout.legend
|
| 74 |
+
assert legend.orientation == 'h'
|
| 75 |
+
assert legend.y < 0 and legend.yanchor == 'top' # sous la zone de tracé, donc loin de l'axe de droite
|
| 76 |
+
assert fig.layout.margin.b >= 100 # place réservée pour la légende
|
| 77 |
+
assert [t.name for t in fig.data] == ['Précipitations (mm)', 'Temp max (°C)', 'Temp min (°C)']
|
| 78 |
+
assert fig.layout.yaxis2.side == 'right'
|