linechart

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package linechart implements a canvas that displays (X,Y) Cartesian coordinates as a line chart.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LabelFormatter

type LabelFormatter func(int, float64) string

LabelFormatter converts a float64 into text for displaying the X and Y axis labels given an index of label and numeric value Index increments from minimum value to maximum values.

func DefaultLabelFormatter

func DefaultLabelFormatter() LabelFormatter

DefaultLabelFormatter returns a LabelFormatter that convert float64 to integers

type Model

type Model struct {
	UpdateHandler   UpdateHandler
	Canvas          canvas.Model
	Style           lipgloss.Style // style applied when drawing runes
	AxisStyle       lipgloss.Style // style applied when drawing X and Y axes
	LabelStyle      lipgloss.Style // style applied when drawing X and Y number value
	XLabelFormatter LabelFormatter // convert to X number values display string
	YLabelFormatter LabelFormatter // convert to Y number values display string

	// whether to automatically set expected values
	// when a value appears beyond the existing bounds
	AutoMinX bool
	AutoMaxX bool
	AutoMinY bool
	AutoMaxY bool

	MaxInterpolationPoints int // maximum points to interpolate for lines/circles
	// contains filtered or unexported fields
}

Model contains state of a linechart with an embedded canvas.Model

func New

func New(w, h int, minX, maxX, minY, maxY float64, opts ...Option) Model

New returns a linechart Model initialized with given width, height, expected data value ranges and various options. Width and height includes area used for chart labeling. If xStep is 0, then will not draw X axis or values below X axis. If yStep is 0, then will not draw Y axis or values left of Y axis.

func (*Model) AutoAdjustRange

func (m *Model) AutoAdjustRange(f canvas.Float64Point) (b bool)

AutoAdjustRange automatically adjusts both the expected X and Y values and the displayed X and Y values if enabled and the given Float64Point is outside of expected ranges. It returns whether or not the display X and Y ranges have been adjusted.

func (*Model) Blur

func (m *Model) Blur()

Blur disables Update events processing.

func (*Model) Clear

func (m *Model) Clear()

Clear will reset linechart canvas including axes and labels.

func (*Model) DrawBrailleCircle

func (m *Model) DrawBrailleCircle(p canvas.Float64Point, f float64)

DrawBrailleCircle draws braille line runes of a given LineStyle on to the linechart such that there is an approximate circle of given float64 radius around the center of a circle at Float64Point data point. Braille runes will not overlap the axes.

func (*Model) DrawBrailleCircleWithStyle

func (m *Model) DrawBrailleCircleWithStyle(c canvas.Float64Point, f float64, s lipgloss.Style)

DrawBrailleCircleWithStyle draws braille line runes of a given LineStyle and style on to the linechart such that there is an approximate circle of given float64 radius around the center of a circle at Float64Point data point. Braille runes will not overlap the axes.

func (*Model) DrawBrailleLine

func (m *Model) DrawBrailleLine(f1 canvas.Float64Point, f2 canvas.Float64Point)

DrawBrailleLine draws braille line runes of a given LineStyle on to the linechart such that there is an approximate straight line between the two given Float64Point data points. Braille runes will not overlap the axes.

func (*Model) DrawBrailleLineWithStyle

func (m *Model) DrawBrailleLineWithStyle(f1 canvas.Float64Point, f2 canvas.Float64Point, s lipgloss.Style)

DrawBrailleLineWithStyle draws braille line runes of a given LineStyle and style on to the linechart such that there is an approximate straight line between the two given Float64Point data points. Braille runes will not overlap the axes.

func (*Model) DrawLine

func (m *Model) DrawLine(f1 canvas.Float64Point, f2 canvas.Float64Point, ls runes.LineStyle)

DrawLine draws line runes of a given LineStyle on to the linechart such that there is an approximate straight line between the two given Float64Point data points.

func (*Model) DrawLineWithStyle

func (m *Model) DrawLineWithStyle(f1 canvas.Float64Point, f2 canvas.Float64Point, ls runes.LineStyle, s lipgloss.Style)

DrawLineWithStyle draws line runes of a given LineStyle and style on to the linechart such that there is an approximate straight line between the two given Float64Point data points.

func (*Model) DrawRune

func (m *Model) DrawRune(f canvas.Float64Point, r rune)

DrawRune draws the rune on to the linechart from a given Float64Point data point.

func (*Model) DrawRuneCircle

func (m *Model) DrawRuneCircle(c canvas.Float64Point, f float64, r rune)

DrawRuneCircle draws the rune on to the linechart such that there is an approximate circle of float64 radious around the center of a circle at Float64Point data point.

func (*Model) DrawRuneCircleWithStyle

func (m *Model) DrawRuneCircleWithStyle(c canvas.Float64Point, f float64, r rune, s lipgloss.Style)

DrawRuneCircleWithStyle draws the rune with style on to the linechart such that there is an approximate circle of float64 radious around the center of a circle at Float64Point data point.

func (*Model) DrawRuneLine

func (m *Model) DrawRuneLine(f1 canvas.Float64Point, f2 canvas.Float64Point, r rune)

DrawRuneLine draws the rune on to the linechart such that there is an approximate straight line between the two given Float64Point data points.

func (*Model) DrawRuneLineWithStyle

func (m *Model) DrawRuneLineWithStyle(f1 canvas.Float64Point, f2 canvas.Float64Point, r rune, s lipgloss.Style)

DrawRuneLineWithStyle draws the rune with style on to the linechart such that there is an approximate straight line between the two given Float64Point data points.

func (*Model) DrawRuneWithStyle

func (m *Model) DrawRuneWithStyle(f canvas.Float64Point, r rune, s lipgloss.Style)

DrawRuneWithStyle draws the rune with style on to the linechart from a given Float64Point data point.

func (*Model) DrawXYAxisAndLabel

func (m *Model) DrawXYAxisAndLabel()

DrawXYAxisAndLabel draws the X, Y axes.

func (*Model) Focus

func (m *Model) Focus()

Focus enables Update events processing.

func (*Model) Focused

func (m *Model) Focused() bool

Focused returns whether canvas is being focused.

func (*Model) GraphHeight

func (m *Model) GraphHeight() int

GraphHeight returns linechart graphing area height.

func (*Model) GraphWidth

func (m *Model) GraphWidth() int

GraphWidth returns linechart graphing area width.

func (*Model) Height

func (m *Model) Height() int

Height returns linechart height.

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the linechart.

func (*Model) MaxX

func (m *Model) MaxX() float64

MaxX returns linechart expected maximum X value.

func (*Model) MaxY

func (m *Model) MaxY() float64

MaxY returns linechart expected maximum Y value.

func (*Model) MinX

func (m *Model) MinX() float64

MinX returns linechart expected minimum X value.

func (*Model) MinY

func (m *Model) MinY() float64

MinY returns linechart expected minimum Y value.

func (*Model) MoveDown

func (m *Model) MoveDown(i float64)

MoveDown will update display Y values to simulate moving down on the linechart chart by given increment.

func (*Model) MoveLeft

func (m *Model) MoveLeft(i float64)

MoveLeft will update display Y values to simulate moving left on the linechart by given increment

func (*Model) MoveRight

func (m *Model) MoveRight(i float64)

MoveRight will update display Y values to simulate moving right on the linechart by given increment.

func (*Model) MoveUp

func (m *Model) MoveUp(i float64)

MoveUp will update display X values to simulate moving up on the linechart chart by given increment.

func (*Model) Origin

func (m *Model) Origin() canvas.Point

Origin returns a canvas Point with the coordinates of the linechart graph (X,Y) origin.

func (*Model) Resize

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

Resize will change linechart display width and height. Existing runes on the linechart will not be redrawn.

func (*Model) ScaleFloat64Point

func (m *Model) ScaleFloat64Point(f canvas.Float64Point) (r canvas.Float64Point)

ScaleFloat64Point returns a Float64Point scaled to the graph size of the linechart from a Float64Point data point.

func (*Model) ScaleFloat64PointForLine

func (m *Model) ScaleFloat64PointForLine(f canvas.Float64Point) (r canvas.Float64Point)

ScaleFloat64PointForLine returns a Float64Point scaled to the graph size of the linechart from a Float64Point data point. Used when drawing line runes with line styles that can combine with the axes.

func (*Model) SetViewXRange

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

SetXRange updates the displayed minimum and maximum X values. Minimum and maximum values will be bounded by the expected X values. Returns whether not displayed X values have updated.

func (*Model) SetViewXYRange

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

SetViewXYRange updates the displayed minimum and maximum X and Y values. Minimum and maximum values will be bounded by the expected values.

func (*Model) SetViewYRange

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

SetYRange updates the displayed minimum and maximum Y values. Minimum and maximum values will be bounded by the expected Y values. Returns whether not displayed Y values have updated.

func (*Model) SetXRange

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

SetXRange updates the minimum and maximum expected X values.

func (*Model) SetXStep

func (m *Model) SetXStep(xStep int)

SetXStep updates the number of steps when displaying X axis values.

func (*Model) SetXYRange

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

SetXYRange updates the minimum and maximum expected X and Y values.

func (*Model) SetYRange

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

SetYRange updates the minimum and maximum expected Y values.

func (*Model) SetYStep

func (m *Model) SetYStep(yStep int)

SetYStep updates the number of steps when displaying Y axis values.

func (*Model) SetZoneManager

func (m *Model) SetZoneManager(zm *zone.Manager)

SetZoneManager enables mouse functionality by setting a bubblezone.Manager to the linechart. The bubblezone.Manager can check bubbletea mouse event Msgs passed to the UpdateHandler handler during an Update(). The root bubbletea model must wrap the View() string with bubblezone.Manager.Scan() to enable mouse functionality. To disable mouse functionality after enabling, call SetZoneManager on nil.

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.

func (*Model) UpdateGraphSizes

func (m *Model) UpdateGraphSizes()

UpdateGraphSizes updates the Model origin, graph width and graph height. This method is should be called whenever the X and Y axes values have changed, for example when X and Y ranges have been adjusted by AutoAdjustRange().

func (Model) View

func (m Model) View() (r string)

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

func (*Model) ViewMaxX

func (m *Model) ViewMaxX() float64

ViewMaxX returns linechart displayed maximum X value.

func (*Model) ViewMaxY

func (m *Model) ViewMaxY() float64

ViewMaxY returns linechart displayed maximum Y value.

func (*Model) ViewMinX

func (m *Model) ViewMinX() float64

ViewMinX returns linechart displayed minimum X value.

func (*Model) ViewMinY

func (m *Model) ViewMinY() float64

ViewMinY returns linechart displayed minimum Y value.

func (*Model) Width

func (m *Model) Width() int

Width returns linechart width.

func (*Model) XStep

func (m *Model) XStep() int

XStep returns number of steps when displaying Y axis values.

func (*Model) YStep

func (m *Model) YStep() int

XStep returns number of steps when displaying Y axis values.

func (*Model) ZoneID

func (m *Model) ZoneID() string

ZoneID will return linechart zone ID used by zone Manager.

func (*Model) ZoneManager

func (m *Model) ZoneManager() *zone.Manager

ZoneManager will return linechart zone Manager.

func (*Model) ZoomIn

func (m *Model) ZoomIn(x, y float64)

ZoomIn will update display X and Y values to simulate zooming into the linechart by given increments.

func (*Model) ZoomOut

func (m *Model) ZoomOut(x, y float64)

ZoomOut will update display X and Y values to simulate zooming into the linechart by given increments.

type Option

type Option func(*Model)

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

lc := New(width, height, minX, maxX, minY, maxY, WithZoneManager(someZoneManager))

func WithAutoXRange

func WithAutoXRange() Option

WithAutoXRange enables automatically setting the minimum and maximum expected X values if new data values are beyond the current range.

func WithAutoXYRange

func WithAutoXYRange() Option

WithAutoXYRange enables automatically setting the minimum and maximum expected X and Y values if new data values are beyond the current ranges.

func WithAutoYRange

func WithAutoYRange() Option

WithAutoYRange enables automatically setting the minimum and maximum expected Y values if new data values are beyond the current range.

func WithKeyMap

func WithKeyMap(k canvas.KeyMap) Option

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

func WithMaxInterpolationPoints added in v2.0.2

func WithMaxInterpolationPoints(n int) Option

WithMaxInterpolationPoints sets the maximum number of points to interpolate for lines and circles. If 0, graph.DefaultMaxPoints is used.

func WithStyles

func WithStyles(as lipgloss.Style, ls lipgloss.Style, s lipgloss.Style) Option

WithStyles sets the default style of the axes, the value shown for the axes and runes drawn on linechart.

func WithUpdateHandler

func WithUpdateHandler(h UpdateHandler) Option

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

func WithXLabelFormatter

func WithXLabelFormatter(fmter 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.

func WithYLabelFormatter

func WithYLabelFormatter(fmter LabelFormatter) Option

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

func WithZoneManager

func WithZoneManager(zm *zone.Manager) Option

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

type UpdateHandler

type UpdateHandler func(*Model, tea.Msg)

UpdateHandler callback invoked during an Update() and passes in the linechart Model and bubbletea Msg.

func XAxisNoZoomUpdateHandler

func XAxisNoZoomUpdateHandler(increment float64) UpdateHandler

XAxisNoZoomUpdateHandler is used by linechart to enable moving the viewing window along the X axis with mouse wheel, holding down the mouse button and moving, and with arrow keys. There is only movement along the X axis with the given increment. Uses linechart Canvas Keymap for keyboard messages.

func XAxisUpdateHandler

func XAxisUpdateHandler(increment float64) UpdateHandler

XAxisUpdateHandler is used by linechart 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 with the given increment. Uses linechart Canvas Keymap for keyboard messages.

func XYAxesUpdateHandler

func XYAxesUpdateHandler(xIncrement, yIncrement float64) UpdateHandler

XYAxesUpdateHandler is used by linechart 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. Uses linechart Canvas Keymap for keyboard messages.

func YAxisNoZoomUpdateHandler

func YAxisNoZoomUpdateHandler(increment float64) UpdateHandler

YAxisNoZoomUpdateHandler is used by steamlinechart to enable moving the viewing window along the Y axis with mouse wheel, holding down the mouse button and moving, and with arrow keys. There is only movement along the Y axis with the given increment. Uses linechart Canvas Keymap for keyboard messages.

func YAxisUpdateHandler

func YAxisUpdateHandler(increment float64) UpdateHandler

YAxisUpdateHandler is used by steamlinechart 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 Y axis with the given increment. Uses linechart Canvas Keymap for keyboard messages.

Directories

Path Synopsis
Package streamlinechart implements a linechart that draws lines going from the right of the chart to the left of the chart
Package streamlinechart implements a linechart that draws lines going from the right of the chart to the left of the chart
Package timeserieslinechart implements a linechart that draws lines for time series data points
Package timeserieslinechart implements a linechart that draws lines for time series data points
Package wavelinechart implements a linechart that draws wave lines on the graph
Package wavelinechart implements a linechart that draws wave lines on the graph

Jump to

Keyboard shortcuts

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