Files
ghstats/internal/card/stats.go
T
tiennm99 442da96f99 refactor(card): add octicon labels to stats card
Replace the 2x3 grid with one row per stat: icon + label + right-aligned
value. Icons (star, commit, PR, issue, code-review, repos) mirror the
Octicons used by github-profile-summary-cards' stats card.
2026-04-18 21:09:46 +07:00

60 lines
1.6 KiB
Go

package card
import (
"fmt"
"strings"
"github.com/tiennm99/ghstats/internal/github"
"github.com/tiennm99/ghstats/internal/theme"
)
type statsCard struct{}
func (statsCard) Filename() string { return "3-stats.svg" }
// statRow is one labeled-by-icon line in the stats card.
type statRow struct {
icon string
label string
value string
}
func (statsCard) SVG(p *github.Profile, t theme.Theme) ([]byte, error) {
const (
width = 500
height = 220
rowX = 25
rowY0 = 70
rowDY = 24
iconSize = 14
valueX = 475 // right-aligned x anchor
)
rows := []statRow{
{iconStar, "Total Stars", formatInt(p.TotalStars)},
{iconCommit, "Total Commits (last year)", formatInt(p.TotalCommits)},
{iconPR, "Total PRs", formatInt(p.TotalPRs)},
{iconIssue, "Total Issues", formatInt(p.TotalIssues)},
{iconReview, "Total PR Reviews", formatInt(p.TotalReviews)},
{iconRepos, "Contributed to (non-fork)", formatInt(p.TotalContributedTo)},
}
var b strings.Builder
b.WriteString(header(width, height, t.Background, t.Stroke, t.StrokeOpacity, t.Title, "Stats"))
scale := float64(iconSize) / 16.0
for i, r := range rows {
y := rowY0 + i*rowDY
fmt.Fprintf(&b, `
<g transform="translate(%d,%.2f) scale(%.3f)" fill="%s">%s</g>
<text x="%d" y="%d" font-size="13" fill="%s">%s</text>
<text x="%d" y="%d" font-size="13" font-weight="600" fill="%s" text-anchor="end">%s</text>`,
rowX, float64(y-iconSize+2), scale, t.Muted, r.icon,
rowX+iconSize+10, y, t.Text, escapeXML(r.label),
valueX, y, t.Accent, escapeXML(r.value))
}
b.WriteString(footer)
return []byte(b.String()), nil
}