terminal_graph/bar_graphs

Pure-Nim horizontal bar charts for terminal applications.

Bars may be rendered as independent grouped rows or as stacked segments. The value range always contains zero, giving positive and negative values a meaningful shared baseline. Most applications should import the terminal_graph faรงade instead of this submodule directly.

Types

BarGraphOptions = object
  width*: int
  mode*: BarMode
  useColor*: bool
  showValues*: bool
  caption*: string
  unit*: string
  glyph*: string
  axisGlyph*: string
  seriesColors*: seq[TerminalColor]
  seriesLegends*: seq[string]
  minimum*: Option[float64]
  maximum*: Option[float64]
  lineEnding*: string
Complete horizontal bar-chart configuration.
BarMode = enum
  bmGrouped, bmStacked
Controls how multiple values for each category are arranged.

Consts

DefaultBarColors: array[8, TerminalColor] = [
    (kind: tckAnsi16, index: 14'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi16, index: 11'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi16, index: 13'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi16, index: 10'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi16, index: 9'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi16, index: 12'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi16, index: 15'u, red: 0'u, green: 0'u, blue: 0'u),
    (kind: tckAnsi16, index: 2'u, red: 0'u, green: 0'u, blue: 0'u)]
Default colors assigned cyclically to bar series.

Procs

proc clearBarRange(options: var BarGraphOptions) {....raises: [], tags: [],
    forbids: [].}
Restores automatic range calculation.
proc initBarGraphOptions(): BarGraphOptions {....raises: [], tags: [], forbids: [].}
Returns defaults for a colored, value-labelled grouped chart.
proc plotBars[T: SomeNumber](labels: openArray[string];
                             series: openArray[seq[T]]): string
Renders multiple horizontal bar series using default options.
proc plotBars[T: SomeNumber](labels: openArray[string];
                             series: openArray[seq[T]]; options: BarGraphOptions): string
Renders multiple grouped or stacked horizontal bar series.
proc plotBars[T: SomeNumber](labels: openArray[string]; values: openArray[T]): string
Renders one horizontal bar series using default options.
proc plotBars[T: SomeNumber](labels: openArray[string]; values: openArray[T];
                             options: BarGraphOptions): string
Renders one horizontal bar series.
proc setBarRange(options: var BarGraphOptions; minimum, maximum: float64) {.
    ...raises: [ValueError], tags: [], forbids: [].}
Fixes the chart range. The range must contain zero.