Charts: strings from data
lib/render/tui_chart.sh - charts and text blocks as strings, for labels, panes and the <spark>, <gauge> and <chart> widgets. The renderers behind tui.chart are in lib/terminal_renderer.sh: Renderers. Guide: Charts.
tui.chart.spark and tui.chart.gauge do not fork and do not read the renderer file, so they are cheap enough for a timer. tui.chart reads it on first use.
| Function | Summary |
|---|---|
tui.chart |
Renders a chart or text block into VAR, lines joined by newlines, ready for tui.output PANE "$VAR". |
tui.chart.spark |
Stores one block glyph (▁ to █) per value in VAR, scaled between the smallest and the largest value. It does not fork and does not read the renderer file. |
tui.chart.gauge |
Stores a bar and a percent in VAR: ████████░░░░ 67%. It does not fork and does not read the renderer file. |
tui.chart
tui.chart KIND VAR [--data NAME --col COL [--label COL] [--last N]] [--class CLASS] [RENDERER ARG...]
Renders a chart or text block into VAR, lines joined by newlines, ready for tui.output PANE "$VAR".
Parameters
KIND: one ofbox divider alert table kv hbar vbar gauge sparkline linechart csv_hbar csv_vbar csv_linechart scatter boxplot forest heatmap histogram banner tree columns badges list quote. They are the renderers oflib/terminal_renderer.sh, which is read on the first use; their arguments and flags (-w 40,-h 8,-c GREEN) are the ones listed in Renderers.--class CLASS: put the colours of a theme class back after every reset in the output, so the chart keeps the background of the pane it is shown in.--data NAME: build the arguments from a dataset.--colnames the column (repeat it for several series),--labelthe column of the labels,--lastlimits to the newest rows.
KIND with --data |
Arguments built |
|---|---|
sparkline, histogram |
the values of --col |
hbar, vbar |
LABEL:VALUE per row (--label, default column 0) |
linechart, boxplot, forest |
one series NAME:v,v,v per --col |
table |
the --cols header and every row |
list |
the cells of --col |
Notes
- Colours and sizes are the renderer’s. Pass
-wto fit a pane. - The renderer file defines functions with generic names (
box,list,table,tree); they are defined in the app’s shell once aKINDis rendered.
Notes
- A size or scale flag (
-w,-h,-n,-m, …) whose value is not a number is refused (rc 1, a message on stderr): the renderers loop forever on one.
Returns: 1 for an unknown KIND, a KIND that does not take --data, an unknown dataset, or a renderer that refuses its arguments.
Example
tui.chart hbar out --data hosts --col load --label host -w 40
tui.output pane_load "$out"
tui.chart.spark
tui.chart.spark VAR [-w N] [-n MIN] [-m MAX] VALUE...
Stores one block glyph (▁ to █) per value in VAR, scaled between the smallest and the largest value. It does not fork and does not read the renderer file.
Parameters
-w N: show only the newestNvalues; fewer values leave the left side blank.-n MIN,-m MAX: a fixed scale instead of the data’s.
Notes
- Values may have decimals. A value that is not a number counts as
0. Equal values draw the middle glyph.
Returns: 1 without VAR.
Example
tui.chart.spark line -w 20 "${samples[@]}"
tui.set_label lbl_trend "$line"
tui.chart.gauge
tui.chart.gauge VAR VALUE [MAX] [-w N]
Stores a bar and a percent in VAR: ████████░░░░ 67%. It does not fork and does not read the renderer file.
Parameters
MAX: the value that fills the bar. Default 100.-w N: the bar’s width in cells. Default 20.
Notes
- A value outside 0 to
MAXis clamped.
Returns: 1 without VAR.
Example
tui.chart.gauge bar "$cpu" 100 -w 12
