Documentation
¶
Overview ¶
Package canvas draws time-series graphs with braille characters, btop-style: 4 dot rows and 2 dot columns packed per terminal cell.
Index ¶
- Constants
- func Bar(width int, frac float64, filled, empty lipgloss.Style) string
- func BigNumber(v int, ramp Ramp) []string
- func BigNumberWidth(n int) int
- func DualBar(width int, frac float64, rampA, rampB Ramp) string
- func GradientBar(width int, frac float64, ramp Ramp, empty lipgloss.Style) string
- func OverlayLabel(block, label string) string
- func Sparkline(values []float64, ramp Ramp) string
- func SparklineScaled(values []float64, ramp Ramp) string
- type Graph
- type Ramp
- type Scale
Constants ¶
const BigNumberHeight = 5
BigNumberHeight is the row count of every BigNumber render.
Variables ¶
This section is empty.
Functions ¶
func Bar ¶
Bar renders a horizontal fraction bar of the given cell width using full blocks and eighth-block edges.
func BigNumber ¶
BigNumber renders v as a 5-line block-digit banner colored along the ramp at value/100 — the btop-style hero readout for headline metrics.
func BigNumberWidth ¶
BigNumberWidth reports the cell width BigNumber needs for n glyphs (3 columns each plus a 1-column gap between glyphs).
func DualBar ¶
DualBar renders a glances-style mixed meter of width cells: the first frac of the bar interpolates across rampA and the remainder across rampB, so a single always-full bar visualizes a direction split (download vs upload, read vs write) while the magnitude lives in the neighboring rate text. Whole bars are memoized per (rampA, rampB, width, fraction-step).
func GradientBar ¶
GradientBar renders a btop-style meter: the filled part interpolates across the ramp along the bar's length (so long bars sweep green → red by position, not by threshold), the remainder renders dim. The edge cell uses an eighth block for sub-cell precision. Fills are memoized per (ramp, width, fraction-step) for typical meter widths — live values repeat far more often than they change, so most frames reuse the string. The fraction is quantized BEFORE the geometry is derived, so a cache step always renders exactly one bar shape.
func OverlayLabel ¶
OverlayLabel writes label into the top-right corner of a rendered block (e.g. a braille graph), shortening the block's top row to make room — the place for a rate graph's auto-scale ceiling. The label is expected pre-styled; when almost no room remains the block returns unchanged.
func Sparkline ¶
Sparkline renders the values (each 0..1) as one row of block glyphs, colored per glyph by ramping on the value.
func SparklineScaled ¶
SparklineScaled renders raw-rate samples (any magnitude) as one row of block glyphs, scaling the window so its tallest sample fills the full height — the btop activity look. All-zero windows render as blanks.
Types ¶
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is a scrolling line graph backed by a ring buffer. Values are fractions in [0,1] (or [0,Max] when Max is set) and render as an area filled from the bottom. Use New; the zero value is not usable.
func New ¶
New returns a graph of the given cell size. The ramp colors cells by the value of their column, from low to high.
type Ramp ¶
type Ramp []string
Ramp is an ordered list of hex colors ("#rrggbb") interpolated left to right across bars and sparklines. Ramps are treated as immutable once built: derived styles are cached per instance.