Functions

Functions exported by @reincharts/core.

import { accessor, applyStroke, clamp, ... } from "@reincharts/core";

accessor

Turns an Accessor into a function.

function accessor<T, R = number>(a: Accessor<T, R>): (d: T, index: number) => R
function accessor<T, R = number>(
    a: Accessor<T, R> | undefined,
): ((d: T, index: number) => R) | undefined

applyStroke

Sets stroke color, width and dash on a context.

function applyStroke(ctx: CanvasRenderingContext2D, { color, width, dash }: StrokeStyle): void

clamp

Limits a value to [min, max].

function clamp(value: number, min: number, max: number): number

computeTimeTicks

Picks time axis ticks among visible bars: most significant boundaries first, skipping any that would sit closer than minSpacing pixels to an accepted tick.

function computeTimeTicks(
    times: ArrayLike<number>,
    start: number,
    end: number,
    x: (index: number) => number,
    formatter: TimeFormatter,
    minSpacing: number,
): TimeTick[]

contrastText

Picks black or white text for a given background color.

function contrastText(background: string): "#131722" | "#ffffff"

createTheme

Creates a theme by deep-merging overrides into a base theme (defaults to lightTheme).

function createTheme(overrides?: DeepPartial<Theme>, base?: Theme): Theme

crisp

Aligns a coordinate to the pixel grid so 1px lines are crisp.

function crisp(v: number, width?: number): number

dashArray

Canvas dash pattern for a LineDash style at a line width.

function dashArray(dash: LineDash | undefined, width?: number): number[]

decimalsFor

Number of decimals needed to display a step without losing precision.

function decimalsFor(step: number): number

drawLabel

Draws a text label inside a filled rounded box; returns the box rect.

function drawLabel(
    ctx: CanvasRenderingContext2D,
    o: LabelOptions,
): { left: number; top: number; width: number; height: number; }

font

CSS font string from the theme (size and weight optional).

function font(theme: Theme, size?: number, weight?: string): string

formatCompact

Compact number formatting, e.g. 1.25M, used for volume.

function formatCompact(value: number): string

formatNumber

Formats a number with a fixed number of decimals and thousands separators.

function formatNumber(value: number, decimals?: number): string

formatPercent

Signed percentage, e.g. "+1.25%".

function formatPercent(value: number, decimals?: number): string

formatPrice

Price formatting with automatic precision: more decimals for small prices.

function formatPrice(value: number, decimals?: number): string

functor

Turns a Functor (a static value or a function of the datum) into a function.

function functor<T, R>(v: Functor<T, R>): ((d: T, index: number) => R)

horizontalLine

Strokes a crisp horizontal line at y from x1 to x2.

function horizontalLine(ctx: CanvasRenderingContext2D, y: number, x1: number, x2: number): void

isFiniteNumber

True for numbers that are not NaN or ±Infinity (type guard).

function isFiniteNumber(v: unknown): v is number

lowerBound

First index whose value is >= target (values must be ascending).

function lowerBound(values: ArrayLike<number>, target: number, lo?: number, hi?: number): number

nearestIndex

Index of the value closest to target (values must be ascending, non-empty).

function nearestIndex(values: ArrayLike<number>, target: number): number

niceStep

The "nice" step (1, 2, 2.5, 5 × 10^n) nearest to span / count.

function niceStep(span: number, count: number): number

niceTicks

Evenly spaced nice ticks covering [min, max].

function niceTicks(min: number, max: number, count: number): number[]

resolveTheme

Resolves the theme prop: a preset name, a full theme, or partial overrides of the light theme.

function resolveTheme(theme: "light" | "dark" | Theme | DeepPartial<Theme> | undefined): Theme

shallowEqual

Shallow equality of two values or plain objects (for useChartState selectors).

function shallowEqual(a: any, b: any): boolean

upperBound

First index whose value is > target (values must be ascending).

function upperBound(values: ArrayLike<number>, target: number, lo?: number, hi?: number): number

verticalLine

Strokes a crisp vertical line at x from y1 to y2.

function verticalLine(ctx: CanvasRenderingContext2D, x: number, y1: number, y2: number): void

withAlpha

Returns a color with the given alpha. Accepts #rgb, #rrggbb and rgb()/rgba().

function withAlpha(color: string, alpha: number): string

On this page