charts

package
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package charts provides terminal chart components for blit. Each chart implements blit.Component and renders to its assigned width/height.

Index

Constants

View Source
const (
	// PaletteSequential ranges from a near-black to the theme Accent color.
	PaletteSequential = "sequential"
	// PaletteDivergent ranges from Negative (low) through Muted (mid) to Positive (high).
	PaletteDivergent = "divergent"
)

Palette names for Heatmap.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bar

type Bar struct {
	// Data is the list of values to plot.
	Data []float64
	// Labels are optional per-bar labels (may be shorter than Data).
	Labels []string
	// Horizontal renders bars left-to-right instead of bottom-to-top.
	Horizontal bool
	// Gradient, when non-nil, fills each bar using a start→end color gradient
	// (reuses the v0.8 Gradient type from the parent package).
	Gradient *blit.Gradient
	// Colors overrides per-bar colors. Cycles if shorter than Data.
	Colors []lipgloss.Color
	// contains filtered or unexported fields
}

Bar renders a bar chart, either vertical or horizontal. Data values are normalized to the available draw area. Colors cycle through the theme palette; a Gradient may override per-bar fill.

func NewBar

func NewBar(data []float64, labels []string, horizontal bool) *Bar

NewBar creates a Bar chart with the given data and labels.

func (*Bar) Focused

func (b *Bar) Focused() bool

Focused reports whether the Bar is focused.

func (*Bar) Init

func (b *Bar) Init() tea.Cmd

Init initializes the Bar component.

func (*Bar) KeyBindings

func (b *Bar) KeyBindings() []blit.KeyBind

KeyBindings returns the key bindings for the Bar.

func (*Bar) SetFocused

func (b *Bar) SetFocused(f bool)

SetFocused sets the focus state of the Bar.

func (*Bar) SetSize

func (b *Bar) SetSize(w, h int)

SetSize sets the width and height of the Bar.

func (*Bar) SetTheme

func (b *Bar) SetTheme(t blit.Theme)

SetTheme updates the theme used by the Bar.

func (*Bar) Update

func (b *Bar) Update(msg tea.Msg, ctx blit.Context) (blit.Component, tea.Cmd)

Update handles incoming messages and updates Bar state.

func (*Bar) View

func (b *Bar) View() string

View renders the Bar as a string.

type Gauge

type Gauge struct {
	// Value is the current reading.
	Value float64
	// Max is the full-scale value.
	Max float64
	// Thresholds are the values at which the band color changes.
	// E.g. []float64{0.6, 0.8} with Max=1.0 gives three bands:
	//   [0,0.6) Positive, [0.6,0.8) Flash, [0.8,1.0] Negative
	Thresholds []float64
	// Label is displayed below the gauge needle value.
	Label string
	// contains filtered or unexported fields
}

Gauge renders a half-circle (semicircle) gauge with colored threshold bands. The needle sweeps from left (0°) to right (180°) as Value increases toward Max. Thresholds partition the arc into colored bands (green → yellow → red by default).

func NewGauge

func NewGauge(value, max float64, thresholds []float64, label string) *Gauge

NewGauge creates a Gauge chart.

func (*Gauge) Focused

func (g *Gauge) Focused() bool

Focused reports whether the Gauge is focused.

func (*Gauge) Init

func (g *Gauge) Init() tea.Cmd

Init initializes the Gauge component.

func (*Gauge) KeyBindings

func (g *Gauge) KeyBindings() []blit.KeyBind

KeyBindings returns the key bindings for the Gauge.

func (*Gauge) SetFocused

func (g *Gauge) SetFocused(f bool)

SetFocused sets the focus state of the Gauge.

func (*Gauge) SetSize

func (g *Gauge) SetSize(w, h int)

SetSize sets the width and height of the Gauge.

func (*Gauge) SetTheme

func (g *Gauge) SetTheme(t blit.Theme)

SetTheme updates the theme used by the Gauge.

func (*Gauge) Update

func (g *Gauge) Update(msg tea.Msg, ctx blit.Context) (blit.Component, tea.Cmd)

Update handles incoming messages and updates Gauge state.

func (*Gauge) View

func (g *Gauge) View() string

View renders the Gauge as a string.

type Heatmap

type Heatmap struct {
	// Grid is a row-major 2-D slice of values.
	Grid [][]float64
	// Palette selects the color scheme: PaletteSequential or PaletteDivergent.
	Palette string
	// Labels provides optional column header labels.
	Labels []string
	// RowLabels provides optional row labels rendered on the left.
	RowLabels []string
	// contains filtered or unexported fields
}

Heatmap renders a 2-D grid where each cell's background intensity represents its float64 value. The color palette is either Sequential or Divergent.

func NewHeatmap

func NewHeatmap(grid [][]float64, palette string) *Heatmap

NewHeatmap creates a Heatmap chart.

func (*Heatmap) Focused

func (h *Heatmap) Focused() bool

Focused reports whether the Heatmap is focused.

func (*Heatmap) Init

func (h *Heatmap) Init() tea.Cmd

Init initializes the Heatmap component.

func (*Heatmap) KeyBindings

func (h *Heatmap) KeyBindings() []blit.KeyBind

KeyBindings returns the key bindings for the Heatmap.

func (*Heatmap) SetFocused

func (h *Heatmap) SetFocused(f bool)

SetFocused sets the focus state of the Heatmap.

func (*Heatmap) SetSize

func (h *Heatmap) SetSize(w, hh int)

SetSize sets the width and height of the Heatmap.

func (*Heatmap) SetTheme

func (h *Heatmap) SetTheme(t blit.Theme)

SetTheme updates the theme used by the Heatmap.

func (*Heatmap) Update

func (h *Heatmap) Update(msg tea.Msg, ctx blit.Context) (blit.Component, tea.Cmd)

Update handles incoming messages and updates Heatmap state.

func (*Heatmap) View

func (h *Heatmap) View() string

View renders the Heatmap as a string.

type Line

type Line struct {
	// Series holds one data slice per line series.
	Series [][]float64
	// Colors maps series index → color hex string ("#rrggbb").
	// Cycles if shorter than Series; falls back to theme colors.
	Colors []string
	// Smooth enables diagonal connectors between adjacent points.
	Smooth bool
	// contains filtered or unexported fields
}

Line renders a multi-series line chart using unicode box-drawing characters. Each series is drawn as a connected path; when Smooth is true the renderer uses diagonal connectors (╱ ╲) between points.

func NewLine

func NewLine(series [][]float64, colors []string, smooth bool) *Line

NewLine creates a Line chart.

func (*Line) Focused

func (l *Line) Focused() bool

Focused reports whether the Line is focused.

func (*Line) Init

func (l *Line) Init() tea.Cmd

Init initializes the Line component.

func (*Line) KeyBindings

func (l *Line) KeyBindings() []blit.KeyBind

KeyBindings returns the key bindings for the Line.

func (*Line) SetFocused

func (l *Line) SetFocused(f bool)

SetFocused sets the focus state of the Line.

func (*Line) SetSize

func (l *Line) SetSize(w, h int)

SetSize sets the width and height of the Line.

func (*Line) SetTheme

func (l *Line) SetTheme(t blit.Theme)

SetTheme updates the theme used by the Line.

func (*Line) Update

func (l *Line) Update(msg tea.Msg, ctx blit.Context) (blit.Component, tea.Cmd)

Update handles incoming messages and updates Line state.

func (*Line) View

func (l *Line) View() string

View renders the Line as a string.

type Ring

type Ring struct {
	// Value is the current progress value.
	Value float64
	// Max is the maximum value (100% fill).
	Max float64
	// Label is displayed in the center of the ring.
	Label string

	// FillColor overrides the theme accent color for the filled arc.
	FillColor lipgloss.Color
	// TrackColor overrides the theme muted color for the unfilled arc.
	TrackColor lipgloss.Color
	// contains filtered or unexported fields
}

Ring renders a circular progress ring using unicode quarter-block characters. The ring fills clockwise from the top as Value approaches Max. A label is centered inside the ring.

func NewRing

func NewRing(value, max float64, label string) *Ring

NewRing creates a Ring chart.

func (*Ring) Focused

func (r *Ring) Focused() bool

Focused reports whether the Ring is focused.

func (*Ring) Init

func (r *Ring) Init() tea.Cmd

Init initializes the Ring component.

func (*Ring) KeyBindings

func (r *Ring) KeyBindings() []blit.KeyBind

KeyBindings returns the key bindings for the Ring.

func (*Ring) SetFocused

func (r *Ring) SetFocused(f bool)

SetFocused sets the focus state of the Ring.

func (*Ring) SetSize

func (r *Ring) SetSize(w, h int)

SetSize sets the width and height of the Ring.

func (*Ring) SetTheme

func (r *Ring) SetTheme(t blit.Theme)

SetTheme updates the theme used by the Ring.

func (*Ring) Update

func (r *Ring) Update(msg tea.Msg, ctx blit.Context) (blit.Component, tea.Cmd)

Update handles incoming messages and updates Ring state.

func (*Ring) View

func (r *Ring) View() string

View renders the Ring as a string.

Jump to

Keyboard shortcuts

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