Documentation
¶
Overview ¶
Package linechart implements a canvas that displays (X,Y) Cartesian coordinates as a line chart.
Index ¶
- type LabelFormatter
- type Model
- func (m *Model) AutoAdjustRange(f canvas.Float64Point) (b bool)
- func (m *Model) Blur()
- func (m *Model) Clear()
- func (m *Model) DrawBrailleCircle(p canvas.Float64Point, f float64)
- func (m *Model) DrawBrailleCircleWithStyle(c canvas.Float64Point, f float64, s lipgloss.Style)
- func (m *Model) DrawBrailleLine(f1 canvas.Float64Point, f2 canvas.Float64Point)
- func (m *Model) DrawBrailleLineWithStyle(f1 canvas.Float64Point, f2 canvas.Float64Point, s lipgloss.Style)
- func (m *Model) DrawLine(f1 canvas.Float64Point, f2 canvas.Float64Point, ls runes.LineStyle)
- func (m *Model) DrawLineWithStyle(f1 canvas.Float64Point, f2 canvas.Float64Point, ls runes.LineStyle, ...)
- func (m *Model) DrawRune(f canvas.Float64Point, r rune)
- func (m *Model) DrawRuneCircle(c canvas.Float64Point, f float64, r rune)
- func (m *Model) DrawRuneCircleWithStyle(c canvas.Float64Point, f float64, r rune, s lipgloss.Style)
- func (m *Model) DrawRuneLine(f1 canvas.Float64Point, f2 canvas.Float64Point, r rune)
- func (m *Model) DrawRuneLineWithStyle(f1 canvas.Float64Point, f2 canvas.Float64Point, r rune, s lipgloss.Style)
- func (m *Model) DrawRuneWithStyle(f canvas.Float64Point, r rune, s lipgloss.Style)
- func (m *Model) DrawXYAxisAndLabel()
- func (m *Model) Focus()
- func (m *Model) Focused() bool
- func (m *Model) GraphHeight() int
- func (m *Model) GraphWidth() int
- func (m *Model) Height() int
- func (m Model) Init() tea.Cmd
- func (m *Model) MaxX() float64
- func (m *Model) MaxY() float64
- func (m *Model) MinX() float64
- func (m *Model) MinY() float64
- func (m *Model) MoveDown(i float64)
- func (m *Model) MoveLeft(i float64)
- func (m *Model) MoveRight(i float64)
- func (m *Model) MoveUp(i float64)
- func (m *Model) Origin() canvas.Point
- func (m *Model) Resize(w, h int)
- func (m *Model) ScaleFloat64Point(f canvas.Float64Point) (r canvas.Float64Point)
- func (m *Model) ScaleFloat64PointForLine(f canvas.Float64Point) (r canvas.Float64Point)
- func (m *Model) SetViewXRange(min, max float64) bool
- func (m *Model) SetViewXYRange(minX, maxX, minY, maxY float64)
- func (m *Model) SetViewYRange(min, max float64) bool
- func (m *Model) SetXRange(min, max float64)
- func (m *Model) SetXStep(xStep int)
- func (m *Model) SetXYRange(minX, maxX, minY, maxY float64)
- func (m *Model) SetYRange(min, max float64)
- func (m *Model) SetYStep(yStep int)
- func (m *Model) SetZoneManager(zm *zone.Manager)
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m *Model) UpdateGraphSizes()
- func (m Model) View() (r string)
- func (m *Model) ViewMaxX() float64
- func (m *Model) ViewMaxY() float64
- func (m *Model) ViewMinX() float64
- func (m *Model) ViewMinY() float64
- func (m *Model) Width() int
- func (m *Model) XStep() int
- func (m *Model) YStep() int
- func (m *Model) ZoneID() string
- func (m *Model) ZoneManager() *zone.Manager
- func (m *Model) ZoomIn(x, y float64)
- func (m *Model) ZoomOut(x, y float64)
- type Option
- func WithAutoXRange() Option
- func WithAutoXYRange() Option
- func WithAutoYRange() Option
- func WithKeyMap(k canvas.KeyMap) Option
- func WithMaxInterpolationPoints(n int) Option
- func WithStyles(as lipgloss.Style, ls lipgloss.Style, s lipgloss.Style) Option
- func WithUpdateHandler(h UpdateHandler) Option
- func WithXLabelFormatter(fmter LabelFormatter) Option
- func WithXYSteps(x, y int) Option
- func WithYLabelFormatter(fmter LabelFormatter) Option
- func WithZoneManager(zm *zone.Manager) Option
- type UpdateHandler
- func XAxisNoZoomUpdateHandler(increment float64) UpdateHandler
- func XAxisUpdateHandler(increment float64) UpdateHandler
- func XYAxesUpdateHandler(xIncrement, yIncrement float64) UpdateHandler
- func YAxisNoZoomUpdateHandler(increment float64) UpdateHandler
- func YAxisUpdateHandler(increment float64) UpdateHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LabelFormatter ¶
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 ¶
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) 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 ¶
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 ¶
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 ¶
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) GraphHeight ¶
GraphHeight returns linechart graphing area height.
func (*Model) GraphWidth ¶
GraphWidth returns linechart graphing area width.
func (*Model) MoveDown ¶
MoveDown will update display Y values to simulate moving down on the linechart chart by given increment.
func (*Model) MoveLeft ¶
MoveLeft will update display Y values to simulate moving left on the linechart by given increment
func (*Model) MoveRight ¶
MoveRight will update display Y values to simulate moving right on the linechart by given increment.
func (*Model) MoveUp ¶
MoveUp will update display X values to simulate moving up on the linechart chart by given increment.
func (*Model) Origin ¶
Origin returns a canvas Point with the coordinates of the linechart graph (X,Y) origin.
func (*Model) Resize ¶
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 ¶
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 ¶
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 ¶
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) SetXYRange ¶
SetXYRange updates the minimum and maximum expected X and Y values.
func (*Model) SetZoneManager ¶
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 ¶
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) ZoneManager ¶
ZoneManager will return linechart zone Manager.
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 ¶
/ WithKeyMap sets the KeyMap used when processing keyboard event messages in Update().
func WithMaxInterpolationPoints ¶ added in v2.0.2
WithMaxInterpolationPoints sets the maximum number of points to interpolate for lines and circles. If 0, graph.DefaultMaxPoints is used.
func WithStyles ¶
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 ¶
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 ¶
WithZoneManager sets the bubblezone Manager used when processing bubbletea Msg mouse events in Update().
type UpdateHandler ¶
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 |