NURLNURL registrynurl-lang.org →

← chart

chart 0.1.1 API

chart.nu

chart — terminal data-visualisation for NURL.

Turn a list of numbers into something you can actually see in a terminal: a one-line sparkline, a labelled horizontal bar chart, a histogram, or a line/scatter plot drawn on a character grid. Every renderer returns an owned String (the caller frees it with string_free), uses only Unicode that any modern terminal renders, and allocates nothing it does not free — leak-clean under ASan/LSan.

This package lives in the NURL registry, NOT the core stdlib: charting is opinionated (which glyphs, which scaling, which layout) in a way the language proper should stay out of, but it is exactly the kind of everyday utility a package ecosystem exists to provide. It is pure NURL — no FFI — and depends only on the shipped stdlib (vec, string, float), so it builds and behaves identically on every platform.

Surface ( chart_sparkline values ) → String ▁▂▃▄▅▆▇█ one-liner ( chart_bars labels values width ) → String labelled h-bars ( chart_hist values bins width ) → String binned histogram ( chart_plot values width height ) → String line/scatter grid ( chart_min values ) / max / sum / _mean → f summary stats

values is a ( Vec f ); labels is a ( Vec String ) (borrowed, never freed or retained). width/height are in terminal cells. Bars and histograms assume non-negative values (the natural shape for a bar chart); a negative value contributes an empty bar. The plot handles any range, including negatives.

The block glyphs give sub-cell precision: a bar is drawn in whole "full block" cells plus one partial left-block for the final eighth, so a value of 3.5 units at 1 cell/unit reads as three full cells and a half cell — far smoother than rounding to whole characters.

API

@ chart_min ( Vec f ) v → f

@ chart_max ( Vec f ) v → f

@ chart_sum ( Vec f ) v → f

@ chart_mean ( Vec f ) v → f

@ chart_sparkline ( Vec f ) v → String

@ chart_bars ( Vec String ) labels ( Vec f ) values i width → String

@ chart_hist ( Vec f ) values i bins i width → String

@ chart_plot ( Vec f ) values i width i height → String


main.nu

chart — draw charts in your terminal from numbers on stdin.

A genuinely-everyday companion to nq and friends: pipe numbers into chart and see them. Four modes, one per renderer in the chart library (src/chart.nu):

chart spark one-line sparkline of the numbers ▁▂▃▄▅▆▇█ chart bar labelled horizontal bars ██████▌ chart hist histogram (bin the numbers, --bins N) chart line line/scatter plot on a grid (--width/--height)

Input is whitespace-separated numbers from stdin (or --file), e.g.

seq 1 20 | chart spark chart line -f temps.txt --height 12 printf '%s\n' 'apples 8' 'pears 6' 'cherries 2' | chart bar

In bar mode each input line is one bar: <label...> <value> (the last token is the value, the rest is the label), or a bare number whose label is its position. Every other mode reads a flat stream of numbers.

Flags (parsed by the stdlib std/args parser): -w / --width N chart width in cells (bar/hist/line; default 40) --height N plot height in rows (line; default 10) -b / --bins N histogram buckets (hist; default 10) -f / --file PATH read numbers from PATH instead of stdin -t / --title TEXT print TEXT above the chart -h / --help show this help

Like the rest of the registry packages it leans on the ecosystem: the chart library does the drawing, the stdlib std/args parses the flags, and the shipped stdlib does everything else. Leak-clean under ASan/LSan on every path.

API

@ main → i