Documentation
¶
Overview ¶
Package timeserieslinechart implements a linechart that draws lines for time series data points
Index ¶
- Constants
- func DateNoZoomUpdateHandler(i int) linechart.UpdateHandler
- func DateTimeLabelFormatter() linechart.LabelFormatter
- func DateUpdateHandler(i int) linechart.UpdateHandler
- func HourNoZoomUpdateHandler(i int) linechart.UpdateHandler
- func HourTimeLabelFormatter() linechart.LabelFormatter
- func HourUpdateHandler(i int) linechart.UpdateHandler
- func SecondNoZoomUpdateHandler(i int) linechart.UpdateHandler
- func SecondUpdateHandler(i int) linechart.UpdateHandler
- type DrawCandleOpts
- type FitYOpts
- type Model
- func (m *Model) ClearAllData()
- func (m *Model) ClearDataSet(n string)
- func (m *Model) ClearY2Axis()
- func (m *Model) Draw()
- func (m *Model) DrawAll()
- func (m *Model) DrawBraille()
- func (m *Model) DrawBrailleAll()
- func (m *Model) DrawBrailleDataSets(names []string)
- func (m *Model) DrawCandle(openName, highName, lowName, closeName string, ...)
- func (m *Model) DrawCandleWithOpts(openName, highName, lowName, closeName string, ...)
- func (m *Model) DrawDataSets(names []string)
- func (m *Model) FitYToView() bool
- func (m *Model) FitYToViewWithOpts(opts FitYOpts) bool
- func (m *Model) Push(t TimePoint)
- func (m *Model) PushDataSet(n string, t TimePoint)
- func (m *Model) Resize(w, h int)
- func (m *Model) SetColumnBackgroundStyle(ts time.Time, s lipgloss.Style)
- func (m *Model) SetDataSetLineStyle(n string, ls runes.LineStyle)
- func (m *Model) SetDataSetStyle(n string, s lipgloss.Style)
- func (m *Model) SetDataSetYAxis(n string, side linechart.YAxisSide)
- func (m *Model) SetLineStyle(ls runes.LineStyle)
- func (m *Model) SetStyle(s lipgloss.Style)
- func (m *Model) SetTimeRange(min, max time.Time)
- func (m *Model) SetViewTimeAndYRange(minX, maxX time.Time, minY, maxY float64)
- func (m *Model) SetViewTimeRange(min, max time.Time)
- func (m *Model) SetViewYRange(min, max float64)
- func (m *Model) SetY2Axis(a linechart.Axis)
- func (m *Model) SetYAxis(a linechart.Axis)
- func (m *Model) SetYRange(min, max float64)
- func (m *Model) SetYScale(s linechart.Scale)
- func (m *Model) TrimBefore(t time.Time) int
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- type Option
- func WithAxesStyles(as lipgloss.Style, ls lipgloss.Style) Option
- func WithDataSetLineStyle(n string, ls runes.LineStyle) Option
- func WithDataSetStyle(n string, s lipgloss.Style) Option
- func WithDataSetTimeSeries(n string, p []TimePoint) Option
- func WithDataSetYAxis(n string, side linechart.YAxisSide) Option
- func WithLineChart(lc *linechart.Model) Option
- func WithLineStyle(ls runes.LineStyle) Option
- func WithStyle(s lipgloss.Style) Option
- func WithTimeRange(min, max time.Time) Option
- func WithTimeSeries(p []TimePoint) Option
- func WithUpdateHandler(h linechart.UpdateHandler) Option
- func WithXLabelFormatter(fmter linechart.LabelFormatter) Option
- func WithXYSteps(x, y int) Option
- func WithY2Axis(a linechart.Axis) Option
- func WithYLabelFormatter(fmter linechart.LabelFormatter) Option
- func WithYRange(min, max float64) Option
- func WithYScale(s linechart.Scale) Option
- func WithZoneManager(zm *zone.Manager) Option
- type TimePoint
Constants ¶
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 DrawCandleOpts ¶ added in v2.7.1
type DrawCandleOpts struct {
// Width is the candle body width in columns; < 1 is treated as 1.
Width int
// Block renders solid block bodies (█ ▄ ▀) instead of line runes.
Block bool
}
DrawCandleOpts configures candle drawing.
type FitYOpts ¶ added in v2.7.1
type FitYOpts struct {
// DataSets selects the data sets to fit. Nil selects all data sets on the left Y axis;
// an empty, non-nil slice selects none. Unknown names are ignored.
DataSets []string
// IncludeZero includes a zero baseline on a linear Y axis.
// It is ignored on a logarithmic Y axis.
IncludeZero bool
}
FitYOpts configures fitting the Y viewport to stored points in the time viewport.
type Model ¶
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 ¶
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 ¶
ClearDataSet will erase stored data set given by name string.
func (*Model) ClearY2Axis ¶ added in v2.8.0
func (m *Model) ClearY2Axis()
ClearY2Axis removes the right Y axis. Data sets keep their axis assignment, and those on the right are drawn against the left axis until a right axis is set again. Existing data will be rescaled.
func (*Model) Draw ¶
func (m *Model) Draw()
Draw will draw lines runes displayed from left to right 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 left to right of the graphing area of the canvas.
func (*Model) DrawBraille ¶
func (m *Model) DrawBraille()
DrawBraille will draw braille runes displayed from left to right 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 left to right of the graphing area of the canvas.
func (*Model) DrawBrailleDataSets ¶
DrawBrailleDataSets will draw braille runes from left to right of the graphing area of the canvas for each data set given by name strings.
func (*Model) DrawCandle ¶
func (m *Model) DrawCandle(openName, highName, lowName, closeName string, bullStyle, bearStyle lipgloss.Style)
DrawCandle draws single-column line-style candles. See DrawCandleWithOpts.
func (*Model) DrawCandleWithOpts ¶ added in v2.7.1
func (m *Model) DrawCandleWithOpts(openName, highName, lowName, closeName string, bullStyle, bearStyle lipgloss.Style, opts DrawCandleOpts)
DrawCandleWithOpts draws candles with the given body width and style. The body spans opts.Width columns centered on the candle's time-scaled column, the wick stays in the center column. Width < 1 is treated as 1.
Side columns are clamped to the graph area: columns at or left of the y-axis (Origin().X when YStep() > 0, or left of Origin().X when YStep() == 0 since there is no axis line) are skipped so wide candles never overdraw the y-axis or its tick labels, both of which live inside the canvas. Values outside the Y viewport are clipped before drawing so candles do not overwrite the x-axis or its labels.
The candle's center column is clamped so its whole body fits in the drawable span (edge inset): edge candles shift inward up to half a body from their true time position instead of rendering half-clipped. This deliberately changes the output for the first and newest candles: at width 1 the inset is zero (half == right == 0) so behavior is unchanged and reduces to the previous newest-candle clamp.
Requires four data sets containing candlestick data open, high, low, close values. Assumes that all data sets have the same number of TimePoints and the TimePoint at the same index of each data set has the same Time value.
func (*Model) DrawDataSets ¶
DrawDataSets will draw lines runes from left to right of the graphing area of the canvas for each data set given by name strings.
func (*Model) FitYToView ¶ added in v2.7.1
FitYToView fits the displayed Y range to all stored points whose timestamps are inside the current time viewport, including both endpoints. See FitYToViewWithOpts for dataset selection and a zero baseline.
func (*Model) FitYToViewWithOpts ¶ added in v2.7.1
FitYToViewWithOpts fits the displayed left Y range to the selected data sets. Data sets drawn against the right Y axis are never fitted, even if selected. It ignores non-finite values and values invalid on the Y scale. If there are no eligible points, it returns false and leaves the ranges unchanged. Constant values get a nonzero range (5% or at least 1 on a linear axis, half a decade on either side on a log axis). Expected Y bounds expand if needed but never shrink, so retained history remains available for zooming. AutoMinY and AutoMaxY are unchanged; this explicit fit overrides manual Y zoom. Only stored points are considered, not interpolated boundary values.
func (*Model) Push ¶
Push will push a TimePoint data value to the default data set to be displayed with Draw.
func (*Model) PushDataSet ¶
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 ¶
Resize will change timeserieslinechart display width and height. Existing data will be rescaled.
func (*Model) SetColumnBackgroundStyle ¶
Set column background style to given lipgloss.Style background corresponding to timestamp at given time.Time.
func (*Model) SetDataSetLineStyle ¶
SetDataSetLineStyle will set the line style of the given data set by name string.
func (*Model) SetDataSetStyle ¶
SetDataSetStyle will set the lipgloss style of the given data set by name string.
func (*Model) SetDataSetYAxis ¶ added in v2.8.0
SetDataSetYAxis puts the data set given by name string on the left or right Y axis, creating the data set if needed. All data sets start on the left axis. A data set on the right axis is drawn, auto-ranged and fitted as a left one while the chart has no right axis (see SetY2Axis). Data sets drawn together by DrawCandle should share one axis.
func (*Model) SetLineStyle ¶
SetLineStyle will set the default line styles of data sets.
func (*Model) SetTimeRange ¶
SetTimeRange updates the minimum and maximum expected time values. Existing data will be rescaled.
func (*Model) SetViewTimeAndYRange ¶
SetViewTimeAndYRange updates the displayed minimum and maximum time and Y values. Existing data will be rescaled.
func (*Model) SetViewTimeRange ¶
SetViewTimeRange updates the displayed minimum and maximum time values. Existing data will be rescaled.
func (*Model) SetViewYRange ¶
SetViewYRange updates the displayed minimum and maximum Y values. Existing data will be rescaled.
func (*Model) SetY2Axis ¶ added in v2.8.0
SetY2Axis adds a right Y axis, or replaces it. See linechart.Model.SetY2Axis. Put data sets on it with SetDataSetYAxis. Data pushed to right-assigned sets before this call was auto-ranged against the left axis, and that left range is not undone. Existing data will be rescaled.
func (*Model) SetYAxis ¶ added in v2.8.0
SetYAxis sets the left Y axis. See linechart.Model.SetYAxis. Existing data will be rescaled.
func (*Model) SetYRange ¶
SetYRange updates the minimum and maximum expected Y values. Existing data will be rescaled.
func (*Model) SetYScale ¶ added in v2.7.1
SetYScale sets the scale of the Y axis. See linechart.Model.SetYScale. On a log Y axis, values that are not greater than zero are not drawn: lines break around them and their candles are left out. Existing data will be rescaled.
func (*Model) TrimBefore ¶ added in v2.7.1
TrimBefore removes points strictly before t from every data set and returns the number removed. Points exactly at t are retained. Like Push, timestamps are compared at millisecond resolution, and data must be chronological. Surviving points are copied to new buffers so discarded storage is released. Styles, expected ranges and viewports are unchanged; call FitYToView to refit Y afterwards. To preserve interpolation at the left edge, trim at an earlier timestamp than the viewport's start to keep a preceding sample.
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 ¶
WithAxesStyles sets the axes line and line label styles.
func WithDataSetLineStyle ¶
WithDataSetLineStyle sets the line style of the data set given by name.
func WithDataSetStyle ¶
WithDataSetStyle sets the lipgloss style of the data set given by name.
func WithDataSetTimeSeries ¶
WithDataSetTimeSeries adds []TimePoint data points to the data set given by name.
func WithDataSetYAxis ¶ added in v2.8.0
WithDataSetYAxis puts the data set given by name on the left or right Y axis. See Model.SetDataSetYAxis. Give it and WithY2Axis before the data set's data (WithDataSetTimeSeries) so that data auto-ranges the right axis.
func WithLineChart ¶
WithLineChart sets internal linechart to given linechart.
func WithLineStyle ¶
WithLineStyle sets the default line style of data sets.
func WithTimeRange ¶
WithTimeRange sets expected and displayed minimun and maximum time values range on the X axis.
func WithTimeSeries ¶
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 ¶
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 WithY2Axis ¶ added in v2.8.0
WithY2Axis adds a right Y axis. See Model.SetY2Axis.
func WithYLabelFormatter ¶
func WithYLabelFormatter(fmter linechart.LabelFormatter) Option
WithYLabelFormatter sets the default Y label formatter for displaying Y values as strings.
func WithYRange ¶
WithYRange sets expected and displayed minimum and maximum Y value range.
func WithYScale ¶ added in v2.7.1
WithYScale sets the scale of the Y axis: linechart.ScaleLinear (the default) or linechart.ScaleLog. See Model.SetYScale. The X axis is time and is always linear.
func WithZoneManager ¶
WithZoneManager sets the bubblezone Manager used when processing bubbletea Msg mouse events in Update().