svg

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package svg provides SVG stats card generation for GitHub profiles.

Index

Constants

View Source
const (
	// DefaultWidth is the default card width in pixels.
	DefaultWidth = 350

	// DefaultPaddingX is the horizontal padding.
	DefaultPaddingX = 25

	// DefaultPaddingY is the vertical padding for the title.
	DefaultPaddingY = 35

	// DefaultBorderRadius is the corner radius.
	DefaultBorderRadius = 4.5

	// DefaultStatRowHeight is the height of each stat row.
	DefaultStatRowHeight = 25

	// DefaultIconSize is the size of stat icons.
	DefaultIconSize = 16
)

Variables

This section is empty.

Functions

func CalculateHeight

func CalculateHeight(numRows int) float64

CalculateHeight returns the required height for a card with the given number of stat rows.

func ChangelogCategoriesByMonthChart

func ChangelogCategoriesByMonthChart(data *chart.CommitTypeData, themeName, title string) *chart.StackedBarChart

ChangelogCategoriesByMonthChart creates a stacked bar chart showing changelog categories by month. This is the stakeholder-focused view showing Added, Fixed, Changed, etc.

func ChangelogCategoriesByMonthChartJSON

func ChangelogCategoriesByMonthChartJSON(data *chart.CommitTypeData, themeName, title string) ([]byte, error)

ChangelogCategoriesByMonthChartJSON generates a JSON IR for changelog categories by month.

func ChangelogCategoriesByMonthChartSVG

func ChangelogCategoriesByMonthChartSVG(data *chart.CommitTypeData, themeName, title string) string

ChangelogCategoriesByMonthChartSVG generates an SVG for changelog categories by month.

func CommitTypesByMonthChart

func CommitTypesByMonthChart(data *chart.CommitTypeData, themeName, title string) *chart.StackedBarChart

CommitTypesByMonthChart creates a stacked bar chart showing conventional commit types by month. This is the developer-focused view showing feat, fix, docs, refactor, etc.

func CommitTypesByMonthChartJSON

func CommitTypesByMonthChartJSON(data *chart.CommitTypeData, themeName, title string) ([]byte, error)

CommitTypesByMonthChartJSON generates a JSON IR for commit types by month.

func CommitTypesByMonthChartSVG

func CommitTypesByMonthChartSVG(data *chart.CommitTypeData, themeName, title string) string

CommitTypesByMonthChartSVG generates an SVG for commit types by month.

func GenerateMonthlyLinesJSON

func GenerateMonthlyLinesJSON(p *profile.UserProfile, themeName string) ([]byte, error)

GenerateMonthlyLinesJSON creates the JSON IR for a monthly lines bar chart. Deprecated: Use MonthlyLinesBarChartJSON for the new generic chart API.

func GenerateMonthlyLinesSVG

func GenerateMonthlyLinesSVG(p *profile.UserProfile, themeName, title string) string

GenerateMonthlyLinesSVG creates the SVG for a monthly lines bar chart. Deprecated: Use MonthlyLinesBarChartSVG for the new generic chart API.

func GenerateSVG

func GenerateSVG(p *profile.UserProfile, themeName, title string) string

GenerateSVG is a convenience function to generate an SVG from a profile. Deprecated: Use ProfileStatsTableSVG for the new generic chart API.

func GenerateSVGBytes

func GenerateSVGBytes(p *profile.UserProfile, themeName, title string) []byte

GenerateSVGBytes is a convenience function to generate SVG bytes from a profile. Deprecated: Use ProfileStatsTable(p, theme, title).RenderBytes() for the new generic chart API.

func MonthlyAdditionsDeletionsBarChart

func MonthlyAdditionsDeletionsBarChart(p *profile.UserProfile, themeName, title string) *chart.BarChart

MonthlyAdditionsDeleteionsBarChart creates a multi-series bar chart.

func MonthlyLinesBarChart

func MonthlyLinesBarChart(p *profile.UserProfile, themeName, title string) *chart.BarChart

MonthlyLinesBarChart creates a bar chart showing net lines by month.

func MonthlyLinesBarChartJSON

func MonthlyLinesBarChartJSON(p *profile.UserProfile, themeName, title string) ([]byte, error)

MonthlyLinesBarChartJSON generates a JSON IR for the monthly lines chart.

func MonthlyLinesBarChartSVG

func MonthlyLinesBarChartSVG(p *profile.UserProfile, themeName, title string) string

MonthlyLinesBarChartSVG generates an SVG bar chart from a profile.

func ProfileStatsTable

func ProfileStatsTable(p *profile.UserProfile, themeName, title string) *chart.TableChart

ProfileStatsTable creates a table chart from a UserProfile.

func ProfileStatsTableJSON

func ProfileStatsTableJSON(p *profile.UserProfile, themeName, title string) ([]byte, error)

ProfileStatsTableJSON generates a JSON IR for the stats table.

func ProfileStatsTableSVG

func ProfileStatsTableSVG(p *profile.UserProfile, themeName, title string) string

ProfileStatsTableSVG generates an SVG stats table from a profile.

func RenderIcon

func RenderIcon(iconType IconType, x, y, size float64, color string) string

RenderIcon returns an SVG group element containing the icon. The icon is rendered at the specified position with the given size and color.

func RenderIconInline

func RenderIconInline(iconType IconType, color string) string

RenderIconInline returns just the path element for embedding in an existing SVG.

func ThemeNames

func ThemeNames() []string

ThemeNames returns all available theme names.

Types

type Card

type Card struct {
	Width        float64
	Height       float64
	PaddingX     float64
	PaddingY     float64
	BorderRadius float64
	Theme        Theme
	Title        string
}

Card represents the base SVG card structure.

func NewCard

func NewCard(title string, theme Theme) *Card

NewCard creates a new card with default dimensions.

func (*Card) RenderBackground

func (c *Card) RenderBackground() string

RenderBackground returns the background rectangle.

func (*Card) RenderFooter

func (c *Card) RenderFooter() string

RenderFooter returns the closing SVG tag.

func (*Card) RenderHeader

func (c *Card) RenderHeader() string

RenderHeader returns the SVG header with XML declaration and opening tag.

func (*Card) RenderStatRows

func (c *Card) RenderStatRows(rows []StatRow, startY float64) string

RenderStatRows renders multiple stat rows starting at the given Y position.

func (*Card) RenderStyles

func (c *Card) RenderStyles() string

RenderStyles returns the CSS styles block.

func (*Card) RenderTitle

func (c *Card) RenderTitle() string

RenderTitle returns the SVG title element.

func (*Card) RenderTitleText

func (c *Card) RenderTitleText() string

RenderTitleText returns the title text element.

func (*Card) SetHeight

func (c *Card) SetHeight(height float64)

SetHeight adjusts the card height.

type IconType

type IconType string

IconType represents the type of icon to render.

const (
	IconStar     IconType = "star"
	IconCommit   IconType = "commit"
	IconPR       IconType = "pr"
	IconIssue    IconType = "issue"
	IconCode     IconType = "code"
	IconRepo     IconType = "repo"
	IconReview   IconType = "review"
	IconCalendar IconType = "calendar"
	IconStreak   IconType = "streak"
)

type StatRow

type StatRow struct {
	Icon  IconType
	Label string
	Value string
}

StatRow represents a single stat row with icon, label, and value.

type StatsCard

type StatsCard struct {
	*Card
	// contains filtered or unexported fields
}

StatsCard generates an SVG stats card from a UserProfile.

func NewStatsCard

func NewStatsCard(p *profile.UserProfile, theme Theme, title string) *StatsCard

NewStatsCard creates a new stats card from a UserProfile.

func NewStatsCardWithOptions

func NewStatsCardWithOptions(p *profile.UserProfile, opts StatsCardOptions) *StatsCard

NewStatsCardWithOptions creates a stats card with custom options.

func (*StatsCard) Render

func (sc *StatsCard) Render() string

Render generates the complete SVG string.

func (*StatsCard) RenderBytes

func (sc *StatsCard) RenderBytes() []byte

RenderBytes returns the SVG as a byte slice.

type StatsCardOptions

type StatsCardOptions struct {
	Theme        string
	Title        string
	HideBorder   bool
	HideTitle    bool
	CustomStats  []StatRow // Additional custom stats to include
	ExcludeStats []string  // Stat labels to exclude
	Width        float64   // Custom width (0 = default)
	BgColor      string    // Override background color
	TitleColor   string    // Override title color
	TextColor    string    // Override text color
	IconColor    string    // Override icon color
}

StatsCardOptions configures the stats card generation.

type Theme

type Theme struct {
	Name        string
	TitleColor  string // hex color for title text
	TextColor   string // hex color for stat labels and values
	IconColor   string // hex color for stat icons
	BgColor     string // hex color for background
	BorderColor string // hex color for border
}

Theme defines the color scheme for an SVG stats card.

func DefaultTheme

func DefaultTheme() Theme

DefaultTheme returns the default theme.

func GetTheme

func GetTheme(name string) Theme

GetTheme returns a theme by name. If the theme is not found, it returns the default theme.

Directories

Path Synopsis
Package chart provides generic SVG chart generation.
Package chart provides generic SVG chart generation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL