Help us shape the future of Go! Take the 2026 Go Developer Survey

viz

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package viz draws terminal charts: braille line charts with axes and legends, sparklines, gauges, and trace waterfalls. It returns strings, so the CLI prints them and the TUI lays them out.

Index

Constants

This section is empty.

Variables

View Source
var Palette = []lipgloss.Color{"#73BF69", "#F2CC0C", "#5794F2", "#FF780A", "#F2495C", "#B877D9", "#8AB8FF", "#FADE2A", "#96D98D", "#FFB357"}

Palette follows Grafana's classic series colours.

Functions

func At

func At(l Line, t time.Time) float64

At is the line's value nearest to t, NaN when it has none.

func BarGauge

func BarGauge(items []Bar, w int, unit string, top float64) string

BarGauge draws one horizontal bar per item, scaled to top (the largest value when 0), name on the left and value on the right, coloured by the item.

func Gauge

func Gauge(frac float64, w int) string

Gauge is a bar filled to frac (0..1), green → amber → red as it fills.

func Human

func Human(v float64, unit string) string

Human formats a value with SI prefixes and its unit: 1.2k/s, 340ms, 2.1GiB.

func LabelName

func LabelName(l map[string]string) string

func Legend

func Legend(lines []Line, w int, unit string) string

Legend shows each series' colour, name and last value, as many as fit on one line.

func LegendOf

func LegendOf(tmpl string, labels map[string]string) string

LegendOf fills a {{label}} template from a series' labels; empty, it names the series by them.

func LineChart

func LineChart(lines []Line, w, h int, unit string) string

LineChart draws lines over a shared time axis in a w×h block (axes and legend included).

func Meter

func Meter(frac float64, w int, label string) string

Meter is an htop bar, w cells wide: [|||| label], the label right-aligned inside it.

func Plot

func Plot(lines []Line, w, h int, o Opts) string

Plot draws the chart without a legend: h-2 rows of plot, the x axis and the time labels.

func PlotOffset

func PlotOffset(lines []Line, h int, o Opts) int

PlotOffset is how many cells the plot area starts right of the chart's left edge, for a chart drawn with these lines and options: clicks on the plot map to a cursor through it.

func RelationGraph

func RelationGraph(center string, in, out []Rel) string

RelationGraph draws one object in a box, what points at it on the left and what it points at on the right.

func Span

func Span(lines []Line) (tmin, tmax time.Time)

Span is the time range the lines cover.

func Sparkline

func Sparkline(vals []float64, w int, color lipgloss.Color) string

Sparkline compresses vals into w block characters (the most recent at the right).

func Waterfall

func Waterfall(spans []core.Span, w int) string

Waterfall draws a trace: one row per span, indented by depth, with a bar placed in time.

Types

type Bar

type Bar struct {
	Name  string
	Value float64
	Color lipgloss.Color
}

Bar is one row of a bar gauge.

type Line

type Line struct {
	Name   string
	Points []core.Point
	Color  lipgloss.Color
}

func FromSeries

func FromSeries(ss []core.Series) []Line

FromSeries names each series by its labels and gives it a palette colour.

func Stacked

func Stacked(lines []Line, hidden map[int]bool) []Line

Stacked adds each line's values to the ones before it, point by point at equal times.

type Opts

type Opts struct {
	// From and To fix the time axis (a dashboard's range); zero fits it to the data.
	From, To  time.Time
	Unit      string
	Hidden    map[int]bool
	Highlight int
	Cursor    float64
	Stack     bool
	// Band shades the columns between two fractions of the time axis (a range being dragged); off when Band[1] <= Band[0]
	Band [2]float64
}

Opts tune Plot: Hidden lines are left out (the axes fit the rest), Highlight draws one line on top with the others faded, Cursor (0..1 across the time axis, <0 none) draws a vertical marker, Stack piles the lines up.

type Rel

type Rel struct {
	Node    string
	Label   string
	Missing bool
}

type Stats

type Stats struct {
	Min, Max, Mean, Last, Total float64
	N                           int
}

Stats summarises a line the way a Grafana table legend does.

func LineStats

func LineStats(l Line) Stats

type WaterfallView

type WaterfallView struct {
	Header, Footer string
	Rows           []string
	Order          []int
}

WaterfallView is a waterfall split in rows, so a screen can scroll it and select a span: Order[i] is the index in spans of Rows[i].

func Waterfalls

func Waterfalls(spans []core.Span, w int) WaterfallView

Jump to

Keyboard shortcuts

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