Files
ghstats/internal
tiennm99andGitHub 462d2af4dd refactor(card): audit title-fit logic — O(1) form + lock-in unit test (#12)
The title fitter was correct but the loop-down-from-maxFont form hid
its intent. Switch to the direct expression:

    ideal = floor(budget / (chars * 0.6))
    clamp to [11, 15]

Same answer for every title; easier to verify at a glance. Hoist the
four constants (leftInset=20, rightSafety=4, minFont=11, maxFont=15,
charRatio=0.6) to package scope so the new unit test can reference
them without re-declaring.

Utilization audit for realistic dracula titles (width=340, budget=316):

  Stats (5)                                        → 15 px (14 %)
  Top Starred Repos (17)                           → 15 px (48 %)
  Most Commit Language (all time) (31)             → 15 px (91 %)
  Commits by Hour (last year, UTC+7.00) (37)       → 14 px (98 %)
  Commits by Weekday (last year, UTC+7.00) (40)    → 13 px (99 %)
  Commits by Weekday (last year, UTC+12.75) (41)   → 12 px (93 %)
  200-char pathological                            → 11 px (floor)

TestFitTitleFontSize pins this table so a future charRatio tweak can't
silently regress any real title. TestCardsFitFrame (the end-to-end
check) plus this unit test now cover both the geometry and the picked-
font-size paths.
2026-04-19 10:04:02 +07:00
..