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) | undefinedapplyStroke
Sets stroke color, width and dash on a context.
function applyStroke(ctx: CanvasRenderingContext2D, { color, width, dash }: StrokeStyle): voidclamp
Limits a value to [min, max].
function clamp(value: number, min: number, max: number): numbercomputeTimeTicks
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): Themecrisp
Aligns a coordinate to the pixel grid so 1px lines are crisp.
function crisp(v: number, width?: number): numberdashArray
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): numberdrawLabel
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): stringformatCompact
Compact number formatting, e.g. 1.25M, used for volume.
function formatCompact(value: number): stringformatNumber
Formats a number with a fixed number of decimals and thousands separators.
function formatNumber(value: number, decimals?: number): stringformatPercent
Signed percentage, e.g. "+1.25%".
function formatPercent(value: number, decimals?: number): stringformatPrice
Price formatting with automatic precision: more decimals for small prices.
function formatPrice(value: number, decimals?: number): stringfunctor
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): voidisFiniteNumber
True for numbers that are not NaN or ±Infinity (type guard).
function isFiniteNumber(v: unknown): v is numberlowerBound
First index whose value is >= target (values must be ascending).
function lowerBound(values: ArrayLike<number>, target: number, lo?: number, hi?: number): numbernearestIndex
Index of the value closest to target (values must be ascending, non-empty).
function nearestIndex(values: ArrayLike<number>, target: number): numberniceStep
The "nice" step (1, 2, 2.5, 5 × 10^n) nearest to span / count.
function niceStep(span: number, count: number): numberniceTicks
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): ThemeshallowEqual
Shallow equality of two values or plain objects (for useChartState selectors).
function shallowEqual(a: any, b: any): booleanupperBound
First index whose value is > target (values must be ascending).
function upperBound(values: ArrayLike<number>, target: number, lo?: number, hi?: number): numberverticalLine
Strokes a crisp vertical line at x from y1 to y2.
function verticalLine(ctx: CanvasRenderingContext2D, x: number, y1: number, y2: number): voidwithAlpha
Returns a color with the given alpha. Accepts #rgb, #rrggbb and rgb()/rgba().
function withAlpha(color: string, alpha: number): string