Shared API reference — 5.4.0

Inspect the constants, symbols, formatter contexts, and public types exported by version 5.4.0.

Signature

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

Executable examples

Source
console.log(Object.keys(AXIS));
console.log(Object.keys(CHART));
console.log(LAYOUT);
Terminal output
n, ns, y, nse, x, we, e, intersectionXY, intersectionX, intersectionY

we, wns, ns, nse, wsn, sne, area

{"MIN_PLOT_HEIGHT":3,"DEFAULT_DECIMAL_PLACES":3,"K_FORMAT_THRESHOLD":1000,"DEFAULT_PADDING":2,"DEFAULT_Y_SHIFT_OFFSET":1}

Public exports

AXIS

Symbols used to draw chart axes.

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

CHART

Symbols used to draw line and area charts.

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

EMPTY

Symbol used for an empty graph cell.

EMPTY: " "

THRESHOLDS

Symbols used to draw X-axis and Y-axis thresholds.

THRESHOLDS: { x: string; y: string }

POINT

Symbol used for point overlays.

POINT: "●"

LAYOUT

Layout and formatting constants used by version 5.4.0.

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;
}

Public types and closed variants

GraphMode

Plot modes supported by version 5.4.0.

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

Color

ANSI color names supported by version 5.4.0.

type Color = `ansi${
  | "Red"
  | "Green"
  | "Black"
  | "Yellow"
  | "Blue"
  | "Magenta"
  | "Cyan"
  | "White"}`;

Coordinates

Input accepted by plot.

type Coordinates = SingleLine | MultiLine;

Point

Numeric X and Y coordinates.

type Point = [x: number, y: number];

MaybePoint

Optional or partially defined axis-center coordinates.

type MaybePoint = Point | undefined | [number | undefined, number | undefined];

Colors

Static or callback-based series colors.

type Colors = Color | Color[] | ColorGetter;

Symbols

Per-call symbol overrides.

type Symbols = {
  /** Axis-symbol overrides. */
  axis?: Partial<typeof AXIS>;
  /** Line and area-symbol overrides. */
  chart?: Partial<typeof CHART>;
  /** Empty-cell symbol. */
  empty?: string;
  /** Background-cell symbol. */
  background?: string;
  /** Border symbol. */
  border?: string;
  /** Threshold-symbol overrides. */
  thresholds?: Partial<typeof THRESHOLDS>;
  /** Point-overlay symbol. */
  point?: string;
};

axis

Partial<typeof AXIS>Optional

Axis-symbol overrides.

Related executable examples:

chart

Partial<typeof CHART>Optional

Line and area-symbol overrides.

Related executable examples:

empty

stringOptional

Empty-cell symbol.

Related executable examples:

background

stringOptional

Background-cell symbol.

Related executable examples:

border

stringOptional

Border symbol.

Related executable examples:

thresholds

Partial<typeof THRESHOLDS>Optional

Threshold-symbol overrides.

Related executable examples:

point

stringOptional

Point-overlay symbol.

Related executable examples:

FormatterHelpers

Context received by the axis formatter.

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

axis

"x" | "y"Required

Axis currently being formatted.

Related executable examples:

xRange

number[]Required

Resolved numeric X range.

Related executable examples:

yRange

number[]Required

Resolved numeric Y range.

Related executable examples:

LineFormatterArgs

Context received by the custom line renderer.

type LineFormatterArgs = {
  /** Original X coordinate. */
  x: number;
  /** Original Y coordinate. */
  y: number;
  /** Resolved plot-column coordinate. */
  plotX: number;
  /** Resolved plot-row coordinate. */
  plotY: number;
  /** Source data series. */
  input: SingleLine;
  /** Source datum index. */
  index: number;
  /** Minimum resolved Y value. */
  minY: number;
  /** Minimum resolved X value. */
  minX: number;
  /** Resolved X expansion table. */
  expansionX: number[];
  /** Resolved Y expansion table. */
  expansionY: number[];
  /** Converts data coordinates to plot coordinates. */
  toPlotCoordinates: (x: number, y: number) => Point;
};

x

numberRequired

Original X coordinate.

Related executable examples:

y

numberRequired

Original Y coordinate.

Related executable examples:

plotX

numberRequired

Resolved plot-column coordinate.

Related executable examples:

plotY

numberRequired

Resolved plot-row coordinate.

Related executable examples:

input

SingleLineRequired

Source data series.

Related executable examples:

index

numberRequired

Source datum index.

Related executable examples:

minY

numberRequired

Minimum resolved Y value.

Related executable examples:

minX

numberRequired

Minimum resolved X value.

Related executable examples:

expansionX

number[]Required

Resolved X expansion table.

Related executable examples:

expansionY

number[]Required

Resolved Y expansion table.

Related executable examples:

toPlotCoordinates

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

Converts data coordinates to plot coordinates.

Related executable examples: