chart

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCache added in v0.1.5

func ClearCache()

ClearCache removes all cached chart renders. Should be called when data changes (e.g., date navigation, new data fetch).

func FormatDurationFromHours

func FormatDurationFromHours(hours float64) string

FormatDurationFromHours formats hours as "H:MM".

func FormatFloat1

func FormatFloat1(v float64) string

FormatFloat1 formats a value with one decimal place.

func FormatInt

func FormatInt(v float64) string

FormatInt formats a value as an integer with proper rounding.

func FormatIntWithCommas

func FormatIntWithCommas(v float64) string

FormatIntWithCommas formats a value as an integer with comma separators.

func FormatPercentage

func FormatPercentage(v float64) string

FormatPercentage formats a value as a percentage with proper rounding.

func GetCached added in v0.1.5

func GetCached(id string, width int, dataHash uint64) (string, bool)

GetCached retrieves a cached chart render if it exists and matches the current parameters. Returns the rendered string and true if found and valid, empty string and false otherwise.

func HashDataPoints added in v0.1.5

func HashDataPoints(data []DataPoint) uint64

HashDataPoints computes a hash for a slice of DataPoints.

func HashSleepStages added in v0.1.5

func HashSleepStages(stages []SleepStage, totalDuration, baselineDuration int) uint64

HashSleepStages computes a hash for a slice of SleepStages.

func HashStackedDataPoints added in v0.1.5

func HashStackedDataPoints(data []StackedDataPoint) uint64

HashStackedDataPoints computes a hash for a slice of StackedDataPoints.

func NormalizeValues

func NormalizeValues(values []float64, minVal, maxVal float64) []float64

NormalizeValues normalizes a slice of values to [0, 1] range.

func RecoveryColor

func RecoveryColor(value float64) color.Color

RecoveryColor returns green/yellow/red based on recovery percentage.

func SetCached added in v0.1.5

func SetCached(id string, width int, dataHash uint64, rendered string)

SetCached stores a rendered chart in the cache.

func SleepColor

func SleepColor(_ float64) color.Color

SleepColor returns the sleep color.

func StrainColor

func StrainColor(_ float64) color.Color

StrainColor returns the strain color (blue).

Types

type Axis

type Axis struct {
	// contains filtered or unexported fields
}

Axis renders an x-axis with labels.

func NewAxis

func NewAxis(labels []string, width int, opts ...AxisOption) *Axis

NewAxis creates a new axis with the given labels.

func (*Axis) Render

func (a *Axis) Render() string

Render renders the axis.

type AxisOption

type AxisOption func(*Axis)

AxisOption configures an Axis.

func WithAxisPositions

func WithAxisPositions(positions []int) AxisOption

WithAxisPositions sets explicit center positions for labels.

func WithAxisTextColor

func WithAxisTextColor(c color.Color) AxisOption

WithAxisTextColor sets the label text color.

type Bar

type Bar struct {
	// contains filtered or unexported fields
}

Bar represents a single vertical bar with optional stacking.

func NewBar

func NewBar(segments []Segment, opts ...BarOption) *Bar

NewBar creates a new bar with the given segments. Values should be normalized to [0, 1] representing the fill percentage.

func NewSimpleBar

func NewSimpleBar(value float64, c color.Color, opts ...BarOption) *Bar

NewSimpleBar creates a bar with a single segment.

func (*Bar) Render

func (b *Bar) Render() string

Render renders the bar as a string.

type BarChart

type BarChart struct {
	// contains filtered or unexported fields
}

BarChart renders a vertical bar chart with labels and optional values.

func NewBarChart

func NewBarChart(data []DataPoint, opts ...BarChartOption) *BarChart

NewBarChart creates a new bar chart.

func (*BarChart) Render

func (bc *BarChart) Render(width int) string

Render renders the bar chart to fit within the given width.

type BarChartOption

type BarChartOption func(*BarChart)

BarChartOption configures a BarChart.

func WithBarChartColorFunc

func WithBarChartColorFunc(f ColorFunc) BarChartOption

WithBarChartColorFunc sets the color function.

func WithBarChartFormatter

func WithBarChartFormatter(f ValueFormatter) BarChartOption

WithBarChartFormatter sets the value formatter.

func WithBarChartHeight

func WithBarChartHeight(h int) BarChartOption

WithBarChartHeight sets the bar height in rows.

func WithBarChartID added in v0.1.5

func WithBarChartID(id string) BarChartOption

WithBarChartID sets the chart ID for caching.

func WithBarChartMax

func WithBarChartMax(max float64) BarChartOption

WithBarChartMax sets the maximum value for scaling.

type BarOption

type BarOption func(*Bar)

BarOption configures a Bar.

func WithBarHeight

func WithBarHeight(h int) BarOption

WithBarHeight sets the bar height in terminal rows.

func WithBarWidth

func WithBarWidth(w int) BarOption

WithBarWidth sets the bar width in characters.

type Cacheable added in v0.1.5

type Cacheable interface {
	// Render renders the chart at the given width.
	Render(width int) string
}

Cacheable is implemented by charts that support render caching.

type CachedChart added in v0.1.5

type CachedChart struct {
	// contains filtered or unexported fields
}

CachedChart stores a rendered chart along with the parameters used to render it.

type ColorFunc

type ColorFunc func(value float64) color.Color

ColorFunc returns a color based on a value.

func StaticColor

func StaticColor(c color.Color) ColorFunc

StaticColor returns a ColorFunc that always returns the given color.

type DataPoint

type DataPoint struct {
	Label string
	Value float64
}

DataPoint represents a single data point with a label and value.

type DualLineChart

type DualLineChart struct {
	// contains filtered or unexported fields
}

DualLineChart renders two line series overlaid on the same chart.

func NewDualLineChart

func NewDualLineChart(series1, series2 []DataPoint, opts ...DualLineChartOption) *DualLineChart

NewDualLineChart creates a new dual line chart.

func (*DualLineChart) Render

func (dlc *DualLineChart) Render(width int) string

Render renders the dual line chart.

type DualLineChartOption

type DualLineChartOption func(*DualLineChart)

DualLineChartOption configures a DualLineChart.

func WithDualLineAutoScale

func WithDualLineAutoScale(auto bool) DualLineChartOption

WithDualLineAutoScale enables auto-scaling min/max from data with padding.

func WithDualLineColors

func WithDualLineColors(c1, c2 color.Color) DualLineChartOption

WithDualLineColors sets the colors for both series.

func WithDualLineFormatter

func WithDualLineFormatter(f ValueFormatter) DualLineChartOption

WithDualLineFormatter sets the value formatter.

func WithDualLineHeight

func WithDualLineHeight(h int) DualLineChartOption

WithDualLineHeight sets the chart height.

func WithDualLineID added in v0.1.5

func WithDualLineID(id string) DualLineChartOption

WithDualLineID sets the chart ID for caching.

func WithDualLineLabels

func WithDualLineLabels(l1, l2 string) DualLineChartOption

WithDualLineLabels sets the labels for both series.

func WithDualLineLegendPosition

func WithDualLineLegendPosition(pos LegendPosition) DualLineChartOption

WithDualLineLegendPosition sets the legend position.

func WithDualLineShowLegend

func WithDualLineShowLegend(show bool) DualLineChartOption

WithDualLineShowLegend shows the legend.

func WithDualLineShowValues

func WithDualLineShowValues(show bool) DualLineChartOption

WithDualLineShowValues shows value labels above data points.

type Legend

type Legend struct {
	// contains filtered or unexported fields
}

Legend renders a legend with colored indicators.

func NewLegend

func NewLegend(items []LegendItem, opts ...LegendOption) *Legend

NewLegend creates a new legend.

func (*Legend) Render

func (l *Legend) Render() string

Render renders the legend.

type LegendItem

type LegendItem struct {
	Label string
	Color color.Color
}

LegendItem represents a single legend entry.

type LegendOption

type LegendOption func(*Legend)

LegendOption configures a Legend.

type LegendPosition

type LegendPosition int

LegendPosition specifies where the legend is rendered.

const (
	LegendBottom LegendPosition = iota
	LegendTopRight
)

type Line

type Line struct {
	// contains filtered or unexported fields
}

Line renders a line using braille characters.

func NewLine

func NewLine(points []float64, width int, opts ...LineOption) *Line

NewLine creates a new line renderer.

func (*Line) Render

func (l *Line) Render() string

Render renders the line using braille characters.

func (*Line) RenderUncolored

func (l *Line) RenderUncolored() string

RenderUncolored renders the line without color styling.

type LineChart

type LineChart struct {
	// contains filtered or unexported fields
}

LineChart renders a line chart with axis labels and optional value display.

func NewLineChart

func NewLineChart(data []DataPoint, opts ...LineChartOption) *LineChart

NewLineChart creates a new line chart.

func (*LineChart) Render

func (lc *LineChart) Render(width int) string

Render renders the line chart.

type LineChartOption

type LineChartOption func(*LineChart)

LineChartOption configures a LineChart.

func WithLineChartColor

func WithLineChartColor(c color.Color) LineChartOption

WithLineChartColor sets the line color.

func WithLineChartFormatter

func WithLineChartFormatter(f ValueFormatter) LineChartOption

WithLineChartFormatter sets the value formatter.

func WithLineChartHeight

func WithLineChartHeight(h int) LineChartOption

WithLineChartHeight sets the chart height.

func WithLineChartID added in v0.1.5

func WithLineChartID(id string) LineChartOption

WithLineChartID sets the chart ID for caching.

func WithLineChartShowDots

func WithLineChartShowDots(show bool) LineChartOption

WithLineChartShowDots shows dots at data points.

func WithLineChartShowValues

func WithLineChartShowValues(show bool) LineChartOption

WithLineChartShowValues shows values at data points.

type LineOption

type LineOption func(*Line)

LineOption configures a Line.

func WithLineHeight

func WithLineHeight(h int) LineOption

WithLineHeight sets the line height in characters.

func WithLineShowDots

func WithLineShowDots(show bool) LineOption

WithLineShowDots shows dots at data points.

type Segment

type Segment struct {
	Value float64
	Color color.Color
}

Segment represents a colored segment of a bar.

type SleepStage

type SleepStage struct {
	Name       string
	DurationMs int     // actual duration in milliseconds
	Percentage float64 // percentage of total sleep
	Color      color.Color
}

SleepStage represents a single sleep stage data.

type SleepStagesChart

type SleepStagesChart struct {
	// contains filtered or unexported fields
}

SleepStagesChart renders a sleep stages breakdown chart.

func NewSleepStagesChart

func NewSleepStagesChart(stages []SleepStage, totalDuration int, opts ...SleepStagesChartOption) *SleepStagesChart

NewSleepStagesChart creates a new sleep stages chart.

func (*SleepStagesChart) Render

func (ssc *SleepStagesChart) Render(width int) string

Render renders the sleep stages chart.

type SleepStagesChartOption

type SleepStagesChartOption func(*SleepStagesChart)

SleepStagesChartOption configures a SleepStagesChart.

func WithSleepStagesBaseline

func WithSleepStagesBaseline(baselineMs int) SleepStagesChartOption

WithSleepStagesBaseline sets the baseline duration for trend comparison.

func WithSleepStagesID added in v0.1.5

func WithSleepStagesID(id string) SleepStagesChartOption

WithSleepStagesID sets the chart ID for caching.

type StackedBarChart

type StackedBarChart struct {
	// contains filtered or unexported fields
}

StackedBarChart renders a stacked vertical bar chart.

func NewStackedBarChart

func NewStackedBarChart(data []StackedDataPoint, opts ...StackedBarChartOption) *StackedBarChart

NewStackedBarChart creates a new stacked bar chart.

func (*StackedBarChart) Render

func (sbc *StackedBarChart) Render(width int) string

Render renders the stacked bar chart.

type StackedBarChartOption

type StackedBarChartOption func(*StackedBarChart)

StackedBarChartOption configures a StackedBarChart.

func WithStackedBarColors

func WithStackedBarColors(colors []color.Color) StackedBarChartOption

WithStackedBarColors sets the segment colors.

func WithStackedBarFormatter

func WithStackedBarFormatter(f ValueFormatter) StackedBarChartOption

WithStackedBarFormatter sets the value formatter.

func WithStackedBarHeight

func WithStackedBarHeight(h int) StackedBarChartOption

WithStackedBarHeight sets the bar height.

func WithStackedBarID added in v0.1.5

func WithStackedBarID(id string) StackedBarChartOption

WithStackedBarID sets the chart ID for caching.

func WithStackedBarLabels

func WithStackedBarLabels(labels []string) StackedBarChartOption

WithStackedBarLabels sets the legend labels.

func WithStackedBarLegendPosition

func WithStackedBarLegendPosition(pos LegendPosition) StackedBarChartOption

WithStackedBarLegendPosition sets the legend position.

func WithStackedBarLegendReverse added in v0.1.19

func WithStackedBarLegendReverse(reverse bool) StackedBarChartOption

WithStackedBarLegendReverse renders legend items in reverse order.

func WithStackedBarShowLegend

func WithStackedBarShowLegend(show bool) StackedBarChartOption

WithStackedBarShowLegend shows the legend.

type StackedDataPoint

type StackedDataPoint struct {
	Label  string
	Values []float64 // values for each segment
}

StackedDataPoint represents a data point with multiple stacked values.

type ValueFormatter

type ValueFormatter func(value float64) string

ValueFormatter formats a float64 value for display.

Jump to

Keyboard shortcuts

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