fix: replace sideways Y-axis arrows with proper top/bottom annotations

main
Sven Geboers 1 month ago
parent aac8a89118
commit ab99b7de18
  1. 21
      explorer.py

@ -691,6 +691,19 @@ def _render_voting_results(voting_results_json) -> None:
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
def _add_y_direction_annotations(fig: go.Figure) -> None:
"""Add ▲ Progressief / ▼ Conservatief labels above and below the Y axis."""
common = dict(
xref="paper",
yref="paper",
x=-0.07,
showarrow=False,
font=dict(size=11, color="#666666"),
)
fig.add_annotation(**common, y=1.02, text="▲ Progressief", xanchor="center")
fig.add_annotation(**common, y=-0.06, text="▼ Conservatief", xanchor="center")
def build_compass_tab(db_path: str, window_size: str) -> None: def build_compass_tab(db_path: str, window_size: str) -> None:
st.subheader("Politiek Kompas") st.subheader("Politiek Kompas")
st.markdown( st.markdown(
@ -809,7 +822,7 @@ def build_compass_tab(db_path: str, window_size: str) -> None:
title=f"Politiek Kompas — {_window_label(window_idx)} (partijen)", title=f"Politiek Kompas — {_window_label(window_idx)} (partijen)",
labels={ labels={
"x": "Links ← → Rechts", "x": "Links ← → Rechts",
"y": "Progressief / Conservatief", "y": "Progressief / Conservatief",
"n": "Kamerleden", "n": "Kamerleden",
}, },
) )
@ -827,7 +840,7 @@ def build_compass_tab(db_path: str, window_size: str) -> None:
hover_data={"party": True, "x": ":.3f", "y": ":.3f"}, hover_data={"party": True, "x": ":.3f", "y": ":.3f"},
color_discrete_map=colour_map, color_discrete_map=colour_map,
title=f"Politiek Kompas — {_window_label(window_idx)}", title=f"Politiek Kompas — {_window_label(window_idx)}",
labels={"x": "Links ← → Rechts", "y": "Progressief / Conservatief"}, labels={"x": "Links ← → Rechts", "y": "Progressief / Conservatief"},
) )
fig.update_layout( fig.update_layout(
@ -836,6 +849,7 @@ def build_compass_tab(db_path: str, window_size: str) -> None:
xaxis={"range": [-1, 1]}, xaxis={"range": [-1, 1]},
yaxis={"range": [-0.6, 0.6]}, yaxis={"range": [-0.6, 0.6]},
) )
_add_y_direction_annotations(fig)
with col1: with col1:
st.plotly_chart(fig, use_container_width=True) st.plotly_chart(fig, use_container_width=True)
@ -921,10 +935,11 @@ def build_trajectories_tab(db_path: str, window_size: str) -> None:
fig.update_layout( fig.update_layout(
title="Partij trajectories", title="Partij trajectories",
xaxis_title="Links ← → Rechts", xaxis_title="Links ← → Rechts",
yaxis_title="Progressief / Conservatief", yaxis_title="Progressief / Conservatief",
height=600, height=600,
legend_title_text="Partij", legend_title_text="Partij",
) )
_add_y_direction_annotations(fig)
st.plotly_chart(fig, use_container_width=True) st.plotly_chart(fig, use_container_width=True)

Loading…
Cancel
Save