Documentation
¶
Overview ¶
Package sparkline implements a canvas that displays time series data as a chart with columns moving from right to left.
Index ¶
- type Model
- func (m *Model) Clear()
- func (m *Model) Draw()
- func (m *Model) DrawBraille()
- func (m *Model) DrawColumnsOnly()
- func (m *Model) Height() int
- func (m Model) Init() tea.Cmd
- func (m *Model) MaxValue() float64
- func (m *Model) Push(f float64)
- func (m *Model) PushAll(f []float64)
- func (m *Model) Resize(w, h int)
- func (m *Model) Scale() float64
- func (m *Model) SetMax(f float64)
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) View() string
- func (m *Model) Width() int
- type Option
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 ¶
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) 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) Push ¶
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 ¶
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 ¶
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) SetMax ¶
SetMax will update the expected maximum values. Existing values will be updated to new scaling.
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 WithKeyMap ¶
WithKeyMap sets the canvas KeyMap used when processing keyboard event messages in Update().
func WithMaxValue ¶
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 WithUpdateHandler ¶
func WithUpdateHandler(h canvas.UpdateHandler) Option
WithUpdateHandler sets the canvas UpdateHandler used when processing bubbletea Msg events in Update().