From ba24ad4fe6ee5b51cd7e02fc80e72e9b7cdee0aa Mon Sep 17 00:00:00 2001 From: Sven Geboers Date: Thu, 2 Apr 2026 21:07:46 +0200 Subject: [PATCH] feat: auto-compute flip directions for all SVD components (Task 6) --- explorer.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/explorer.py b/explorer.py index 4348ea7..399e35d 100644 --- a/explorer.py +++ b/explorer.py @@ -2877,6 +2877,19 @@ def build_svd_components_tab(db_path: str) -> None: {p: len(v) for p, v in party_mp_vectors.items()} if party_mp_vectors else {} ) + # Auto-compute flip directions for all components based on party centroids + # This ensures right-wing parties consistently appear on the right side + try: + from analysis.svd_labels import compute_flip_direction + + for comp in range(1, 11): + flip = compute_flip_direction(comp, party_scores) + if comp in SVD_THEMES: + SVD_THEMES[comp]["flip"] = flip + except Exception: + # If flip computation fails, keep existing flip values in SVD_THEMES + pass + # Convert party_scores (possibly [x,y] lists or legacy vectors) into explicit (x,y) coords party_coords: dict = {} for p, v in party_scores.items():