wavelinechart

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: 10 Imported by: 0

Documentation

Overview

Package wavelinechart implements a linechart that draws wave lines on the graph

Index

Constants

View Source
const DefaultDataSetName = "default"

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

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

Model contains state of a wavelinechart with an embedded linechart.Model A data set is a list of (X,Y) Cartesian coordinates. For each data set, wavelinecharts can only plot a single rune in each column of the graph canvas by mapping (X,Y) data points values in Cartesian coordinates to the (X,Y) canvas coordinates of the graph. If multiple data points map to the same column, then the latest data point will be used for that column. By default, there is a line through the graph X axis without any plotted points. Uses linechart Model UpdateHandler() for processing keyboard and mouse messages.

func New

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

New returns a wavelinechart Model initialized with given linechart Model and various options. By default, the chart will auto set X and Y value ranges, and only enable 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 for each column of the graphing area of the canvas. Uses default data set.

func (*Model) DrawAll

func (m *Model) DrawAll()

DrawAll will draw lines runes for each column of the graphing area of the canvas for all data sets. Will always draw default data set.

func (*Model) DrawDataSets

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

DrawDataSets will draw lines runes for each column of the graphing area of the canvas for each data set given by name strings.

func (*Model) Plot

func (m *Model) Plot(f canvas.Float64Point)

Plot will map a Float64Point data value to a canvas coordinates to be displayed with Draw. Uses default data set.

func (*Model) PlotDataSet

func (m *Model) PlotDataSet(n string, f canvas.Float64Point)

PlotDataSet will map a Float64Point data value to a canvas coordinates to be displayed with Draw. Uses given data set by name string.

func (*Model) Resize

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

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

func (*Model) SetDataSetStyles

func (m *Model) SetDataSetStyles(n string, ls runes.LineStyle, s lipgloss.Style)

SetDataSetStyles will set the styles of the given data set by name string.

func (*Model) SetStyles

func (m *Model) SetStyles(ls runes.LineStyle, s lipgloss.Style)

SetStyles will set the default styles of data sets.

func (*Model) SetViewXRange

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

SetViewXRange updates the displayed minimum and maximum X values. Existing data will be rescaled.

func (*Model) SetViewXYRange

func (m *Model) SetViewXYRange(minX, maxX, minY, maxY float64)

SetViewXYRange updates the displayed minimum and maximum X and Y 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) Update

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

Update processes bubbletea Msg to by invoking UpdateMsgHandlerFunc callback if wavelinechart is focused.

type Option

type Option func(*Model)

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

wlc := New(width, height, WithStyles(someLineStyle, someLipglossStyle))

func WithAxesStyles

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

WithAxesStyles sets the axes line and line label styles.

func WithDataSetPoints

func WithDataSetPoints(n string, f []canvas.Float64Point) Option

WithDataSetPoints maps []Float64Point data points to canvas coordinates for the data set given by name.

func WithDataSetStyles

func WithDataSetStyles(n string, ls runes.LineStyle, s lipgloss.Style) Option

WithDataSetStyles sets the line style and lipgloss style of the data set given by name.

func WithLineChart

func WithLineChart(lc *linechart.Model) Option

WithLineChart sets internal linechart to given linechart.

func WithPoints

func WithPoints(f []canvas.Float64Point) Option

WithPoints maps []Float64Point data points to canvas coordinates for the default data set.

func WithStyles

func WithStyles(ls runes.LineStyle, s lipgloss.Style) Option

WithStyles sets the default line style and lipgloss style of data sets.

func WithUpdateHandler

func WithUpdateHandler(h linechart.UpdateHandler) Option

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

func WithXRange

func WithXRange(min, max float64) Option

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

func WithXYRange

func WithXYRange(minX, maxX, minY, maxY float64) Option

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

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 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().

Jump to

Keyboard shortcuts

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