import { d as ChartEncoding, g as ChartTemplateDef, P as PivotDef } from './types-DHaPWLqG.js'; /** * Chart pivot — a derived Category-B operator that re-routes encoding *fields* * across position/legend/facet *channels* to surface alternative views of the * same semantic spec (orientation swap, series↔axis role swap, facet split). * * The host stores the chosen pivot *state id* as a single override keyed by * `PivotDef.key` (default `'pivot'`) inside `chart_spec.chartProperties`, exactly * like any other encoding action. The compiler — not the host — owns the channel * permutation: at assemble time it enumerates the valid states for the current * encodings + data, picks the stored id (falling back to the identity state when * the id is stale or absent), and composes the resulting encoding map BEFORE the * rest of the pipeline runs (so sort/overflow/layout all resolve post-pivot). * * This module is intentionally backend-agnostic: it operates purely on the * abstract `ChartEncoding` map + the raw data table, so the same enumeration * drives Vega-Lite, ECharts and Chart.js. * * MVP linearization. The full design models the pivot states as the orbit of a * channel-permutation group, linearized by a Gray code so adjacent steps differ * by one generator. This first increment exposes a curated *star* of single- * generator views around the authored identity (identity → orientation → role → * facet), which is a valid finite cycle (Z/n over the ordered list) that always * returns to the authored view. Richer products land later. * * Role-swap has two type-preserving flavors: discrete↔color-hue (a category * moves between a banded axis and the legend — bars/lines) and, on position * marks only, measure↔(color-gradient | size) (a quantitative field moves * between a precise position axis and a demoted auxiliary channel — scatter). * * Two distinct group actions drive the channel moves, matching the design doc: * - τ (transpose): flip two axis *slots* wholesale (`x↔y` orientation). Profile- * agnostic, always occupancy-preserving — declared via `PivotDef.transpose`. * - σ (permute): reassign a *field* to a same-profile channel (axis ↔ color/size) * — declared via `PivotDef.permute`, admitted by the Young-block profile rule. * Keeping them separate is what lets the must-present guard drop out entirely. */ /** Resolved pivot surface attached to the assembled spec as `_pivot`. */ interface PivotSurface { key: string; label: string; /** Number of states in the cycle (>= 2 when a control should show). */ length: number; /** Index of the active state within `ids`. */ index: number; /** Ordered state ids; `ids[0]` is always the identity (authored) view. */ ids: string[]; /** Parallel human labels for each state. */ labels: string[]; } /** A redundant identity encoding added by a local Arrange operator. */ interface EncodingAugmentation { kind: 'facet-identity'; sourceChannel: 'color' | 'group'; facetChannel: 'column' | 'row'; colorEncoding: ChartEncoding; } /** Internal: a fully enumerated pivot for a given encoding map + data. */ interface PivotComputation { key: string; label: string; ids: string[]; labels: string[]; statesById: Record>; augmentationById: Record; /** * Chart-type override per state id, set only for chart-type *transition* * states (§4.6). Absent/undefined entries render with the authored template. */ chartTypeById: Record; } /** Build the standard cartesian pivot declaration from its permissible domains. */ declare function makeCartesianPivot(opts?: Partial): PivotDef; /** * Enumerate the pivot states for an encoding map + data under a template's * `PivotDef` by walking the *orbit* of the generators at runtime: start from the * authored identity and repeatedly apply one more δ (breadth-first), deduping by * {@link encodingKey} (the stabilizer quotient) and rejecting non-renderable * states (see {@link isRenderableState}). State ids are operator *paths* (e.g. * `orient|series:row`, `type:Strip Plot`); labels compose the per-step operator * notation with `·`. Returns `null` when no template pivot is declared. The * identity (authored) view is always state 0; a control should only render when * `ids.length > 1`. * * `resolveTemplate` lets the walk cross θ (chart-type) edges: after a transition * switches `chartType`, subsequent generators come from the *target* template's * pivot def. Backends that omit it leave θ states as leaves (no composition past * a chart-type change). */ declare function computePivot(template: ChartTemplateDef, base: Record, data: any[], resolveTemplate?: (chartType: string) => ChartTemplateDef | undefined, opts?: { includeTransitions?: boolean; key?: string; label?: string; preferFacetTarget?: boolean; }): PivotComputation | null; /** * Resolve the active pivot state for the stored override and return both the * transformed encodings and the serializable surface (or the untouched base * encodings + `undefined` surface when no multi-state pivot applies). */ declare function applyPivot(template: ChartTemplateDef, base: Record, data: any[], chartProperties: Record | undefined, resolveTemplate?: (chartType: string) => ChartTemplateDef | undefined): { encodings: Record; augmentation: EncodingAugmentation | undefined; chartType: string | undefined; surface: PivotSurface | undefined; }; /** Both control surfaces resolved for the current input. */ interface TransformSurface { /** Control B — chart-type transitions (dropdown). Absent when no siblings. */ chartType?: PivotSurface; /** Control A — local rearrangement group (stepper). Absent when trivial. */ arrange?: PivotSurface; } /** Override keys the two controls read/write under `chartProperties`. */ declare const TRANSFORM_CHART_TYPE_KEY = "chartType"; declare const TRANSFORM_ARRANGE_KEY = "arrange"; /** * Control A enumeration: the local rearrangement group (τ/σ/γ only, no θ) of a * template, BFS-composed and deduped exactly like {@link computePivot} but with * chart-type transitions excluded. Runs on the *effective* object's identity * encoding (post-θ), so it offers exactly the moves that make sense there. */ declare function computeArrangeStates(template: ChartTemplateDef, base: Record, data: any[]): PivotComputation | null; /** * Control B enumeration: the one-hop chart-type transitions (θ only) of a * template, enumerated from the object's *identity* encoding — no composition, * no τ/σ/γ. Each state re-routes fields for a sibling chart type and carries a * `chartType` override the compiler re-dispatches on. State 0 is the authored * type (`default`, no override); labels are the sibling chart-type display * names so the dropdown reads "Bar Chart · Line Chart · …". Returns `null` when * the template declares no transitions. */ declare function computeChartTypeStates(template: ChartTemplateDef, base: Record, data: any[], resolveTemplate?: (chartType: string) => ChartTemplateDef | undefined): PivotComputation | null; /** * Resolve the active state for the two independent controls and return the * transformed encodings + both surfaces. Order (design §4.10.1): apply the * chart-type transition (Control B) from the authored identity FIRST, re-select * the sibling template, THEN enumerate + apply that object's local arrange group * (Control A). A stale/absent `arrange` id falls back to identity — which is the * reset-on-θ behavior for free (design §4.10.2). */ declare function applyTransform(template: ChartTemplateDef, base: Record, data: any[], chartProperties: Record | undefined, resolveTemplate?: (chartType: string) => ChartTemplateDef | undefined): { encodings: Record; augmentation: EncodingAugmentation | undefined; chartType: string | undefined; surface: TransformSurface; }; export { type PivotComputation as P, TRANSFORM_ARRANGE_KEY as T, type PivotSurface as a, TRANSFORM_CHART_TYPE_KEY as b, type TransformSurface as c, applyPivot as d, applyTransform as e, computeArrangeStates as f, computeChartTypeStates as g, computePivot as h, makeCartesianPivot as m };