From eea1734a042b0e6a1630df3a131ed0e1f962b747 Mon Sep 17 00:00:00 2001 From: shay Date: Sat, 25 Jul 2026 16:23:28 -0700 Subject: [PATCH] fix(languages): center donut chart and legend based on card midline. --- generator/src/widgets/languages.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/generator/src/widgets/languages.py b/generator/src/widgets/languages.py index 401a82a..00bb9a6 100644 --- a/generator/src/widgets/languages.py +++ b/generator/src/widgets/languages.py @@ -40,12 +40,18 @@ def render_languages_widget(languages: list[LanguageData], theme_name: str = "da for lang in langs: lang.percentage = round(lang.percentage * factor, 1) - # Calculate center position to align with legend - legend_start = 20 - legend_height = len(langs) * 22 - cy = legend_start + legend_height / 2 cx, r = 60, 44 inner_r = 28 + # The donut is 2 * (r + stroke-width/2) = 104px tall, but the legend block + # is only 22px per language. Centering the donut on the legend alone put + # its top above the card body whenever the legend was shorter than the + # donut (<= 3 languages), overlapping the card title. Center the donut and + # the legend on the body's midline instead; at >= 4 languages this is + # identical to the old geometry. + legend_height = len(langs) * 22 + rows_h = max(legend_height + 40, 120) + cy = rows_h / 2 + legend_start = (rows_h - legend_height) / 2 circumference = 2 * math.pi * r arcs = "" @@ -102,7 +108,6 @@ def render_languages_widget(languages: list[LanguageData], theme_name: str = "da # title="Languages", which adds a 36px translate to inner. The 36 is # already baked into the card height (rows_h + 36); the attribution # adds another 16 on top, positioned 8px from the bottom of the card. - rows_h = max(len(langs) * 22 + 40, 120) footer_h = 16 card_h = rows_h + 36 + footer_h inner += f'''