barchart

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package barchart implements a widget that draws multiple bars displaying values and their relative ratios.

Index

Constants

View Source
const DefaultBarColor = cell.ColorRed

DefaultBarColor is the default color of a bar, unless specified otherwise via the BarColors option.

View Source
const DefaultBarGap = 1

DefaultBarGap is the default value for the BarGap option.

View Source
const DefaultChar = draw.DefaultRectChar

DefaultChar is the default value for the Char option.

View Source
const DefaultLabelColor = cell.ColorGreen

DefaultLabelColor is the default color of a bar label, unless specified otherwise via the LabelColors option.

View Source
const DefaultValueColor = cell.ColorYellow

DefaultValueColor is the default color of a bar value, unless specified otherwise via the ValueColors option.

Variables

This section is empty.

Functions

This section is empty.

Types

type BarChart

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

BarChart displays multiple bars showing relative ratios of values.

Each bar can have a text label under it explaining the meaning of the value and can display the value itself inside the bar.

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

func New

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

New returns a new BarChart.

func (*BarChart) Draw

func (bc *BarChart) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error

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

func (*BarChart) Keyboard

func (*BarChart) Keyboard(k *terminalapi.Keyboard) error

Keyboard input isn't supported on the BarChart widget.

func (*BarChart) Mouse

func (*BarChart) Mouse(m *terminalapi.Mouse) error

Mouse input isn't supported on the BarChart widget.

func (*BarChart) Options

func (bc *BarChart) Options() widgetapi.Options

Options implements widgetapi.Widget.Options.

func (*BarChart) ValueCapacity added in v0.8.0

func (bc *BarChart) 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.

func (*BarChart) Values

func (bc *BarChart) Values(values []int, max int, opts ...Option) error

Values sets the values to be displayed by the BarChart. Each value ends up in its own bar. The values must not be negative and must be less or equal the maximum value. A bar displaying the maximum value is a full bar, taking all available vertical space. Provided options override values set when New() was called.

type Option

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

Option is used to provide options.

func BarColors

func BarColors(colors []cell.Color) Option

BarColors sets the colors of each of the bars. Bars are created on a call to Values(), each value ends up in its own Bar. The first supplied color applies to the bar displaying the first value. Any bars that don't have a color specified use the DefaultBarColor.

func BarGap

func BarGap(width int) Option

BarGap sets the width of the space between the bars. Must be a positive or zero integer. Defaults to DefaultBarGap.

func BarWidth

func BarWidth(width int) Option

BarWidth sets the width of the bars. If not set, or set to zero, the bars use all the space available to the widget. Must be a positive or zero integer.

func Char

func Char(ch rune) Option

Char sets the rune that is used when drawing the rectangle representing the bars.

func LabelColors

func LabelColors(colors []cell.Color) Option

LabelColors sets the colors of each of the labels under the bars. Bars are created on a call to Values(), each value ends up in its own Bar. The first supplied color applies to the label of the bar displaying the first value. Any labels that don't have a color specified use the DefaultLabelColor.

func Labels

func Labels(labels []string) Option

Labels sets the labels displayed under each bar, Bars are created on a call to Values(), each value ends up in its own Bar. The first supplied label applies to the bar displaying the first value. If not specified, the corresponding bar (or all the bars) don't have a label.

func ShowValues

func ShowValues() Option

ShowValues tells the bar chart to display the actual values inside each of the bars.

func ValueColors

func ValueColors(colors []cell.Color) Option

ValueColors sets the colors of each of the values in the bars. Bars are created on a call to Values(), each value ends up in its own Bar. The first supplied color applies to the bar displaying the first value. Any values that don't have a color specified use the DefaultValueColor.

Directories

Path Synopsis
Binary barchartdemo displays a couple of BarChart widgets.
Binary barchartdemo displays a couple of BarChart widgets.

Jump to

Keyboard shortcuts

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