Shared API reference — 6.0.0

Inspect shared symbols, callback contexts, constants, defaults, and stable error contracts.

Signature

Signature
import * as asciiChart from 'simple-ascii-chart'

Executable examples

Constants and errors

Source
console.log(DEFAULT_SYMBOLS.sparkline.levels);
console.log(Object.keys(ANSI_COLORS));
console.log(ChartErrorCode);
Terminal output
▁ ▂ ▃ ▄ ▅ ▆ ▇ █

ansiBlack, ansiRed, ansiGreen, ansiYellow, ansiBlue, ansiMagenta, ansiCyan, ansiWhite, ansiBrightBlack, ansiBrightRed, ansiBrightGreen, ansiBrightYellow, ansiBrightBlue, ansiBrightMagenta, ansiBrightCyan, ansiBrightWhite

ERR_CHART_INVALID_TYPE
ERR_CHART_INVALID_VALUE
ERR_CHART_DUPLICATE_ID
ERR_CHART_OUT_OF_DOMAIN
ERR_CHART_LAYOUT

Public exports

ANSI_COLORS

Maps supported color names to ANSI SGR sequences.

ANSI_COLORS: {
  readonly ansiBlack: "";
  readonly ansiRed: "";
  readonly ansiGreen: "";
  readonly ansiYellow: "";
  readonly ansiBlue: "";
  readonly ansiMagenta: "";
  readonly ansiCyan: "";
  readonly ansiWhite: "";
  readonly ansiBrightBlack: "";
  readonly ansiBrightRed: "";
  readonly ansiBrightGreen: "";
  readonly ansiBrightYellow: "";
  readonly ansiBrightBlue: "";
  readonly ansiBrightMagenta: "";
  readonly ansiBrightCyan: "";
  readonly ansiBrightWhite: "";
}

ANSI_RESET

ANSI sequence that clears active terminal styling.

ANSI_RESET = ""

AXIS

Symbols used by plot and structured-chart rendering.

AXIS: {
  n: string;
  ns: string;
  y: string;
  nse: string;
  nsw: string;
  x: string;
  we: string;
  e: string;
  intersectionXY: string;
  intersectionX: string;
  intersectionY: string;
  y2: string;
}

CHART

Default line and area glyphs used by plot series.

CHART: {
  we: string;
  wns: string;
  ns: string;
  nse: string;
  wsn: string;
  sne: string;
  area: string;
}

EMPTY

Default glyph used for an unoccupied terminal cell.

EMPTY = " "

THRESHOLDS

Default glyphs used for vertical and horizontal thresholds.

THRESHOLDS: {
  x: string;
  y: string;
}

POINT

Default glyph used for point overlays.

POINT = "●"

LAYOUT

Minimum dimensions and padding constraints shared by plot layout.

LAYOUT: {
  readonly MIN_PLOT_HEIGHT: 3;
  readonly DEFAULT_DECIMAL_PLACES: 3;
  readonly K_FORMAT_THRESHOLD: 1000;
  readonly DEFAULT_PADDING: 2;
  readonly DEFAULT_Y_SHIFT_OFFSET: 1;
}

DEFAULT_SYMBOLS

Public read-only catalog of renderer defaults. Per-call overrides are merged from these values.

DEFAULT_SYMBOLS: DeepReadonly<typeof defaultSymbols>

ChartErrorCode

Stable machine-readable error-code catalog used by public chart errors.

ChartErrorCode: {
  readonly ERR_CHART_INVALID_TYPE: "ERR_CHART_INVALID_TYPE";
  readonly ERR_CHART_INVALID_VALUE: "ERR_CHART_INVALID_VALUE";
  readonly ERR_CHART_DUPLICATE_ID: "ERR_CHART_DUPLICATE_ID";
  readonly ERR_CHART_OUT_OF_DOMAIN: "ERR_CHART_OUT_OF_DOMAIN";
  readonly ERR_CHART_LAYOUT: "ERR_CHART_LAYOUT";
}

ChartTypeError

Type/shape error with stable chart metadata.

declare class ChartTypeError extends TypeError {
  /** Stable machine-readable category for the validation failure. */
  readonly code: ChartErrorCode;
  /** Public input path that failed validation. */
  readonly path: string;
  /**
   * Creates a type or shape error with stable chart metadata.
   * @param {ChartErrorCode} code - Machine-readable chart error code.
   * @param {string} path - Public input path that failed validation.
   * @param {string} message - Human-readable validation failure.
   */
  constructor(code: ChartErrorCode, path: string, message: string);
}

ChartRangeError

Range/value error with stable chart metadata.

declare class ChartRangeError extends RangeError {
  /** Stable machine-readable category for the validation failure. */
  readonly code: ChartErrorCode;
  /** Public input path that failed validation. */
  readonly path: string;
  /**
   * Creates a range or value error with stable chart metadata.
   * @param {ChartErrorCode} code - Machine-readable chart error code.
   * @param {string} path - Public input path that failed validation.
   * @param {string} message - Human-readable validation failure.
   */
  constructor(code: ChartErrorCode, path: string, message: string);
}

Public types and closed variants

GraphMode

Rendering primitive used for a series.

type GraphMode = 'line' | 'point' | 'bar' | 'horizontalBar';

Interpolation

Line-segment interpolation policy.

type Interpolation = 'step' | 'linear';

Overflow

Behavior for line geometry outside an explicit domain.

type Overflow = 'clip' | 'discard';

Renderer

Plot-cell renderer backend.

type Renderer = 'ascii' | 'braille';

ChartWidth

Fixed plot width or the active terminal width.

type ChartWidth = number | 'auto';

LabelCollisionPolicy

Resolution policy for X-axis labels that do not fit.

type LabelCollisionPolicy = 'hide' | 'truncate' | 'wrap' | 'error';

LegendPosition

Legend placement. auto chooses right or bottom from available width.

type LegendPosition = 'left' | 'right' | 'top' | 'bottom' | 'auto';

BarLayout

Multi-series bar arrangement.

type BarLayout = 'overlap' | 'grouped' | 'stacked' | 'normalized';

XScale

X-axis scale selected explicitly or inferred from data.

type XScale = 'linear' | 'band' | 'time';

Color

One of the 16 supported ANSI foreground colors.

type Color = `ansi${'Red' | 'Green' | 'Black' | 'Yellow' | 'Blue' | 'Magenta' | 'Cyan' | 'White' | 'BrightBlack' | 'BrightRed' | 'BrightGreen' | 'BrightYellow' | 'BrightBlue' | 'BrightMagenta' | 'BrightCyan' | 'BrightWhite'}`;

ChartX

Native X-axis value accepted by structured charts.

type ChartX = string | number | Date;

PlotCoordinates

Coordinates accepted by plot.

type PlotCoordinates = PlotLine | readonly PlotLine[];

ChartDatum

A structured chart datum. A null y-value creates a gap.

type ChartDatum = readonly [x: X, y: number | null];

CandlestickDatum

One financial OHLC sample positioned on a numeric X axis.

type CandlestickDatum = readonly [x: number, open: number, high: number, low: number, close: number];

HeatmapValue

One discrete value rendered in a heatmap cell. Null reserves an empty cell.

type HeatmapValue = string | number | null;

HistogramData

Numeric histogram data accepted by plot.

type HistogramData = readonly HistogramDatum[];

SparklineColor

One color for all glyphs or colors mapped by input position.

type SparklineColor = Color | readonly (Color | undefined)[];

Symbols

Symbols shared by plot, renderChart, and candlestick.

type Symbols = {
  /** Axis line, tick, boundary, and intersection glyph overrides. */
  axis?: Partial<typeof AXIS>;
  /** Line and filled-area glyph overrides. */
  chart?: Partial<typeof CHART>;
  /** One-column glyph for unoccupied plot cells. */
  empty?: string;
  /** One-column glyph painted behind plot data. */
  background?: string;
  /** One-column glyph used for the plot border. */
  border?: string;
  /** Horizontal and vertical threshold glyph overrides. */
  thresholds?: Partial<typeof THRESHOLDS>;
  /** One-column point glyph. */
  point?: string;
  /** Shared candlestick glyph overrides. */
  candlestick?: CandlestickSymbols;
  /** Shared annotation glyph overrides. */
  annotations?: AnnotationSymbols;
  /** One-column glyph used when labels are truncated. */
  ellipsis?: string;
};

axis

Partial<typeof AXIS>Optional

Axis line, tick, boundary, and intersection glyph overrides.

Related executable examples: Constants and errors

chart

Partial<typeof CHART>Optional

Line and filled-area glyph overrides.

Related executable examples: Constants and errors

empty

stringOptional

One-column glyph for unoccupied plot cells.

Related executable examples: Constants and errors

background

stringOptional

One-column glyph painted behind plot data.

Related executable examples: Constants and errors

border

stringOptional

One-column glyph used for the plot border.

Related executable examples: Constants and errors

thresholds

Partial<typeof THRESHOLDS>Optional

Horizontal and vertical threshold glyph overrides.

Related executable examples: Constants and errors

candlestick

CandlestickSymbolsOptional

Shared candlestick glyph overrides.

Related executable examples: Constants and errors

annotations

AnnotationSymbolsOptional

Shared annotation glyph overrides.

Related executable examples: Constants and errors

ellipsis

stringOptional

One-column glyph used when labels are truncated.

Related executable examples: Constants and errors

SparklineSymbols

Per-call sparkline glyph overrides.

type SparklineSymbols = Readonly<{
  /** Exactly eight one-column glyphs ordered from lowest to highest. */
  levels?: readonly [string, string, string, string, string, string, string, string];
  /** One-column glyph used for `null`. */
  empty?: string;
}>;

levels

readonly [string, string, string, string, string, string, string, string]Optional

Exactly eight one-column glyphs ordered from lowest to highest.

Related executable examples: Constants and errors

HeatmapSymbols

Per-call heatmap glyph overrides.

type HeatmapSymbols = Readonly<{
  /** Default one-column categorical cell glyph. */
  cell?: string;
  /** Default one-column glyph for values below a threshold. */
  belowThreshold?: string;
  /** Default one-column glyph for values at or above a threshold. */
  aboveThreshold?: string;
  /** One-column glyph used for `null`. */
  empty?: string;
  /** Display-safe text inserted between cells. */
  gap?: string;
}>;

cell

stringOptional

Default one-column categorical cell glyph.

Related executable examples: Constants and errors

belowThreshold

stringOptional

Default one-column glyph for values below a threshold.

Related executable examples: Constants and errors

aboveThreshold

stringOptional

Default one-column glyph for values at or above a threshold.

Related executable examples: Constants and errors

gap

stringOptional

Display-safe text inserted between cells.

Related executable examples: Constants and errors

CandlestickSymbols

Shared candlestick glyph overrides.

type CandlestickSymbols = Readonly<{
  /** One-column wick glyph. */
  wick?: string;
  /** One-column glyph used when close is greater than open. */
  rising?: string;
  /** One-column glyph used when close is less than open. */
  falling?: string;
  /** One-column glyph used when close equals open. */
  unchanged?: string;
}>;

rising

stringOptional

One-column glyph used when close is greater than open.

Related executable examples: Constants and errors

falling

stringOptional

One-column glyph used when close is less than open.

Related executable examples: Constants and errors

unchanged

stringOptional

One-column glyph used when close equals open.

Related executable examples: Constants and errors

AnnotationSymbols

Shared annotation glyph overrides.

type AnnotationSymbols = Readonly<{
  /** One-column reference-span fill glyph. */
  span?: string;
  /** One-column arrow-line glyph. */
  arrowLine?: string;
  /** Direction-specific arrowhead glyphs. */
  arrowHeads?: ArrowHeadSymbols;
  /** Error-bar glyphs. */
  errorBar?: ErrorBarSymbols;
}>;

span

stringOptional

One-column reference-span fill glyph.

Related executable examples: Constants and errors

arrowLine

stringOptional

One-column arrow-line glyph.

Related executable examples: Constants and errors

arrowHeads

ArrowHeadSymbolsOptional

Direction-specific arrowhead glyphs.

Related executable examples: Constants and errors

ArrowHeadSymbols

Direction-specific one-column annotation arrowheads.

type ArrowHeadSymbols = Readonly<{
  /** Left-facing arrowhead. */
  left?: string;
  /** Right-facing arrowhead. */
  right?: string;
  /** Up-facing arrowhead. */
  up?: string;
  /** Down-facing arrowhead. */
  down?: string;
  /** Up-left arrowhead. */
  upLeft?: string;
  /** Up-right arrowhead. */
  upRight?: string;
  /** Down-left arrowhead. */
  downLeft?: string;
  /** Down-right arrowhead. */
  downRight?: string;
}>;

ErrorBarSymbols

One-column glyphs used by annotation error bars.

type ErrorBarSymbols = Readonly<{
  /** Horizontal whisker glyph. */
  horizontal?: string;
  /** Vertical whisker glyph. */
  vertical?: string;
  /** Left cap glyph. */
  leftCap?: string;
  /** Right cap glyph. */
  rightCap?: string;
  /** Top cap glyph. */
  topCap?: string;
  /** Bottom cap glyph. */
  bottomCap?: string;
  /** Error-bar center glyph. */
  center?: string;
}>;

ColorContext

Data and plot coordinates supplied to conditional color callbacks.

type ColorContext = {
  /** Zero-based source-series index. */
  series: number;
  /** Rendering mode used by the occupied cell. */
  mode: GraphMode;
  /** Numeric data-space X coordinate. */
  x: number;
  /** Numeric data-space Y coordinate. */
  y: number;
  /** Zero-based plot-column coordinate. */
  plotX: number;
  /** Zero-based plot-row coordinate. */
  plotY: number;
};

series

numberRequired

Zero-based source-series index.

Related executable examples: Constants and errors

mode

GraphModeRequired

Rendering mode used by the occupied cell.

Related executable examples: Constants and errors

plotX

numberRequired

Zero-based plot-column coordinate.

Related executable examples: Constants and errors

FormatterHelpers

Resolved axis context supplied to numeric formatters.

type FormatterHelpers = {
  /** Axis currently being formatted. */
  axis: 'x' | 'y';
  /** Resolved numeric X extent. */
  xRange: number[];
  /** Resolved numeric Y extent. */
  yRange: number[];
};

axis

'x' | 'y'Required

Axis currently being formatted.

Related executable examples: Constants and errors

LineFormatterArgs

Source and plot coordinates supplied to custom line formatters.

type LineFormatterArgs = {
  /** Numeric data-space X coordinate. */
  x: number;
  /** Numeric data-space Y coordinate. */
  y: number;
  /** Zero-based plot-column coordinate. */
  plotX: number;
  /** Zero-based plot-row coordinate. */
  plotY: number;
  /** Complete source series. */
  input: SingleLine;
  /** Zero-based datum index in the source series. */
  index: number;
  /** Resolved minimum Y value. */
  minY: number;
  /** Resolved minimum X value. */
  minX: number;
  /** Expanded numeric X coordinates used by the renderer. */
  expansionX: number[];
  /** Expanded numeric Y coordinates used by the renderer. */
  expansionY: number[];
  /** Converts data coordinates into plot coordinates. */
  toPlotCoordinates: (x: number, y: number) => Point;
};

plotX

numberRequired

Zero-based plot-column coordinate.

Related executable examples: Constants and errors

index

numberRequired

Zero-based datum index in the source series.

Related executable examples: Constants and errors

expansionX

number[]Required

Expanded numeric X coordinates used by the renderer.

Related executable examples: Constants and errors

expansionY

number[]Required

Expanded numeric Y coordinates used by the renderer.

Related executable examples: Constants and errors

toPlotCoordinates

(x: number, y: number) => PointRequired

Converts data coordinates into plot coordinates.

Related executable examples: Constants and errors

ValueLabelContext

Source metadata supplied to bar value-label formatters.

type ValueLabelContext = Readonly<{
  /** Zero-based source-series index. */
  seriesIndex: number;
  /** Structured-series identifier when available. */
  seriesId?: string;
  /** Structured-series or legend name when available. */
  seriesName?: string;
  /** Zero-based index in the source series. */
  datumIndex: number;
  /** Native source X value. */
  x: X;
  /** Raw source Y value. */
  y: number;
  /** Bar orientation. */
  mode: 'bar' | 'horizontalBar';
  /** Resolved multi-series bar layout. */
  layout: BarLayout;
}>;

seriesIndex

numberRequired

Zero-based source-series index.

Related executable examples: Constants and errors

seriesId

stringOptional

Structured-series identifier when available.

Related executable examples: Constants and errors

seriesName

stringOptional

Structured-series or legend name when available.

Related executable examples: Constants and errors

datumIndex

numberRequired

Zero-based index in the source series.

Related executable examples: Constants and errors

mode

'bar' | 'horizontalBar'Required

Bar orientation.

Related executable examples: Constants and errors

layout

BarLayoutRequired

Resolved multi-series bar layout.

Related executable examples: Constants and errors