chart

package
v0.78.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chart draws plain series as lines of cells for a board. Each chart fills exactly the width and height it is given, and colors its cells with the codes the caller passes, so the board's palette paints them in the terminal's own colors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Beside

func Beside(gap int, blocks ...[]gotermboard.Line) []gotermboard.Line

Beside lays blocks of lines side by side, gap spaces apart, each as wide as its widest line.

func Compact

func Compact(v float64) string

Compact writes a value short enough for an axis: 1.2M, 12k, 1.6k, 12 or 1.5.

func Document

func Document(c Chart, height int) gotermboard.Document

Document lays a chart out at whatever width the board gives it, at a fixed height, as a row's Panel takes it.

Types

type Band

type Band struct {
	Name      string
	Low, High []Point
	Code      string
}

Band is the range between two edges, oldest first, shaded where no line runs, as the range a forecast may land in.

type Bar

type Bar struct {
	Label string
	Value float64
	Code  string
	Stack []Part
}

Bar is one value of a bar chart. A bar with a Stack draws each part over the one before it, from zero, so its height is their sum and its Value and Code go unread. A stack draws in whole rows, so a part under half a row can draw none.

type Bars

type Bars struct {
	Bars []Bar
	// Max is the value drawn full height, and the axis reaches further where a value goes past.
	// Zero takes the largest value.
	Max float64
	// ValueLabel writes a value on the value axis. Nil writes Compact.
	ValueLabel func(float64) string
}

Bars draws one upright bar per value, each in its own color, over a value axis labeled at the top, the middle and zero, with each bar's label under the axis.

func (Bars) Lines

func (c Bars) Lines(width, height int) []gotermboard.Line

Lines is the chart in width by height cells: the bars, then the axis, then their labels.

type Chart

type Chart interface {
	Lines(width, height int) []gotermboard.Line
}

Chart is any of them, laid out in a width and height of cells.

type HeatRow

type HeatRow struct {
	Label  string
	Values []float64
}

HeatRow is one row of a heatmap, named at its left.

type Heatmap

type Heatmap struct {
	Rows []HeatRow
	// Columns names each column of values on a line above the rows, where the name fits beside
	// the one before it. An empty name leaves its column unnamed, and no names draw no line.
	Columns []string
	Code    string
	// Max is the value drawn as a full block. Zero takes the largest value.
	Max float64
}

Heatmap shades a grid of values, as hour of day against weekday, from a light shade to a full block in one color. A shade orders by density in any theme, where a ramp of the sixteen colors orders differently in each.

func (Heatmap) Lines

func (h Heatmap) Lines(width, height int) []gotermboard.Line

Lines is the heatmap in width by height cells. Each column of values takes an equal share of the width past the row labels, with a gap where the share is three cells or more, and each row an equal share of the lines under the names. Given fewer lines than the rows and the names, it drops the names first, then ends on a +N line counting the rows that did not fit.

type Layer added in v0.36.0

type Layer struct {
	Name   string
	Points []Point
	Code   string
}

Layer is one band of a stacked area: its own thickness at each reading, oldest first, joined straight between readings and zero outside them. Its Code is a foreground code, which the chart moves to the background where the layer sits above another inside a cell.

type Meter added in v0.32.0

type Meter struct {
	Parts []Part
	// Max is the value the whole width draws. Zero takes the parts' sum.
	Max float64
}

Meter draws one bar across a line, to an eighth of a cell, each part after the one before it in its own color. A cell two parts share takes the color of the part holding more of it.

func (Meter) Lines added in v0.32.0

func (m Meter) Lines(width, height int) []gotermboard.Line

Lines is the meter on the first of height lines, each width cells wide.

type Part added in v0.32.0

type Part struct {
	Value float64
	Code  string
}

Part is one share of a stacked bar or a meter, in its own color.

type Point

type Point struct {
	At    time.Time
	Value float64
}

Point is one reading of a series.

type Series

type Series struct {
	// Name is the legend's word for it.
	Name   string
	Points []Point
	Code   string
	// Dotted draws every other dot along the line, as a forecast reads.
	Dotted bool
	// Columns draws each reading as an eighth-block column up from the axis's foot, across the
	// time until the next reading, or until the axis's end for the last, rather than as a line.
	// A count per day reads this way. A reading's column ends a cell short where it is three or
	// more cells wide, so neighbors read apart, and readings sharing a cell draw their mean.
	Columns bool
}

Series is a line of readings, oldest first, in one color.

type Span added in v0.34.0

type Span struct {
	Label      string
	Start, End time.Time
	Code       string
	// Text sits after the bar where it fits and else before it, such as how long the span took.
	Text string
}

Span is one row of a timeline: its label at the left, then a bar from Start to End in its own color. A span whose End is not after its Start is a moment, drawn as a milestone's ◆. A span with a Start and no End is still under way and runs to the axis's end, so a chart of work under way sets the timeline's To to now. A span with no Start draws its label alone, as what has not happened.

type Sparkline

type Sparkline struct {
	Values []float64
	Code   string
	// Max is the value drawn full height. Zero takes the largest value.
	Max float64
	// Fill widens each value into an even run of columns where there are fewer values than
	// columns, so a short series spans the chart rather than its right edge.
	Fill bool
}

Sparkline draws values, oldest first, as columns of eighth blocks with the newest at the right edge. A value of zero or less draws nothing, and any value above zero draws at least ▁, so a quiet stretch reads apart from an empty one.

func (Sparkline) Lines

func (s Sparkline) Lines(width, height int) []gotermboard.Line

Lines is the sparkline in width by height cells. More values than columns are averaged in even runs, so the whole span shows, and with Fill fewer values are each widened into a run of columns.

type StackedArea added in v0.36.0

type StackedArea struct {
	// Layers stack in order, the first on the axis.
	Layers []Layer
	// From and To bound the time axis. A zero one takes the readings' first or last time.
	From, To time.Time
	// Max is the value drawn full height, and the axis reaches further where the stack goes past.
	// Zero takes the tallest stack.
	Max float64
	// TimeLabel and ValueLabel name the axes' marks, as TimeSeries' do.
	TimeLabel  func(time.Time) string
	ValueLabel func(float64) string
}

StackedArea draws layers over time, each on top of the ones before it from zero, as a stacked area chart or a cumulative flow diagram reads. A layer's edge falls to an eighth of a row: where two layers meet inside a cell, the lower one fills it from the bottom and the upper one paints the rest as the cell's background.

func (StackedArea) Legend added in v0.36.0

func (c StackedArea) Legend() gotermboard.Line

Legend names each layer that has a name beside its mark, the top layer first, as the chart reads down.

func (StackedArea) Lines added in v0.36.0

func (c StackedArea) Lines(width, height int) []gotermboard.Line

Lines is the chart in width by height cells, over the axes TimeSeries draws.

type TimeSeries

type TimeSeries struct {
	// Series draw in order, so a later one covers an earlier where they cross.
	Series []Series
	Bands  []Band
	// From and To bound the time axis. A zero one takes the readings' first or last time, moved an
	// hour out where every reading shares one time. A zero To reaches a Columns series' last
	// reading plus the step before it, so that reading's column shows.
	From, To time.Time
	// Min and Max bound the value axis, which reaches further where a reading goes past. Where
	// Max is not above Min, the axis runs from zero, or the lowest reading below it, to the largest
	// reading.
	Min, Max float64
	// TimeLabel names the time under a column, drawn where the name changes. Nil names the
	// minute, the hour, the weekday or the date by how long the axis runs.
	TimeLabel func(time.Time) string
	// ValueLabel writes a value on the value axis. Nil writes Compact.
	ValueLabel func(float64) string
}

TimeSeries draws series over time as braille lines, over a time axis and a value axis.

func (TimeSeries) Legend

func (c TimeSeries) Legend() gotermboard.Line

Legend names each series and band that has a name, beside the mark it draws in.

func (TimeSeries) Lines

func (c TimeSeries) Lines(width, height int) []gotermboard.Line

Lines is the chart in width by height cells. The time axis takes the last two lines where there are four or more, and the value axis takes the left columns where there are twelve or more.

type Timeline added in v0.34.0

type Timeline struct {
	Spans []Span
	// From and To bound the time axis. A zero one takes the spans' earliest start or latest end. A
	// span wholly outside them draws its label alone.
	From, To time.Time
	// TimeLabel names the time under a column of the axis. Nil names how far along the axis it
	// sits: 45s, 12m, 3h or 2d.
	TimeLabel func(time.Time) string
}

Timeline draws spans of time on one time axis, a row each, as a Gantt chart or a trace waterfall lays them out. Each bar starts on the cell its span starts in and runs to where it ends, so a long span stands out by its length and a wait between two shows as the gap between their bars.

func (Timeline) Lines added in v0.34.0

func (t Timeline) Lines(width, height int) []gotermboard.Line

Lines is the timeline in width by height cells: a row per span, then a line naming the time along the axis. Given fewer lines than that, it drops the axis first, then ends on a +N line counting the spans that did not fit. A bar starts on the cell its start falls in and ends to an eighth of a cell, and a span lasting any time at all draws at least ▏.

Jump to

Keyboard shortcuts

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