/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Temporal fold (#824) — what a row shows in a bucket that holds more than * one of its cells or points: ONE, their declared `fold`. * * Cells and chart points sit at their own instants; the scale's resolution * decides the buckets. Where a bucket is coarser than the data — weekly cells * on a MONTH axis — it shows one element whose value is its members' fold * (`sum` / `mean` / `min` / `max` / `last` / `count`), never the members piled * into one column. Every kind that places values by bucket folds alike: heat, * weight and segment cells, table numerals, and a chart's line, area and * column layers (scatter and band layers draw every point). * * A fold keeps what it does not change. A bucket with ONE member keeps that * member as it is — its own instant, label and text — unless the fold is * `count`, which always counts; so at the data's own resolution nothing moves, * and a list whose buckets each hold one member comes back as the very same * array (a row memo keyed on it skips). A bucket with several members sits at * the period's start, or at their shared instant when they share one. * * @packageDocumentation */ import { type ValueTypeOf } from "@elaraai/east"; import { Plan } from "@elaraai/e3-ui/internal"; import { type PlanInstantValue } from "./instant.js"; import type { PlanWords } from "./words.js"; /** A fold, as its tag — `PlanFoldType` (derived from the East type, never mirrored). */ export type PlanFold = ValueTypeOf["type"]; type HeatCellsValue = ValueTypeOf; type HeatCellValue = ValueTypeOf; type WeightCellValue = ValueTypeOf; type SegmentCellValue = ValueTypeOf; type TableCellValue = ValueTypeOf; type TableSeriesValue = ValueTypeOf; type ChartLayerValue = ValueTypeOf; type ChartPointValue = ValueTypeOf; /** * The period a canvas buckets by — what a fold groups instants by. The scale * owns it (`PlanScale.period`): one object per key, so a memo can depend on * it and re-fold only when the resolution changes, not on every pan. */ export interface PlanPeriod { /** Names the period: two periods with one key floor every instant alike. */ readonly key: string; /** The start of the period holding an instant — the instant itself when * it rides another arm than the axis's. */ floor(t: PlanInstantValue): PlanInstantValue; } /** * Fold a bucket's numbers. * * @param values - The members' values, in axis order (`last` reads the final one) * @param fold - The fold * @returns The folded value — `count` counts (0 for none); every other fold is * `undefined` for no values */ export declare function foldNumbers(values: readonly number[], fold: PlanFold): number | undefined; /** One bucket's members. */ export interface BucketGroup { /** Where the bucket's folded element sits — the members' own instant when * they share one, else the period's start. */ at: PlanInstantValue; /** The members, in axis order (members at one instant keep their order). */ members: C[]; } /** * Group elements by the period that holds each — by the instant itself * without a period — buckets and members in axis order. * * @remarks * Instants with a comparable order sort; an ordinal set without its index map * (the ledger's height measure) keeps insertion order, which is all a height * needs. * * @param items - The elements * @param atOf - An element's instant * @param period - The canvas's period, when a scale is known * @param ordinal - The ordinal axis's value → index map, when the axis is ordinal * @returns One group per bucket */ export declare function bucketGroups(items: readonly C[], atOf: (c: C) => PlanInstantValue, period: PlanPeriod | undefined, ordinal?: ReadonlyMap): BucketGroup[]; /** * Fold a heat arm's cells. * * @remarks * A folded cell prints a label only where its members did — a row painted by * depth alone stays that way — and then its value through the arm's `format` * (a `count`, as a plain number). A cell with no value in any member is no * data, except under `count`, which counts 0. * * @param cells - The cells * @param fold - The arm's fold * @param period - The canvas's period * @param ordinal - The ordinal axis's value → index map, when the axis is ordinal * @param print - How a folded value prints * @returns The folded cells — `cells` itself when nothing folds */ export declare function foldHeatCells(cells: HeatCellValue[], fold: PlanFold, period: PlanPeriod | undefined, ordinal: ReadonlyMap | undefined, print: (v: number) => string): HeatCellValue[]; /** * Fold a weight arm's cells — each bucket's booked fraction folded, and pale * (planned) only when every member is. * * @param cells - The cells * @param fold - The arm's fold * @param period - The canvas's period * @param ordinal - The ordinal axis's value → index map, when the axis is ordinal * @returns The folded cells — `cells` itself when nothing folds */ export declare function foldWeightCells(cells: WeightCellValue[], fold: PlanFold, period: PlanPeriod | undefined, ordinal: ReadonlyMap | undefined): WeightCellValue[]; /** * Fold a segment arm's cells — each fill's weights folded across the members * (a member without the fill weighs 0 there; `count` counts the members that * carry it), the fills in the order they first appear. A folded segment * carries no in-bar label: a label described one cell. * * @param cells - The cells * @param fold - The arm's fold * @param period - The canvas's period * @param ordinal - The ordinal axis's value → index map, when the axis is ordinal * @returns The folded cells — `cells` itself when nothing folds */ export declare function foldSegmentCells(cells: SegmentCellValue[], fold: PlanFold, period: PlanPeriod | undefined, ordinal: ReadonlyMap | undefined): SegmentCellValue[]; /** * Fold any heat-kind arm — heat, weight or segments — by its own fold. * * @param arm - The arm * @param period - The canvas's period * @param ordinal - The ordinal axis's value → index map, when the axis is ordinal * @param w - The canvas's words — a folded heat label prints through the arm's `format` * @returns The folded arm — `arm` itself when nothing folds */ export declare function foldHeatArm(arm: HeatCellsValue, period: PlanPeriod | undefined, ordinal: ReadonlyMap | undefined, w: PlanWords): HeatCellsValue; /** * Fold table cells — a bucket's values folded; a folded cell carries no text * or tone override (the renderer prints and tones its value, as it does any * cell's). * * @param cells - The cells * @param fold - The series' fold * @param period - The canvas's period * @param ordinal - The ordinal axis's value → index map, when the axis is ordinal * @returns The folded cells — `cells` itself when nothing folds */ export declare function foldTableCells(cells: TableCellValue[], fold: PlanFold, period: PlanPeriod | undefined, ordinal: ReadonlyMap | undefined): TableCellValue[]; /** * Fold a table row's value series, each by its own fold. * * @param series - The series * @param period - The canvas's period * @param ordinal - The ordinal axis's value → index map, when the axis is ordinal * @returns The folded series — `series` itself when nothing folds */ export declare function foldTableSeries(series: TableSeriesValue[], period: PlanPeriod | undefined, ordinal: ReadonlyMap | undefined): TableSeriesValue[]; /** * Fold a chart layer's points — a bucket's finite values folded (a gap, a * non-finite `y`, is no value; a bucket of gaps stays one). * * @param points - The points * @param fold - The layer's fold * @param period - The canvas's period * @param ordinal - The ordinal axis's value → index map, when the axis is ordinal * @returns The folded points — `points` itself when nothing folds */ export declare function foldChartPoints(points: ChartPointValue[], fold: PlanFold, period: PlanPeriod | undefined, ordinal: ReadonlyMap | undefined): ChartPointValue[]; /** * Fold a chart row's layers — its line, area and column layers each by its * own fold; scatter, band and reference layers as they are. * * @param layers - The layers * @param period - The canvas's period * @param ordinal - The ordinal axis's value → index map, when the axis is ordinal * @returns The folded layers — `layers` itself when nothing folds */ export declare function foldChartLayers(layers: ChartLayerValue[], period: PlanPeriod | undefined, ordinal: ReadonlyMap | undefined): ChartLayerValue[]; export {}; //# sourceMappingURL=fold.d.ts.map