Documentation
¶
Overview ¶
Package barchart implements a canvas that displays a bar chart with bars going either horizontally or vertically.
Index ¶
- type BarData
- type BarValue
- type Model
- func (m *Model) BarDataFromPoint(p canvas.Point) (r BarData)
- func (m *Model) BarGap() int
- func (m *Model) BarWidth() int
- func (m *Model) Clear()
- func (m *Model) Draw()
- func (m *Model) Height() int
- func (m *Model) Horizontal() bool
- func (m Model) Init() tea.Cmd
- func (m *Model) MaxValue() float64
- func (m *Model) Push(lv BarData)
- func (m *Model) PushAll(lv []BarData)
- func (m *Model) Resize(w, h int)
- func (m *Model) Scale() float64
- func (m *Model) SetBarGap(g int)
- func (m *Model) SetBarWidth(w int)
- func (m *Model) SetHorizontal(b bool)
- func (m *Model) SetMax(f float64)
- func (m *Model) SetShowAxis(b bool)
- func (m *Model) SetZoneManager(zm *zone.Manager)
- func (m *Model) ShowAxis() bool
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) View() (r string)
- func (m *Model) Width() int
- func (m *Model) ZoneID() string
- func (m *Model) ZoneManager() *zone.Manager
- type Option
- func WithBarGap(g int) Option
- func WithBarWidth(w int) Option
- func WithDataSet(d []BarData) Option
- func WithHorizontalBars() Option
- func WithMaxValue(f float64) Option
- func WithNoAutoBarWidth() Option
- func WithNoAutoMaxValue() Option
- func WithNoAxis() Option
- func WithStyles(as lipgloss.Style, ls lipgloss.Style) Option
- func WithZoneManager(zm *zone.Manager) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BarData ¶
BarData contains a label for the bar and a list of BarValues. If displaying vertical bars, the length of the label string will be bounded by the width of each bar. If displaying horizontal bars, the length of the label string will not be bounded and will affect where the vertical axis line starts.
type Model ¶
type Model struct {
Canvas canvas.Model
AxisStyle lipgloss.Style // style applied when drawing axis
LabelStyle lipgloss.Style // style applied when drawing axis labels
AutoMaxValue bool // whether to automatically set max value when adding data
AutoBarWidth bool // whether to automatically set bar width
// contains filtered or unexported fields
}
Model contains state of a barchart
func New ¶
New returns a barchart Model initialized with given width, height and various options. By default, barchart will automatically scale bar to new maximum data values, bar width to fill up the canvas and have one gap between bars, and display bars vertically. If the given data values are too small compared to the max value, then it is possible that the rendering of the bars will not be accurate in terms of proportions due to the limitations of the block element runes.
func (*Model) BarDataFromPoint ¶
BarDataFromPoint returns a possible BarData containing all BarValues drawn for the rune on the barchart canvas at the given Point.
func (*Model) Draw ¶
func (m *Model) Draw()
Draw will display the the scaled data values as bars on to the barchart canvas. The order of the bars will be displayed from left to right, or from top to bottom in the same order as the data was inserted.
func (*Model) Horizontal ¶
Horizontal returns whether displaying bars horizontally.
func (*Model) Push ¶
Push adds given BarData to barchart data set. Negative values will be treated as the value 0. Data will be scaled using expected max value and barchart size.
func (*Model) PushAll ¶
PushAll adds all data values in []BarData to barchart data set. Negative values will be treated as the value 0. Data will be scaled using expected max value and barchart size.
func (*Model) Resize ¶
Resize will change barchart display width and height. Existing data values will be updated to new scaling.
func (*Model) SetBarWidth ¶
SetBarWidth will set the bar width drawn of each bar. If AutoBarWidth is enabled, then this method will do nothing.
func (*Model) SetHorizontal ¶
SetHorizontal will either enable or disable drawing bars horizontally on to the barchart canvas.
func (*Model) SetMax ¶
SetMax will update the expected maximum values and scale factor. Existing values will be updated to new scaling.
func (*Model) SetShowAxis ¶
SetShowAxis will either enable or disable drawing axis and labels on to the barchart canvas.
func (*Model) SetZoneManager ¶
SetZoneManager enables mouse functionality by setting a bubblezone.Manager to the linechart. To disable mouse functionality after enabling, call SetZoneManager on nil.
func (*Model) ShowAxis ¶
ShowAxis returns whether drawing axis and labels on to the barchart canvas.
func (*Model) ZoneManager ¶
ZoneManager will return linechart zone Manager.
type Option ¶
type Option func(*Model)
Option is used to set options when initializing a barchart. Example:
bc := New(width, height, WithMaxValue(someValue))
func WithBarGap ¶
WithBarGap sets the empty spaces between bars when drawing.
func WithBarWidth ¶
WithBarWidth sets the bar widths when when drawing.
func WithDataSet ¶
WithDataSet adds all bar data values in []BarData to barchart data set.
func WithHorizontalBars ¶
func WithHorizontalBars() Option
WithHorizontalBars displays bars horizontally from right to left, with each bar displayed from top to bottom.
func WithMaxValue ¶
WithMaxValue sets the expected maximum data value to given float64.
func WithNoAutoBarWidth ¶
func WithNoAutoBarWidth() Option
WithNoAutoBarWidth disables automatically setting the bar widths to fill the canvas when drawing.
func WithNoAutoMaxValue ¶
func WithNoAutoMaxValue() Option
WithNoAutoMaxValue disables automatically setting the max value if new data greater than the current max is added.
func WithNoAxis ¶
func WithNoAxis() Option
WithNoAxis disables drawing axis and labels on to the barchart.
func WithStyles ¶
WithStyles sets the axis line and label string styles.
func WithZoneManager ¶
WithZoneManager sets the bubblezone Manager used when processing bubbletea Msg mouse events in Update().