sparkline

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: Apache-2.0 Imports: 12 Imported by: 13

Documentation

Overview

Package sparkline is a widget that draws a graph showing a series of values as vertical bars.

Index

Constants

View Source
const DefaultColor = cell.ColorGreen

DefaultColor is the default value for the Color option.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is used to provide options.

func Color

func Color(c cell.Color) Option

Color sets the color of the SparkLine. Defaults to DefaultColor if not set.

func Height

func Height(h int) Option

Height sets a fixed height for the SparkLine. If not provided or set to zero, the SparkLine takes all the available vertical space in the container. Must be a positive or zero integer.

func Label

func Label(text string, cOpts ...cell.Option) Option

Label adds a label above the SparkLine.

type SparkLine

type SparkLine struct {
	// contains filtered or unexported fields
}

SparkLine draws a graph showing a series of values as vertical bars.

Bars can have sub-cell height. The graphs scale adjusts dynamically based on the largest visible value.

Implements widgetapi.Widget. This object is thread-safe.

func New

func New(opts ...Option) (*SparkLine, error)

New returns a new SparkLine.

func (*SparkLine) Add

func (sl *SparkLine) Add(data []int, opts ...Option) error

Add adds data points to the SparkLine. Each data point is represented by one bar on the SparkLine. Zero value data points are valid and are represented by an empty space on the SparkLine (i.e. a missing bar).

At least one data point must be provided. All data points must be positive integers.

The last added data point will be the one displayed all the way on the right of the SparkLine. If there are more data points than we can fit bars to the width of the SparkLine, only the last n data points that fit will be visible.

Provided options override values set when New() was called.

func (*SparkLine) Clear

func (sl *SparkLine) Clear()

Clear removes all the data points in the SparkLine, effectively returning to an empty graph.

func (*SparkLine) Draw

func (sl *SparkLine) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error

Draw draws the SparkLine widget onto the canvas. Implements widgetapi.Widget.Draw.

func (*SparkLine) Keyboard

func (*SparkLine) Keyboard(k *terminalapi.Keyboard, meta *widgetapi.EventMeta) error

Keyboard input isn't supported on the SparkLine widget.

func (*SparkLine) Mouse

func (*SparkLine) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error

Mouse input isn't supported on the SparkLine widget.

func (*SparkLine) Options

func (sl *SparkLine) Options() widgetapi.Options

Options implements widgetapi.Widget.Options.

func (*SparkLine) ValueCapacity added in v0.8.0

func (sl *SparkLine) ValueCapacity() int

ValueCapacity returns the number of values that can fit into the canvas. This is essentially the number of available cells on the canvas 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.

Directories

Path Synopsis
Binary sparklinedemo displays a couple of SparkLine widgets.
Binary sparklinedemo displays a couple of SparkLine widgets.

Jump to

Keyboard shortcuts

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