timeserieslinechart

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: 12 Imported by: 1

Documentation

Overview

Package timeserieslinechart implements a linechart that draws lines for time series data points

Index

Constants

View Source
const DefaultDataSetName = "default"

Variables

This section is empty.

Functions

func DateNoZoomUpdateHandler

func DateNoZoomUpdateHandler(i int) linechart.UpdateHandler

DateNoZoomUpdateHandler is used by timeserieslinechart to enable moving the viewing window by using the mouse scroll wheel, holding down mouse button and moving, and moving the viewing window with the arrow keys. There is only movement along the X axis by day increments. Uses linechart Canvas Keymap for keyboard messages.

func DateTimeLabelFormatter

func DateTimeLabelFormatter() linechart.LabelFormatter

func DateUpdateHandler

func DateUpdateHandler(i int) linechart.UpdateHandler

DateUpdateHandler is used by timeserieslinechart to enable zooming in and out with the mouse wheel or page up and page down, moving the viewing window by holding down mouse button and moving, and moving the viewing window with the arrow keys. There is only movement along the X axis by day increments. Uses linechart Canvas Keymap for keyboard messages.

func HourNoZoomUpdateHandler

func HourNoZoomUpdateHandler(i int) linechart.UpdateHandler

HourNoZoomUpdateHandler is used by timeserieslinechart to enable moving the viewing window by using the mouse scroll wheel, holding down mouse button and moving, and moving the viewing window with the arrow keys. There is only movement along the X axis by hour increments. Uses linechart Canvas Keymap for keyboard messages.

func HourTimeLabelFormatter

func HourTimeLabelFormatter() linechart.LabelFormatter

func HourUpdateHandler

func HourUpdateHandler(i int) linechart.UpdateHandler

HourUpdateHandler is used by timeserieslinechart to enable zooming in and out with the mouse wheel or page up and page down, moving the viewing window by holding down mouse button and moving, and moving the viewing window with the arrow keys. There is only movement along the X axis by hour increments. Uses linechart Canvas Keymap for keyboard messages.

func SecondNoZoomUpdateHandler

func SecondNoZoomUpdateHandler(i int) linechart.UpdateHandler

SecondNoZoomUpdateHandler is used by timeserieslinechart to enable moving the viewing window by using the mouse scroll wheel, holding down mouse button and moving, and moving the viewing window with the arrow keys. There is only movement along the X axis by second increments. Uses linechart Canvas Keymap for keyboard messages.

func SecondUpdateHandler

func SecondUpdateHandler(i int) linechart.UpdateHandler

SecondUpdateHandler is used by timeserieslinechart to enable zooming in and out with the mouse wheel or page up and page down, moving the viewing window by holding down mouse button and moving, and moving the viewing window with the arrow keys. There is only movement along the X axis by second increments. Uses linechart Canvas Keymap for keyboard messages.

Types

type Model

type Model struct {
	linechart.Model
	// contains filtered or unexported fields
}

Model contains state of a timeserieslinechart with an embedded linechart.Model The X axis contains time.Time values and the Y axis contains float64 values. A data set consists of a sequence TimePoints in chronological order. If multiple TimePoints map to the same column, then average value the time points will be used as the Y value of the column. The X axis contains a time range and the Y axis contains a numeric value range. Uses linechart Model UpdateHandler() for processing keyboard and mouse messages.

func New

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

New returns a timeserieslinechart Model initialized from width, height, Y value range and various options. By default, the chart will set time.Now() as the minimum time, enable auto set X and Y value ranges, and only allow moving viewport on X axis.

func (*Model) ClearAllData

func (m *Model) ClearAllData()

ClearAllData will reset stored data values in all data sets.

func (*Model) ClearDataSet

func (m *Model) ClearDataSet(n string)

ClearDataSet will erase stored data set given by name string.

func (*Model) Draw

func (m *Model) Draw()

Draw will draw lines runes displayed from right to left of the graphing area of the canvas. Uses default data set.

func (*Model) DrawAll

func (m *Model) DrawAll()

DrawAll will draw lines runes for all data sets from right to left of the graphing area of the canvas.

func (*Model) DrawBraille

func (m *Model) DrawBraille()

DrawBraille will draw braille runes displayed from right to left of the graphing area of the canvas. Uses default data set.

func (*Model) DrawBrailleAll

func (m *Model) DrawBrailleAll()

DrawBrailleAll will draw braille runes for all data sets from right to left of the graphing area of the canvas.

func (*Model) DrawBrailleDataSets

func (m *Model) DrawBrailleDataSets(names []string)

DrawBrailleDataSets will draw braille runes from right to left of the graphing area of the canvas for each data set given by name strings.

func (*Model) DrawDataSets

func (m *Model) DrawDataSets(names []string)

DrawDataSets will draw lines runes from right to left of the graphing area of the canvas for each data set given by name strings.

func (*Model) Push

func (m *Model) Push(t TimePoint)

Push will push a TimePoint data value to the default data set to be displayed with Draw.

func (*Model) PushDataSet

func (m *Model) PushDataSet(n string, t TimePoint)

Push will push a TimePoint data value to a data set to be displayed with Draw. Using given data set by name string.

func (*Model) Resize

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

Resize will change timeserieslinechart display width and height. Existing data will be rescaled.

func (*Model) SetDataSetLineStyle

func (m *Model) SetDataSetLineStyle(n string, ls runes.LineStyle)

SetDataSetLineStyle will set the line style of the given data set by name string.

func (*Model) SetDataSetStyle

func (m *Model) SetDataSetStyle(n string, s lipgloss.Style)

SetDataSetStyle will set the lipgloss style of the given data set by name string.

func (*Model) SetLineStyle

func (m *Model) SetLineStyle(ls runes.LineStyle)

SetLineStyle will set the default line styles of data sets.

func (*Model) SetStyle

func (m *Model) SetStyle(s lipgloss.Style)

SetStyle will set the default lipgloss styles of data sets.

func (*Model) SetTimeRange

func (m *Model) SetTimeRange(min, max time.Time)

SetTimeRange updates the minimum and maximum expected time values. Existing data will be rescaled.

func (*Model) SetViewTimeAndYRange

func (m *Model) SetViewTimeAndYRange(minX, maxX time.Time, minY, maxY float64)

SetViewTimeAndYRange updates the displayed minimum and maximum time and Y values. Existing data will be rescaled.

func (*Model) SetViewTimeRange

func (m *Model) SetViewTimeRange(min, max time.Time)

SetViewTimeRange updates the displayed minimum and maximum time values. Existing data will be rescaled.

func (*Model) SetViewYRange

func (m *Model) SetViewYRange(min, max float64)

SetViewYRange updates the displayed minimum and maximum Y values. Existing data will be rescaled.

func (*Model) SetYRange

func (m *Model) SetYRange(min, max float64)

SetYRange updates the minimum and maximum expected Y values. Existing data will be rescaled.

func (Model) Update

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

Update processes bubbletea Msg to by invoking UpdateHandlerFunc callback if linechart is focused.

type Option

type Option func(*Model)

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

tslc := New(width, height, minX, maxX, minY, maxY, WithStyles(someLineStyle, someLipglossStyle))

func WithAxesStyles

func WithAxesStyles(as lipgloss.Style, ls lipgloss.Style) Option

WithAxesStyles sets the axes line and line label styles.

func WithDataSetLineStyle

func WithDataSetLineStyle(n string, ls runes.LineStyle) Option

WithDataSetLineStyle sets the line style of the data set given by name.

func WithDataSetStyle

func WithDataSetStyle(n string, s lipgloss.Style) Option

WithDataSetStyle sets the lipgloss style of the data set given by name.

func WithDataSetTimeSeries

func WithDataSetTimeSeries(n string, p []TimePoint) Option

WithDataSetTimeSeries adds []TimePoint data points to the data set given by name.

func WithLineChart

func WithLineChart(lc *linechart.Model) Option

WithLineChart sets internal linechart to given linechart.

func WithLineStyle

func WithLineStyle(ls runes.LineStyle) Option

WithLineStyle sets the default line style of data sets.

func WithStyle

func WithStyle(s lipgloss.Style) Option

WithStyle sets the default lipgloss style of data sets.

func WithTimeRange

func WithTimeRange(min, max time.Time) Option

WithTimeRange sets expected and displayed minimun and maximum time values range on the X axis.

func WithTimeSeries

func WithTimeSeries(p []TimePoint) Option

WithTimeSeries adds []TimePoint values to the default data set.

func WithUpdateHandler

func WithUpdateHandler(h linechart.UpdateHandler) Option

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

func WithXLabelFormatter

func WithXLabelFormatter(fmter linechart.LabelFormatter) Option

WithXLabelFormatter sets the default X label formatter for displaying X values as strings.

func WithXYSteps

func WithXYSteps(x, y int) Option

WithXYSteps sets the number of steps when drawing X and Y axes values. If X steps 0, then X axis will be hidden. If Y steps 0, then Y axis will be hidden.

func WithYLabelFormatter

func WithYLabelFormatter(fmter linechart.LabelFormatter) Option

WithYLabelFormatter sets the default Y label formatter for displaying Y values as strings.

func WithYRange

func WithYRange(min, max float64) Option

WithYRange sets expected and displayed minimum and maximum Y value range.

func WithZoneManager

func WithZoneManager(zm *zone.Manager) Option

WithZoneManager sets the bubblezone Manager used when processing bubbletea Msg mouse events in Update().

type TimePoint

type TimePoint struct {
	Time  time.Time
	Value float64
}

Jump to

Keyboard shortcuts

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