sparkline

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sparkline implements a canvas that displays time series data as a chart with columns moving from right to left.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {
	AutoMaxValue bool           // whether to automatically set max value when adding data
	Style        lipgloss.Style // style applied when drawing columns
	Canvas       canvas.Model
	// contains filtered or unexported fields
}

Model contains state of a sparkline

func New

func New(w, h int, opts ...Option) Model

New returns a sparkline Model initialized with given width, height and various options. By default, sparkline will automatically scale bars to new maximum data values.

func (*Model) Clear

func (m *Model) Clear()

Clear will reset sparkline canvas and data.

func (*Model) Draw

func (m *Model) Draw()

Draw will display the the scaled data values on to the sparkline canvas using columns. Sparkline style will be applied across entire canvas. Columns representing the data will be displayed going from from the bottom to the top and coming from the left to the right of the canvas.

func (*Model) DrawBraille

func (m *Model) DrawBraille()

DrawBraille will display the the scaled data values on to the sparkline canvas using braille lines. Sparkline style will be applied across entire canvas. Braille lines representing the data will be displayed going from from the bottom to the top and coming from the left to the right of the canvas.

func (*Model) DrawColumnsOnly

func (m *Model) DrawColumnsOnly()

DrawColumnsOnly is the same as Draw except the the style will only be applied to the columns and not to the entire canvas.

func (*Model) Height

func (m *Model) Height() int

Height returns sparkline height.

func (Model) Init

func (m Model) Init() tea.Cmd

func (*Model) MaxValue

func (m *Model) MaxValue() float64

MaxValue returns expected maximum data value.

func (*Model) Push

func (m *Model) Push(f float64)

Push adds float64 data value to sparkline data buffer. Negative values will be treated as the value 0. Data will be scaled using expected max value and sparkline height.

func (*Model) PushAll

func (m *Model) PushAll(f []float64)

PushAll adds all data values in []float64 to sparkline data buffer. Negative values will be treated as the value 0. Data will be scaled using expected max value and sparkline height.

func (*Model) Resize

func (m *Model) Resize(w, h int)

Resize will change sparkline display width and height. Existing data values will be updated to new scaling. If new width is less than previous width, then older data will be lost after resize.

func (*Model) Scale

func (m *Model) Scale() float64

Scale returns data scaling factor.

func (*Model) SetMax

func (m *Model) SetMax(f float64)

SetMax will update the expected maximum values. Existing values will be updated to new scaling.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update forwards bubbletea Msg to underlying canvas.

func (Model) View

func (m Model) View() string

View returns a string used by the bubbletea framework to display the sparkline.

func (*Model) Width

func (m *Model) Width() int

Width returns sparkline width.

type Option

type Option func(*Model)

Option is used to set options when initializing a sparkline. Example:

sl := New(width, height, WithMaxValue(someValue), WithNoAuto())

func WithData

func WithData(d []float64) Option

WithData adds all data values in []float64 to sparkline data buffer.

func WithKeyMap

func WithKeyMap(k canvas.KeyMap) Option

WithKeyMap sets the canvas KeyMap used when processing keyboard event messages in Update().

func WithMaxValue

func WithMaxValue(f float64) Option

WithMaxValue sets the expected maximum data value to given float64.

func WithNoAutoMaxValue

func WithNoAutoMaxValue() Option

WithNoAutoMaxValue disables automatically setting the max value if new data greater than the current max is added.

func WithStyle

func WithStyle(s lipgloss.Style) Option

WithStyle sets the default column style.

func WithUpdateHandler

func WithUpdateHandler(h canvas.UpdateHandler) Option

WithUpdateHandler sets the canvas UpdateHandler used when processing bubbletea Msg events in Update().

Jump to

Keyboard shortcuts

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