mirror of
https://github.com/tiennm99/ghstats.git
synced 2026-05-17 20:59:14 +00:00
442da96f99
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.
60 lines
1.6 KiB
Go
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
|
|
}
|