Documentation ¶
Overview ¶
Package linechart contains a widget that displays line charts.
Index ¶
- type LineChart
- func (lc *LineChart) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error
- func (lc *LineChart) Keyboard(k *terminalapi.Keyboard) error
- func (lc *LineChart) Mouse(m *terminalapi.Mouse) error
- func (lc *LineChart) Options() widgetapi.Options
- func (lc *LineChart) Series(label string, values []float64, opts ...SeriesOption) error
- func (lc *LineChart) ValueCapacity() int
- type Option
- func AxesCellOpts(co ...cell.Option) Option
- func XAxisUnscaled() Option
- func XLabelCellOpts(co ...cell.Option) Option
- func XLabelsHorizontal() Option
- func XLabelsVertical() Option
- func YAxisAdaptive() Option
- func YAxisCustomScale(min, max float64) Option
- func YLabelCellOpts(co ...cell.Option) Option
- func ZoomHightlightColor(c cell.Color) Option
- func ZoomStepPercent(perc int) Option
- type SeriesOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LineChart ¶
type LineChart struct {
// contains filtered or unexported fields
}
LineChart draws line charts.
Each line chart has an identifying label and a set of values that are plotted.
The size of the two axes is determined from the values. The X axis will have a number of evenly distributed data points equal to the largest count of values among all the labeled line charts. The Y axis will be sized so that it can conveniently accommodate the largest value among all the labeled line charts. This determines the used scale.
LineChart supports mouse based zoom, zooming is achieved by either highlighting an area on the graph (left mouse clicking and dragging) or by using the mouse scroll button.
Implements widgetapi.Widget. This object is thread-safe.
func (*LineChart) Keyboard ¶
func (lc *LineChart) Keyboard(k *terminalapi.Keyboard) error
Keyboard implements widgetapi.Widget.Keyboard.
func (*LineChart) Mouse ¶
func (lc *LineChart) Mouse(m *terminalapi.Mouse) error
Mouse implements widgetapi.Widget.Mouse.
func (*LineChart) Series ¶
func (lc *LineChart) Series(label string, values []float64, opts ...SeriesOption) error
Series sets the values that should be displayed as the line chart with the provided label. The values that should not be displayed on the line chart should be represented as math.NaN values on the values slice. Subsequent calls with the same label replace any previously provided values.
func (*LineChart) ValueCapacity ¶ added in v0.7.0
ValueCapacity returns the number of values that could be fit onto the X axis without a need to rescale the X axis. This is essentially the number of available pixels on the braille canvas based on the width of the LineChart as observed on the last call to draw. Returns zero if draw wasn't called.
Note that this capacity changes each time the terminal resizes, so there is no guarantee this remains the same next time Draw is called. Should be used as a hint only.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is used to provide options to New().
func AxesCellOpts ¶
AxesCellOpts set the cell options for the X and Y axes.
func XAxisUnscaled ¶ added in v0.7.0
func XAxisUnscaled() Option
XAxisUnscaled when provided, stops the LineChart from rescaling the X axis when it can't fit all the values in the series, instead the LineCharts only displays the last n values that fit into its width. This is useful to create an impression of values rolling through the linechart right to left. Note that this results in hiding of values from the beginning of the series that didn't fit completely and might hide some shorter series as this effectively makes the X axis start at a non-zero value.
The default behavior is to rescale the X axis to display all the values. This option takes no effect if all the values on the series fit into the LineChart area.
func XLabelCellOpts ¶
XLabelCellOpts set the cell options for the labels on the X axis.
func XLabelsHorizontal ¶ added in v0.7.0
func XLabelsHorizontal() Option
XLabelsHorizontal makes the labels under the X axis flow horizontally. This is the default option.
func XLabelsVertical ¶ added in v0.7.0
func XLabelsVertical() Option
XLabelsVertical makes the labels under the X axis flow vertically. Defaults to labels that flow horizontally.
func YAxisAdaptive ¶ added in v0.6.0
func YAxisAdaptive() Option
YAxisAdaptive makes the Y axis adapt its base value depending on the provided series. Without this option, the Y axis always starts at the zero value regardless of values available in the series. When this option is specified and the series don't contain value zero, the Y axis will be adapted to the minimum value for all-positive series or the maximum value for all-negative series. The Y axis still starts at the zero value if the series contain both positive and negative values.
func YAxisCustomScale ¶ added in v0.7.0
YAxisCustomScale when provided, the scale of the Y axis will be based on the specified minimum and maximum value instead of determining those from the LineChart series. Useful to visually stabilize the Y axis for LineChart applications that continuously feed values. The default behavior is to continuously determine the minimum and maximum value from the series before drawing the LineChart. Even when this option is provided, the LineChart would still rescale the Y axis if a value is encountered that is outside of the range specified here, i.e. smaller than the minimum or larger than the maximum. Both the minimum and the maximum must be valid numbers and the minimum must be smaller than the maximum.
Providing this option also sets YAxisAdaptive.
func YLabelCellOpts ¶
YLabelCellOpts set the cell options for the labels on the Y axis.
func ZoomHightlightColor ¶ added in v0.7.0
ZoomHightlightColor sets the background color of the area that is selected with mouse in order to zoom the linechart. Defaults to color number 235.
func ZoomStepPercent ¶ added in v0.7.0
ZoomStepPercent sets the zooming step on each mouse scroll event as the percentage of the size of the X axis. The value must be in range 0 < value <= 100. Defaults to zoom.DefaultScrollStep.
type SeriesOption ¶
type SeriesOption interface {
// contains filtered or unexported methods
}
SeriesOption is used to provide options to Series.
func SeriesCellOpts ¶
func SeriesCellOpts(co ...cell.Option) SeriesOption
SeriesCellOpts sets the cell options for this series. Note that the braille canvas has resolution of 2x4 pixels per cell, but each cell can only have one set of cell options set. Meaning that where series share a cell, the last drawn series sets the cell options. Series are drawn in alphabetical order based on their name.
func SeriesXLabels ¶
func SeriesXLabels(labels map[int]string) SeriesOption
SeriesXLabels is used to provide custom labels for the X axis. The argument maps the positions in the provided series to the desired label. The labels are only used if they fit under the axis. Custom labels are property of the line chart, since there is only one X axis, providing multiple custom labels overwrites the previous value.
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
axes
Package axes calculates the required layout and draws the X and Y axes of a line chart.
|
Package axes calculates the required layout and draws the X and Y axes of a line chart. |
zoom
Package zoom contains code that tracks the current zoom level.
|
Package zoom contains code that tracks the current zoom level. |
Binary linechartdemo displays a linechart widget.
|
Binary linechartdemo displays a linechart widget. |