/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The Plan's one shared scale (`Plan Spec.md` §3): pure arithmetic over the * axis's own numeric domain, with no DOM, testable in isolation. * * A scale is built from ONE of the three axis kinds (#631): * * - `time`: a half-open UTC window `[min, max)` divided by a calendar * resolution (d3-time intervals; ISO weeks, Monday-start); * - `number`: a half-open numeric window `[min, max)` divided by a `step`, * bucket edges on whole multiples of the step; * - `ordinal`: the declared values, one bucket each, in order. * * The engine that cuts a domain into buckets, and the time arm, are the time * parts the Plan shares with the Calendar (`../shared/time/scale.ts`, #1148); * this module adds the number and ordinal arms and the Plan's instants. Every * kind is the same thing to the engine, a numeric domain (epoch ms, the value, * the ordinal INDEX) with a period function over it, which is what keeps the * eight row renderers kind-agnostic: they consume fractions and bucket * indices, and only ever hand the scale an instant. * * Every row receives it through `PlanScaleContext` and positions against it. * An instant of ANOTHER arm than the scale's positions nowhere (`NaN` / `-1` * / `undefined`); the canvas diagnoses the mismatch by row * (`model.axisKindMismatches`) instead of misplacing anything. * * On an ordinal scale an interval's END names its LAST bucket (inclusive): * values are buckets, not edges, so `[PLATES, FINISH]` covers PLATES, PRINT * and FINISH, and `endFracOf` is the far edge of the named bucket. On the * other two kinds intervals stay half-open, and `endFracOf` is `fracOf`. * * @packageDocumentation */ import { type TickFormat } from "@elaraai/east-ui-components/internal"; import { type Scale, type ScaleBucket, type TimeResolution, type TimeWindow } from "../shared/time/scale.js"; import { type PlanAxisKind, type PlanInstantValue } from "./instant.js"; import { type PlanWords } from "./words.js"; /** A concrete bucket resolution: the IR `TimeResolutionType` with `auto` resolved away. */ export type PlanResolution = TimeResolution; /** A half-open time window `[min, max)`. */ export type PlanWindow = TimeWindow; /** * Resolve the declared resolution (`auto` → window-derived): ≤ 14 days ⇒ * `day`, ≤ ~40 weeks ⇒ `week` (the Plan's home unit), else `month`. * * @param declared - The IR resolution tag (may be `"auto"` or undefined) * @param window - The resolved window the buckets span * @returns The concrete resolution */ export declare function effectiveResolution(declared: string | undefined, window: PlanWindow): PlanResolution; /** One bucket of the scale. */ export type PlanBucket = ScaleBucket; /** * What a scale is built from: the decoded axis arm plus the resolved window * (slice range ▸ declared), as plain values. * * Every arm takes the canvas's `words` (#820): the locale its ruler labels and * its words for a reader format in ({@link PLAN_WORDS} when omitted). * * @property time - A UTC window divided by a calendar resolution; `format` a date-token pattern * @property number - A numeric window divided by `step`; `format` the shared value format (`Chart.format.*`) * @property ordinal - The declared values, one bucket each */ export type PlanScaleSpec = { kind: "time"; window: PlanWindow; resolution: PlanResolution; now?: Date | undefined; format?: string | undefined; words?: PlanWords | undefined; } | { kind: "number"; window: { min: number; max: number; }; step: number; now?: number | undefined; format?: TickFormat | undefined; words?: PlanWords | undefined; } | { kind: "ordinal"; values: readonly string[]; now?: string | undefined; words?: PlanWords | undefined; }; /** * The one shared scale every row positions against: the window, the buckets, * and the continuous and quantised mappings, over the Plan's instants * (`{ time | number | ordinal }`). One of another arm positions nowhere. */ export type PlanScale = Scale; /** * Build the shared scale for an axis spec. * * The window widens OUTWARD to whole periods (#949): a 12-week window at MONTH * resolution draws whole months (June to September); an aligned window is * unchanged, so a 12-week window at WEEK resolution is exactly 12 equal * columns, and a `[1, 9)` number window at step 1 eight columns labelled `1` … * `8`. An ordinal scale is its list: one bucket per value, labelled by it. * * @param spec - The axis kind with its resolved window / period / values * @returns The scale, or `undefined` for an empty or inverted window, a * non-positive step or an empty list */ export declare function planScale(spec: PlanScaleSpec): PlanScale | undefined; //# sourceMappingURL=scale.d.ts.map