Files
github-readme-stats/generator/src/widgets/focus.py
T
shayandClaude Opus 5 769cde552d feat(widgets): attribution on every widget, and make it legible
Five of the seven standalone widgets and all three placeholder cards
carried no attribution at all, and where it did render it was font-size 9
at opacity 0.5 (about 2.1:1 contrast) at the bottom of a 1500px card. Each
embedded widget sits on a public profile and is the only organic
acquisition surface we have.

Shared helper so the styling can't drift again. font-size 10, opacity
0.75 (about 3.1:1), still using the theme's text_secondary so it stays
roughly 4x fainter than the user's own content. Composite output is
byte-identical in size; four standalone cards grow 16px where the footer
would otherwise collide with existing content.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BwMoSbmK77Ph7XaV5YnAdS
2026-08-22 16:10:26 -07:00

68 lines
2.8 KiB
Python

"""Focus areas widget rendering."""
from ..models import FocusCategory
from ..themes import THEMES, FOCUS_COLORS
from ..utils import escape, card_wrapper
from .attribution import FOOTER_H, attribution_text
def render_focus_widget(categories: list[FocusCategory], theme_name: str = "dark", period: str = "1y", settings: dict | None = None) -> str:
"""Renders the focus areas widget with horizontal bars.
Settings:
max_categories (int): Max categories to show (default 6)
"""
t = THEMES[theme_name]
s = settings or {}
max_cats = min(max(int(s.get("max_categories", 6)), 1), 10)
cats = sorted(categories, key=lambda c: -c.percentage)[:max_cats]
if not cats:
return ""
# Format period for display
period_map = {
"1w": "last week",
"1m": "last month",
"3m": "last 3 months",
"6m": "last 6 months",
"1y": "last year",
"all": "all time"
}
period_display = period_map.get(period, period)
max_pct = cats[0].percentage if cats else 100
max_pct = max(max_pct, 1) # Avoid division by zero
bar_max_w = 210
items = ""
for i, cat in enumerate(cats):
color = FOCUS_COLORS[i % len(FOCUS_COLORS)]
y = i * 36
bar_w = (cat.percentage / max_pct) * bar_max_w
items += f'''
<g transform="translate(16, {y})">
<text x="0" y="14" font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
font-size="12" font-weight="600" fill="{t["text"]}">{escape(cat.category)}</text>
<rect x="90" y="4" width="{bar_max_w}" height="14" rx="7" fill="{t["grid"]}"/>
<rect x="90" y="4" width="{bar_w}" height="14" rx="7" fill="{color}" opacity="0.8">
<animate attributeName="width" from="0" to="{bar_w}" dur="0.7s" fill="freeze"/>
</rect>
<text x="90" y="32" font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
font-size="9" fill="{t["text_secondary"]}">{cat.commit_count} commits</text>
<text x="{90 + bar_max_w + 8}" y="15" font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
font-size="12" font-weight="700" fill="{color}">{cat.percentage:.0f}%</text>
</g>'''
# Add period subtitle
subtitle_y = len(cats) * 36 + 8
items += f'''
<text x="16" y="{subtitle_y}" font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
font-size="9" fill="{t["text_secondary"]}" opacity="0.7">Recent activity · {period_display}</text>'''
# The period subtitle leaves only 8px below it, so reserve FOOTER_H for
# the attribution footer.
card_h = len(cats) * 36 + 54 + FOOTER_H
items += attribution_text(t, 190, card_h - 36 - 8)
return card_wrapper(items, 380, card_h, t, "Recent Focus")