chart

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 chart provides generic SVG chart generation.

Index

Constants

View Source
const (
	BarPaddingX     = 50
	BarPaddingY     = 30
	BarLabelHeight  = 20
	BarGap          = 4
	BarBorderRadius = 4
)

Bar chart layout constants

View Source
const (
	TablePaddingX     = 25
	TablePaddingY     = 35
	TableRowHeight    = 25
	TableIconSize     = 16
	TableBorderRadius = 4.5
)

Table layout constants

View Source
const (
	StackedBarLegendHeight = 30
)

Stacked bar layout constants

Variables

CCToChangelogCategory maps conventional commit types to changelog categories.

View Source
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.

View Source
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.

View Source
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.

ChangelogCategories lists categories in display order (stakeholder priority).

ConventionalCommitTypes lists all CC types in display order.

View Source
var DefaultSeriesColors = []string{
	"#2ea043",
	"#da3633",
	"#58a6ff",
	"#8b949e",
	"#d29922",
	"#a371f7",
	"#f78166",
	"#3fb950",
	"#db61a2",
	"#79c0ff",
}

DefaultSeriesColors provides distinct colors for series.

Functions

func ThemeNames

func ThemeNames() []string

ThemeNames returns all available theme names.

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

func NewBarChart(title string, themeName string) *BarChart

NewBarChart creates a new bar chart.

func (*BarChart) AddSeries

func (b *BarChart) AddSeries(name string, data []float64) *BarChart

AddSeries adds a data series.

func (*BarChart) AddSeriesWithColor

func (b *BarChart) AddSeriesWithColor(name string, data []float64, color string) *BarChart

AddSeriesWithColor adds a data series with a custom color.

func (*BarChart) Render

func (b *BarChart) Render() string

Render generates the SVG string.

func (*BarChart) RenderBytes

func (b *BarChart) RenderBytes() []byte

RenderBytes returns the SVG as bytes.

func (*BarChart) SetDimensions

func (b *BarChart) SetDimensions(width, height int) *BarChart

SetDimensions sets custom dimensions.

func (*BarChart) SetXLabels

func (b *BarChart) SetXLabels(labels []string) *BarChart

SetXLabels sets the X-axis labels.

func (*BarChart) SetYLabel

func (b *BarChart) SetYLabel(label string) *BarChart

SetYLabel sets the Y-axis label.

func (*BarChart) ToJSON

func (b *BarChart) ToJSON() ([]byte, error)

ToJSON returns the chart as JSON.

func (*BarChart) Type

func (b *BarChart) Type() ChartType

Type returns the chart type.

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 ChartType

type ChartType string

ChartType identifies the type of chart.

const (
	TypeTable   ChartType = "table"
	TypeBar     ChartType = "bar"
	TypeLine    ChartType = "line"
	TypeHeatmap ChartType = "heatmap"
)

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

type Dimensions struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

Dimensions specifies chart dimensions.

func DefaultDimensions

func DefaultDimensions() Dimensions

DefaultDimensions returns sensible defaults.

type IconPath

type IconPath struct {
	Name string `json:"name"`
	Path string `json:"path"` // SVG path data
}

IconPath defines a custom SVG icon.

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

func CalculatePercentages(series []Series) []Series

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) Render

func (t *TableChart) Render() string

Render generates the SVG string.

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.

func (*TableChart) Type

func (t *TableChart) Type() ChartType

Type returns the chart type.

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.

func GetTheme

func GetTheme(name string) Theme

GetTheme returns a theme by name, defaulting to "default".

Jump to

Keyboard shortcuts

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