plot — 5.4.0

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

Signature

Signature
plot(coordinates: Coordinates, settings?: Settings): string

Executable examples

Source
plot([[0, 2], [1, 5], [2, 3], [3, 8]], {
  width: 30,
  height: 10,
  title: 'Requests',
  color: 'ansiCyan',
  xLabel: 'minute',
  yLabel: 'requests',
});
Terminal output

Requests                         
  ▲                               
 8┤                            ┏━ 
  │                            ┃  
r │                            ┃  
e │                            ┃  
q5┤         ┏━━━━━━━━┓         ┃  
u │         ┃        ┃         ┃  
e │         ┃        ┃         ┃  
s3┤         ┃        ┗━━━━━━━━━┛  
t │         ┃                     
s2┤━━━━━━━━━┛                     
  └┬─────────┬────────┬─────────┬▶
   0         1        2         3 
               minute             

Settings

Configuration accepted by plot in version 5.4.0.

type Settings = {
  /** Static or callback-based series colors. */
  color?: Colors;
  /** Plot width in terminal columns. */
  width?: number;
  /** Plot height in terminal rows. */
  height?: number;
  /** Explicit Y-axis range as `[minimum, maximum]`. */
  yRange?: [number, number];
  /** Reserves enough space for complete Y-axis tick labels. */
  showTickLabel?: boolean;
  /** Hides the X-axis line. */
  hideXAxis?: boolean;
  /** Hides X-axis tick markers and labels. */
  hideXAxisTicks?: boolean;
  /** Hides the Y-axis line. */
  hideYAxis?: boolean;
  /** Hides Y-axis tick markers and labels. */
  hideYAxisTicks?: boolean;
  /** Explicit numeric X-axis tick values. */
  customXAxisTicks?: number[];
  /** Explicit numeric Y-axis tick values. */
  customYAxisTicks?: number[];
  /** Chart title rendered above the plot. */
  title?: string;
  /** X-axis label. */
  xLabel?: string;
  /** Y-axis label. */
  yLabel?: string;
  /** Numeric reference lines. */
  thresholds?: Threshold[];
  /** Point overlays. */
  points?: GraphPoint[];
  /** Fills the area between line series and the X-axis baseline. */
  fillArea?: boolean;
  /** Legend placement and labels. */
  legend?: Legend;
  /** Explicit X-axis and Y-axis intersection. */
  axisCenter?: MaybePoint;
  /** Shared numeric axis-label formatter. */
  formatter?: Formatter;
  /** Custom renderer function for occupied series cells. */
  lineFormatter?: (args: LineFormatterArgs) => CustomSymbol | CustomSymbol[];
  /** Per-call symbol overrides. */
  symbols?: Symbols;
  /** Graph primitive. Defaults to `line`. */
  mode?: GraphMode;
  /** Logs out-of-bounds drawing attempts. */
  debugMode?: boolean;
};

color

ColorsOptional

Static or callback-based series colors.

Related executable examples:

width

numberOptional

Plot width in terminal columns.

Related executable examples:

height

numberOptional

Plot height in terminal rows.

Related executable examples:

yRange

[number, number]Optional

Explicit Y-axis range as [minimum, maximum].

Related executable examples:

showTickLabel

booleanOptional

Reserves enough space for complete Y-axis tick labels.

Related executable examples:

hideXAxis

booleanOptional

Hides the X-axis line.

Related executable examples:

hideXAxisTicks

booleanOptional

Hides X-axis tick markers and labels.

Related executable examples:

hideYAxis

booleanOptional

Hides the Y-axis line.

Related executable examples:

hideYAxisTicks

booleanOptional

Hides Y-axis tick markers and labels.

Related executable examples:

customXAxisTicks

number[]Optional

Explicit numeric X-axis tick values.

Related executable examples:

customYAxisTicks

number[]Optional

Explicit numeric Y-axis tick values.

Related executable examples:

title

stringOptional

Chart title rendered above the plot.

Related executable examples:

xLabel

stringOptional

X-axis label.

Related executable examples:

yLabel

stringOptional

Y-axis label.

Related executable examples:

thresholds

Threshold[]Optional

Numeric reference lines.

Related executable examples:

points

GraphPoint[]Optional

Point overlays.

Related executable examples:

fillArea

booleanOptional

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

Related executable examples:

legend

LegendOptional

Legend placement and labels.

Related executable examples:

axisCenter

MaybePointOptional

Explicit X-axis and Y-axis intersection.

Related executable examples:

formatter

FormatterOptional

Shared numeric axis-label formatter.

Related executable examples:

lineFormatter

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

Custom renderer function for occupied series cells.

Related executable examples:

symbols

SymbolsOptional

Per-call symbol overrides.

Related executable examples:

mode

GraphModeOptional

Graph primitive. Defaults to line.

Related executable examples:

debugMode

booleanOptional

Logs out-of-bounds drawing attempts.

Related executable examples:

Legend

Legend configuration.

type Legend = {
  /** Legend position. */
  position?: "left" | "right" | "top" | "bottom";
  /** Series label or labels. */
  series?: string | string[];
  /** Point label or labels. */
  points?: string | string[];
  /** Threshold label or labels. */
  thresholds?: string | string[];
};

position

"left" | "right" | "top" | "bottom"Optional

Legend position.

Related executable examples:

series

string | string[]Optional

Series label or labels.

Related executable examples:

points

string | string[]Optional

Point label or labels.

Related executable examples:

thresholds

string | string[]Optional

Threshold label or labels.

Related executable examples:

Threshold

Numeric X-axis or Y-axis threshold.

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

x

numberOptional

X coordinate for a vertical threshold.

Related executable examples:

y

numberOptional

Y coordinate for a horizontal threshold.

Related executable examples:

color

ColorOptional

ANSI threshold color.

Related executable examples:

GraphPoint

Numeric point overlay.

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

x

numberRequired

X coordinate.

Related executable examples:

y

numberRequired

Y coordinate.

Related executable examples:

color

ColorOptional

ANSI point color.

Related executable examples: