Documentation
¶
Overview ¶
Package chart provides generic SVG chart generation.
Index ¶
- Constants
- Variables
- func ThemeNames() []string
- type Axis
- type BarChart
- func (b *BarChart) AddSeries(name string, data []float64) *BarChart
- func (b *BarChart) AddSeriesWithColor(name string, data []float64, color string) *BarChart
- func (b *BarChart) Render() string
- func (b *BarChart) RenderBytes() []byte
- func (b *BarChart) SetDimensions(width, height int) *BarChart
- func (b *BarChart) SetXLabels(labels []string) *BarChart
- func (b *BarChart) SetYLabel(label string) *BarChart
- func (b *BarChart) ToJSON() ([]byte, error)
- func (b *BarChart) Type() ChartType
- type ChangelogCategory
- type Chart
- type ChartType
- type CommitTypeData
- type CommitTypeSummary
- type ConventionalCommitType
- type Dimensions
- type IconPath
- type Metadata
- type MonthlyCommitTypes
- type Series
- type StackedBarChart
- func (s *StackedBarChart) AddSeries(name string, data []float64) *StackedBarChart
- func (s *StackedBarChart) AddSeriesWithColor(name string, data []float64, color string) *StackedBarChart
- func (s *StackedBarChart) Render() string
- func (s *StackedBarChart) RenderBytes() []byte
- func (s *StackedBarChart) SetDimensions(width, height int) *StackedBarChart
- func (s *StackedBarChart) SetXLabels(labels []string) *StackedBarChart
- func (s *StackedBarChart) ShowLegend(show bool) *StackedBarChart
- func (s *StackedBarChart) ToJSON() ([]byte, error)
- func (s *StackedBarChart) Type() ChartType
- type TableChart
- func (t *TableChart) AddRow(icon, label, value string) *TableChart
- func (t *TableChart) AddRowWithColor(icon, label, value, color string) *TableChart
- func (t *TableChart) Render() string
- func (t *TableChart) RenderBytes() []byte
- func (t *TableChart) SetDimensions(width, height int) *TableChart
- func (t *TableChart) ToJSON() ([]byte, error)
- func (t *TableChart) Type() ChartType
- type TableRow
- type Theme
Constants ¶
const ( BarPaddingX = 50 BarPaddingY = 30 BarLabelHeight = 20 BarGap = 4 BarBorderRadius = 4 )
Bar chart layout constants
const ( TablePaddingX = 25 TablePaddingY = 35 TableRowHeight = 25 TableIconSize = 16 TableBorderRadius = 4.5 )
Table layout constants
const (
StackedBarLegendHeight = 30
)
Stacked bar layout constants
Variables ¶
var CCToChangelogCategory = map[ConventionalCommitType]ChangelogCategory{ CCFeat: CLAdded, CCFix: CLFixed, CCDocs: CLDocumentation, CCStyle: CLInternal, CCRefactor: CLChanged, CCPerf: CLPerformance, CCTest: CLTests, CCBuild: CLBuild, CCCI: CLInfrastructure, CCChore: CLInternal, CCRevert: CLFixed, CCSecurity: CLSecurity, CCDeps: CLDependencies, CCOther: CLOther, }
CCToChangelogCategory maps conventional commit types to changelog categories.
var CCTypeColors = map[ConventionalCommitType]string{ CCFeat: "#2ea043", CCFix: "#da3633", CCRefactor: "#58a6ff", CCDocs: "#d29922", CCTest: "#a371f7", CCChore: "#8b949e", CCBuild: "#f78166", CCCI: "#db61a2", CCPerf: "#3fb950", CCDeps: "#79c0ff", CCSecurity: "#f85149", CCStyle: "#6e7681", CCRevert: "#ff7b72", CCOther: "#484f58", }
CCTypeColors maps CC types to colors.
var CCTypeLabels = map[ConventionalCommitType]string{ CCFeat: "Features", CCFix: "Fixes", CCRefactor: "Refactor", CCDocs: "Docs", CCTest: "Tests", CCChore: "Chore", CCBuild: "Build", CCCI: "CI", CCPerf: "Perf", CCDeps: "Deps", CCSecurity: "Security", CCStyle: "Style", CCRevert: "Revert", CCOther: "Other", }
CCTypeLabels provides human-readable labels for CC types.
var CLCategoryColors = map[ChangelogCategory]string{ CLAdded: "#2ea043", CLFixed: "#da3633", CLChanged: "#58a6ff", CLSecurity: "#f85149", CLPerformance: "#3fb950", CLDeprecated: "#d29922", CLRemoved: "#ff7b72", CLBreaking: "#f85149", CLDependencies: "#79c0ff", CLDocumentation: "#d29922", CLBuild: "#f78166", CLTests: "#a371f7", CLInfrastructure: "#db61a2", CLInternal: "#8b949e", CLOther: "#484f58", }
CLCategoryColors maps changelog categories to colors.
var ChangelogCategories = []ChangelogCategory{ CLAdded, CLFixed, CLChanged, CLSecurity, CLPerformance, CLBreaking, CLDependencies, CLDocumentation, CLBuild, CLTests, CLInfrastructure, CLInternal, CLOther, }
ChangelogCategories lists categories in display order (stakeholder priority).
var ConventionalCommitTypes = []ConventionalCommitType{ CCFeat, CCFix, CCRefactor, CCDocs, CCTest, CCChore, CCBuild, CCCI, CCPerf, CCDeps, CCSecurity, CCStyle, CCRevert, CCOther, }
ConventionalCommitTypes lists all CC types in display order.
var DefaultSeriesColors = []string{
"#2ea043",
"#da3633",
"#58a6ff",
"#8b949e",
"#d29922",
"#a371f7",
"#f78166",
"#3fb950",
"#db61a2",
"#79c0ff",
}
DefaultSeriesColors provides distinct colors for series.
Functions ¶
Types ¶
type Axis ¶
type Axis struct {
Label string `json:"label,omitempty"`
Labels []string `json:"labels,omitempty"` // For categorical axes
Min *float64 `json:"min,omitempty"` // For numeric axes
Max *float64 `json:"max,omitempty"`
}
Axis represents a chart axis configuration.
type BarChart ¶
type BarChart struct {
ChartType ChartType `json:"type"`
Metadata Metadata `json:"metadata"`
Dimensions Dimensions `json:"dimensions"`
XAxis Axis `json:"x_axis"`
YAxis Axis `json:"y_axis"`
Series []Series `json:"series"`
// contains filtered or unexported fields
}
BarChart renders data as a vertical bar chart.
func NewBarChart ¶
NewBarChart creates a new bar chart.
func (*BarChart) AddSeriesWithColor ¶
AddSeriesWithColor adds a data series with a custom color.
func (*BarChart) RenderBytes ¶
RenderBytes returns the SVG as bytes.
func (*BarChart) SetDimensions ¶
SetDimensions sets custom dimensions.
func (*BarChart) SetXLabels ¶
SetXLabels sets the X-axis labels.
type ChangelogCategory ¶
type ChangelogCategory string
ChangelogCategory represents a structured-changelog category.
const ( CLAdded ChangelogCategory = "Added" CLChanged ChangelogCategory = "Changed" CLFixed ChangelogCategory = "Fixed" CLSecurity ChangelogCategory = "Security" CLPerformance ChangelogCategory = "Performance" CLDeprecated ChangelogCategory = "Deprecated" CLRemoved ChangelogCategory = "Removed" CLBreaking ChangelogCategory = "Breaking" CLDependencies ChangelogCategory = "Dependencies" CLDocumentation ChangelogCategory = "Documentation" CLBuild ChangelogCategory = "Build" CLTests ChangelogCategory = "Tests" CLInfrastructure ChangelogCategory = "Infrastructure" CLInternal ChangelogCategory = "Internal" CLOther ChangelogCategory = "Other" )
Changelog category constants (matching structured-changelog).
type Chart ¶
type Chart interface {
Type() ChartType
Render() string
RenderBytes() []byte
ToJSON() ([]byte, error)
}
Chart is the interface all chart types implement.
type CommitTypeData ¶
type CommitTypeData struct {
Username string `json:"username"`
From string `json:"from"`
To string `json:"to"`
TotalCount int `json:"total_count"`
Monthly []MonthlyCommitTypes `json:"monthly"`
Summary CommitTypeSummary `json:"summary"`
}
CommitTypeData holds commit type analysis data.
type CommitTypeSummary ¶
type CommitTypeSummary struct {
ByCCType map[string]int `json:"by_cc_type"`
ByCLCat map[string]int `json:"by_changelog_category"`
}
CommitTypeSummary holds aggregate commit type counts.
type ConventionalCommitType ¶
type ConventionalCommitType string
ConventionalCommitType represents a conventional commit type.
const ( CCFeat ConventionalCommitType = "feat" CCFix ConventionalCommitType = "fix" CCDocs ConventionalCommitType = "docs" CCStyle ConventionalCommitType = "style" CCRefactor ConventionalCommitType = "refactor" CCPerf ConventionalCommitType = "perf" CCTest ConventionalCommitType = "test" CCBuild ConventionalCommitType = "build" CCCI ConventionalCommitType = "ci" CCChore ConventionalCommitType = "chore" CCRevert ConventionalCommitType = "revert" CCSecurity ConventionalCommitType = "security" CCDeps ConventionalCommitType = "deps" CCOther ConventionalCommitType = "other" )
Conventional commit type constants.
type Dimensions ¶
Dimensions specifies chart dimensions.
func DefaultDimensions ¶
func DefaultDimensions() Dimensions
DefaultDimensions returns sensible defaults.
type Metadata ¶
type Metadata struct {
Title string `json:"title"`
Subtitle string `json:"subtitle,omitempty"`
Generated time.Time `json:"generated"`
Theme string `json:"theme"`
}
Metadata contains common chart metadata.
type MonthlyCommitTypes ¶
type MonthlyCommitTypes struct {
YearMonth string `json:"year_month"` // "2025-01"
Year int `json:"year"`
Month int `json:"month"`
MonthName string `json:"month_name"` // "Jan"
Total int `json:"total"`
ByCCType map[string]int `json:"by_cc_type"` // Conventional commit types
ByCLCat map[string]int `json:"by_changelog_category"` // Changelog categories
}
MonthlyCommitTypes holds commit type counts for a single month.
type Series ¶
type Series struct {
Name string `json:"name"`
Data []float64 `json:"data"`
Color string `json:"color,omitempty"`
}
Series represents a data series for bar/line charts.
func CalculatePercentages ¶
CalculatePercentages converts absolute values to percentages for 100% stacked charts.
type StackedBarChart ¶
type StackedBarChart struct {
ChartType ChartType `json:"type"`
Metadata Metadata `json:"metadata"`
Dimensions Dimensions `json:"dimensions"`
XAxis Axis `json:"x_axis"`
YAxis Axis `json:"y_axis"`
Series []Series `json:"series"`
Legend bool `json:"legend"`
// contains filtered or unexported fields
}
StackedBarChart renders data as a stacked vertical bar chart.
func NewStackedBarChart ¶
func NewStackedBarChart(title string, themeName string) *StackedBarChart
NewStackedBarChart creates a new stacked bar chart.
func (*StackedBarChart) AddSeries ¶
func (s *StackedBarChart) AddSeries(name string, data []float64) *StackedBarChart
AddSeries adds a data series with automatic color assignment.
func (*StackedBarChart) AddSeriesWithColor ¶
func (s *StackedBarChart) AddSeriesWithColor(name string, data []float64, color string) *StackedBarChart
AddSeriesWithColor adds a data series with a specific color.
func (*StackedBarChart) Render ¶
func (s *StackedBarChart) Render() string
Render generates the SVG string.
func (*StackedBarChart) RenderBytes ¶
func (s *StackedBarChart) RenderBytes() []byte
RenderBytes returns the SVG as bytes.
func (*StackedBarChart) SetDimensions ¶
func (s *StackedBarChart) SetDimensions(width, height int) *StackedBarChart
SetDimensions sets custom dimensions.
func (*StackedBarChart) SetXLabels ¶
func (s *StackedBarChart) SetXLabels(labels []string) *StackedBarChart
SetXLabels sets the X-axis labels.
func (*StackedBarChart) ShowLegend ¶
func (s *StackedBarChart) ShowLegend(show bool) *StackedBarChart
ShowLegend enables or disables the legend.
func (*StackedBarChart) ToJSON ¶
func (s *StackedBarChart) ToJSON() ([]byte, error)
ToJSON returns the chart as JSON.
func (*StackedBarChart) Type ¶
func (s *StackedBarChart) Type() ChartType
Type returns the chart type.
type TableChart ¶
type TableChart struct {
ChartType ChartType `json:"type"`
Metadata Metadata `json:"metadata"`
Dimensions Dimensions `json:"dimensions"`
Rows []TableRow `json:"rows"`
IconPaths []IconPath `json:"icon_paths,omitempty"` // Custom icon definitions
// contains filtered or unexported fields
}
TableChart renders data as a styled table/card with icon-label-value rows.
func NewTableChart ¶
func NewTableChart(title string, themeName string) *TableChart
NewTableChart creates a new table chart.
func (*TableChart) AddRow ¶
func (t *TableChart) AddRow(icon, label, value string) *TableChart
AddRow adds a row to the table.
func (*TableChart) AddRowWithColor ¶
func (t *TableChart) AddRowWithColor(icon, label, value, color string) *TableChart
AddRowWithColor adds a row with a custom color.
func (*TableChart) RenderBytes ¶
func (t *TableChart) RenderBytes() []byte
RenderBytes returns the SVG as bytes.
func (*TableChart) SetDimensions ¶
func (t *TableChart) SetDimensions(width, height int) *TableChart
SetDimensions sets custom dimensions.
func (*TableChart) ToJSON ¶
func (t *TableChart) ToJSON() ([]byte, error)
ToJSON returns the chart as JSON.
type TableRow ¶
type TableRow struct {
Icon string `json:"icon"` // Icon name or custom path
Label string `json:"label"`
Value string `json:"value"`
Color string `json:"color,omitempty"` // Optional row-specific color
}
TableRow represents a single row in the table.
type Theme ¶
type Theme struct {
Name string `json:"name"`
TitleColor string `json:"title_color"`
TextColor string `json:"text_color"`
BackgroundColor string `json:"background_color"`
BorderColor string `json:"border_color"`
GridColor string `json:"grid_color"`
PositiveColor string `json:"positive_color"`
NegativeColor string `json:"negative_color"`
AccentColor string `json:"accent_color"`
}
Theme defines colors for chart rendering.