terminal_graph/sparkline_graphs

Compact, single-line graphs for small numeric sequences.

Sparklines support automatic or explicit ranges, NaN gaps, custom glyphs, standard, indexed, or RGB palettes and configurable handling for constant nonzero data. Most applications should access this API through import terminal_graph.

Types

SparklineConstantMode = enum
  scmLowest, scmMiddle
Selects the glyph used when every finite value is equal and nonzero.
SparklineOptions = object
  minimum*: Option[float64]
  maximum*: Option[float64]
  ticks*: seq[string]
  gapGlyph*: string
  useColor*: bool
  palette*: seq[TerminalColor]
  constantMode*: SparklineConstantMode
Complete sparkline rendering configuration.

Consts

FireSparklinePalette: array[8, TerminalColor] = [
    (kind: tckAnsi256, index: 226'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi256, index: 220'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi256, index: 214'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi256, index: 208'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi256, index: 202'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi256, index: 196'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi256, index: 160'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi256, index: 124'u, red: 0'u, green: 0'u, blue: 0'u)]
Built-in ANSI-256 gradient from yellow to deep red.
SparklineTicks: array[8, string] = ["▁", "▂", "▃", "▄", "▅", "▆",
                                    "▇", "█"]
Default glyphs ordered from the lowest to the highest value.

Procs

proc clearSparklineMaximum(options: var SparklineOptions) {....raises: [],
    tags: [], forbids: [].}
Restores automatic upper-bound calculation.
proc clearSparklineMinimum(options: var SparklineOptions) {....raises: [],
    tags: [], forbids: [].}
Restores automatic lower-bound calculation.
proc clearSparklineRange(options: var SparklineOptions) {....raises: [], tags: [],
    forbids: [].}
Restores automatic minimum and maximum calculation.
proc initSparklineOptions(): SparklineOptions {....raises: [], tags: [],
    forbids: [].}

Returns defaults with automatic scaling and a fire palette available.

Coloring remains disabled until useColor is set. Constant nonzero data uses the middle glyph, while an all-zero series uses the lowest.

proc setSparklineMaximum(options: var SparklineOptions; maximum: float64) {.
    ...raises: [ValueError], tags: [], forbids: [].}
Sets only the upper scale bound; the lower bound remains automatic.
proc setSparklineMinimum(options: var SparklineOptions; minimum: float64) {.
    ...raises: [ValueError], tags: [], forbids: [].}
Sets only the lower scale bound; the upper bound remains automatic.
proc setSparklineRange(options: var SparklineOptions; minimum, maximum: float64) {.
    ...raises: [ValueError], tags: [], forbids: [].}
Sets an explicit scale shared by every value in the sparkline.
proc sparkline[T: SomeNumber](data: openArray[T]): string
Renders data with automatic scaling and default options.
proc sparkline[T: SomeNumber](data: openArray[T]; rawOptions: SparklineOptions): string

Renders data as a compact sparkline using rawOptions.

NaN values produce gapGlyph without affecting automatic scaling. Infinite values raise ValueError. Values outside an explicit range are clamped to the lowest or highest tick.