plot — 6.0.0

Render numeric line, point, vertical-bar, and horizontal-bar charts with a compact settings object.

Signature

Signature
plot(data: PlotCoordinates, settings?: Settings): string

Executable examples

Numeric plot

Source
plot([[0, 2], [1, 5], [2, 3], [3, 8]], {
  width: 30,
  height: 10,
  title: 'Requests',
  color: 'ansiCyan',
  interpolation: 'linear',
  xAxis: { ticks: 4, label: 'minute' },
  yAxis: { domain: [0, 10], label: 'requests' },
});
Terminal output

Requests                         
  ▲                               
  │                               
  │                               
r8┤                           ┏━━ 
e │                         ┏━┛   
q5┤         ┏┓            ┏━┛     
u │      ┏━━┛┗━━━━┓     ┏━┛       
e3┤  ┏━━━┛        ┗━━━━━┛         
s2┤━━┛                            
t │                               
s │                               
  └┬─────────┬────────┬─────────┬▶
   0         1        2         3 
               minute             

Settings

Complete configuration for numeric plot rendering.

type Settings = {
  /** Static series color configuration. */
  color?: Colors;
  /** Fixed plot width or `auto` for active terminal columns. Defaults to an input-derived width. */
  width?: ChartWidth;
  /** Plot height in terminal rows. Defaults to an input-derived height unless `aspectRatio` applies. */
  height?: number;
  /** Desired physical width-to-height ratio used when height is derived. */
  aspectRatio?: number;
  /** Explicit numeric Y extent as `[minimum, maximum]`. */
  yRange?: [number, number];
  /** Line behavior outside explicit domains. Defaults to `discard`. */
  overflow?: Overflow;
  /** Plot-cell backend. Defaults to `ascii`. */
  renderer?: Renderer;
  /** Reserves enough width for complete Y-axis tick labels. */
  showTickLabel?: boolean;
  /** Hides the X-axis line, ticks, labels, and axis label. */
  hideXAxis?: boolean;
  /** Hides X-axis tick markers and labels while retaining the axis line. */
  hideXAxisTicks?: boolean;
  /** Hides the Y-axis line, ticks, labels, and axis label. */
  hideYAxis?: boolean;
  /** Hides Y-axis tick markers and labels while retaining the axis line. */
  hideYAxisTicks?: boolean;
  /** Explicit finite X-axis tick values. */
  customXAxisTicks?: number[];
  /** Explicit finite Y-axis tick values. */
  customYAxisTicks?: number[];
  /** Title rendered above the chart. */
  title?: string;
  /** ANSI color applied to the title. */
  titleColor?: Color;
  /** X-axis label. */
  xLabel?: string;
  /** Y-axis label. */
  yLabel?: string;
  /** Numeric horizontal and/or vertical reference lines. */
  thresholds?: Threshold[];
  /** Point overlays rendered in data coordinates. */
  points?: GraphPoint[];
  /** Fills the region between line series and the X-axis baseline. */
  fillArea?: boolean;
  /** Legend placement, labels, and ANSI color. */
  legend?: Legend;
  /** Explicit X/Y axis intersection; `undefined` preserves an inferred coordinate. */
  axisCenter?: MaybePoint;
  /** Shared numeric axis-label formatter. Structured axis formatters take precedence. */
  formatter?: Formatter;
  /** Custom glyph callback for occupied series cells. */
  lineFormatter?: (args: LineFormatterArgs) => CustomSymbol | CustomSymbol[];
  /** Per-call glyph overrides. */
  symbols?: Symbols;
  /** ANSI color applied to the configured border glyph. */
  borderColor?: Color;
  /** ANSI color applied to background glyphs. */
  backgroundColor?: Color;
  /** Graph primitive. Defaults to `line`. */
  mode?: GraphMode;
  /** Line-segment interpolation. Defaults to `step`. */
  interpolation?: Interpolation;
  /** Shared or per-series dynamic color strategy. */
  coloring?: Coloring | readonly (Coloring | undefined)[];
  /** Multi-series bar arrangement. Defaults to `overlap`. */
  barLayout?: BarLayout;
  /** Enables bar endpoint labels or configures their text and color. */
  valueLabels?: ChartValueLabels;
  /** Logs out-of-bounds drawing attempts for diagnostics. */
  debugMode?: boolean;
  /** Structured X-axis fields; each supplied field overrides its flat alias. */
  xAxis?: XAxis;
  /** Structured Y-axis fields; each supplied field overrides its flat alias. */
  yAxis?: YAxis;
};

color

ColorsOptional

Static series color configuration.

Related executable examples: Numeric plot

width

ChartWidthOptional

Fixed plot width or auto for active terminal columns. Defaults to an input-derived width.

Related executable examples: Numeric plot

height

numberOptional

Plot height in terminal rows. Defaults to an input-derived height unless aspectRatio applies.

Related executable examples: Numeric plot

aspectRatio

numberOptional

Desired physical width-to-height ratio used when height is derived.

Related executable examples: Numeric plot

yRange

[number, number]Optional

Explicit numeric Y extent as [minimum, maximum].

Related executable examples: Numeric plot

overflow

OverflowOptional

Line behavior outside explicit domains. Defaults to discard.

Related executable examples: Numeric plot

renderer

RendererOptional

Plot-cell backend. Defaults to ascii.

Related executable examples: Numeric plot

showTickLabel

booleanOptional

Reserves enough width for complete Y-axis tick labels.

Related executable examples: Numeric plot

hideXAxis

booleanOptional

Hides the X-axis line, ticks, labels, and axis label.

Related executable examples: Numeric plot

hideXAxisTicks

booleanOptional

Hides X-axis tick markers and labels while retaining the axis line.

Related executable examples: Numeric plot

hideYAxis

booleanOptional

Hides the Y-axis line, ticks, labels, and axis label.

Related executable examples: Numeric plot

hideYAxisTicks

booleanOptional

Hides Y-axis tick markers and labels while retaining the axis line.

Related executable examples: Numeric plot

customXAxisTicks

number[]Optional

Explicit finite X-axis tick values.

Related executable examples: Numeric plot

customYAxisTicks

number[]Optional

Explicit finite Y-axis tick values.

Related executable examples: Numeric plot

title

stringOptional

Title rendered above the chart.

Related executable examples: Numeric plot

titleColor

ColorOptional

ANSI color applied to the title.

Related executable examples: Numeric plot

xLabel

stringOptional

X-axis label.

Related executable examples: Numeric plot

yLabel

stringOptional

Y-axis label.

Related executable examples: Numeric plot

thresholds

Threshold[]Optional

Numeric horizontal and/or vertical reference lines.

Related executable examples: Numeric plot

points

GraphPoint[]Optional

Point overlays rendered in data coordinates.

Related executable examples: Numeric plot

fillArea

booleanOptional

Fills the region between line series and the X-axis baseline.

Related executable examples: Numeric plot

legend

LegendOptional

Legend placement, labels, and ANSI color.

Related executable examples: Numeric plot

axisCenter

MaybePointOptional

Explicit X/Y axis intersection; undefined preserves an inferred coordinate.

Related executable examples: Numeric plot

formatter

FormatterOptional

Shared numeric axis-label formatter. Structured axis formatters take precedence.

Related executable examples: Numeric plot

lineFormatter

(args: LineFormatterArgs) => CustomSymbol | CustomSymbol[]Optional

Custom glyph callback for occupied series cells.

Related executable examples: Numeric plot

symbols

SymbolsOptional

Per-call glyph overrides.

Related executable examples: Numeric plot

borderColor

ColorOptional

ANSI color applied to the configured border glyph.

Related executable examples: Numeric plot

backgroundColor

ColorOptional

ANSI color applied to background glyphs.

Related executable examples: Numeric plot

mode

GraphModeOptional

Graph primitive. Defaults to line.

Related executable examples: Numeric plot

interpolation

InterpolationOptional

Line-segment interpolation. Defaults to step.

Related executable examples: Numeric plot

coloring

Coloring | readonly (Coloring | undefined)[]Optional

Shared or per-series dynamic color strategy.

Related executable examples: Numeric plot

barLayout

BarLayoutOptional

Multi-series bar arrangement. Defaults to overlap.

Related executable examples: Numeric plot

valueLabels

ChartValueLabelsOptional

Enables bar endpoint labels or configures their text and color.

Related executable examples: Numeric plot

debugMode

booleanOptional

Logs out-of-bounds drawing attempts for diagnostics.

Related executable examples: Numeric plot

xAxis

XAxisOptional

Structured X-axis fields; each supplied field overrides its flat alias.

Related executable examples: Numeric plot

yAxis

YAxisOptional

Structured Y-axis fields; each supplied field overrides its flat alias.

Related executable examples: Numeric plot

Legend

Legend placement, labels, and color for plot.

type Legend = {
  /** Placement relative to the plot. Defaults to `bottom`. */
  position?: LegendPosition;
  /** One series label or labels indexed by source series. */
  series?: string | string[];
  /** One point label or labels indexed by overlay point. */
  points?: string | string[];
  /** One threshold label or labels indexed by threshold. */
  thresholds?: string | string[];
  /** ANSI color applied to legend labels. */
  color?: Color;
};

position

LegendPositionOptional

Placement relative to the plot. Defaults to bottom.

Related executable examples: Numeric plot

series

string | string[]Optional

One series label or labels indexed by source series.

Related executable examples: Numeric plot

points

string | string[]Optional

One point label or labels indexed by overlay point.

Related executable examples: Numeric plot

thresholds

string | string[]Optional

One threshold label or labels indexed by threshold.

Related executable examples: Numeric plot

color

ColorOptional

ANSI color applied to legend labels.

Related executable examples: Numeric plot

Threshold

Numeric vertical and/or horizontal reference line.

type Threshold = {
  /** X coordinate for a vertical reference line. */
  x?: number;
  /** Y coordinate for a horizontal reference line. */
  y?: number;
  /** ANSI color applied to the reference line. */
  color?: Color;
};

x

numberOptional

X coordinate for a vertical reference line.

Related executable examples: Numeric plot

y

numberOptional

Y coordinate for a horizontal reference line.

Related executable examples: Numeric plot

color

ColorOptional

ANSI color applied to the reference line.

Related executable examples: Numeric plot

GraphPoint

Point overlay positioned in numeric data coordinates.

type GraphPoint = {
  /** Numeric X coordinate. */
  x: number;
  /** Numeric Y coordinate. */
  y: number;
  /** ANSI color applied to the point glyph. */
  color?: Color;
};

x

numberRequired

Numeric X coordinate.

Related executable examples: Numeric plot

y

numberRequired

Numeric Y coordinate.

Related executable examples: Numeric plot

color

ColorOptional

ANSI color applied to the point glyph.

Related executable examples: Numeric plot

XAxis

Structured X-axis configuration.

type XAxis = {
  /** Scale kind. Defaults to the kind inferred from X values. */
  scale?: XScale;
  /** Explicit category order or continuous scale extent. */
  domain?: XAxisDomain<X>;
  /** Exact native tick values or an exact tick count of at least two. */
  ticks?: number | readonly X[];
  /** Axis label rendered outside tick labels. */
  label?: string;
  /** Formatter called with native X values. */
  formatter?: AxisFormatter<X>;
  /** Hides the axis line, ticks, labels, and axis label. */
  hidden?: boolean;
  /** Hides tick markers and labels while retaining the axis line. */
  hideTicks?: boolean;
  /** Handling for labels that do not fit the available width. */
  labelCollision?: LabelCollisionPolicy;
  /** ANSI color applied to the axis line, ticks, tick labels, and label. */
  color?: Color;
};

scale

XScaleOptional

Scale kind. Defaults to the kind inferred from X values.

Related executable examples: Numeric plot

domain

XAxisDomain<X>Optional

Explicit category order or continuous scale extent.

Related executable examples: Numeric plot

ticks

number | readonly X[]Optional

Exact native tick values or an exact tick count of at least two.

Related executable examples: Numeric plot

label

stringOptional

Axis label rendered outside tick labels.

Related executable examples: Numeric plot

formatter

AxisFormatter<X>Optional

Formatter called with native X values.

Related executable examples: Numeric plot

hidden

booleanOptional

Hides the axis line, ticks, labels, and axis label.

Related executable examples: Numeric plot

hideTicks

booleanOptional

Hides tick markers and labels while retaining the axis line.

Related executable examples: Numeric plot

labelCollision

LabelCollisionPolicyOptional

Handling for labels that do not fit the available width.

Related executable examples: Numeric plot

color

ColorOptional

ANSI color applied to the axis line, ticks, tick labels, and label.

Related executable examples: Numeric plot

YAxis

Numeric Y-axis configuration.

type YAxis = {
  /** Explicit numeric extent as `[minimum, maximum]`. */
  domain?: readonly [number, number];
  /** Exact numeric tick values or an exact tick count of at least two. */
  ticks?: number | readonly number[];
  /** Axis label rendered outside tick labels. */
  label?: string;
  /** Formatter called for each numeric Y-axis tick. */
  formatter?: Formatter;
  /** Hides the axis line, ticks, labels, and axis label. */
  hidden?: boolean;
  /** Hides tick markers and labels while retaining the axis line. */
  hideTicks?: boolean;
  /** Reserves enough width for complete Y-axis tick labels. */
  showTickLabel?: boolean;
  /** ANSI color applied to the axis line, ticks, tick labels, and label. */
  color?: Color;
};

domain

readonly [number, number]Optional

Explicit numeric extent as [minimum, maximum].

Related executable examples: Numeric plot

ticks

number | readonly number[]Optional

Exact numeric tick values or an exact tick count of at least two.

Related executable examples: Numeric plot

label

stringOptional

Axis label rendered outside tick labels.

Related executable examples: Numeric plot

formatter

FormatterOptional

Formatter called for each numeric Y-axis tick.

Related executable examples: Numeric plot

hidden

booleanOptional

Hides the axis line, ticks, labels, and axis label.

Related executable examples: Numeric plot

hideTicks

booleanOptional

Hides tick markers and labels while retaining the axis line.

Related executable examples: Numeric plot

showTickLabel

booleanOptional

Reserves enough width for complete Y-axis tick labels.

Related executable examples: Numeric plot

color

ColorOptional

ANSI color applied to the axis line, ticks, tick labels, and label.

Related executable examples: Numeric plot

Coloring

Dynamic per-cell series-color strategy.

type Coloring = {
  /** Selects callback-based colors. */
  type: 'conditional';
  /** Returns a color or `undefined` to use the static series fallback. */
  getColor: (context: ColorContext) => Color | undefined;
} | {
  /** Selects equal-band palette coloring. */
  type: 'gradient';
  /** Data-space axis used to select a palette band. */
  by: 'x' | 'y';
  /** Nonempty ordered ANSI color palette. */
  colors: readonly Color[];
  /** Optional finite palette extent. Defaults to the resolved chart domain. */
  domain?: readonly [number, number];
};

type

'conditional' | 'gradient'Required

Selects callback-based colors.

Related executable examples: Numeric plot

getColor

(context: ColorContext) => Color | undefinedRequired

Returns a color or undefined to use the static series fallback.

Related executable examples: Numeric plot

by

'x' | 'y'Required

Data-space axis used to select a palette band.

Related executable examples: Numeric plot

colors

readonly Color[]Required

Nonempty ordered ANSI color palette.

Related executable examples: Numeric plot

domain

readonly [number, number]Optional

Optional finite palette extent. Defaults to the resolved chart domain.

Related executable examples: Numeric plot

ChartValueLabels

Enables bar endpoint labels or configures their text and ANSI color.

type ChartValueLabels = boolean | {
  /** Formats the rendered value; normalized layouts receive a percentage. */
  formatter?: ValueLabelFormatter<X>;
  /** ANSI color applied to every value label. */
  color?: Color;
};

formatter

ValueLabelFormatter<X>Optional

Formats the rendered value; normalized layouts receive a percentage.

Related executable examples: Numeric plot

color

ColorOptional

ANSI color applied to every value label.

Related executable examples: Numeric plot