import * as asciiChart from 'simple-ascii-chart'Shared API reference — 6.0.0
Signature
Executable examples
Constants and errors
console.log(DEFAULT_SYMBOLS.sparkline.levels);
console.log(Object.keys(ANSI_COLORS));
console.log(ChartErrorCode);▁ ▂ ▃ ▄ ▅ ▆ ▇ █
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_LAYOUTPublic exports
ANSI_COLORS
Maps supported color names to ANSI SGR sequences.
ANSI_COLORS: {
readonly ansiBlack: "[30m";
readonly ansiRed: "[31m";
readonly ansiGreen: "[32m";
readonly ansiYellow: "[33m";
readonly ansiBlue: "[34m";
readonly ansiMagenta: "[35m";
readonly ansiCyan: "[36m";
readonly ansiWhite: "[37m";
readonly ansiBrightBlack: "[90m";
readonly ansiBrightRed: "[91m";
readonly ansiBrightGreen: "[92m";
readonly ansiBrightYellow: "[93m";
readonly ansiBrightBlue: "[94m";
readonly ansiBrightMagenta: "[95m";
readonly ansiBrightCyan: "[96m";
readonly ansiBrightWhite: "[97m";
}ANSI_RESET
ANSI sequence that clears active terminal styling.
ANSI_RESET = "[0m"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
Axis line, tick, boundary, and intersection glyph overrides.
Related executable examples: Constants and errors
chart
Line and filled-area glyph overrides.
Related executable examples: Constants and errors
empty
One-column glyph for unoccupied plot cells.
Related executable examples: Constants and errors
background
One-column glyph painted behind plot data.
Related executable examples: Constants and errors
border
One-column glyph used for the plot border.
Related executable examples: Constants and errors
thresholds
Horizontal and vertical threshold glyph overrides.
Related executable examples: Constants and errors
candlestick
Shared candlestick glyph overrides.
Related executable examples: Constants and errors
annotations
Shared annotation glyph overrides.
Related executable examples: Constants and errors
ellipsis
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
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
Default one-column categorical cell glyph.
Related executable examples: Constants and errors
belowThreshold
Default one-column glyph for values below a threshold.
Related executable examples: Constants and errors
aboveThreshold
Default one-column glyph for values at or above a threshold.
Related executable examples: Constants and errors
gap
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
One-column glyph used when close is greater than open.
Related executable examples: Constants and errors
falling
One-column glyph used when close is less than open.
Related executable examples: Constants and errors
unchanged
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
One-column reference-span fill glyph.
Related executable examples: Constants and errors
arrowLine
One-column arrow-line glyph.
Related executable examples: Constants and errors
arrowHeads
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
Zero-based source-series index.
Related executable examples: Constants and errors
mode
Rendering mode used by the occupied cell.
Related executable examples: Constants and errors
plotX
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
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
Zero-based plot-column coordinate.
Related executable examples: Constants and errors
index
Zero-based datum index in the source series.
Related executable examples: Constants and errors
expansionX
Expanded numeric X coordinates used by the renderer.
Related executable examples: Constants and errors
expansionY
Expanded numeric Y coordinates used by the renderer.
Related executable examples: Constants and errors
toPlotCoordinates
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
Zero-based source-series index.
Related executable examples: Constants and errors
seriesId
Structured-series identifier when available.
Related executable examples: Constants and errors
seriesName
Structured-series or legend name when available.
Related executable examples: Constants and errors
datumIndex
Zero-based index in the source series.
Related executable examples: Constants and errors
mode
Bar orientation.
Related executable examples: Constants and errors
layout
Resolved multi-series bar layout.
Related executable examples: Constants and errors