terminal_graph/xy_graphs

Search:
Group by:

Scatter plots and irregularly spaced connected XY graphs.

Unlike the sample-indexed renderer in line_graphs, this module maps explicit numeric X and Y coordinates onto a terminal canvas. Axes cross at zero whenever zero is visible; automatic ranges include zero by default. NaN points break connected paths, while infinities are rejected.

Types

XYPlotOptions = object
  width*: int
  height*: int
  useColor*: bool
  showAxes*: bool
  includeZero*: bool
  showRanges*: bool
  caption*: string
  xLabel*: string
  yLabel*: string
  axisColor*: TerminalColor
  labelColor*: TerminalColor
  minimumX*: Option[float64]
  maximumX*: Option[float64]
  minimumY*: Option[float64]
  maximumY*: Option[float64]
  lineEnding*: string
Complete scatter/XY graph configuration.
XYPoint = object
  x*: float64
  y*: float64
One point in a two-dimensional numeric coordinate system.
XYSeries = object
  name*: string
  points*: seq[XYPoint]
  color*: TerminalColor
  marker*: string
  connect*: bool
One named XY series. Points are connected in their supplied order.

Consts

DefaultXYColors: 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 XY series.

Procs

proc clearXRange(options: var XYPlotOptions) {....raises: [], tags: [], forbids: [].}
Restores automatic horizontal scaling.
proc clearYRange(options: var XYPlotOptions) {....raises: [], tags: [], forbids: [].}
Restores automatic vertical scaling.
proc initXYPlotOptions(): XYPlotOptions {....raises: [], tags: [], forbids: [].}
Returns defaults suitable for a colored terminal plot.
proc initXYSeries(name: string; points: openArray[XYPoint];
                  color = colorDefault; marker = "●"; connect = true): XYSeries {.
    ...raises: [], tags: [], forbids: [].}
Creates a series without rendering it.
proc plotScatter(points: openArray[XYPoint]): string {....raises: [ValueError],
    tags: [], forbids: [].}
Renders one scatter series using default options.
proc plotScatter(points: openArray[XYPoint]; options: XYPlotOptions): string {.
    ...raises: [ValueError], tags: [], forbids: [].}
Renders one unconnected scatter series.
proc plotScatter[X, Y: SomeNumber](xValues: openArray[X]; yValues: openArray[Y]): string
Renders paired arrays as a scatter plot using default options.
proc plotScatter[X, Y: SomeNumber](xValues: openArray[X]; yValues: openArray[Y];
                                   options: XYPlotOptions): string
Renders paired X and Y arrays as a scatter plot.
proc plotScatterMany(series: openArray[XYSeries]): string {.
    ...raises: [ValueError], tags: [], forbids: [].}
Renders multiple scatter series using default options.
proc plotScatterMany(series: openArray[XYSeries]; options: XYPlotOptions): string {.
    ...raises: [ValueError], tags: [], forbids: [].}
Renders multiple series as unconnected points.
proc plotXY(points: openArray[XYPoint]): string {....raises: [ValueError],
    tags: [], forbids: [].}
Renders one connected XY series using default options.
proc plotXY(points: openArray[XYPoint]; options: XYPlotOptions): string {.
    ...raises: [ValueError], tags: [], forbids: [].}
Renders one irregularly spaced connected series.
proc plotXY[X, Y: SomeNumber](xValues: openArray[X]; yValues: openArray[Y]): string
Renders paired arrays using default options.
proc plotXY[X, Y: SomeNumber](xValues: openArray[X]; yValues: openArray[Y];
                              options: XYPlotOptions): string
Renders paired X and Y arrays as an irregular connected series.
proc plotXYMany(series: openArray[XYSeries]): string {....raises: [ValueError],
    tags: [], forbids: [].}
Renders multiple XY series using default options.
proc plotXYMany(series: openArray[XYSeries]; options: XYPlotOptions): string {.
    ...raises: [ValueError], tags: [], forbids: [].}
Renders multiple XY series, honoring each series' connect setting.
proc setXRange(options: var XYPlotOptions; minimum, maximum: float64) {.
    ...raises: [ValueError], tags: [], forbids: [].}
Sets a fixed horizontal viewport.
proc setYRange(options: var XYPlotOptions; minimum, maximum: float64) {.
    ...raises: [ValueError], tags: [], forbids: [].}
Sets a fixed vertical viewport.
proc xyPoint[X, Y: SomeNumber](x: X; y: Y): XYPoint
Constructs an XYPoint from integer or floating-point coordinates.
proc xyPoints[X, Y: SomeNumber](xValues: openArray[X]; yValues: openArray[Y]): seq[
    XYPoint]
Pairs equally sized X and Y arrays into points.