/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * A chart row's geometry as numbers (#743) — the columns' stacked extents, * the value domain each axis side spans, the points a continuous series * draws, and each layer's value per bucket. The marks, the gutter ticks and * the crosshair readout all read it, so an axis can never label a scale the * marks do not use. * * Everything here is in DATA units and window FRACTIONS — the row maps them * into its viewBox. Positions are the scale's UNCLAMPED `fracOf`: clamping a * vertex to the window edge moves the data (a line then meets the edge at the * wrong value), where clipping the drawn segment does not. * * A point whose `y` is not finite (`NaN`) is a GAP: lines and areas break * there instead of interpolating across it, and it counts toward no domain. * * @packageDocumentation */ import { scaleLinear } from "@visx/scale"; import type { ValueTypeOf } from "@elaraai/east"; import { Plan } from "@elaraai/e3-ui/internal"; import type { PlanInstantValue } from "../instant.js"; import type { PlanScale } from "../scale.js"; import type { PlanWords } from "../words.js"; /** A decoded chart row kind. */ export type ChartKindValue = Extract["kind"], { type: "chart"; }>["value"]; /** A decoded chart layer. */ export type ChartLayerValue = ValueTypeOf; /** A decoded `{t, y}` chart point. */ export type ChartPointValue = ValueTypeOf; /** A decoded `{t, lo, hi}` band point — the band arm's own point type. */ export type ChartBandPointValue = Extract["value"]["points"][number]; /** A decoded value-axis declaration. */ export type ChartAxisValue = ValueTypeOf; /** A decoded breach threshold. */ export type PlanBreachValue = ValueTypeOf; /** Which value axis a layer scales against. */ export type ChartSide = ValueTypeOf["type"]; /** A value axis's scale — data value → plot px. */ export type ValueScale = ReturnType>; /** Px of air above and below the marks. */ export declare const PAD_Y = 4; /** * Whether a value breaches a layer's threshold. The layer's own decoded * variant is read as it is — never rebuilt (#743 item 6). * * @param v - The value * @param breach - The layer's threshold, when it declares one * @returns `true` beyond the threshold; `false` for a gap */ export declare function breached(v: number, breach: PlanBreachValue | undefined): boolean; /** One drawn column, in data units and window fractions. */ export interface ColumnGeometry { /** Left / right edges as window fractions (inset within the bucket). */ x0: number; x1: number; /** The span it covers on its axis — `lo` ≤ `hi`; a stack's part sits on the parts before it. */ lo: number; hi: number; /** The column's own value. */ value: number; side: ChartSide; /** Beyond its layer's breach threshold. */ warn: boolean; /** At or after the now instant — a column that starts at now is the * period in progress, drawn to the right of the now line (#949). */ planned: boolean; /** Its stack series' first-appearance index (0 for an unstacked column). */ seriesIndex: number; } /** The chart's column geometry: what is drawn, and every column's extent. */ export interface ColumnLayout { /** The columns inside the render bounds, in layer then point order. */ drawn: ColumnGeometry[]; /** Every column's span per side — drawn or not — for the value domain. */ extents: { left: number[]; right: number[]; }; } /** * Lay out a chart's columns. * * @remarks * A column with a `series` stacks on its SIDE's stack at its bucket; one * without starts at the baseline. Stacks are kept per value-axis side, so a * left-axis column never becomes the base of a right-axis one (#743 item 4), * and per sign, so positive parts climb from 0 and negative parts descend from * it. A column outside the render bounds is not drawn, but it still stacks — * by its period — so the domain it contributes is the same wherever the * window sits. A gap draws nothing. * * @param layers - The chart's layers * @param scale - The shared scale * @returns The drawn columns and every column's extent */ export declare function layoutColumns(layers: readonly ChartLayerValue[], scale: PlanScale): ColumnLayout; /** A value axis's extent. */ export interface ValueDomain { min: number; max: number; } /** * The explicit tick positions of an axis (its `ChartTickValuesType` number arm). * * @param axis - The axis declaration * @returns The positions; empty when none are declared */ export declare function axisTicks(axis: ChartAxisValue | undefined): readonly number[]; /** * The domain each value axis spans. * * @remarks * Derived from the geometry the row draws: line and scatter values; an area's * values AND its baseline (0); a band's bounds; reference lines and dots; and * each column's span — its baseline and, stacked, its stack's ends (#743 item * 2). Explicit tick positions are inside it too. A declared domain wins over * the derived one. No data spans `[0, 1]`, and an empty span opens to one * unit. * * @param kind - The chart row * @param columns - Its column layout ({@link layoutColumns}) * @returns The left and right domains */ export declare function chartDomains(kind: ChartKindValue, columns: ColumnLayout): { left: ValueDomain; right: ValueDomain; }; /** * A value axis's scale over a plot `height` px tall — `min` at the bottom and * `max` at the top, inside {@link PAD_Y} of air. * * @param domain - The axis's domain * @param height - The plot's height (px) * @returns The scale */ export declare function valueScale(domain: ValueDomain, height: number): ValueScale; /** A point of a continuous series, at its unclamped window fraction. */ export interface Placed

{ p: P; /** The point's window fraction — below 0 before the window, above 1 past it. */ f: number; } /** * The points of a continuous series (line / area / band) the row draws, at * their TRUE fractions (#743 item 3). * * @remarks * A point is kept when it lies inside the render bounds or when its segment to * either neighbour reaches them — the segment that crosses a window edge then * keeps its real slope, and the plot clips it. A point is dropped only when * both its segments lie wholly to one side, which puts its neighbours on that * side too, so the segment now joining them is never drawn in view either. A * point the axis cannot place (`NaN` fraction) is kept as a gap. * * @param points - The series' points, in draw order * @param scale - The shared scale * @returns The points worth drawing, placed */ export declare function drawnPoints

(points: readonly P[], scale: PlanScale): Placed

[]; /** * Split a line's placed points at the now instant — solid up to it, dashed * after, the dashed run starting from the last observed point so the two * meet. * * @param placed - The line's drawn points * @param nowFrac - The now instant's fraction, when it is in the window * @returns The observed and planned runs */ export declare function splitAtNow

(placed: readonly Placed

[], nowFrac: number | undefined): { before: Placed

[]; after: Placed

[]; }; /** * A value axis's tick formatter — the declared `Chart.format.*` spec through * the shared chart-axis `tickFormatter` (#190); an undeclared axis keeps the * terse bare-number default of the spec ruler (the shared module's `tick` * arm, #850): a whole number, else one decimal, never grouped. Both speak the * canvas's locale (#820) — `2.5` is `2,5` in `de-DE`. * * @param axis - The axis declaration * @param locale - The BCP 47 locale the numbers format in * @returns The formatter */ export declare function axisFormatter(axis: ChartAxisValue | undefined, locale: string): (v: number) => string; /** A layer the crosshair reads a value from. */ export interface ReadoutLayer { /** Its index in `kind.layers`. */ index: number; kind: "line" | "area" | "column" | "scatter" | "band"; } /** * The layers with a value to read at a bucket — every data layer; reference * marks are not measures. * * @param kind - The chart row * @returns The layers, in layer order */ export declare function readoutLayers(kind: ChartKindValue): ReadoutLayer[]; /** * Each readout layer's value at each bucket, formatted by its axis — the * crosshair's text (#743). A layer's value at a bucket is its LAST value in * the bucket (a band's `lo–hi`) — a gap is no value; a layer with none there * reads `—`. Buckets where no layer has a value are absent. * * @param kind - The chart row * @param scale - The shared scale * @param w - The canvas's words — the locale values format in, and a band's range (#820) * @returns Bucket index → one text per {@link readoutLayers} entry */ export declare function readoutTable(kind: ChartKindValue, scale: PlanScale, w: PlanWords): Map; //# sourceMappingURL=chart-geometry.d.ts.map