terminal_graph/candle_graphs

Pure-Nim OHLC candlestick charts for terminal applications.

Candles are placed at equally spaced columns in their supplied order. The renderer returns a string and never writes to or changes terminal state. Optional labels identify ordered periods; they do not affect spacing.

Types

Candle = object
  open*: float64
  high*: float64
  low*: float64
  close*: float64
One open-high-low-close price interval.
CandlePlotOptions = object
  width*: int
  height*: int
  useColor*: bool
  showAxis*: bool
  showLabels*: bool
  caption*: string
  unit*: string
  risingColor*: TerminalColor
  fallingColor*: TerminalColor
  unchangedColor*: TerminalColor
  axisColor*: TerminalColor
  labelColor*: TerminalColor
  wickGlyph*: string
  risingGlyph*: string
  fallingGlyph*: string
  unchangedGlyph*: string
  minimum*: Option[float64]
  maximum*: Option[float64]
  yAxisValueFormatter*: AxisValueFormatter
  lineEnding*: string

Complete candlestick-chart configuration.

width and height describe the price canvas. Axis labels, caption, baseline, and period-label rows are outside that canvas.

Procs

proc candle[O, H, L, C: SomeNumber](open: O; high: H; low: L; close: C): Candle
Constructs a candle from integer or floating-point prices.
proc clearCandleRange(options: var CandlePlotOptions) {....raises: [], tags: [],
    forbids: [].}
Restores automatic price bounds.
proc initCandlePlotOptions(): CandlePlotOptions {....raises: [], tags: [],
    forbids: [].}
Returns defaults for a colored 60 by 16 candlestick canvas.
proc plotCandles(candles: openArray[Candle]): string {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
Renders an ordered OHLC sequence using default options.
proc plotCandles(candles: openArray[Candle]; options: CandlePlotOptions): string {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
Renders an ordered OHLC sequence without period labels.
proc plotCandles(labels: openArray[string]; candles: openArray[Candle]): string {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
Renders a labelled OHLC sequence using default options.
proc plotCandles(labels: openArray[string]; candles: openArray[Candle];
                 options: CandlePlotOptions): string {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
Renders an ordered OHLC sequence with optional period labels.
proc setCandleRange(options: var CandlePlotOptions; minimum, maximum: float64) {.
    ...raises: [ValueError], tags: [], forbids: [].}
Sets a fixed price viewport.