mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
fix(languages): center donut chart and legend based on card midline.
This commit is contained in:
@@ -40,12 +40,18 @@ def render_languages_widget(languages: list[LanguageData], theme_name: str = "da
|
|||||||
for lang in langs:
|
for lang in langs:
|
||||||
lang.percentage = round(lang.percentage * factor, 1)
|
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
|
cx, r = 60, 44
|
||||||
inner_r = 28
|
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
|
circumference = 2 * math.pi * r
|
||||||
|
|
||||||
arcs = ""
|
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
|
# title="Languages", which adds a 36px translate to inner. The 36 is
|
||||||
# already baked into the card height (rows_h + 36); the attribution
|
# already baked into the card height (rows_h + 36); the attribution
|
||||||
# adds another 16 on top, positioned 8px from the bottom of the card.
|
# adds another 16 on top, positioned 8px from the bottom of the card.
|
||||||
rows_h = max(len(langs) * 22 + 40, 120)
|
|
||||||
footer_h = 16
|
footer_h = 16
|
||||||
card_h = rows_h + 36 + footer_h
|
card_h = rows_h + 36 + footer_h
|
||||||
inner += f'''
|
inner += f'''
|
||||||
|
|||||||
Reference in New Issue
Block a user