termbar

package module
v0.0.0-...-dff3053 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: MIT Imports: 5 Imported by: 0

README

termbar

Generate terminal bar charts in Go.

a: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 50
b: ▇▇▇▇▇▇▇▇▇ 25
c: ▇▇▇ 15
d: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 78

TODO

  • Stacked bars
  • Grouped bars
  • Sparklines
  • Basic color support?
  • Vertical bar chart?

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bar

type Bar struct {
	Label string
	Value float64
	Chars string
}

type Bars

type Bars []Bar

func (Bars) MaxLabelWidth

func (bars Bars) MaxLabelWidth() int

MaxLabelWidth returns the max length of the Label from a list of Bars

func (Bars) MaxValue

func (bars Bars) MaxValue() float64

MaxValue returns the maxiumum Value from a list of Bars

type Chart

type Chart interface {
	Print(io.Writer)
}

type ChartOption

type ChartOption interface {
	HorizontalOption
	SparklineOption
	// contains filtered or unexported methods
}

func WithMaxVal

func WithMaxVal(m float64) ChartOption

WithMaxVal sets the max value bars will be made relative to. By default, the bar with the highest value will take up the full width and all other bars will be sized relative to it. However, for charts where an absolute max value is desired, such as a percentage, you can use this option to make all bars sized relative to a specific value (i.e. 100.0 for % bars)

func WithMaxWidth

func WithMaxWidth(w int) ChartOption

WithMaxWidth sets the maximum character width of the chart

type Horizontal

type Horizontal struct {
	Chart

	Bars Bars
	// contains filtered or unexported fields
}

Horizontal is a horizontal bar chart

func NewHorizontal

func NewHorizontal(values Bars, options ...HorizontalOption) *Horizontal

NewHorizontal returns a new horizontal bar chart. By default, it will produce a set of bars that look like:

a: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 50

b: ▇▇▇▇▇▇▇▇▇ 25

c: ▇▇▇ 15

d: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 78

func (*Horizontal) Print

func (c *Horizontal) Print(w io.Writer)

Print the bar chart to a writer

type HorizontalOption

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

HorizontalOption is an option for a horizontal bar graph

func WithBarChars

func WithBarChars(s string) HorizontalOption

WithBarChars sets the characters to use in the bar

func WithLabelSeparator

func WithLabelSeparator(s string) HorizontalOption

WithLabelSeparator sets the separator to use between the label and bar

func WithValueFormatter

func WithValueFormatter(f func(Bar) string) HorizontalOption

WithValueFormatter sets a formatter function for displaying the value after the bar

type Sparkline

type Sparkline struct {
	Chart

	Bars Bars
	// contains filtered or unexported fields
}

func NewSparkline

func NewSparkline(bars Bars, options ...SparklineOption) *Sparkline

NewSparkline creates a Sparkline chart from a set of bars

func (*Sparkline) Print

func (c *Sparkline) Print(w io.Writer)

type SparklineOption

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

SparklineOption is an option for a sparkline

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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