{"version":3,"sources":["../../src/core/types.ts","../../src/core/encoding-overrides.ts","../../src/core/chart-transitions.ts","../../src/core/pivot.ts","../../src/core/encoding-actions.ts","../../src/core/axis-detection.ts","../../src/core/band-dodge.ts","../../src/core/type-registry.ts","../../src/core/semantic-types.ts","../../src/core/decisions.ts","../../src/core/field-semantics.ts","../../src/core/resolve-semantics.ts","../../src/core/filter-overflow.ts","../../src/core/compute-layout.ts","../../src/core/static-series.ts","../../src/core/recommendation.ts","../../src/core/chart-type-recommendation.ts"],"names":["channels","isDiscrete","uniqueValues","isTemporal","groupAxis","ar","nRows","channel","chosen"],"mappings":";;;AAqBO,IAAM,QAAA,GAAW;AAAA,EACpB,GAAA;AAAA,EAAK,GAAA;AAAA,EAAK,IAAA;AAAA,EAAM,IAAA;AAAA,EAAM,IAAA;AAAA,EAAM,OAAA;AAAA,EAAS,SAAA;AAAA,EAAW,MAAA;AAAA,EAAQ,OAAA;AAAA,EAAS,YAAA;AAAA,EAAc,QAAA;AAAA,EAC/E,KAAA;AAAA,EAAO,UAAA;AAAA,EAAY,WAAA;AAAA,EAAa,QAAA;AAAA,EAAU,QAAA;AAAA,EAAU,OAAA;AAAA,EACpD,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,KAAA;AAAA,EAAO,OAAA;AAAA,EAAS,OAAA;AAAA;AAAA;AAAA,EAGhC,OAAA;AAAA;AAAA,EAEA,QAAA;AAAA,EAAU,OAAA;AAAA,EAAS;AACvB;AAEO,IAAM,aAAA,GAA0C;AAAA,EACnD,EAAA,EAAI,CAAC,GAAA,EAAK,IAAA,EAAM,GAAA,EAAK,IAAA,EAAM,UAAA,EAAY,WAAA,EAAa,IAAA,EAAM,QAAA,EAAU,QAAA,EAAU,OAAO,CAAA;AAAA,EACrF,SAAA,EAAW,CAAC,OAAA,EAAS,OAAA,EAAS,QAAQ,OAAA,EAAS,MAAA,EAAQ,WAAW,YAAY,CAAA;AAAA,EAC9E,OAAA,EAAS,CAAC,MAAA,EAAQ,M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A,CAAI,IAAI,SAAS,CAAA,CAAG,OAAA,EAAQ,CAAE,CAAA,CAExG,IAAA,CAAK,CAAC,CAAA,EAAG,CAAA,KAAM,CAAA,CAAE,KAAA,GAAQ,CAAA,CAAE,KAAK,CAAA;AACzC;AAYO,SAAS,2BAAA,CACZ,IAAA,EACA,aAAA,EACA,OAAA,GAAsC,EAAC,EAClB;AACrB,EAAA,MAAM,OAAA,GAAU,WAAA,CAAY,IAAA,EAAM,aAAa,CAAA;AAC/C,EAAA,IAAI,MAAA,GAAS,eAAe,OAAO,CAAA;AACnC,EAAA,IAAI,QAAQ,cAAA,EAAgB;AACxB,IAAA,MAAM,OAAA,GAAU,IAAI,GAAA,CAAI,OAAA,CAAQ,cAAc,CAAA;AAC9C,IAAA,MAAA,GAAS,OAAO,MAAA,CAAO,CAAA,CAAA,KAAK,QAAQ,GAAA,CAAI,CAAA,CAAE,SAAS,CAAC,CAAA;AAAA,EACxD;AACA,EAAA,IAAI,OAAA,CAAQ,OAAO,IAAA,EAAM,MAAA,GAAS,OAAO,KAAA,CAAM,CAAA,EAAG,QAAQ,GAAG,CAAA;AAC7D,EAAA,OAAO,MAAA;AACX;AAeO,SAAS,mBAAA,CACZ,IAAA,EACA,aAAA,EACA,OAAA,GAAsC,EAAC,EAC/B;AACR,EAAA,OAAO,2BAAA,CAA4B,MAAM,aAAA,EAAe,OAAO,EAAE,GAAA,CAAI,CAAA,CAAA,KAAK,EAAE,SAAS,CAAA;AACzF","file":"index.cjs","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ZeroDecision, ColorSchemeRecommendation } from './semantic-types';\nimport type { LabelSizingDecision } from './decisions';\nimport type { SemanticAnnotation, FormatSpec, DomainConstraint, TickConstraint } from './field-semantics';\nimport type { ColorDecisionResult } from './color-decisions';\n\n/**\n * Core types for the chart engine library.\n * No React or UI framework dependencies — pure TypeScript.\n */\n\n// ---------------------------------------------------------------------------\n// Data Types\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Channel & Encoding\n// ---------------------------------------------------------------------------\n\nexport const channels = [\n    \"x\", \"y\", \"x2\", \"y2\", \"id\", \"color\", \"opacity\", \"size\", \"shape\", \"strokeDash\", \"column\",\n    \"row\", \"latitude\", \"longitude\", \"radius\", \"detail\", \"group\",\n    \"open\", \"high\", \"low\", \"close\", \"angle\",\n    // Connected Scatter Plot: the sequence field that defines the line's\n    // connection order (the trajectory), independent of the x value.\n    \"order\",\n    // KPI Card: one row per tile, no chart axes.\n    \"metric\", \"value\", \"goal\",\n] as const;\n\nexport const channelGroups: Record<string, string[]> = {\n    \"\": [\"x\", \"x2\", \"y\", \"y2\", \"latitude\", \"longitude\", \"id\", \"radius\", \"detail\", \"order\"],\n    \"legends\": [\"color\", \"group\", \"size\", \"shape\", \"text\", \"opacity\", \"strokeDash\"],\n    \"price\": [\"open\", \"high\", \"low\", \"close\"],\n    \"facets\": [\"column\", \"row\"],\n    \"kpi\": [\"metric\", \"value\", \"goal\"],\n};\n\n/**\n * Encoding definition for a single channel, using field names directly.\n * This is the library-level encoding — no fieldID indirection.\n */\nexport interface ChartEncoding {\n    field?: string;\n    type?: \"quantitative\" | \"nominal\" | \"ordinal\" | \"temporal\";\n    aggregate?: 'count' | 'sum' | 'average' | 'mean';\n    sortOrder?: \"ascending\" | \"descending\";\n    sortBy?: string;\n    scheme?: string;\n}\n\n/**\n * An encoding value that allows either a single encoding or an array of\n * encodings (static series). Array form is only valid on measure channels\n * (y, x-as-measure) where all fields resolve to quantitative.\n *\n * When an array is provided, the assembler folds (unpivots) the specified\n * fields into a long-form representation with a synthesized key column\n * (for color/legend) and value column (for the measure axis).\n */\nexport type EncodingValue = ChartEncoding | ChartEncoding[];\n\n/**\n * Shorthand for a channel encoding: a bare field-name string is treated as\n * `{ field: <string> }`. This lets callers write `{ x: \"weight\" }` instead of\n * `{ x: { field: \"weight\" } }` to keep simple specs terse (e.g. for demos).\n *\n * Shorthands are also accepted inside static-series arrays, so\n * `{ y: [\"sales\", \"profit\"] }` expands to `[{ field: \"sales\" }, { field: \"profit\" }]`.\n */\nexport type EncodingShorthand = string;\n\n/**\n * Channel value as accepted in raw user input, before shorthand normalization.\n * Normalized to {@link EncodingValue} by `normalizeEncodingShorthand`.\n */\nexport type RawEncodingValue =\n    | ChartEncoding\n    | EncodingShorthand\n    | (ChartEncoding | EncodingShorthand)[];\n\n/**\n * Metadata produced by static series normalization.\n * Captures the original multi-field intent so backends can emit\n * appropriate legend labels and the pipeline can short-circuit\n * series counting.\n */\nexport interface StaticSeriesMetadata {\n    /** Which channel had the array encoding ('y' or 'x') */\n    channel: string;\n    /** Original field names from the array entries */\n    fields: string[];\n    /** Synthetic column name for the series discriminator */\n    keyColumn: string;\n    /** Synthetic column name for the measure values */\n    valueColumn: string;\n}\n\n// ============================================================================\n// Phase 0: Semantic Resolution Types\n// ============================================================================\n\n/**\n * Everything Phase 0 decides for a single channel.\n *\n * Combines the original ChartEncoding (user intent) with resolved\n * decisions derived from semantic type, data values, and channel context.\n * All downstream phases (layout, assembly, instantiation) read this —\n * no nested FieldSemantics reference needed.\n */\nexport interface ChannelSemantics {\n    // --- Identity ---\n    /** Field name bound to this channel */\n    field: string;\n    /** The semantic annotation for this field */\n    semanticAnnotation: SemanticAnnotation;\n\n    // --- Encoding type ---\n    /**\n     * Final encoding type for this channel.\n     * Resolved from semantic type + data characteristics + channel rules.\n     */\n    type: 'quantitative' | 'nominal' | 'ordinal' | 'temporal';\n\n    // --- Formatting ---\n    /** Axis/legend number format */\n    format?: FormatSpec;\n    /** Tooltip format (typically higher precision) */\n    tooltipFormat?: FormatSpec;\n    /**\n     * Temporal format string (temporal fields on any channel).\n     * E.g., \"%Y\", \"%b %d\", \"%H:%M\".\n     */\n    temporalFormat?: string;\n\n    // --- Aggregation ---\n    /** Default aggregate function when used as a measure */\n    aggregationDefault?: 'sum' | 'average';\n\n    // --- Scale ---\n    /**\n     * Zero-baseline decision (positional quantitative channels only).\n     * Present only on 'x' and 'y' channels with type 'quantitative'.\n     */\n    zero?: ZeroDecision;\n    /** Recommended scale type */\n    scaleType?: 'linear' | 'log' | 'sqrt' | 'symlog';\n    /** Whether to apply \"nice\" rounding to domain endpoints */\n    nice?: boolean;\n    /** Domain bounds constraint */\n    domainConstraint?: DomainConstraint;\n    /** Tick mark constraints */\n    tickConstraint?: TickConstraint;\n\n    // --- Ordering ---\n    /**\n     * Canonical ordinal sort order for this field's values.\n     * E.g., month names, day-of-week, quarters.\n     */\n    ordinalSortOrder?: string[];\n    /** Whether the canonical order is cyclic (wraps around) */\n    cyclic?: boolean;\n    /** Whether the axis should be reversed (e.g., Rank: 1 at top) */\n    reversed?: boolean;\n    /** Default sort direction */\n    sortDirection?: 'ascending' | 'descending';\n\n    // --- Color ---\n    /** Color scheme recommendation (color channel only) */\n    colorScheme?: ColorSchemeRecommendation;\n\n    // --- Histogram ---\n    /** Whether this field benefits from binning */\n    binningSuggested?: boolean;\n\n    // --- Stacking ---\n    /** Whether values can be stacked, and how */\n    stackable?: 'sum' | 'normalize' | false;\n}\n\n/** Phase 0 output: one entry per channel. */\nexport type SemanticResult = Record<string, ChannelSemantics>;\n\n// ============================================================================\n// Phase 1: Layout Types\n// ============================================================================\n\n/**\n * How the template's primary mark encodes its quantitative value\n * on the positional (value) axis.\n *\n * Grounded in perceptual accuracy ranking:\n *   1. Position along a common scale — most accurate\n *   2. Length from a shared baseline\n *   3. Area\n *   4. Color saturation / luminance\n *\n * Drives zero-baseline, scale tightness, and compression behavior.\n */\nexport type MarkCognitiveChannel = 'position' | 'length' | 'area' | 'color';\n\n/**\n * Template's layout intent — returned by declareLayoutMode().\n */\nexport interface LayoutDeclaration {\n    /**\n     * Which axes allocate fixed bands per data position.\n     * Banded axes use the spring model; non-banded use gas pressure.\n     */\n    axisFlags?: {\n        x?: { banded: boolean };\n        y?: { banded: boolean };\n    };\n\n    /**\n     * Resolved encoding types after any template-driven type conversion.\n     * E.g., detectBandedAxis may convert Q→O for a bar chart axis.\n     * These override the Phase 0 decisions for layout purposes.\n     */\n    resolvedTypes?: Record<string, 'nominal' | 'ordinal' | 'quantitative' | 'temporal'>;\n\n    /**\n     * Template-specific overrides to layout parameters.\n     */\n    paramOverrides?: Partial<AssembleOptions>;\n\n    /**\n     * Which axes use binned encoding (e.g. histogram).\n     * The assembler auto-detects this from template.encoding if not set.\n     */\n    binnedAxes?: Record<string, boolean | { maxbins?: number }>;\n\n    /**\n     * Treat a discrete `color` field as an axis-grouping field for sizing,\n     * even though the template uses the `color` channel rather than `group`.\n     * When set, computeLayout sizes the discrete axis per-band (xStepUnit\n     * 'group') and budgets the band step across categories, so the chart does\n     * not balloon and each sub-lane shrinks as the subgroup count grows.\n     * Used by charts (e.g. boxplot) that dodge by color via an explicit offset.\n     */\n    colorActsAsGroup?: boolean;\n\n    /**\n     * Override the number of sub-lanes the grouping field reserves per band.\n     * When unset, computeLayout uses the global distinct count of the group\n     * field. Templates that render `local` (compact) dodge set this to the\n     * per-band max cardinality (`maxPerBand`) so the band is budgeted for only\n     * as many lanes as the busiest band actually uses.\n     */\n    groupLaneCount?: number;\n\n    /**\n     * Custom overflow strategy for deciding which discrete values to keep\n     * when a channel overflows. If not provided, the default strategy is used.\n     *\n     * @param channel       The overflowing channel ('x', 'y', 'color', etc.)\n     * @param fieldName     The field on that channel\n     * @param uniqueValues  All unique values in the data for that field\n     * @param maxToKeep     Maximum number of values that fit\n     * @param context       Abstract context with data and channel info\n     * @returns             The values to keep (in display order)\n     */\n    overflowStrategy?: OverflowStrategy;\n}\n\n/**\n * Custom overflow strategy function type.\n * Returns the values to keep when a channel has too many discrete values.\n */\nexport type OverflowStrategy = (\n    channel: string,\n    fieldName: string,\n    uniqueValues: any[],\n    maxToKeep: number,\n    context: OverflowStrategyContext,\n) => any[];\n\n/** Context passed to overflow strategy functions. */\nexport interface OverflowStrategyContext {\n    /** Full data table */\n    data: any[];\n    /** Per-channel semantic info */\n    channelSemantics: Record<string, ChannelSemantics>;\n    /** Original user encodings (for sort info) */\n    encodings: Record<string, ChartEncoding>;\n    /** Mark types present in the template */\n    allMarkTypes: Set<string>;\n}\n\n/**\n * Per-channel maximum values that can fit on the canvas.\n *\n * Computed once by `computeChannelBudgets` using the most conservative\n * assumptions (minStep, minSubplotSize, maxStretch).  Passed to\n * `filterOverflow` so it only needs to decide *which* values to keep\n * and filter rows — no layout math.\n *\n * Pipeline:  computeChannelBudgets → filterOverflow → computeLayout\n */\nexport interface ChannelBudgets {\n    /** Maximum discrete values to keep per channel.\n     *  Channels not present here are uncapped (`Infinity`). */\n    maxValues: Record<string, number>;\n    /** Facet grid decision (if facet channels exist) */\n    facetGrid?: FacetGridResult;\n}\n\n/** Result of overflow filtering. */\nexport interface OverflowResult {\n    /** Data after removing overflow rows */\n    filteredData: any[];\n    /** Nominal value counts per channel (post-overflow) */\n    nominalCounts: Record<string, number>;\n    /** Detailed truncation info for overflow styling */\n    truncations: TruncationWarning[];\n    /** Warning messages for the UI */\n    warnings: ChartWarning[];\n}\n\n/**\n * Result of facet grid computation (from computeFacetGrid).\n *\n * Decides the visual grid layout (including column-only wrapping)\n * and the maximum number of unique values to keep per facet channel.\n *\n * Pipeline:  computeFacetGrid → filterOverflow (uses caps) → computeLayout (uses grid)\n */\nexport interface FacetGridResult {\n    /** Visual columns per row (after wrapping for column-only) */\n    columns: number;\n    /** Visual rows (after wrapping for column-only) */\n    rows: number;\n    /** Max unique values to keep for the column channel */\n    maxColumnValues: number;\n    /** Max unique values to keep for the row channel */\n    maxRowValues: number;\n}\n\n/**\n * Describes one axis that was truncated due to overflow.\n */\nexport interface TruncationWarning {\n    /** Severity level for UI display */\n    severity: 'warning';\n    /** Machine-readable code */\n    code: 'overflow';\n    /** Human-readable message */\n    message: string;\n    /** Which channel overflowed ('x', 'y', 'color', etc.) */\n    channel: string;\n    /** Field name on the overflowing axis */\n    field: string;\n    /** Values retained (in display order) */\n    keptValues: any[];\n    /** Number of items omitted */\n    omittedCount: number;\n    /** Placeholder string to append to the axis domain */\n    placeholder: string;\n}\n\n/**\n * Phase 1 output: all layout decisions.\n *\n * LayoutResult is **target-agnostic** — it describes abstract dimensions\n * and step sizes that any rendering backend can consume.  It is the\n * backend's responsibility to translate these values into its own\n * coordinate system:\n *\n *   subplotWidth / subplotHeight\n *     The intended data-area (plot area) size in pixels.  This does NOT\n *     include axis labels, titles, legends, or margins.  Each backend\n *     must add its own margins/padding around this area.\n *\n *   xStep / yStep\n *     Pixel distance per discrete position on each axis.  A backend\n *     rendering bars should derive bar width from step and stepPadding.\n *     VL uses `width: {step: N}` natively; ECharts must compute\n *     explicit barWidth / barCategoryGap.\n *\n *   stepPadding\n *     Fraction of each step reserved for inter-category spacing (0–1).\n *     Usable bar width = step × (1 − stepPadding).\n *\n *   facet (columns / rows / subplot sizes)\n *     When faceting is active, the subplot dimensions are already\n *     divided for the facet grid.  Each backend is responsible for\n *     facet wrapping (e.g. column-only → wrapped rows), panel\n *     positioning, header labels, and shared/per-panel axis titles.\n *\n * Backends should NOT modify LayoutResult.  They read it and translate\n * to their native format (VL encoding props, ECharts grid/axis config, etc.).\n */\nexport interface LayoutResult {\n    /** Final subplot width in px (after stretch) */\n    subplotWidth: number;\n    /** Final subplot height in px (after stretch) */\n    subplotHeight: number;\n\n    /** Computed step size for X axis (px per discrete position) */\n    xStep: number;\n    /** Computed step size for Y axis (px per discrete position) */\n    yStep: number;\n\n    /** Whether the step size is per-item or per-group. */\n    xStepUnit?: 'item' | 'group';\n    yStepUnit?: 'item' | 'group';\n\n    /** Number of banded continuous items on each axis (0 if not banded-continuous) */\n    xContinuousAsDiscrete: number;\n    yContinuousAsDiscrete: number;\n\n    /** Number of nominal/ordinal items on each axis */\n    xNominalCount: number;\n    yNominalCount: number;\n\n    /** Label sizing decisions per axis */\n    xLabel: LabelSizingDecision;\n    yLabel: LabelSizingDecision;\n\n    /**\n     * Canvas-adaptive header font size (px) for axis titles and chart title.\n     * Derived from the backend's `baseTitleFontSize`, scaled subtly with the\n     * (sub)plot size. Backends should use this instead of hardcoded constants.\n     */\n    titleFontSize: number;\n    /**\n     * Canvas-adaptive font size (px) for legend entries. Slightly smaller than\n     * {@link titleFontSize}. Backends should use this for legend text.\n     */\n    legendFontSize: number;\n\n    /** Facet layout (if applicable) */\n    facet?: {\n        columns: number;\n        rows: number;\n        subplotWidth: number;\n        subplotHeight: number;\n    };\n\n    /**\n     * Gap between facet panels in px, as set by the backend.\n     * Backends use this to configure their own spacing\n     * (VL config.facet.spacing, ECharts GAP, etc.).\n     */\n    effectiveFacetGap: number;\n\n    /**\n     * Inter-category padding fraction (0–1) used by the layout engine.\n     * Renderers (especially ECharts) should use this to size bars:\n     *   barWidth = step × (1 − stepPadding)\n     */\n    stepPadding: number;\n\n    /** Items truncated due to overflow */\n    truncations: TruncationWarning[];\n}\n\n// ============================================================================\n// Phase 2: Instantiation Types\n// ============================================================================\n\n/**\n * Context passed to template instantiate() and to the shared assembler's\n * Phase 2 logic. Combines semantic decisions, layout results, and original\n * inputs.\n */\nexport interface InstantiateContext {\n    /** Per-channel semantic decisions (Phase 0) */\n    channelSemantics: Record<string, ChannelSemantics>;\n\n    /** Layout decisions (Phase 1) */\n    layout: LayoutResult;\n\n    /** The data table (array of row objects, post-overflow filtering) */\n    table: any[];\n\n    /**\n     * The full data table (array of row objects, BEFORE overflow filtering).\n     *\n     * `table` may have categories silently dropped by `filterOverflow` to\n     * fit the canvas. Templates that need an honest view of the raw data\n     * — e.g. a \"top-N + Others\" rollup, an annotation that summarizes\n     * what wasn't shown, or a sparkline reference — should read from\n     * `fullTable` instead.\n     *\n     * Optional for backwards-compatibility; backends that don't set it\n     * fall back to `table`.\n     */\n    fullTable?: any[];\n\n    /** Resolved VL encoding objects (built by assembler from Phase 0 decisions) */\n    resolvedEncodings: Record<string, any>;\n\n    /** Original user-level encodings */\n    encodings: Record<string, ChartEncoding>;\n\n    /** User-configured chart properties */\n    chartProperties?: Record<string, any>;\n\n    /** Static series metadata (present when input used array-valued encoding) */\n    staticSeries?: StaticSeriesMetadata;\n\n    /**\n     * Base (target) chart dimensions — the size layout aims for before\n     * pressure-driven stretch. This is the resolved `chart_spec.baseSize`\n     * (NOT the hard ceiling). The ceiling is `baseSize × maxStretchX/Y`,\n     * available via `assembleOptions.maxStretchX` / `maxStretchY`.\n     */\n    canvasSize: { width: number; height: number };\n\n    /** Field name → semantic type (string or enriched annotation) */\n    semanticTypes: Record<string, string | SemanticAnnotation>;\n\n    /** Chart type name */\n    chartType: string;\n\n    /** Assembly options (layout tuning parameters from the caller) */\n    assembleOptions?: AssembleOptions;\n\n    /**\n     * Backend-agnostic color decisions.\n     * Computed once per chart from semantic + layout context and reused\n     * by all backends to map into their native color configuration.\n     */\n    colorDecisions?: ColorDecisionResult;\n}\n\n\n\n// ---------------------------------------------------------------------------\n// Chart Template\n// ---------------------------------------------------------------------------\n\n/**\n * The minimal, render-time context an option's applicability check reads.\n *\n * Shared by both option families so they use one predicate convention:\n *   - `ChartPropertyDef.check` (Category A, data-aware properties)\n *   - `EncodingActionDef.isApplicable` (Category B, encoding actions)\n *\n * `encodings` is always present (it's all a host needs to gate an encoding\n * action). The remaining fields are populated by the compiler during assembly\n * and let data-aware *properties* inspect the actual values + resolved\n * semantics; a predicate that only reads `encodings` (e.g. \"is color bound?\")\n * works with the bare `{ encodings }` a host can build on its own.\n */\nexport interface OptionEvalContext {\n    /** User-level encodings (channel → field binding). Always present. */\n    encodings: Record<string, ChartEncoding>;\n    /** Per-channel semantic decisions (Phase 0). Present during assembly. */\n    channelSemantics?: Record<string, ChannelSemantics>;\n    /** Full (pre-overflow) data rows, for data-aware preconditions. */\n    data?: any[];\n    /** Current user-set chart property overrides. */\n    chartProperties?: Record<string, any>;\n}\n\n/**\n * Defines a configurable property for a chart template.\n * Describes the value domain; the app decides how to render it.\n */\n\n/** The value-domain variants a property can take (the discriminated arm). */\nexport type ChartPropertyVariant =\n    | { type: 'continuous'; min: number; max: number; step?: number; defaultValue?: number }\n    | { type: 'discrete';  options: { value: any; label: string }[]; defaultValue?: any }\n    | { type: 'binary';    defaultValue?: boolean };\n\n/**\n * The renderable descriptor of a property: its identity, label, and value\n * domain. This is the part a host needs to draw a control, and it is shared\n * verbatim by both sides of the Flint↔host boundary:\n *\n *   - `ChartPropertyDef`  = `ChartProperty` + the applicability *rule* (`check`)\n *   - `ChartOption`       = `ChartProperty` + the resolved *answer* (`applicable`/`value`)\n *\n * Keeping the descriptor common means the template definition and the resolved\n * option never drift in shape; they differ only by rule-vs-answer.\n */\nexport type ChartProperty = {\n    key: string;\n    label: string;\n} & ChartPropertyVariant;\n\nexport type ChartPropertyDef = ChartProperty & {\n    /**\n     * The single applicability check for this property, co-located with it so a\n     * reader sees *why* an option is offered without digging into the compiler.\n     * Pure — reads only `OptionEvalContext` — and returns:\n     *   - `applicable`: is this property worth offering for the current spec +\n     *     data? It subsumes both structural gates (a channel is bound, e.g.\n     *     `!!ctx.encodings.color?.field`) and data-aware ones (a wide-range axis,\n     *     an additive single-sign measure, …). A property with no `check`\n     *     is always offered.\n     *   - `recommendedValue` (optional): the engine's suggested default, used to\n     *     seed the control when the host hasn't set an explicit value.\n     *\n     * Because it requires no live data to answer a structural check, a static\n     * host (the encoding-shelf popover) can call it with just `{ encodings }`;\n     * a data-aware property then reports `applicable: false` there — surfacing\n     * only in the data-aware quick-config bar — without needing a separate flag.\n     */\n    check?: (ctx: OptionEvalContext) => { applicable: boolean; recommendedValue?: any };\n};\n\n/**\n * A chart property descriptor annotated with its applicability and resolved\n * value for a *specific* spec + dataset. Produced by `getChartOptions` (and\n * carried on the assembled spec under `_options`).\n *\n * This is the contract between Flint and any host (Data Formulator, an AI agent,\n * another renderer):\n *\n *   - `applicable` — did this property pass its precondition for this render?\n *     Each property answers via its own `check`: structural ones (e.g. stack\n *     mode) are applicable when their channel is bound; data-aware ones (e.g.\n *     per-axis log scale, faceted independent y) only when the data warrants it\n *     (wide-range continuous axis, faceted quantitative y, …). A host should\n *     surface a control only when it is applicable; passing a non-applicable\n *     property to the compiler is accepted but silently ignored.\n *   - `value` — the value Flint will actually use: the host's explicit choice\n *     (from `chart_spec.chartProperties[key]`) when set, otherwise the engine's\n *     recommended default. Hosts seed their control from this so an \"auto\"\n *     recommendation (e.g. log on a 10⁶× axis) is reflected without the host\n *     having to recompute it.\n *\n * A `ChartOption` shares the renderable `ChartProperty` descriptor with the\n * template def but carries the *answer* (`applicable`/`value`) instead of the\n * *rule* (`check`). That keeps it a resolved, serializable view a host consumes\n * across the spec/JSON boundary (Python path included), where the rule function\n * wouldn't survive anyway.\n */\nexport type ChartOption = ChartProperty & {\n    /** Did this property pass its precondition for the current spec + data? */\n    applicable: boolean;\n    /** Explicit host choice if set, otherwise the engine's recommended default. */\n    value: any;\n};\n\n\n/**\n * Defines a \"quick action\" whose effect is an **encoding transform** (Category B):\n * sort, color scheme, aggregate, type, orientation (x↔y swap), etc.\n *\n * These operate at a different pipeline stage than ChartPropertyDef:\n *\n *   Category B (this type):  (encoding + override) ──► transformed encoding ──► assemble ──► spec\n *                                         └──── set() ────┘\n *   Category A (properties): encoding ──► assemble ──► spec ──► (props tweak spec in instantiate)\n *\n * An encoding action transforms the *input* to assembly, so the full pipeline\n * (semantic resolution → overflow → layout → assembly) re-runs on the result.\n * That is exactly why structural options must live here: sort changes which\n * categories survive overflow, aggregate changes the data values, orientation\n * changes which axis is banded — none of which can be faked by patching the\n * assembled spec afterwards. ChartPropertyDef, by contrast, only overrides the\n * already-assembled spec and is limited to visual decoration (cornerRadius,\n * opacity, curve, donut hole).\n *\n * Storage = override, not encoding state. The action's value is stored by the\n * host as a *configuration override* (exactly like a chart property), keyed by\n * `key` inside `chart_spec.chartProperties`. The encoding map (the encoding\n * shelf's state) is left untouched. The compiler — not the host — applies the\n * override at assemble time:\n *\n *   transformedEncodings = set(currentEncodings, chartProperties[key])\n *\n * So Flint always sees just \"override value + current encoding\" and composes\n * them; it never mutates persistent encoding state. (See applyEncodingOverrides.)\n *\n *   get(encodings)        → derive the control's displayed value from the base\n *                           encodings when no override is set\n *   set(encodings, value) → compose: return the encodings with the override applied\n *\n * `set` is declarative: it returns what the encodings should be after the\n * override, not a list of imperative operations. Any transform — changing one\n * property, swapping two channels, clearing a channel — is just \"produce a new\n * map\", so there is no operation taxonomy to grow.\n *\n * `dependencies` declares which encoding channels the override is computed\n * against. It is a pure declaration consumed by the *host*: when the user edits\n * one of these channels in the encoding shelf, the host clears (resets) the\n * override so a stale value can't linger. Flint never resets — reset is host\n * logic; Flint only ever composes override + current encoding.\n *\n * The control shape mirrors ChartPropertyDef so the host can reuse the same\n * renderers; only the pipeline stage differs (encoding transform vs spec tweak).\n */\nexport type EncodingActionDef = {\n    key: string;\n    label: string;\n    /**\n     * Channels this override is computed against. When the host detects an edit\n     * to any of these channels in the encoding shelf, it resets this override to\n     * default. Pure declaration — Flint itself never reads this for composition.\n     */\n    dependencies?: string[];\n    /** How to render the control (same value domains as ChartPropertyDef). */\n    control:\n        | { type: 'continuous'; min: number; max: number; step?: number }\n        | { type: 'discrete';  options: { value: any; label: string }[] }\n        | { type: 'binary' };\n    /**\n     * Optional applicability predicate — the single gate for whether this action\n     * is offered. It reads the shared `OptionEvalContext`; in practice an action\n     * only needs `ctx.encodings`, so it subsumes both channel-assignment checks\n     * (is a channel bound? e.g. `!!ctx.encodings.color?.field`) and type checks\n     * (e.g. Sort needs a discrete category axis, so it must not appear on a\n     * purely temporal/quantitative chart). Pure. Defaults to always-applicable.\n     */\n    isApplicable?: (ctx: OptionEvalContext) => boolean;\n    /** Derive the displayed control value from the base encodings map (pure). */\n    get: (encodings: Record<string, ChartEncoding>) => any;\n    /** Compose: return the encodings with this override value applied (pure). */\n    set: (encodings: Record<string, ChartEncoding>, value: any) => Record<string, ChartEncoding>;\n};\n\n/**\n * A chart-type transition: a pivot state that re-views the same data as a\n * *sibling* chart type. Unlike orientation/role/series moves (which stay within\n * one template), a transition changes `chartType` and, optionally, re-routes one\n * field across channels. It is the \"chart type as another group coordinate\"\n * generator (see design doc §4.6). Examples: Grouped Bar ↔ Stacked Bar (the\n * dodge series moves between `group` and `color`), Scatter ↔ Strip/Jitter (a\n * discrete `color` swaps onto the `x` category axis).\n */\nexport interface PivotTransition {\n    /** Target chart type to render as. Must be a registered sibling template. */\n    to: string;\n    /** State label shown in the pivot control (e.g. 'Stacked', 'Grouped', 'Jitter'). */\n    label: string;\n    /**\n     * Optional channel re-route applied before switching templates.\n     * - `move`: source field → target channel; source channel cleared (target must be empty).\n     * - `swap`: exchange the fields on the two channels (or spill the displaced\n     *   field to a third channel — see `spill`).\n     *\n     * `from` may be a literal channel name or the sentinel `'series'`, which\n     * resolves at runtime to whichever grouping channel (`color`/`column`/`row`/\n     * `group`) currently holds the discrete series field.\n     */\n    route?: { from: string; to: string; mode?: 'move' | 'swap'; spill?: string };\n    /** Only offer when the routed source field is discrete (nominal/ordinal). */\n    requireDiscreteSource?: boolean;\n    /** Only offer when the routed source field's distinct count is within this budget. */\n    maxSourceCardinality?: number;\n    /**\n     * Only offer when the *domain* position axis (the non-measure x/y) carries an\n     * ordered type — `temporal` or `ordinal`, never plain `nominal`. This is the\n     * hard gate for bar → line/area: you may not connect unordered categories.\n     * Per the design decision, order is taken from the resolved encoding type\n     * (derived from the semantic type), NOT inferred from sort state.\n     */\n    requireOrderedAxis?: boolean;\n    /**\n     * Only offer when every value on the *measure* position axis is ≥ 0. The gate\n     * for part-to-whole / filled siblings (pie, area) where a negative magnitude\n     * would misread.\n     */\n    requireNonNegative?: boolean;\n    /**\n     * Only offer when the *domain* axis distinct count is within this budget — the\n     * low-cardinality guard for pie/rose (few slices) and line → bar (few ticks).\n     */\n    maxCategoryCardinality?: number;\n    /**\n     * Only offer when NO discrete series channel (color/group/column/row) is bound\n     * — the single-series guard for a part-to-whole pie/donut.\n     */\n    requireNoSeries?: boolean;\n    /**\n     * Only offer when a discrete series channel (color/group/detail/column/row) IS\n     * bound — the multi-series guard for small-multiple siblings (e.g. Line →\n     * Sparkline needs a series to make one strip per category).\n     */\n    requireSeries?: boolean;\n    /**\n     * Only offer when BOTH position axes (x and y) are measures (quantitative or\n     * aggregated) — the guard for a fitted trend (Scatter → Regression): a\n     * regression line is meaningless over a nominal/category axis.\n     */\n    requireBiaxialMeasure?: boolean;\n    /**\n     * Only offer when the `size` channel is NOT bound — keeps a fitted-trend\n     * sibling (Regression) to a clean 2-variable scatter rather than layering it\n     * over a bubble chart.\n     */\n    requireNoSize?: boolean;\n    /**\n     * After routing, force the *domain* (non-measure) position axis onto this\n     * channel, swapping `x`/`y` wholesale if it currently sits on the other. Used\n     * for bar → line/area: a *horizontal* bar carries the ordered/temporal domain\n     * on `y`, but a line pins time to the horizontal, so the transition must\n     * re-orient to `x` (otherwise you get a nonsensical vertical line chart).\n     */\n    orientDomainAxis?: 'x' | 'y';\n}\n\n/**\n * Declarative pivot configuration carried by a chart template. Each generator\n * declares its *permissible transformation domain* compactly — the candidate\n * swap pairs, the shiftable channels, the sibling chart types — and the compiler\n * filters those candidates lazily against the actual encodings + data (type\n * compatibility, channel availability, cardinality budgets) when assembling. See\n * core/pivot.ts for the enumeration/composition semantics.\n */\nexport interface PivotDef {\n    /** Override key the host stores the chosen state id under. Default `'pivot'`. */\n    key?: string;\n    /** Human label for the control. Default `'View'`. */\n    label?: string;\n    /**\n     * τ (transpose): axis-slot pairs that may be exchanged *wholesale* — the\n     * orientation/flip generator. Each pair (typically `['x','y']`) swaps the two\n     * channels' full encodings, so it is profile-agnostic (a bar's category↔measure\n     * flip, a scatter's measure↔measure flip, a heatmap's dimension↔dimension flip\n     * all read the same). It is suppressed only when a continuous-temporal position\n     * axis must stay horizontal (line/area). Because both slots stay occupied, a\n     * transpose can never violate a must-present constraint. A template that should\n     * never flip (e.g. a line, to avoid a vertical line chart) simply omits this.\n     * Ids/labels: `flip:x-y` / `τ_x↔y`. Default none.\n     */\n    transpose?: string[][];\n    /**\n     * σ (permute): permutable *blocks* of channels whose *fields* may be reordered\n     * among themselves — distinct from {@link transpose}, this reassigns a field to\n     * a compatible channel rather than flipping two slots. The compiler enumerates\n     * the within-block pairings and admits an *axis ↔ auxiliary* swap only when the\n     * two ends share a profile (the Young-block rule of the design doc §3.6.1):\n     *   - measure ↔ measure, on position marks only — a quantitative field trades a\n     *     precise position axis for a demoted `color`/`size` channel (scatter);\n     *   - category ↔ discrete `color` — a banded axis dimension trades places with\n     *     the legend series (bars).\n     * `x↔y` is NOT a permute (it is a {@link transpose}); pure auxiliary↔auxiliary\n     * pairs (e.g. `color↔size`) are not offered. Order within a block is irrelevant;\n     * ids/labels canonicalize each pair (`swap:x-color` / `σ_x↔color`). Default none.\n     */\n    permute?: string[][];\n    /**\n     * γ (shift): grouping channels the single discrete *series* field may be\n     * routed across — typically `['color','group','column','row']`. The compiler\n     * filters to channels the template actually declares, that are empty, and\n     * within the per-channel cardinality budget. This is what unifies stacked /\n     * grouped / faceted presentations as states of one template. Default none.\n     */\n    shift?: string[];\n    /** Max distinct categories for a facet split to be offered. Default 12. */\n    facetBudget?: number;\n    /**\n     * θ (chart-type transition): sibling chart types to consider re-rendering the\n     * same data as (e.g. Grouped Bar ↔ Stacked Bar, Scatter ↔ Jitter). Each\n     * admitted transition becomes one extra state in the orbit. Default none.\n     */\n    transitions?: PivotTransition[];\n}\n\n/**\n * Chart template definition — pure data, no UI/icon dependencies.\n * This is the reusable core that defines chart structure, encoding channels,\n * and processing logic.\n *\n * Three-phase pipeline hooks:\n *   1. declareLayoutMode — declare axis flags, type overrides, param overrides\n *   2. instantiate — build final spec from resolved encodings + layout\n */\nexport interface ChartTemplateDef {\n    /** Display name of the chart type, e.g. \"Scatter Plot\" */\n    chart: string;\n    /** Vega-Lite spec skeleton (mark + encoding structure) */\n    template: any;\n    /** Which encoding channels are available for this chart */\n    channels: string[];\n\n    /**\n     * How the primary mark encodes its quantitative value.\n     * Determines zero-baseline, scale tightness, and compression behavior.\n     *\n     * Examples:\n     *   - Bar, Histogram, Lollipop, Waterfall, Pyramid: 'length'\n     *   - Area, Streamgraph, Density: 'area'\n     *   - Line, Scatter, Boxplot, Candlestick, Strip: 'position'\n     *   - Heatmap: 'color'\n     */\n    markCognitiveChannel: MarkCognitiveChannel;\n\n    /**\n     * Phase 1a: Declare layout intent.\n     * Runs BEFORE layout computation.\n     *\n     * Inspects channel semantics and data to decide:\n     * - Which axes are banded (need spring model)\n     * - Any type conversions (Q→O for banded axis)\n     * - Layout parameter overrides (σ, step multiplier, etc.)\n     * Grouping (from group channel + discrete axis detection)\n     */\n    declareLayoutMode?: (\n        channelSemantics: Record<string, ChannelSemantics>,\n        table: any[],\n        chartProperties?: Record<string, any>,\n    ) => LayoutDeclaration;\n\n    /**\n     * Optional encoding-normalization hook.\n     * Runs BEFORE semantics resolution and layout, after pivot / encoding-action\n     * overrides have been composed. Lets a template re-route the *authored*\n     * channel map so the WHOLE pipeline (semantics, faceting, overflow, layout)\n     * resolves against the normalized encodings — not just the final spec.\n     *\n     * Example: a sparkline \"table\" remaps its series field (`color`/`detail`)\n     * onto the `row` facet channel when no `row` is bound, so the layout engine\n     * allocates one stacked strip per series instead of overlaying them.\n     *\n     * Return the (possibly new) encoding map. Returning the input unchanged is a\n     * no-op. Pure — must not mutate the input.\n     *\n     * NOTE: currently honored by the Vega-Lite assembler only; ECharts / Chart.js\n     * wiring is a follow-up.\n     */\n    normalizeEncodings?: (\n        encodings: Record<string, ChartEncoding>,\n        table: any[],\n    ) => Record<string, ChartEncoding>;\n\n    /**\n     * Build the final spec from resolved encodings + layout.\n     * Runs AFTER layout computation.\n     *\n     * Receives the spec skeleton (deep clone of template),\n     * and a context with resolved encodings, semantic decisions,\n     * and layout result. Handles both encoding mapping and mark sizing.\n     *\n     * @param spec       The Vega-Lite spec skeleton (deep clone of template)\n     * @param context    Complete context with all phase outputs\n     */\n    instantiate: (\n        spec: any,\n        context: InstantiateContext,\n    ) => void;\n\n    /** Optional configurable properties for the chart type */\n    properties?: ChartPropertyDef[];\n\n    /**\n     * Opt out of a backend's *generic* column/row facet-splitting pass, even\n     * though the template declares `x`/`y` (so the axis-less `hasAxes` gate\n     * alone would not exempt it).\n     *\n     * Set by templates that build their own composite, self-contained figure\n     * — one that already spans multiple internal axis pairs / sub-panels\n     * (e.g. a Sparkline table's one-row-per-series strips, a Bar Table's\n     * bar+%+value columns) — and so handle `column`/`row` themselves inside\n     * `instantiate` rather than being pre-split into N single-facet calls\n     * whose per-panel output a generic single-axis-pair combiner (e.g. the\n     * Plotly backend's `facet.ts`) cannot correctly recombine.\n     *\n     * Currently honored by the Plotly assembler only.\n     */\n    selfManagesFacets?: boolean;\n\n    /**\n     * Optional encoding-level quick actions (Category B). Clicking one of these\n     * mutates the encodings map (the same state the encoding shelf edits),\n     * rather than chart-native config. See EncodingActionDef.\n     */\n    encodingActions?: EncodingActionDef[];\n\n    /**\n     * Optional pivot declaration — a derived Category-B operator that re-routes\n     * encoding fields across position/legend/facet channels to surface\n     * alternative views (orientation swap, series↔axis role swap, facet split).\n     * The host stores the chosen state id under `PivotDef.key` in\n     * chartProperties; the compiler enumerates + composes the permutation. See\n     * core/pivot.ts (computePivot / applyPivot).\n     */\n    pivot?: PivotDef;\n\n    /**\n     * Optional post-processing hook.\n     * Called after instantiation and layout application, before the final\n     * result is returned.  Receives the assembled spec/option and the\n     * effective canvas size so the template can adjust visual parameters\n     * (e.g. symbol size, line width) proportionally.\n     */\n    postProcess?: (\n        spec: any,\n        context: InstantiateContext,\n    ) => void;\n}\n\n// ---------------------------------------------------------------------------\n// Warnings\n// ---------------------------------------------------------------------------\n\n/** A warning produced during chart assembly */\nexport interface ChartWarning {\n    /** Warning severity */\n    severity: 'info' | 'warning' | 'error';\n    /** Short machine-readable warning code */\n    code: string;\n    /** Human-readable description */\n    message: string;\n    /** Optional: which channel(s) or field(s) triggered the warning */\n    channel?: string;\n    field?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Unified Assembly Input\n// ---------------------------------------------------------------------------\n\n/**\n * Unified input for all chart assembly functions (Vega-Lite, ECharts, Chart.js).\n *\n * Instead of passing multiple positional arguments, callers provide a single\n * JSON-serializable object with four top-level keys:\n *\n * ```ts\n * const result = assembleVegaLite({\n *   data: { values: myRows },\n *   semantic_types: { weight: 'Quantity', origin: 'Country' },\n *   chart_spec: {\n *     chartType: 'Scatter Plot',\n *     encodings: { x: { field: 'weight' }, y: { field: 'mpg' } },\n *     canvasSize: { width: 400, height: 300 },\n *   },\n *   options: { addTooltips: true },\n * });\n * ```\n */\nexport interface ChartAssemblyInput {\n    /**\n    * Data source — either inline rows or a reference the host can resolve.\n     *\n     * - `{ values: any[] }` — an array of row objects (like Vega-Lite `data.values`).\n    * - `{ url: string }`   — a URL or path reference to JSON/CSV data.\n    *   Hosts that need local semantic/layout decisions should resolve this to\n    *   rows before assembly. The MCP renderer reads local JSON/CSV/TSV\n    *   files referenced by path; it does not fetch remote URLs.\n     *\n     * At least one of `values` or `url` must be provided.\n     */\n    data: { values: any[]; url?: never } | { url: string; values?: never };\n\n    /**\n     * Per-column semantic type annotations.\n     *\n     * Maps field names to semantic type strings (e.g., `\"Quantity\"`, `\"Country\"`,\n     * `\"Year\"`, `\"Percentage\"`). These drive encoding type resolution, zero-baseline\n     * decisions, color schemes, formatting, and more.\n     *\n     * Fields not listed here fall back to `inferVisCategory()` which inspects\n     * raw data values.\n     */\n    semantic_types?: Record<string, string | SemanticAnnotation>;\n\n    /**\n     * Chart specification — describes *what* to draw.\n     */\n    chart_spec: {\n        /** Template name, e.g. `\"Scatter Plot\"`, `\"Bar Chart\"` */\n        chartType: string;\n        /** Channel → encoding map (e.g., `{ x: { field: 'weight' }, y: { field: 'mpg' } }`).\n         * A bare string is shorthand for `{ field: <string> }` (e.g. `{ x: 'weight' }`). */\n        encodings: Record<string, RawEncodingValue>;\n        /**\n         * Base (target) chart size in pixels — the size layout aims for when the\n         * data fits comfortably (default: `{ width: 400, height: 320 }`).\n         *\n         * For faceted charts this is the whole-chart target; panels divide it.\n         * The chart may grow beyond `baseSize` under pressure (dense axes, many\n         * facet panels), bounded by `canvasSize`.\n         */\n        baseSize?: { width: number; height: number };\n        /**\n         * Hard ceiling on the rendered size in pixels (optional).\n         *\n         * The final image — a single plot OR an entire facet grid — never exceeds\n         * this box. The per-dimension growth allowance is derived from the ratio\n         * to `baseSize`: `βx = canvasSize.width / baseSize.width`,\n         * `βy = canvasSize.height / baseSize.height` (each clamped to ≥ 1).\n         *\n         * When omitted, the ceiling defaults to `baseSize × options.maxStretch`\n         * (default 1.5×) in each dimension.\n         */\n        canvasSize?: { width: number; height: number };\n        /** Template-specific configurable properties (e.g., bar corner radius, show labels) */\n        chartProperties?: Record<string, any>;\n    };\n\n    /**\n     * Options for the assembler — layout tuning, tooltips, etc.\n     * All fields are optional and have sensible defaults.\n     */\n    options?: AssembleOptions;\n\n    /**\n     * Localized display names for fields (column name → display label).\n     * When present, used as axis titles and legend headers instead of raw field names.\n     */\n    field_display_names?: Record<string, string>;\n}\n\n// ---------------------------------------------------------------------------\n// Assembly Options\n// ---------------------------------------------------------------------------\n\n/**\n * Options for the chart assembly function.\n * Includes layout tuning parameters — all have sensible defaults.\n */\nexport interface AssembleOptions {\n    /** Whether to add tooltips to the chart (default: false) */\n    addTooltips?: boolean;\n    /**\n     * Fraction of each step reserved for inter-category padding (0–1).\n     * VL pads *inside* the step (band = step × (1 − padding)), so this\n     * value should match VL's paddingInner.  ECharts pads *outside* the\n     * band, so the layout engine passes this through so ECharts can\n     * compute barWidth = step × (1 − stepPadding) explicitly.\n     *\n     * Default: 0.1 (matching VL's default band paddingInner).\n     */\n    stepPadding?: number;\n    /** Power-law exponent for discrete axis stretch (default: 0.5) */\n    elasticity?: number;\n    /**\n     * Default maximum stretch multiplier used when the spec provides no\n     * explicit `canvasSize` ceiling (default: 2).\n     *\n     * This is a **unified** budget: the combined stretch from facet\n     * layout AND discrete/banded axis sizing must stay within this\n     * factor.  For example, with maxStretch=2 and a 400px base,\n     * the total chart width never exceeds 800px regardless of how\n     * many facet columns or discrete axis items there are.\n     *\n     * When `chart_spec.canvasSize` IS set, the per-dimension caps\n     * `maxStretchX`/`maxStretchY` are derived from `canvasSize / baseSize`\n     * instead and this scalar is ignored.\n     */\n    maxStretch?: number;\n    /**\n     * Resolved per-dimension stretch cap for the X (width) axis.\n     *\n     * Normally derived by the assembler from `canvasSize / baseSize`\n     * (or `maxStretch` when no ceiling is set). Callers rarely set this\n     * directly. Falls back to `maxStretch` when absent.\n     */\n    maxStretchX?: number;\n    /**\n     * Resolved per-dimension stretch cap for the Y (height) axis.\n     *\n     * Normally derived by the assembler from `canvasSize / baseSize`\n     * (or `maxStretch` when no ceiling is set). Callers rarely set this\n     * directly. Falls back to `maxStretch` when absent.\n     */\n    maxStretchY?: number;\n    /** Power-law exponent for facet subplot stretch — lower = more conservative (default: 0.3) */\n    facetElasticity?: number;\n    /** Minimum pixels per discrete axis item (default: 6) */\n    minStep?: number;\n    /** Maximum number of distinct color values before overflow truncation (default: 24) */\n    maxColorValues?: number;\n    /** Minimum facet subplot size in px (default: 60) */\n    minSubplotSize?: number;\n    /**\n     * Fixed overhead in px for axis labels, titles, legend, etc.\n     * Subtracted once from the total canvas budget (not per-panel).\n     * Each backend sets its own default; core uses { width: 0, height: 0 }.\n     */\n    facetFixedPadding?: { width: number; height: number };\n    /**\n     * Gap in px between adjacent facet panels (spacing, headers).\n     * Used directly by the core layout engine to compute subplot sizes\n     * and max canvas dimensions.\n     * Each backend sets its own value (VL ≈ 10, ECharts ≈ 14); core uses 0.\n     */\n    facetGap?: number;\n    /**\n     * Explicit number of facet COLUMNS for a column-wrapped facet, overriding\n     * the auto-computed wrap. When set (≥ 1) the layout uses this many columns\n     * (clamped to the distinct column count) and wraps the remaining panels\n     * into as many rows as needed. Surfaced to hosts as the `facetColumns`\n     * chart property so users can dial the wrap in interactively; undefined =\n     * auto (fill the width).\n     */\n    facetColumns?: number;\n    /**\n     * Base pixels per discrete category at a 300px baseline canvas.\n     * Scaled proportionally with canvas size by the core layout engine.\n     * The final default step size is:\n     *\n     *   defaultStepSize = defaultBandSize × max(1, canvasSize/300)\n     *\n     * Backends set this to match their native bar/band rendering:\n     *   - VL:  ~20 (VL uses width:{step:N} which auto-sizes the plot area)\n     *   - EC:  ~20 (ECharts adds generous grid margins)\n     *   - CJS: ~30 (Chart.js fills the canvas; wider bands look more native)\n     *\n     * Templates can override via paramOverrides for chart types that need\n     * more space per band (e.g. jitter: 40, funnel: 50, sankey: 60).\n     *\n     * Default: 20.\n     */\n    defaultBandSize?: number;\n    /**\n     * Maximum pixels per discrete category at a 300px baseline canvas,\n     * scaled proportionally with canvas size (like {@link defaultBandSize}).\n     *\n     * This is the **sparse-expansion ceiling**. When few categories share a\n     * wide plot, each band grows to fill the available width but never past\n     * `maxBandSize`, so one or two bars can't balloon to the whole canvas.\n     * The band is thus clamped to `[minStep, maxBandSize]`:\n     *\n     *   step = clamp(availableWidth / N, minStep, maxBandSize)\n     *\n     * Backends set this to match their native sparse-bar rendering:\n     *   - VL:  = defaultBandSize (VL's step-based sizing doesn't fill a container)\n     *   - EC / CJS / Plotly: much larger (these fill their plot area natively)\n     *\n     * Defaults to {@link defaultBandSize} (no expansion beyond the base band).\n     */\n    maxBandSize?: number;\n    /**\n     * Backend-native base font size (px) for axis **tick labels**, at a 300px\n     * reference canvas. The core scales it subtly with canvas size and uses it\n     * as the ceiling of the shrink→rotate→cap ladder, so a chart never renders\n     * ticks below its backend's native scale on a comfortable canvas.\n     *\n     * Learned from each renderer's defaults:\n     *   - Vega-Lite: 10   - ECharts: 12   - Chart.js: 12   - Plotly: 12\n     *\n     * Default: 10.\n     */\n    baseLabelFontSize?: number;\n    /**\n     * Backend-native base font size (px) for **headers** (axis titles, legend,\n     * chart title), at a 300px reference canvas. Scaled subtly with canvas size\n     * (grows up to +4 on large canvases, shrinks toward the base in small\n     * multiples) so headers stay proportionate to the chart.\n     *\n     * Learned from each renderer's defaults:\n     *   - Vega-Lite: 11   - ECharts: 12   - Chart.js: 12   - Plotly: 14\n     *\n     * Default: 11.\n     */\n    baseTitleFontSize?: number;\n    /**\n     * When true, continuous X and Y axes stretch together using the\n     * larger of the two per-axis stretch factors. This preserves the\n     * aspect ratio of the data space. (default: false — axes stretch\n     * independently based on their own density.)\n     */\n    maintainContinuousAxisRatio?: boolean;\n    /**\n     * Gas-pressure tuning for continuous axes (default: scatter-plot settings).\n     * - A single number overrides markCrossSection (σ) for both axes.\n     * - An object allows per-axis σ plus optional elasticity / maxStretch:\n     *   `{ x: 100, y: 0, elasticity: 0.7, maxStretch: 2 }`\n     *   x/y = 0 means \"don't stretch this axis\".\n     *   Useful for line/area charts where horizontal crowding matters\n     *   far more than vertical.\n     */\n    continuousMarkCrossSection?: number | {\n        x: number;\n        y: number;\n        /** Per-axis stretch elasticity (default: 0.3). Higher → more responsive. */\n        elasticity?: number;\n        /** Per-axis stretch cap (default: 1.5). */\n        maxStretch?: number;\n        /**\n         * Which axis uses series-count-based pressure instead of pixel counting.\n         * - 'x' or 'y': that axis uses nSeries × σ / dim for pressure.\n         * - 'auto': auto-detect — in 2D (both continuous), defaults to 'y';\n         *   in 1D (one continuous + one discrete), uses the continuous axis.\n         * The σ for the series axis is used directly (not sqrt'd) since series\n         * count is inherently 1D.\n         */\n        seriesCountAxis?: 'x' | 'y' | 'auto';\n    };\n    /**\n     * Resistance to aspect-ratio distortion when faceting.\n     *\n     * When faceting divides one dimension (e.g. width by column count),\n     * the subplot aspect ratio drifts away from the single-plot ratio.\n     * Line and area charts are very sensitive to this because their\n     * visual signal is encoded in slopes and curve shapes.\n     *\n     * This parameter partially compensates by shrinking the undivided\n     * dimension so the panel aspect ratio stays closer to the original:\n     *\n     *   arDrift = facetedAR / baseAR          (< 1 when panel is narrower)\n     *   correctedDim = dim × arDrift ^ resistance\n     *\n     * - 0 (default): no correction — current behavior.\n     * - 0.3–0.5: moderate resistance (recommended for line / area).\n     * - 1: fully preserve the single-plot aspect ratio.\n     */\n    facetAspectRatioResistance?: number;\n    /**\n     * Whether to auto-wrap column-only facets into a 2D grid.\n     *\n     * When `true` (default), `computeFacetGrid` considers wrapping N\n     * column facets into multiple rows, choosing the layout whose\n     * overall aspect ratio best matches the canvas AR.\n     *\n     * When `false`, column-only facets stay in a single row (capped\n     * at the maximum that fits the canvas budget). Useful for small\n     * multiples that should always be side-by-side.\n     */\n    autoFacetWrap?: boolean;\n    /**\n     * Target aspect ratio for a single band (step height ÷ step width).\n     *\n     * When a banded (discrete) axis is opposite a continuous axis, each\n     * band has a natural AR = continuousAxisSize / stepSize.  If that\n     * exceeds the target, the continuous axis is shrunk via a log-space\n     * blend so bands don't become excessively tall/wide.\n     *\n     * - `undefined` / 0: no band-AR correction.\n     * - Typical values: 8–15 (VL default ≈ 10, ECharts ≈ 12).\n     *\n     * Only affects charts with exactly one banded axis and one\n     * continuous axis (e.g. bar, lollipop).  Has no effect on\n     * scatter, line, or fully-banded charts.\n     */\n    targetBandAR?: number;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ChartEncoding, ChartTemplateDef } from './types';\n\n/**\n * Compose a template's encoding-action overrides onto the base encodings.\n *\n * Category-B quick options (sort, color scheme, aggregate, orientation, …) are\n * stored by the host as *configuration overrides* keyed by the action's `key`\n * inside `chartProperties` — exactly like a chart property. They are NOT written\n * into the encoding map. This function is where the compiler composes them:\n * for each `encodingAction` whose override is present, it applies the action's\n * `set(encodings, value)` to produce the transformed encodings that feed the\n * rest of assembly.\n *\n * Backends call this once, at the very top of `assemble`, so every downstream\n * phase (semantic resolution → overflow → layout → instantiate) — and the\n * `InstantiateContext.encodings` handed to templates — sees the transformed\n * encodings. The base `encodings` argument is never mutated.\n *\n * An absent override (`undefined`) means \"no override\" and is skipped, so the\n * base encoding value (whatever the encoding shelf set, if anything) stands.\n * Because the override key matches the action key, charts saved before this\n * mechanism — which stored e.g. `chartProperties.colorScheme` directly — are\n * picked up automatically with no separate legacy fallback.\n */\nexport function applyEncodingOverrides(\n    template: ChartTemplateDef,\n    encodings: Record<string, ChartEncoding>,\n    chartProperties?: Record<string, any>,\n): Record<string, ChartEncoding> {\n    const actions = template.encodingActions;\n    if (!actions || actions.length === 0 || !chartProperties) return encodings;\n\n    let result = encodings;\n    for (const action of actions) {\n        const override = chartProperties[action.key];\n        if (override !== undefined) {\n            result = action.set(result, override);\n        }\n    }\n    return result;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Central chart-type **transition registry** — the θ graph.\n *\n * This is the single source of truth for which sibling chart types a given chart\n * can re-render as (Control B / `θ` in the two-control transform model). It\n * replaces the per-template, per-backend inline `transitions` arrays: a chart\n * template no longer declares what it can turn into — the compiler looks the\n * edges up here by chart-type display name.\n *\n * Design notes (design-docs/chart-transform-two-axes.md §4, and the \"registry\"\n * discussion):\n *   - Edges are keyed by the *authored* chart type's display name.\n *   - Each edge is a CANDIDATE. It is still gated at runtime against the live\n *     encoding + data (route feasibility + the declarative gates on\n *     `PivotTransition`: requireOrderedAxis / requireNonNegative /\n *     maxCategoryCardinality / requireNoSeries / requireDiscreteSource /\n *     maxSourceCardinality) AND against backend availability (an edge is hidden\n *     when the target template does not exist in the active backend's registry).\n *   - So \"not all mappings make sense\" is handled twice: only sensible edges are\n *     declared here (the §4 catalog), and even a declared edge is withheld when\n *     the data / backend does not support it.\n *   - Edges should be *reversible*: if A → B is declared, B → A generally should\n *     be too (verified by tests), so a transform round-trips home.\n *\n * Grouped by data-signature family (design doc §4).\n */\n\nimport { PivotTransition } from './types';\n\nexport const CHART_TRANSITIONS: Record<string, PivotTransition[]> = {\n    // ── Categorical comparison — D × M (§4.1) ──────────────────────────────\n    'Bar Chart': [\n        // Ordered-axis bridge into the trend family (§4.9). Only when the domain\n        // axis is temporal/ordinal — an unordered nominal bar never sprouts a line.\n        // orientDomainAxis:'x' re-orients a horizontal bar so time stays horizontal.\n        { to: 'Line Chart', label: 'Line', requireOrderedAxis: true, orientDomainAxis: 'x' },\n        { to: 'Area Chart', label: 'Area', requireOrderedAxis: true, requireNonNegative: true, orientDomainAxis: 'x' },\n        // Same D×M signature, lighter ink.\n        { to: 'Lollipop Chart', label: 'Lollipop' },\n    ],\n    'Lollipop Chart': [\n        { to: 'Bar Chart', label: 'Bar' },\n    ],\n    'Grouped Bar Chart': [\n        {\n            to: 'Stacked Bar Chart',\n            label: 'Stacked',\n            route: { from: 'group', to: 'color', mode: 'move' },\n            requireDiscreteSource: true,\n        },\n        // A 2-sided grouped bar reads as a population pyramid (mirrored).\n        {\n            to: 'Pyramid Chart',\n            label: 'Pyramid',\n            route: { from: 'group', to: 'color', mode: 'move' },\n            requireDiscreteSource: true,\n            maxSourceCardinality: 2,\n        },\n    ],\n    'Stacked Bar Chart': [\n        {\n            to: 'Grouped Bar Chart',\n            label: 'Grouped',\n            route: { from: 'color', to: 'group', mode: 'move' },\n            requireDiscreteSource: true,\n            maxSourceCardinality: 12,\n        },\n    ],\n    // Population pyramid = a 2-sided category × measure; its complement is the\n    // side-by-side grouped bar (the 2 sides dodged instead of mirrored).\n    'Pyramid Chart': [\n        {\n            to: 'Grouped Bar Chart',\n            label: 'Grouped',\n            route: { from: 'color', to: 'group', mode: 'move' },\n            requireDiscreteSource: true,\n        },\n    ],\n\n    // ── Trend over an ordered domain — T × M (§4.2) ────────────────────────\n    'Line Chart': [\n        { to: 'Area Chart', label: 'Area', requireNonNegative: true },\n        // Back to discrete-period comparison; only readable with few ticks.\n        { to: 'Bar Chart', label: 'Bar', maxCategoryCardinality: 30 },\n        // Small-multiple trend strips (one per series) — needs a series. Route\n        // the series onto `color` (from wherever it sits — color OR a column/row\n        // facet) so the Sparkline template picks it up as its row series.\n        { to: 'Sparkline', label: 'Sparklines', requireSeries: true, route: { from: 'series', to: 'color', mode: 'move' } },\n    ],\n    'Area Chart': [\n        { to: 'Line Chart', label: 'Line' },\n        { to: 'Bar Chart', label: 'Bar', maxCategoryCardinality: 30 },\n        { to: 'Streamgraph', label: 'Stream', requireSeries: true, requireNonNegative: true, route: { from: 'series', to: 'color', mode: 'move' } },\n    ],\n    // Small-multiple trend table → a single overlaid multi-series line.\n    'Sparkline': [\n        { to: 'Line Chart', label: 'Line' },\n    ],\n    // Flowing composition → back to baseline-anchored trend / area. Both reads\n    // are safe; note Streamgraph → Line is intentionally *one-directional* (there\n    // is no Line → Streamgraph — see the note above).\n    'Streamgraph': [\n        { to: 'Area Chart', label: 'Area' },\n        { to: 'Line Chart', label: 'Line' },\n    ],\n\n    // ── Two-measure relationship — M₁ × M₂ (§4.3) ──────────────────────────\n    'Scatter Plot': [\n        {\n            to: 'Strip Plot',\n            label: 'Jitter',\n            route: { from: 'series', to: 'x', mode: 'swap', spill: 'color' },\n        },\n        // Add a fitted trend layer over the same cloud — only a clean\n        // two-measure scatter (both axes quantitative, no size bubble).\n        { to: 'Regression', label: 'Trend', requireBiaxialMeasure: true, requireNoSize: true },\n    ],\n    'Regression': [\n        { to: 'Scatter Plot', label: 'Scatter' },\n    ],\n    'Strip Plot': [\n        {\n            to: 'Scatter Plot',\n            label: 'Scatter',\n            route: { from: 'color', to: 'x', mode: 'swap', spill: 'color' },\n        },\n        // A strip plot is a per-category distribution: box (summary) + violin\n        // (density) are the same {x:category, y:measure} layout, no route.\n        { to: 'Boxplot', label: 'Box' },\n        { to: 'Violin Plot', label: 'Violin' },\n    ],\n\n    // ── Univariate distribution — M (§4.4) ─────────────────────────────────\n    'Histogram': [\n        { to: 'Density Plot', label: 'Density' },\n        { to: 'ECDF Plot', label: 'ECDF' },\n    ],\n    'Density Plot': [\n        { to: 'Histogram', label: 'Histogram' },\n        { to: 'ECDF Plot', label: 'ECDF' },\n    ],\n    'ECDF Plot': [\n        { to: 'Histogram', label: 'Histogram' },\n        { to: 'Density Plot', label: 'Density' },\n    ],\n    'Boxplot': [\n        { to: 'Violin Plot', label: 'Violin' },\n        { to: 'Strip Plot', label: 'Strip' },\n    ],\n    'Violin Plot': [\n        { to: 'Boxplot', label: 'Box' },\n        { to: 'Strip Plot', label: 'Strip' },\n    ],\n};\n\n/**\n * Look up the candidate θ transitions for a chart type (by display name).\n * Returns an empty array when the chart declares none.\n */\nexport function getChartTransitions(chart: string | undefined): PivotTransition[] {\n    if (!chart) return [];\n    return CHART_TRANSITIONS[chart] ?? [];\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Chart pivot — a derived Category-B operator that re-routes encoding *fields*\n * across position/legend/facet *channels* to surface alternative views of the\n * same semantic spec (orientation swap, series↔axis role swap, facet split).\n *\n * The host stores the chosen pivot *state id* as a single override keyed by\n * `PivotDef.key` (default `'pivot'`) inside `chart_spec.chartProperties`, exactly\n * like any other encoding action. The compiler — not the host — owns the channel\n * permutation: at assemble time it enumerates the valid states for the current\n * encodings + data, picks the stored id (falling back to the identity state when\n * the id is stale or absent), and composes the resulting encoding map BEFORE the\n * rest of the pipeline runs (so sort/overflow/layout all resolve post-pivot).\n *\n * This module is intentionally backend-agnostic: it operates purely on the\n * abstract `ChartEncoding` map + the raw data table, so the same enumeration\n * drives Vega-Lite, ECharts and Chart.js.\n *\n * MVP linearization. The full design models the pivot states as the orbit of a\n * channel-permutation group, linearized by a Gray code so adjacent steps differ\n * by one generator. This first increment exposes a curated *star* of single-\n * generator views around the authored identity (identity → orientation → role →\n * facet), which is a valid finite cycle (Z/n over the ordered list) that always\n * returns to the authored view. Richer products land later.\n *\n * Role-swap has two type-preserving flavors: discrete↔color-hue (a category\n * moves between a banded axis and the legend — bars/lines) and, on position\n * marks only, measure↔(color-gradient | size) (a quantitative field moves\n * between a precise position axis and a demoted auxiliary channel — scatter).\n *\n * Two distinct group actions drive the channel moves, matching the design doc:\n *   - τ (transpose): flip two axis *slots* wholesale (`x↔y` orientation). Profile-\n *     agnostic, always occupancy-preserving — declared via `PivotDef.transpose`.\n *   - σ (permute): reassign a *field* to a same-profile channel (axis ↔ color/size)\n *     — declared via `PivotDef.permute`, admitted by the Young-block profile rule.\n * Keeping them separate is what lets the must-present guard drop out entirely.\n */\n\nimport { ChartEncoding, ChartTemplateDef, PivotDef, PivotTransition } from './types';\nimport { getChartTransitions } from './chart-transitions';\n\n/** Resolved pivot surface attached to the assembled spec as `_pivot`. */\nexport interface PivotSurface {\n    key: string;\n    label: string;\n    /** Number of states in the cycle (>= 2 when a control should show). */\n    length: number;\n    /** Index of the active state within `ids`. */\n    index: number;\n    /** Ordered state ids; `ids[0]` is always the identity (authored) view. */\n    ids: string[];\n    /** Parallel human labels for each state. */\n    labels: string[];\n}\n\n/** A redundant identity encoding added by a local Arrange operator. */\nexport interface EncodingAugmentation {\n    kind: 'facet-identity';\n    sourceChannel: 'color' | 'group';\n    facetChannel: 'column' | 'row';\n    colorEncoding: ChartEncoding;\n}\n\n/** Internal: a fully enumerated pivot for a given encoding map + data. */\nexport interface PivotComputation {\n    key: string;\n    label: string;\n    ids: string[];\n    labels: string[];\n    statesById: Record<string, Record<string, ChartEncoding>>;\n    augmentationById: Record<string, EncodingAugmentation | undefined>;\n    /**\n     * Chart-type override per state id, set only for chart-type *transition*\n     * states (§4.6). Absent/undefined entries render with the authored template.\n     */\n    chartTypeById: Record<string, string | undefined>;\n}\n\nconst DISCRETE_TYPES = new Set(['nominal', 'ordinal']);\n\nfunction isDiscrete(enc: ChartEncoding | undefined): boolean {\n    return !!enc?.field && !!enc.type && DISCRETE_TYPES.has(enc.type);\n}\n\nfunction isMeasure(enc: ChartEncoding | undefined): boolean {\n    return !!enc?.field && (enc.type === 'quantitative' || !!enc.aggregate);\n}\n\nfunction isTemporal(enc: ChartEncoding | undefined): boolean {\n    return enc?.type === 'temporal';\n}\n\n/**\n * Whether a temporal position axis is rendered as discrete *bands* (so it acts\n * as a category for pivot purposes) rather than a continuous time scale. Length\n * marks (bars/histograms) and color marks (heatmaps) band their categorical\n * axis; only position marks (line/area/scatter) lay time out continuously, where\n * \"time stays horizontal\" is the convention we preserve.\n */\nfunction temporalActsDiscrete(template: ChartTemplateDef): boolean {\n    return template.markCognitiveChannel !== 'position';\n}\n\nfunction clone(encodings: Record<string, ChartEncoding>): Record<string, ChartEncoding> {\n    const out: Record<string, ChartEncoding> = {};\n    for (const [ch, enc] of Object.entries(encodings)) {\n        out[ch] = { ...enc };\n    }\n    return out;\n}\n\nfunction distinctCount(data: any[], field: string | undefined): number {\n    if (!field || !Array.isArray(data)) return 0;\n    const seen = new Set<unknown>();\n    for (const row of data) {\n        if (row && row[field] != null) seen.add(row[field]);\n    }\n    return seen.size;\n}\n\n/** Build the standard cartesian pivot declaration from its permissible domains. */\nexport function makeCartesianPivot(opts: Partial<PivotDef> = {}): PivotDef {\n    return {\n        key: opts.key ?? 'pivot',\n        label: opts.label ?? 'View',\n        transpose: opts.transpose ?? [],\n        permute: opts.permute ?? [],\n        shift: opts.shift ?? [],\n        facetBudget: opts.facetBudget ?? 12,\n        transitions: opts.transitions,\n    };\n}\n\n/**\n * Canonical channel order so a swap pair has a stable id/label regardless of the\n * order it was declared in (e.g. `['color','x']` is normalized to `x ↔ color`).\n */\nconst CHANNEL_ORDER = ['x', 'y', 'color', 'size', 'group', 'column', 'row'];\nfunction orderPair(a: string, b: string): [string, string] {\n    const ia = CHANNEL_ORDER.indexOf(a);\n    const ib = CHANNEL_ORDER.indexOf(b);\n    return (ia <= ib ? [a, b] : [b, a]) as [string, string];\n}\n\n/**\n * Human-friendly channel names for the arrange labels shown in the UI (the\n * dropdown/switcher). Keeps the stored *ids* untouched — only the display text.\n */\nconst CHANNEL_DISPLAY: Record<string, string> = {\n    x: 'X',\n    y: 'Y',\n    color: 'Color',\n    size: 'Size',\n    group: 'Groups',\n    column: 'Columns',\n    row: 'Rows',\n    detail: 'Detail',\n    opacity: 'Opacity',\n};\nfunction chDisplay(ch: string): string {\n    return CHANNEL_DISPLAY[ch] ?? ch.charAt(0).toUpperCase() + ch.slice(1);\n}\n\n/** The set of channels whose bound field differs between two encodings. */\nfunction changedChannels(\n    a: Record<string, ChartEncoding>,\n    b: Record<string, ChartEncoding>,\n): Set<string> {\n    const out = new Set<string>();\n    for (const ch of new Set([...Object.keys(a), ...Object.keys(b)])) {\n        if (a[ch]?.field !== b[ch]?.field) out.add(ch);\n    }\n    return out;\n}\n\n/**\n * Transpose generator (τ): exchange two axis *slots* wholesale (`x↔y`). This is\n * the orientation/flip — it carries each channel's full encoding to the other,\n * so it is profile-agnostic (category↔measure on a bar, measure↔measure on a\n * scatter, dimension↔dimension on a heatmap). It is suppressed only when a\n * continuous-temporal position axis must stay horizontal (line/area keep time on\n * `x`). Because both slots stay occupied it can never drop a required channel.\n * Returns `null` when either slot is unbound or the temporal-horizontal rule\n * blocks the flip.\n */\nfunction transposeState(\n    base: Record<string, ChartEncoding>,\n    template: ChartTemplateDef,\n    pair: [string, string],\n): { id: string; label: string; enc: Record<string, ChartEncoding> } | null {\n    const [a, b] = orderPair(pair[0], pair[1]);\n    const ea = base[a];\n    const eb = base[b];\n    if (!ea?.field || !eb?.field) return null; // both slots must be bound\n    // Keep a continuous-temporal axis horizontal (no vertical time on position marks).\n    if (!temporalActsDiscrete(template) && (isTemporal(ea) || isTemporal(eb))) return null;\n    const next = clone(base);\n    next[a] = { ...eb };\n    next[b] = { ...ea };\n    return { id: `flip:${a}-${b}`, label: `${chDisplay(a)} ⇄ ${chDisplay(b)}`, enc: next };\n}\n\ntype ChannelProfile = 'measure' | 'category' | 'time';\n\n/**\n * The profile a bound field presents on a channel: `measure` (quantitative or\n * aggregated), `category` (discrete, or a temporal axis the chart bands), or\n * `time` (continuous temporal). Two channels may exchange fields under {@link\n * permuteSwapState} only when their profiles match — the Young-block rule.\n */\nfunction channelProfile(enc: ChartEncoding | undefined, template: ChartTemplateDef): ChannelProfile | null {\n    if (!enc?.field) return null;\n    if (isMeasure(enc)) return 'measure';\n    if (isDiscrete(enc) || (isTemporal(enc) && temporalActsDiscrete(template))) return 'category';\n    return 'time';\n}\n\n/**\n * Permute generator (σ): reassign a field between a position *axis* and an\n * *auxiliary* channel (`color`/`size`), admitting the swap only when both ends\n * share a {@link channelProfile} — the Young-block rule. This single predicate\n * subsumes the old measure↔measure and category↔color cases:\n *   - `measure` profile: position marks only (a bar's length-measure is privileged\n *     and never demotes to color/size); the peer quantities trade the precise axis.\n *   - `category` profile: the auxiliary must be `color` (only it carries a discrete\n *     series); the banded axis dimension and the legend series exchange places.\n * `x↔y` is handled by {@link transposeState}, not here, and pure auxiliary pairs\n * (`color↔size`) are never offered. No must-present guard is needed: both ends are\n * already bound, so the swap preserves occupancy by construction.\n * Returns `null` when no profile-preserving interpretation admits the pair.\n */\nfunction permuteSwapState(\n    base: Record<string, ChartEncoding>,\n    template: ChartTemplateDef,\n    pair: [string, string],\n): { id: string; label: string; enc: Record<string, ChartEncoding> } | null {\n    const [a, b] = orderPair(pair[0], pair[1]);\n    // Canonical ordering keeps a position axis as `a`; the auxiliary is `b`.\n    const posCh = a === 'x' || a === 'y' ? a : null;\n    const auxCh = b;\n    if (!posCh || (auxCh !== 'color' && auxCh !== 'size')) return null;\n    const posEnc = base[posCh];\n    const auxEnc = base[auxCh];\n    if (!posEnc?.field || !auxEnc?.field) return null; // both ends must be bound\n    if (posEnc.field === auxEnc.field) return null;\n\n    const profile = channelProfile(posEnc, template);\n    if (!profile || profile !== channelProfile(auxEnc, template)) return null; // different profile\n\n    const id = `swap:${a}-${b}`;\n    const label = `${chDisplay(a)} ⇄ ${chDisplay(b)}`;\n\n    if (profile === 'measure') {\n        // Demoting a measure to an aux channel only reads on position marks; on a\n        // length mark (bar) the value axis is privileged. Carry only the semantic\n        // core so downstream assembly re-derives scales/schemes per channel.\n        if (template.markCognitiveChannel !== 'position') return null;\n        const next = clone(base);\n        next[posCh] = measureCore(auxEnc);\n        next[auxCh] = measureCore(posEnc);\n        return { id, label, enc: next };\n    }\n\n    if (profile === 'category') {\n        // Only `color` carries a discrete series to exchange with a banded axis.\n        if (auxCh !== 'color') return null;\n        const next = clone(base);\n        next[posCh] = { ...auxEnc };\n        next.color = { ...posEnc };\n        return { id, label, enc: next };\n    }\n\n    return null; // continuous time does not demote to an auxiliary channel\n}\nfunction measureCore(enc: ChartEncoding): ChartEncoding {\n    const core: ChartEncoding = { field: enc.field, type: enc.type };\n    if (enc.aggregate) core.aggregate = enc.aggregate;\n    return core;\n}\n\n/**\n * Default grouping channels a discrete *series* field can occupy, used to locate\n * the current series when a transition references the `'series'` sentinel. The\n * shiftable domain offered to the user is the template's declared `shift` list\n * (filtered against these semantics); this constant is the resolution fallback.\n */\nconst GROUPING_CHANNELS = ['color', 'group', 'column', 'row'];\n\n/** Per-target budgets: facets allow more panels than a color/dodge legend. */\nfunction routeBudget(target: string, facetBudget: number): number {\n    if (target === 'column' || target === 'row') return facetBudget;\n    if (target === 'group') return 12; // dodged sub-bars get cramped past ~12\n    return 20; // color legend\n}\n\n/** Operator label for routing the series from its current channel onto another. */\nfunction routeLabel(from: string, to: string): string {\n    return `${chDisplay(from)} ⇄ ${chDisplay(to)}`;\n}\n\n/** Locate a discrete series for chart-type transition routing. */\nfunction findTransitionSeries(\n    base: Record<string, ChartEncoding>,\n    candidates: string[],\n    channels: string[],\n): { channel: string; enc: ChartEncoding } | null {\n    for (const channel of candidates) {\n        if (channels.includes(channel) && isDiscrete(base[channel])) {\n            return { channel, enc: base[channel]! };\n        }\n    }\n    return null;\n}\n\n/**\n * Identity channels augment onto empty facets; facet channels shift normally.\n * Keeping the sources independent avoids destructive color-to-facet moves and\n * lets a chart with both color and column offer two distinct row alternatives.\n */\nfunction seriesRoutingStates(\n    base: Record<string, ChartEncoding>,\n    template: ChartTemplateDef,\n    data: any[],\n    shiftChannels: string[],\n    facetBudget: number,\n    preferredFacet?: 'column' | 'row',\n): { id: string; enc: Record<string, ChartEncoding>; label: string; augmentation?: EncodingAugmentation }[] {\n    const channels = template.channels ?? [];\n    const out: { id: string; enc: Record<string, ChartEncoding>; label: string; augmentation?: EncodingAugmentation }[] = [];\n\n    const identitySource: 'color' | 'group' | undefined = isDiscrete(base.color)\n        ? 'color'\n        : (!base.color?.field && isDiscrete(base.group) ? 'group' : undefined);\n    if (identitySource && shiftChannels.includes(identitySource) && channels.includes(identitySource)) {\n        const identityEncoding = base[identitySource]!;\n        const card = distinctCount(data, identityEncoding.field);\n        const facetTargets = preferredFacet ? [preferredFacet] : ['column', 'row'] as const;\n        for (const target of facetTargets) {\n            if (!shiftChannels.includes(target) || !channels.includes(target)) continue;\n            if (base[target]?.field || card > routeBudget(target, facetBudget)) continue;\n            const next = clone(base);\n            delete next[identitySource];\n            next[target] = { ...identityEncoding };\n            out.push({\n                id: `augment:${target}`,\n                enc: next,\n                label: `Color + ${chDisplay(target)}`,\n                augmentation: {\n                    kind: 'facet-identity',\n                    sourceChannel: identitySource,\n                    facetChannel: target,\n                    colorEncoding: { ...identityEncoding },\n                },\n            });\n        }\n    }\n\n    const facetSource = (['column', 'row'] as const).find(channel =>\n        shiftChannels.includes(channel) && channels.includes(channel) && isDiscrete(base[channel]),\n    );\n    if (facetSource) {\n        const facetEncoding = base[facetSource]!;\n        const card = distinctCount(data, facetEncoding.field);\n        for (const target of shiftChannels) {\n            if (target === facetSource || target === 'group') continue;\n            if ((target === 'column' || target === 'row') && preferredFacet && target !== preferredFacet) continue;\n            if (!channels.includes(target) || base[target]?.field) continue;\n            if (card > routeBudget(target, facetBudget)) continue;\n            const next = clone(base);\n            delete next[facetSource];\n            next[target] = { ...facetEncoding };\n            out.push({ id: `series:${target}`, enc: next, label: routeLabel(facetSource, target) });\n        }\n    }\n    return out;\n}\n\n/** Preferred small-multiple direction for the compact dynamic Arrange surface. */\nfunction preferredFacetTarget(base: Record<string, ChartEncoding>): 'column' | 'row' {\n    const domain = domainAxisEnc(base);\n    return domain === base.y ? 'row' : 'column';\n}\n\n/** Facet channel newly targeted by a composed transformation, if any. */\nfunction changedFacetTarget(\n    authored: Record<string, ChartEncoding>,\n    transformed: Record<string, ChartEncoding>,\n): 'column' | 'row' | undefined {\n    for (const channel of ['column', 'row'] as const) {\n        if (transformed[channel]?.field && transformed[channel]?.field !== authored[channel]?.field) {\n            return channel;\n        }\n    }\n    return undefined;\n}\n\n/**\n * The *domain* position axis encoding — the non-measure x/y (a category/time\n * axis). Prefers whichever position channel is not a measure.\n */\nfunction domainAxisEnc(base: Record<string, ChartEncoding>): ChartEncoding | undefined {\n    if (base.x?.field && !isMeasure(base.x)) return base.x;\n    if (base.y?.field && !isMeasure(base.y)) return base.y;\n    return undefined;\n}\n\n/** The *measure* position axis encoding — the quantitative/aggregated x/y. */\nfunction measureAxisEnc(base: Record<string, ChartEncoding>): ChartEncoding | undefined {\n    if (base.x?.field && isMeasure(base.x)) return base.x;\n    if (base.y?.field && isMeasure(base.y)) return base.y;\n    return undefined;\n}\n\n/**\n * Evaluate a transition's declarative *data-characteristic* gates against the\n * authored encoding + data (design-docs/chart-transform-two-axes.md §4.9.3).\n * These are the \"not all mappings make sense\" guards: a candidate edge is only\n * offered when the shared fields actually support the sibling's reading.\n */\nfunction transitionGatesPass(\n    base: Record<string, ChartEncoding>,\n    data: any[],\n    t: PivotTransition,\n): boolean {\n    if (t.requireOrderedAxis) {\n        const domain = domainAxisEnc(base);\n        // Ordered = temporal or ordinal; plain nominal never qualifies.\n        if (!domain || !(domain.type === 'temporal' || domain.type === 'ordinal')) return false;\n    }\n    if (t.requireNonNegative) {\n        const measure = measureAxisEnc(base);\n        if (measure?.field) {\n            for (const row of data) {\n                const v = row?.[measure.field];\n                if (typeof v === 'number' && v < 0) return false;\n            }\n        }\n    }\n    if (t.maxCategoryCardinality != null) {\n        const domain = domainAxisEnc(base);\n        if (domain?.field && distinctCount(data, domain.field) > t.maxCategoryCardinality) return false;\n    }\n    if (t.requireNoSeries) {\n        for (const ch of GROUPING_CHANNELS) {\n            if (isDiscrete(base[ch])) return false;\n        }\n    }\n    if (t.requireSeries) {\n        const seriesChannels = ['color', 'group', 'detail', 'column', 'row'];\n        if (!seriesChannels.some((ch) => isDiscrete(base[ch]))) return false;\n    }\n    if (t.requireBiaxialMeasure) {\n        if (!isMeasure(base.x) || !isMeasure(base.y)) return false;\n    }\n    if (t.requireNoSize) {\n        if (base.size?.field) return false;\n    }\n    return true;\n}\n\n/**\n * Build the encoding map for a chart-type *transition* (§4.6). A transition\n * re-views the same data as a sibling chart type, optionally re-routing one\n * field across channels first. Returns `null` when the transition's constraints\n * (source presence, discreteness, cardinality budget, target occupancy) are not\n * met. The `chartType` it returns tells the compiler to re-select the sibling\n * template for rendering while the authored chartType / encodings stay intact.\n */\nfunction transitionState(\n    base: Record<string, ChartEncoding>,\n    data: any[],\n    template: ChartTemplateDef,\n    t: PivotTransition,\n): { enc: Record<string, ChartEncoding>; chartType: string; label: string } | null {\n    if (!transitionGatesPass(base, data, t)) return null;\n    const enc = clone(base);\n    const route = t.route;\n    if (route) {\n        // Resolve the source channel. `'series'` finds the discrete grouping\n        // field wherever it sits (color/column/row); a literal name is used as-is.\n        const fromCh = route.from === 'series'\n            ? findTransitionSeries(base, GROUPING_CHANNELS, template.channels ?? [])?.channel\n            : route.from;\n        if (!fromCh) return null;\n        const srcEnc = base[fromCh];\n        if (!srcEnc?.field) return null; // nothing to re-route\n        if (t.requireDiscreteSource && !isDiscrete(srcEnc)) return null;\n        if (t.maxSourceCardinality != null &&\n            distinctCount(data, srcEnc.field) > t.maxSourceCardinality) return null;\n        const mode = route.mode ?? 'move';\n        const dstEnc = base[route.to];\n        if (mode === 'swap') {\n            // The source field takes the target channel; the field displaced from\n            // the target spills to `spill` (default: the vacated source channel).\n            const spillCh = route.spill ?? fromCh;\n            // Don't clobber an unrelated field already sitting on the spill slot.\n            if (spillCh !== fromCh && base[spillCh]?.field) return null;\n            enc[route.to] = { ...srcEnc };\n            delete enc[fromCh];\n            if (dstEnc?.field) enc[spillCh] = { ...dstEnc };\n            else delete enc[spillCh];\n        } else {\n            // move: bring the source field onto the target channel. If it is\n            // already there (from === to, e.g. `series` resolved to the target),\n            // it's a no-op; otherwise the target must be empty so we don't clobber.\n            if (fromCh !== route.to) {\n                if (dstEnc?.field) return null;\n                delete enc[fromCh];\n                enc[route.to] = { ...srcEnc };\n            }\n        }\n    }\n    // Re-orient the domain axis for the sibling if requested (bar → line/area):\n    // a horizontal bar carries the ordered/temporal domain on `y`, but a line\n    // pins it to the horizontal — swap x/y wholesale so we never render a\n    // vertical line chart.\n    if (t.orientDomainAxis) {\n        const target = t.orientDomainAxis;\n        const other = target === 'x' ? 'y' : 'x';\n        const domainOnOther = !!enc[other]?.field && !isMeasure(enc[other]);\n        const targetFreeForDomain = !enc[target]?.field || isMeasure(enc[target]);\n        if (domainOnOther && targetFreeForDomain) {\n            const a = enc[target];\n            const b = enc[other];\n            if (b) enc[target] = { ...b }; else delete enc[target];\n            if (a) enc[other] = { ...a }; else delete enc[other];\n        }\n    }\n    return { enc, chartType: t.to, label: t.label };\n}\n\n/**\n * A single applied generator (one step / one \"delta\"): the abstract operator\n * δ ∈ {σ, γ, θ} re-expressed as a concrete neighbor of a given encoding under a\n * given template. `id` is the step token used to build composite path ids,\n * `label` is its operator notation, and `chartType` is set only for θ steps.\n */\ninterface PivotStep {\n    id: string;\n    label: string;\n    enc: Record<string, ChartEncoding>;\n    chartType?: string;\n    augmentation?: EncodingAugmentation;\n}\n\n/**\n * Enumerate the *one-step* neighbors of an encoding under a template's pivot\n * def — the generators δ applicable to `enc` right now. This is the building\n * block of the runtime orbit walk: the same enumerator runs on every reachable\n * state, so composing transforms is just \"apply one more δ\". The generators are\n * pure functions of the passed encoding (not the authored base), which is what\n * lets γ∘σ, σ∘θ, … fall out without any special-casing.\n */\nfunction pivotSteps(\n    template: ChartTemplateDef,\n    enc: Record<string, ChartEncoding>,\n    data: any[],\n    opts?: { local?: boolean; transitions?: boolean; preferFacetTarget?: boolean },\n    resolveTemplate?: (chartType: string) => ChartTemplateDef | undefined,\n): PivotStep[] {\n    const def = template.pivot;\n    if (!def) return [];\n    const includeLocal = opts?.local !== false;\n    const includeTransitions = opts?.transitions !== false;\n    const steps: PivotStep[] = [];\n    // τ: each declared axis-slot pair contributes its wholesale flip (orientation).\n    if (includeLocal) for (const pair of def.transpose ?? []) {\n        if (pair.length !== 2) continue;\n        const s = transposeState(enc, template, [pair[0], pair[1]]);\n        if (s) steps.push({ id: s.id, label: s.label, enc: s.enc });\n    }\n    // σ: each permutable block contributes its within-block axis↔aux field swaps as\n    // candidate one-step moves; the orbit BFS composes them to close the block's\n    // symmetric group. Profile-mismatched pairs return null and are dropped.\n    if (includeLocal) for (const block of def.permute ?? []) {\n        for (let i = 0; i < block.length; i++) {\n            for (let j = i + 1; j < block.length; j++) {\n                const s = permuteSwapState(enc, template, [block[i], block[j]]);\n                if (s) steps.push({ id: s.id, label: s.label, enc: s.enc });\n            }\n        }\n    }\n    if (includeLocal && def.shift && def.shift.length) {\n        const preferredFacet = opts?.preferFacetTarget ? preferredFacetTarget(enc) : undefined;\n        for (const s of seriesRoutingStates(enc, template, data, def.shift, def.facetBudget ?? 12, preferredFacet)) {\n            steps.push({ id: s.id, label: s.label, enc: s.enc, augmentation: s.augmentation });\n        }\n    }\n    // θ: chart-type transitions are sourced from the CENTRAL registry (keyed by\n    // the template's chart name), not the template itself — a template no longer\n    // declares what it can turn into. A candidate edge is emitted only when its\n    // target template exists in the active backend (via `resolveTemplate`, when\n    // supplied); the per-edge data gates run inside transitionState.\n    if (includeTransitions) {\n        for (const t of getChartTransitions(template.chart)) {\n            if (resolveTemplate && !resolveTemplate(t.to)) continue; // backend can't render it\n            const st = transitionState(enc, data, template, t);\n            // Operator notation: θ = chart-type transition, subscripted by the target view.\n            if (st) steps.push({ id: `type:${t.to}`, label: `θ_→${t.label.toLowerCase()}`, enc: st.enc, chartType: st.chartType });\n        }\n    }\n    return steps;\n}\n\n/**\n * Canonical fingerprint of an encoding map (+ effective chart type) used to\n * dedup orbit states. Two paths that land on the same channel→field assignment\n * collapse to one state — this is the group *stabilizer* quotient (e.g. σ∘σ = id\n * folds back onto `default`; faceting then jittering reaches the same strip plot\n * as jittering directly). Only the semantic core (field/type/aggregate) and the\n * occupied channel set matter; cosmetic encoding props are ignored.\n */\nfunction encodingKey(enc: Record<string, ChartEncoding>, chartType: string | undefined): string {\n    const cells = Object.keys(enc)\n        .filter((ch) => enc[ch]?.field)\n        .sort()\n        .map((ch) => {\n            const e = enc[ch];\n            return `${ch}=${e.field}/${e.type ?? ''}/${e.aggregate ?? ''}`;\n        });\n    return `${chartType ?? ''}::${cells.join(',')}`;\n}\n\n/**\n * Reject orbit states that would be structurally invalid for their (effective)\n * template — primarily the cartesian invariant that a chart with both `x` and\n * `y` channels must keep *both* position axes bound (a scatter/line/bar with a\n * missing x or y is not a renderable view). This guards composed paths from\n * walking into degenerate encodings even if an individual generator is locally\n * type-preserving.\n */\nfunction isRenderableState(template: ChartTemplateDef, enc: Record<string, ChartEncoding>): boolean {\n    const channels = template.channels ?? [];\n    if (channels.includes('x') && channels.includes('y')) {\n        if (!enc.x?.field || !enc.y?.field) return false;\n    }\n    return true;\n}\n\n/** Hard cap on orbit size so a rich generator set can't produce an unwieldy control. */\nconst MAX_PIVOT_STATES = 12;\n\n/**\n * Enumerate the pivot states for an encoding map + data under a template's\n * `PivotDef` by walking the *orbit* of the generators at runtime: start from the\n * authored identity and repeatedly apply one more δ (breadth-first), deduping by\n * {@link encodingKey} (the stabilizer quotient) and rejecting non-renderable\n * states (see {@link isRenderableState}). State ids are operator *paths* (e.g.\n * `orient|series:row`, `type:Strip Plot`); labels compose the per-step operator\n * notation with `·`. Returns `null` when no template pivot is declared. The\n * identity (authored) view is always state 0; a control should only render when\n * `ids.length > 1`.\n *\n * `resolveTemplate` lets the walk cross θ (chart-type) edges: after a transition\n * switches `chartType`, subsequent generators come from the *target* template's\n * pivot def. Backends that omit it leave θ states as leaves (no composition past\n * a chart-type change).\n */\nexport function computePivot(\n    template: ChartTemplateDef,\n    base: Record<string, ChartEncoding>,\n    data: any[],\n    resolveTemplate?: (chartType: string) => ChartTemplateDef | undefined,\n    opts?: { includeTransitions?: boolean; key?: string; label?: string; preferFacetTarget?: boolean },\n): PivotComputation | null {\n    const def = template.pivot;\n    if (!def) return null;\n    const key = opts?.key ?? def.key ?? 'pivot';\n    const label = opts?.label ?? def.label ?? 'View';\n    const includeTransitions = opts?.includeTransitions !== false;\n\n    const ids: string[] = ['default'];\n    const labels: string[] = ['Default'];\n    const statesById: Record<string, Record<string, ChartEncoding>> = {\n        default: clone(base),\n    };\n    const augmentationById: Record<string, EncodingAugmentation | undefined> = {\n        default: undefined,\n    };\n    const chartTypeById: Record<string, string | undefined> = {\n        default: undefined,\n    };\n\n    interface OrbitNode {\n        id: string;\n        label: string;\n        enc: Record<string, ChartEncoding>;\n        chartType: string | undefined;\n        template: ChartTemplateDef;\n        augmentation: EncodingAugmentation | undefined;\n    }\n\n    const seen = new Set<string>([encodingKey(base, undefined)]);\n    const queue: OrbitNode[] = [{ id: 'default', label: 'Default', enc: clone(base), chartType: undefined, template, augmentation: undefined }];\n    // The authored chart type *is* home: a θ path that lands back on it (e.g.\n    // Stacked → Grouped → Stacked) is not a new view, so we normalize its\n    // effective chartType to `undefined`. This lets the stabilizer dedup fold\n    // such round-trips onto the identity instead of showing them as extra states.\n    const authoredChart = template.chart;\n\n    while (queue.length > 0 && ids.length < MAX_PIVOT_STATES) {\n        const cur = queue.shift()!;\n        for (const step of pivotSteps(cur.template, cur.enc, data, {\n            local: true,\n            transitions: includeTransitions,\n            preferFacetTarget: opts?.preferFacetTarget,\n        }, resolveTemplate)) {\n            // A θ step switches the effective chart type (and thus the template\n            // whose generators apply next); σ/γ steps stay on the current one.\n            let nextChartType = step.chartType ?? cur.chartType;\n            if (nextChartType === authoredChart) nextChartType = undefined; // back home\n            // A θ step switches the effective template (and thus the generators\n            // that apply next). When no resolver is supplied — or it can't resolve\n            // the target — the θ state becomes a *leaf*: we strip its pivot so no\n            // further (wrong-template) generators compose past the chart-type\n            // change. σ/γ/τ steps stay on the current template.\n            const resolved = step.chartType ? resolveTemplate?.(step.chartType) : undefined;\n            const nextTemplate: ChartTemplateDef = step.chartType\n                ? (resolved ?? { ...cur.template, pivot: undefined })\n                : cur.template;\n            if (!isRenderableState(nextTemplate, step.enc)) continue; // avoid invalid combos\n            if (opts?.preferFacetTarget) {\n                const facetTarget = changedFacetTarget(base, step.enc);\n                if (facetTarget && facetTarget !== preferredFacetTarget(step.enc)) continue;\n            }\n            // Drop OVERLAPPING arrangement compositions. Composing two generators\n            // that touch a shared channel yields a confusing 3-cycle (flip X⇄Y then\n            // swap Y⇄Color rotates all three axes, not a clean pairwise swap). We\n            // only compose steps whose moved channels are DISJOINT from what the\n            // path already moved — so every state is a single generator or an\n            // INDEPENDENT combo. The generators themselves are unchanged (the\n            // overlapping states still exist in theory), we just don't enumerate them.\n            if (step.chartType === undefined && cur.id !== 'default') {\n                const already = changedChannels(base, cur.enc);\n                const now = changedChannels(cur.enc, step.enc);\n                let overlaps = false;\n                for (const ch of now) {\n                    if (already.has(ch)) { overlaps = true; break; }\n                }\n                if (overlaps) continue;\n            }\n            const fp = encodingKey(step.enc, nextChartType);\n            if (seen.has(fp)) continue; // dedup (stabilizer)\n            seen.add(fp);\n            const id = cur.id === 'default' ? step.id : `${cur.id}|${step.id}`;\n            // Compositions are now always DISJOINT (see the overlap guard above),\n            // so a plain operator join reads cleanly with no double-counted channel\n            // (e.g. `X ⇄ Y · Color ⇄ Columns`). θ states join the same way.\n            const stepLabel = cur.id === 'default' ? step.label : `${cur.label} · ${step.label}`;\n            ids.push(id);\n            labels.push(stepLabel);\n            statesById[id] = step.enc;\n            chartTypeById[id] = nextChartType;\n            const augmentation = step.chartType\n                ? undefined\n                : (step.augmentation ?? cur.augmentation);\n            augmentationById[id] = augmentation;\n            queue.push({ id, label: stepLabel, enc: step.enc, chartType: nextChartType, template: nextTemplate, augmentation });\n            if (ids.length >= MAX_PIVOT_STATES) break;\n        }\n    }\n\n    return { key, label, ids, labels, statesById, augmentationById, chartTypeById };\n}\n\n/**\n * Resolve the active pivot state for the stored override and return both the\n * transformed encodings and the serializable surface (or the untouched base\n * encodings + `undefined` surface when no multi-state pivot applies).\n */\nexport function applyPivot(\n    template: ChartTemplateDef,\n    base: Record<string, ChartEncoding>,\n    data: any[],\n    chartProperties: Record<string, any> | undefined,\n    resolveTemplate?: (chartType: string) => ChartTemplateDef | undefined,\n): { encodings: Record<string, ChartEncoding>; augmentation: EncodingAugmentation | undefined; chartType: string | undefined; surface: PivotSurface | undefined } {\n    const comp = computePivot(template, base, data, resolveTemplate);\n    if (!comp || comp.ids.length <= 1) {\n        return { encodings: base, augmentation: undefined, chartType: undefined, surface: undefined };\n    }\n    const stored = chartProperties?.[comp.key];\n    const id = typeof stored === 'string' && comp.ids.includes(stored) ? stored : comp.ids[0];\n    const index = comp.ids.indexOf(id);\n    return {\n        encodings: comp.statesById[id],\n        augmentation: comp.augmentationById[id],\n        chartType: comp.chartTypeById[id],\n        surface: {\n            key: comp.key,\n            label: comp.label,\n            length: comp.ids.length,\n            index,\n            ids: comp.ids,\n            labels: comp.labels,\n        },\n    };\n}\n\n// ─── Factored two-control model (design-docs/chart-transform-two-axes.md) ─────\n//\n// The single composed orbit above is re-exposed as TWO independent controls:\n//   - Control B (chart type, θ): a one-hop transition menu enumerated from the\n//     object's *identity* — no composition, independent of Control A.\n//   - Control A (arrange, τ/σ/γ): the local group of the *effective* chart type\n//     (authored, or the θ-selected sibling), BFS-composed and deduped.\n// The two are stored as separate override keys (`chartType`, `arrange`). A θ\n// switch resets `arrange` to identity and rebuilds Control A on the new object.\n\n/** Both control surfaces resolved for the current input. */\nexport interface TransformSurface {\n    /** Control B — chart-type transitions (dropdown). Absent when no siblings. */\n    chartType?: PivotSurface;\n    /** Control A — local rearrangement group (stepper). Absent when trivial. */\n    arrange?: PivotSurface;\n}\n\n/** Override keys the two controls read/write under `chartProperties`. */\nexport const TRANSFORM_CHART_TYPE_KEY = 'chartType';\nexport const TRANSFORM_ARRANGE_KEY = 'arrange';\n\n/** Build a PivotSurface for a chosen state id within a computation. */\nfunction buildSurface(comp: PivotComputation, id: string): PivotSurface {\n    const index = Math.max(0, comp.ids.indexOf(id));\n    return {\n        key: comp.key,\n        label: comp.label,\n        length: comp.ids.length,\n        index,\n        ids: comp.ids,\n        labels: comp.labels,\n    };\n}\n\n/**\n * Control A enumeration: the local rearrangement group (τ/σ/γ only, no θ) of a\n * template, BFS-composed and deduped exactly like {@link computePivot} but with\n * chart-type transitions excluded. Runs on the *effective* object's identity\n * encoding (post-θ), so it offers exactly the moves that make sense there.\n */\nexport function computeArrangeStates(\n    template: ChartTemplateDef,\n    base: Record<string, ChartEncoding>,\n    data: any[],\n): PivotComputation | null {\n    return computePivot(template, base, data, undefined, {\n        includeTransitions: false,\n        key: TRANSFORM_ARRANGE_KEY,\n        label: 'Arrange',\n        preferFacetTarget: true,\n    });\n}\n\n/**\n * Control B enumeration: the one-hop chart-type transitions (θ only) of a\n * template, enumerated from the object's *identity* encoding — no composition,\n * no τ/σ/γ. Each state re-routes fields for a sibling chart type and carries a\n * `chartType` override the compiler re-dispatches on. State 0 is the authored\n * type (`default`, no override); labels are the sibling chart-type display\n * names so the dropdown reads \"Bar Chart · Line Chart · …\". Returns `null` when\n * the template declares no transitions.\n */\nexport function computeChartTypeStates(\n    template: ChartTemplateDef,\n    base: Record<string, ChartEncoding>,\n    data: any[],\n    resolveTemplate?: (chartType: string) => ChartTemplateDef | undefined,\n): PivotComputation | null {\n    // Transitions come from the central registry (keyed by chart name), NOT from\n    // the template's pivot def — so a template with no local τ/σ/γ group (e.g. a\n    // Pyramid) can still offer chart-type siblings.\n    const transitions = getChartTransitions(template.chart);\n    if (transitions.length === 0) return null;\n\n    const ids: string[] = ['default'];\n    const labels: string[] = [template.chart];\n    const statesById: Record<string, Record<string, ChartEncoding>> = { default: clone(base) };\n    const augmentationById: Record<string, EncodingAugmentation | undefined> = { default: undefined };\n    const chartTypeById: Record<string, string | undefined> = { default: undefined };\n    const seenChartTypes = new Set<string>([template.chart]);\n\n    for (const t of transitions) {\n        // Backend gate: skip a target the active backend can't render.\n        if (resolveTemplate && !resolveTemplate(t.to)) continue;\n        const st = transitionState(base, data, template, t);\n        if (!st) continue;\n        // One sibling per target chart type; skip a hop back to the authored type.\n        if (seenChartTypes.has(st.chartType)) continue;\n        seenChartTypes.add(st.chartType);\n        const id = `type:${t.to}`;\n        ids.push(id);\n        labels.push(st.chartType);\n        statesById[id] = st.enc;\n        chartTypeById[id] = st.chartType;\n    }\n\n    if (ids.length <= 1) return null;\n    return { key: TRANSFORM_CHART_TYPE_KEY, label: 'Chart type', ids, labels, statesById, augmentationById, chartTypeById };\n}\n\n/**\n * Resolve the two transform override ids from `chartProperties`, with a\n * backward-compatible shim for the legacy single composed `pivot` id: a\n * `type:*` token routes to the chart-type override and the remaining τ/σ/γ\n * tokens (before it) route to arrange. Because a θ resets arrange in the new\n * model, tokens *after* a `type:*` token are dropped (best-effort migration).\n */\nfunction resolveTransformOverrides(\n    chartProperties: Record<string, any> | undefined,\n): { chartTypeId: string | undefined; arrangeId: string | undefined } {\n    let chartTypeId = chartProperties?.[TRANSFORM_CHART_TYPE_KEY];\n    let arrangeId = chartProperties?.[TRANSFORM_ARRANGE_KEY];\n    if (typeof chartTypeId !== 'string') chartTypeId = undefined;\n    if (typeof arrangeId !== 'string') arrangeId = undefined;\n\n    if (chartTypeId === undefined && arrangeId === undefined) {\n        const legacy = chartProperties?.pivot;\n        if (typeof legacy === 'string' && legacy.length > 0 && legacy !== 'default') {\n            const tokens = legacy.split('|');\n            const typeIdx = tokens.findIndex((t) => t.startsWith('type:'));\n            if (typeIdx >= 0) {\n                chartTypeId = tokens[typeIdx];\n                const local = tokens.slice(0, typeIdx);\n                arrangeId = local.length ? local.join('|') : undefined;\n            } else {\n                arrangeId = legacy;\n            }\n        }\n    }\n    return { chartTypeId, arrangeId };\n}\n\n/**\n * Resolve the active state for the two independent controls and return the\n * transformed encodings + both surfaces. Order (design §4.10.1): apply the\n * chart-type transition (Control B) from the authored identity FIRST, re-select\n * the sibling template, THEN enumerate + apply that object's local arrange group\n * (Control A). A stale/absent `arrange` id falls back to identity — which is the\n * reset-on-θ behavior for free (design §4.10.2).\n */\nexport function applyTransform(\n    template: ChartTemplateDef,\n    base: Record<string, ChartEncoding>,\n    data: any[],\n    chartProperties: Record<string, any> | undefined,\n    resolveTemplate?: (chartType: string) => ChartTemplateDef | undefined,\n): {\n    encodings: Record<string, ChartEncoding>;\n    augmentation: EncodingAugmentation | undefined;\n    chartType: string | undefined;\n    surface: TransformSurface;\n} {\n    const { chartTypeId, arrangeId } = resolveTransformOverrides(chartProperties);\n\n    // Control B — chart type (θ), from the authored identity.\n    let effectiveTemplate = template;\n    let effectiveEnc = base;\n    let chartType: string | undefined;\n    let chartTypeSurface: PivotSurface | undefined;\n    const ctComp = computeChartTypeStates(template, base, data, resolveTemplate);\n    if (ctComp && ctComp.ids.length > 1) {\n        const id = chartTypeId && ctComp.ids.includes(chartTypeId) ? chartTypeId : 'default';\n        effectiveEnc = ctComp.statesById[id];\n        chartType = ctComp.chartTypeById[id];\n        if (chartType) {\n            const resolved = resolveTemplate?.(chartType);\n            if (resolved) effectiveTemplate = resolved;\n        }\n        chartTypeSurface = buildSurface(ctComp, id);\n    }\n\n    // Control A — arrange (τ/σ/γ), on the effective object.\n    let encodings = effectiveEnc;\n    let augmentation: EncodingAugmentation | undefined;\n    let arrangeSurface: PivotSurface | undefined;\n    const arrComp = computeArrangeStates(effectiveTemplate, effectiveEnc, data);\n    if (arrComp && arrComp.ids.length > 1) {\n        const id = arrangeId && arrComp.ids.includes(arrangeId) ? arrangeId : arrComp.ids[0];\n        encodings = arrComp.statesById[id];\n        augmentation = arrComp.augmentationById[id];\n        arrangeSurface = buildSurface(arrComp, id);\n    }\n\n    return {\n        encodings,\n        augmentation,\n        chartType,\n        surface: { chartType: chartTypeSurface, arrange: arrangeSurface },\n    };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ChartEncoding, EncodingActionDef } from './types';\n\n/**\n * Reusable factories for Category-B encoding actions (see EncodingActionDef).\n *\n * These are authored once and attached to many templates, so the per-chart\n * knowledge (which channel is the category axis, which carries the measure)\n * lives in one place instead of being re-implemented per template.\n */\n\n/** The semantic sort choices the Sort control exposes. */\nexport type SortChoice = 'value-asc' | 'value-desc';\n\n// A measure is a quantitative channel or any aggregated channel.\nconst isMeasureEnc = (e?: ChartEncoding): boolean =>\n    !!e?.field && (!!e.aggregate || e.type === 'quantitative');\n\n// A sortable category axis is discrete (nominal/ordinal). Temporal axes are\n// deliberately excluded: reordering a time axis by value scrambles the\n// chronology, so Sort should not apply to them.\nconst isDiscreteCategoryEnc = (e?: ChartEncoding): boolean =>\n    !!e?.field && !e.aggregate && e.type !== 'quantitative' && e.type !== 'temporal';\n\n/**\n * Identify the discrete category axis and the measure axis among a pair of\n * position channels, so Sort works under either orientation (vertical or\n * horizontal) and only when a discrete axis actually exists.\n *\n * Returns `null` when there is no discrete category + measure pair to sort —\n * e.g. a temporal-x time series, or two quantitative axes (scatter). Callers\n * use this both to gate visibility and to no-op safely.\n */\nfunction resolveSortChannels(\n    encodings: Record<string, ChartEncoding>,\n    candidates: [string, string],\n): { category: string; measure: string } | null {\n    const category = candidates.find(c => isDiscreteCategoryEnc(encodings[c]));\n    const measure = candidates.find(c => isMeasureEnc(encodings[c]));\n    if (!category || !measure || category === measure) return null;\n    return { category, measure };\n}\n\n/**\n * Sort the category axis of a bar-like chart by the measure value.\n *\n * Encoding model: a value sort writes `sortBy = <measure channel>` (one of\n * 'x' | 'y', which the assembler understands) on the category channel.\n * \"Default\" clears the sort so the field's canonical ordering wins — the\n * natural order for ordinal/temporal-like categories, or alphabetic otherwise,\n * as decided by semantic resolution. The action is only applicable — and only\n * visible — when one position channel is a discrete category and the other is\n * a measure.\n *\n * @param channels Position-channel pair (default ['x', 'y']); the orientation\n *                 (which one is the category) is resolved per-encoding at runtime.\n */\nexport function makeSortAction(options?: {\n    key?: string;\n    label?: string;\n    channels?: [string, string];\n}): EncodingActionDef {\n    const candidates = options?.channels ?? ['x', 'y'];\n    return {\n        key: options?.key ?? 'sort',\n        label: options?.label ?? 'Sort',\n        dependencies: candidates,\n        isApplicable: (ctx) => resolveSortChannels(ctx.encodings, candidates) !== null,\n        control: {\n            type: 'discrete',\n            options: [\n                { value: undefined, label: 'Default' },\n                { value: 'value-desc', label: 'Value ↓' },\n                { value: 'value-asc', label: 'Value ↑' },\n            ],\n        },\n        get: (encodings) => {\n            const resolved = resolveSortChannels(encodings, candidates);\n            if (!resolved) return undefined;\n            const { category, measure } = resolved;\n            const enc = encodings[category];\n            if (enc.sortBy === measure) {\n                return enc.sortOrder === 'descending' ? 'value-desc' : 'value-asc';\n            }\n            // Any other sort (label order, custom value order, sort-by-color)\n            // isn't representable by this control → show as Default.\n            return undefined;\n        },\n        set: (encodings, value: SortChoice | undefined) => {\n            const resolved = resolveSortChannels(encodings, candidates);\n            if (!resolved) return encodings;\n            const { category, measure } = resolved;\n            const base = encodings[category];\n            let next: ChartEncoding;\n            switch (value) {\n                case 'value-asc':\n                    next = { ...base, sortBy: measure, sortOrder: 'ascending' };\n                    break;\n                case 'value-desc':\n                    next = { ...base, sortBy: measure, sortOrder: 'descending' };\n                    break;\n                default:\n                    next = { ...base, sortBy: undefined, sortOrder: undefined };\n            }\n            return { ...encodings, [category]: next };\n        },\n    };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ChannelSemantics } from './types';\n\ntype EncodingType = 'nominal' | 'ordinal' | 'quantitative' | 'temporal';\n\ntype BandedAxisResult = {\n    axis: 'x' | 'y';\n    resolvedTypes?: Record<string, EncodingType>;\n};\n\nconst isDiscrete = (type: string | undefined): boolean =>\n    type === 'nominal' || type === 'ordinal';\n\nconst getFieldCardinality = (field: string, table: any[]): number =>\n    new Set(table.map((row: any) => row[field]).filter((value: any) => value != null)).size;\n\n/** Resolve a backend-neutral discrete encoding type for a field. */\nexport function resolveDiscreteType(\n    currentType: string,\n    field: string | undefined,\n    table: any[],\n): 'nominal' | 'ordinal' {\n    if (currentType === 'nominal') return 'nominal';\n    if (currentType === 'ordinal') return 'ordinal';\n    if (currentType === 'temporal') return 'ordinal';\n    if (currentType === 'quantitative' && field && table.length > 0) {\n        return getFieldCardinality(field, table) <= 20 ? 'ordinal' : 'nominal';\n    }\n    return 'nominal';\n}\n\n/** Choose the position axis that should use banded layout. */\nexport function detectBandedAxisFromSemantics(\n    channelSemantics: Record<string, ChannelSemantics>,\n    table: any[],\n    options: { preferAxis?: 'x' | 'y' } = {},\n): BandedAxisResult | null {\n    const xType = channelSemantics.x?.type;\n    const yType = channelSemantics.y?.type;\n\n    if (xType && isDiscrete(xType)) return { axis: 'x' };\n    if (yType && isDiscrete(yType)) return { axis: 'y' };\n\n    if (xType && yType) {\n        if (xType === 'quantitative' && yType !== 'quantitative') {\n            return { axis: 'y' };\n        }\n        if (yType === 'quantitative' && xType !== 'quantitative') {\n            return { axis: 'x' };\n        }\n        return { axis: options.preferAxis || 'x' };\n    }\n\n    if (xType) {\n        const newType = resolveDiscreteType(xType, channelSemantics.x?.field, table);\n        return { axis: 'x', resolvedTypes: { x: newType } };\n    }\n    if (yType) {\n        const newType = resolveDiscreteType(yType, channelSemantics.y?.field, table);\n        return { axis: 'y', resolvedTypes: { y: newType } };\n    }\n\n    return null;\n}\n\n/** Choose a banded axis and force its encoding type to be discrete. */\nexport function detectBandedAxisForceDiscrete(\n    channelSemantics: Record<string, ChannelSemantics>,\n    table: any[],\n    options: { preferAxis?: 'x' | 'y' } = {},\n): BandedAxisResult | null {\n    const result = detectBandedAxisFromSemantics(channelSemantics, table, options);\n    if (!result) return null;\n\n    const axis = result.axis;\n    const semantics = channelSemantics[axis];\n    if (!semantics) return result;\n\n    if (!isDiscrete(semantics.type)) {\n        const newType = resolveDiscreteType(semantics.type, semantics.field, table);\n        return {\n            axis,\n            resolvedTypes: { ...result.resolvedTypes, [axis]: newType },\n        };\n    }\n\n    return result;\n}","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Band-dodge decision: does a secondary discrete channel (`color`, or an explicit\n * `group` field) subdivide a categorical axis band into side-by-side sub-lanes\n * (\"dodge\"), or is it redundant/nested with the axis (render one full-width glyph\n * per band, \"nested\")?\n *\n * This is the single source of truth shared by the layout engine\n * (`compute-layout.ts`) and every backend template that dodges by color/group\n * (VL boxplot/violin/grouped-bar, ECharts, Chart.js). Keeping the decision here\n * prevents the layout and the templates from drifting apart (the class of bug\n * where the band is budgeted for a different lane count than the glyph is sized\n * for). See `design-docs/boxplot-color-dodge-heuristic.md`.\n *\n * Two independent quantities, deliberately NOT the same number:\n *   - the **gate** (`dodge`): keyed off the max per-band sub-cardinality — \"does\n *     any single band actually contain more than one sub-value?\"\n *   - the **lane count** (`laneCount`): the *global* distinct sub-value count,\n *     because that is what a global band-offset scale (VL `xOffset`, an ECharts\n *     series-per-group, a Chart.js dataset-per-group) physically reserves per\n *     band. Sizing a glyph by the max-per-band instead would overlap in sparse\n *     cross-products.\n */\n\n/** Default fraction of single-valued bands above which `auto` snaps to `none`\n *  (mostly-1:1 / dirty near-1:1 data). Tunable via `planBandDodge` options. */\nexport const DEFAULT_NESTED_SNAP_THRESHOLD = 0.9;\n\n/** Resolved dodge mode (what actually renders). */\nexport type DodgeMode = 'none' | 'local' | 'global';\n\n/** User-facing `dodge` chart-property values (`auto` defers to the compiler). */\nexport type DodgeOption = 'auto' | DodgeMode;\n\nexport interface BandDodgePlan {\n    /** Compiler's recommended default mode. */\n    mode: DodgeMode;\n    /** Back-compat: does the recommendation subdivide the band? (`mode !== 'none'`). */\n    dodge: boolean;\n    /** Lanes a *global* offset scale reserves per band = global distinct\n     *  sub-values (the `global` mode lane count). */\n    laneCount: number;\n    /** True when local and global dodge can produce different layouts. */\n    ambiguous: boolean;\n    /** Most distinct sub-values co-occurring within any single band. */\n    maxPerBand: number;\n    /** Global distinct sub-values. */\n    global: number;\n    /** Number of distinct axis bands. */\n    bandCount: number;\n}\n\nexport interface PlanBandDodgeOptions {\n    /** Fraction of single-valued bands above which `auto` snaps to `none`.\n     *  Defaults to {@link DEFAULT_NESTED_SNAP_THRESHOLD}. */\n    nestedSnapThreshold?: number;\n}\n\n/** Pure recommendation from the per-band statistics. */\nfunction recommendMode(\n    maxPerBand: number,\n    globalCount: number,\n    nestedFraction: number,\n    threshold: number,\n): DodgeMode {\n    // Nothing subdivides any band → full-width.\n    if (maxPerBand <= 1) return 'none';\n    // Mostly single-valued (a few dirty/outlier multi-color bands) → snap to\n    // full-width rather than dodge the whole chart for a couple of rows.\n    if (nestedFraction >= threshold) return 'none';\n    // Every occupied band spans the full sub-domain → uniform global grid.\n    if (maxPerBand >= globalCount) return 'global';\n    // Sparse / spiky → compact, centered per-band lanes.\n    return 'local';\n}\n\n/**\n * Decide whether `subField` dodges `axisField` for the given data.\n *\n * Confident zones (never ambiguous):\n *   - `maxPerBand <= 1`  → nested (redundant/nested with the axis; `color == x`\n *     or a 1:1 different-field pair).\n *   - `maxPerBand === global` → dodge (clean full cross-product).\n * Ambiguous zone (`1 < maxPerBand < global`, e.g. sparse cross-products or dirty\n * near-1:1 data): the `auto` lean is resolved by a configurable threshold on the\n * fraction of single-valued bands, and `ambiguous` is set so a host can surface\n * the toggle.\n */\nexport function planBandDodge(\n    table: ReadonlyArray<Record<string, unknown>>,\n    axisField: string,\n    subField: string,\n    options?: PlanBandDodgeOptions,\n): BandDodgePlan {\n    const perBand = new Map<unknown, Set<unknown>>();\n    const global = new Set<unknown>();\n    for (const row of table) {\n        global.add(row[subField]);\n        const key = row[axisField];\n        let bandSet = perBand.get(key);\n        if (!bandSet) perBand.set(key, (bandSet = new Set()));\n        bandSet.add(row[subField]);\n    }\n\n    const globalCount = Math.max(1, global.size);\n    const bandCount = perBand.size;\n    let maxPerBand = 0;\n    let singleValuedBands = 0;\n    let completeBands = 0;\n    for (const bandSet of perBand.values()) {\n        if (bandSet.size > maxPerBand) maxPerBand = bandSet.size;\n        if (bandSet.size <= 1) singleValuedBands++;\n        if (bandSet.size === globalCount) completeBands++;\n    }\n\n    const threshold = options?.nestedSnapThreshold ?? DEFAULT_NESTED_SNAP_THRESHOLD;\n    const nestedFraction = bandCount > 0 ? singleValuedBands / bandCount : 1;\n    const mode = recommendMode(maxPerBand, globalCount, nestedFraction, threshold);\n\n    return {\n        mode,\n        dodge: mode !== 'none',\n        laneCount: globalCount,\n        ambiguous: maxPerBand > 1 && completeBands < bandCount,\n        maxPerBand,\n        global: globalCount,\n        bandCount,\n    };\n}\n\n/** Number of sub-lanes a resolved mode reserves per band. */\nexport function laneCountForMode(plan: BandDodgePlan, mode: DodgeMode): number {\n    if (mode === 'global') return plan.global;\n    if (mode === 'local') return Math.max(1, plan.maxPerBand);\n    return 1;\n}\n\n/**\n * Apply a user `dodge` override on top of a plan. `none`/`local`/`global` are\n * hard overrides; `auto` (or unset) follows the compiler recommendation. A dodge\n * mode is downgraded to `none` when nothing actually subdivides a band\n * (`maxPerBand <= 1`), so forcing dodge on redundant color can't collapse it.\n */\nexport function resolveDodge(\n    plan: BandDodgePlan,\n    override?: string,\n): { mode: DodgeMode; laneCount: number } {\n    let mode: DodgeMode =\n        override === 'none' || override === 'local' || override === 'global'\n            ? override\n            : plan.mode;\n    if (mode !== 'none' && plan.maxPerBand <= 1) mode = 'none';\n    return { mode, laneCount: laneCountForMode(plan, mode) };\n}\n\n// ---------------------------------------------------------------------------\n// Back-compat shim (pre-`local` callers that only need a dodge boolean).\n// `local` currently renders via the global offset path, so its lane count is\n// the global one until the per-backend `local` renderer lands (Stage 2).\n// ---------------------------------------------------------------------------\n\n/** @deprecated user-facing values; prefer {@link DodgeOption}. */\nexport type ColorLayoutMode = DodgeOption;\n\n/** @deprecated prefer {@link resolveDodge}. Maps the mode to a dodge boolean and\n *  the global lane count (the only lane count the current renderers support). */\nexport function resolveBandDodge(\n    plan: BandDodgePlan,\n    override?: string,\n): { dodge: boolean; laneCount: number } {\n    // Legacy override spellings → new modes.\n    const normalized = override === 'dodge' ? 'global' : override === 'nested' ? 'none' : override;\n    const { mode } = resolveDodge(plan, normalized);\n    return { dodge: mode !== 'none', laneCount: plan.laneCount };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * =============================================================================\n * TYPE REGISTRY — Single Source of Truth\n * =============================================================================\n *\n * Every recognized semantic type is registered here with its orthogonal\n * compilation dimensions. This is the ONLY place where per-type properties\n * are defined. All other files (field-semantics.ts, semantic-types.ts)\n * derive helper functions by querying this registry.\n *\n * To add a new semantic type: add an entry here.\n * To query a type's properties: use `getRegistryEntry()`.\n * =============================================================================\n */\n\n// ---------------------------------------------------------------------------\n// Visualization Categories\n// ---------------------------------------------------------------------------\n\nexport type VisCategory = 'quantitative' | 'ordinal' | 'nominal' | 'temporal' | 'geographic';\n\n// ---------------------------------------------------------------------------\n// Registry Dimension Types\n// ---------------------------------------------------------------------------\n\n/** Top-level type family */\nexport type T0Family = 'Temporal' | 'Measure' | 'Discrete' | 'Geographic' | 'Categorical' | 'Identifier';\n\n/** Mid-level category within a family */\nexport type T1Category =\n    | 'DateTime' | 'DateGranule' | 'Duration'\n    | 'Amount' | 'Physical' | 'Proportion' | 'SignedMeasure' | 'GenericMeasure'\n    | 'Rank' | 'Score'\n    | 'GeoCoordinate' | 'GeoPlace'\n    | 'Entity' | 'Coded' | 'Binned'\n    | 'ID';\n\nexport type DomainShape = 'open' | 'bounded' | 'fixed' | 'cyclic';\nexport type AggRole = 'additive' | 'intensive' | 'signed-additive' | 'dimension' | 'identifier';\nexport type DivergingClass = 'none' | 'inherent' | 'conditional';\nexport type FormatClass = 'currency' | 'percent'\n    | 'unit-suffix' | 'integer' | 'decimal' | 'plain';\n\n/**\n * Zero-baseline classification for quantitative axes.\n *\n * - `meaningful`: 0 = absence of the measured thing; axis should include 0 (Count, Revenue).\n * - `arbitrary`:  0 is arbitrary or nonexistent; data-fit the axis (Temperature, Year, Rank).\n * - `contextual`: 0 is meaningful but data-fitting may be better when data is far from 0 (Percentage, Score).\n * - `none`:       Not a quantitative type; zero question is irrelevant (all categorical/temporal types).\n */\nexport type ZeroBaseline = 'meaningful' | 'arbitrary' | 'contextual' | 'none';\n\nexport interface TypeRegistryEntry {\n    t0: T0Family;\n    t1: T1Category;\n    visEncodings: VisCategory[];\n    aggRole: AggRole;\n    domainShape: DomainShape;\n    diverging: DivergingClass;\n    formatClass: FormatClass;\n    /** Zero-baseline classification for quantitative axes */\n    zeroBaseline: ZeroBaseline;\n    /** Domain padding fraction for non-zero axes (0 = no padding) */\n    zeroPad: number;\n}\n\n// ---------------------------------------------------------------------------\n// The Registry\n// ---------------------------------------------------------------------------\n\n/**\n * Static registry mapping every recognized semantic type to its\n * tier membership and orthogonal compilation dimensions.\n *\n * Types not in this registry are treated as 'Unknown' → nominal/plain.\n */\nconst TYPE_REGISTRY: Record<string, TypeRegistryEntry> = {\n    // --- Temporal: DateTime ---\n    DateTime:      { t0: 'Temporal', t1: 'DateTime', visEncodings: ['temporal'],           aggRole: 'dimension',  domainShape: 'open',    diverging: 'none', formatClass: 'plain',           zeroBaseline: 'none', zeroPad: 0 },\n    Date:          { t0: 'Temporal', t1: 'DateTime', visEncodings: ['temporal'],           aggRole: 'dimension',  domainShape: 'open',    diverging: 'none', formatClass: 'plain',           zeroBaseline: 'none', zeroPad: 0 },\n    Time:          { t0: 'Temporal', t1: 'DateTime', visEncodings: ['temporal'],           aggRole: 'dimension',  domainShape: 'open',    diverging: 'none', formatClass: 'plain',           zeroBaseline: 'none', zeroPad: 0 },\n    Timestamp:     { t0: 'Temporal', t1: 'DateTime', visEncodings: ['temporal'],           aggRole: 'dimension',  domainShape: 'open',    diverging: 'none', formatClass: 'plain',           zeroBaseline: 'none', zeroPad: 0 },\n\n    // --- Temporal: DateGranule ---\n    Year:          { t0: 'Temporal', t1: 'DateGranule', visEncodings: ['temporal', 'ordinal'], aggRole: 'dimension', domainShape: 'open',    diverging: 'none', formatClass: 'integer',        zeroBaseline: 'arbitrary', zeroPad: 0.03 },\n    Quarter:       { t0: 'Temporal', t1: 'DateGranule', visEncodings: ['ordinal'],            aggRole: 'dimension', domainShape: 'cyclic',  diverging: 'none', formatClass: 'plain',          zeroBaseline: 'none', zeroPad: 0 },\n    Month:         { t0: 'Temporal', t1: 'DateGranule', visEncodings: ['ordinal'],            aggRole: 'dimension', domainShape: 'cyclic',  diverging: 'none', formatClass: 'plain',          zeroBaseline: 'none', zeroPad: 0 },\n    Week:          { t0: 'Temporal', t1: 'DateGranule', visEncodings: ['ordinal'],            aggRole: 'dimension', domainShape: 'cyclic',  diverging: 'none', formatClass: 'plain',          zeroBaseline: 'none', zeroPad: 0 },\n    Day:           { t0: 'Temporal', t1: 'DateGranule', visEncodings: ['ordinal'],            aggRole: 'dimension', domainShape: 'cyclic',  diverging: 'none', formatClass: 'plain',          zeroBaseline: 'none', zeroPad: 0 },\n    Hour:          { t0: 'Temporal', t1: 'DateGranule', visEncodings: ['ordinal'],            aggRole: 'dimension', domainShape: 'cyclic',  diverging: 'none', formatClass: 'integer',        zeroBaseline: 'arbitrary', zeroPad: 0 },\n    YearMonth:     { t0: 'Temporal', t1: 'DateGranule', visEncodings: ['temporal', 'ordinal'], aggRole: 'dimension', domainShape: 'open',   diverging: 'none', formatClass: 'plain',          zeroBaseline: 'none', zeroPad: 0 },\n    YearQuarter:   { t0: 'Temporal', t1: 'DateGranule', visEncodings: ['temporal', 'ordinal'], aggRole: 'dimension', domainShape: 'open',   diverging: 'none', formatClass: 'plain',          zeroBaseline: 'none', zeroPad: 0 },\n    YearWeek:      { t0: 'Temporal', t1: 'DateGranule', visEncodings: ['temporal', 'ordinal'], aggRole: 'dimension', domainShape: 'open',   diverging: 'none', formatClass: 'plain',          zeroBaseline: 'none', zeroPad: 0 },\n    Decade:        { t0: 'Temporal', t1: 'DateGranule', visEncodings: ['temporal', 'ordinal'], aggRole: 'dimension', domainShape: 'open',   diverging: 'none', formatClass: 'integer',        zeroBaseline: 'arbitrary', zeroPad: 0.03 },\n\n    // --- Temporal: Duration ---\n    Duration:      { t0: 'Temporal', t1: 'Duration', visEncodings: ['quantitative'],       aggRole: 'additive',   domainShape: 'open',    diverging: 'none', formatClass: 'unit-suffix',     zeroBaseline: 'meaningful', zeroPad: 0 },\n\n    // --- Measure: Amount ---\n    Amount:        { t0: 'Measure', t1: 'Amount', visEncodings: ['quantitative'],          aggRole: 'additive',   domainShape: 'open',    diverging: 'none',        formatClass: 'currency',   zeroBaseline: 'meaningful', zeroPad: 0 },\n    Price:         { t0: 'Measure', t1: 'Amount', visEncodings: ['quantitative'],          aggRole: 'intensive',  domainShape: 'open',    diverging: 'none',        formatClass: 'currency',   zeroBaseline: 'meaningful', zeroPad: 0 },\n\n    // --- Measure: Physical ---\n    Quantity:      { t0: 'Measure', t1: 'Physical', visEncodings: ['quantitative'],        aggRole: 'additive',   domainShape: 'open',    diverging: 'none',        formatClass: 'unit-suffix', zeroBaseline: 'meaningful', zeroPad: 0 },\n    Temperature:   { t0: 'Measure', t1: 'Physical', visEncodings: ['quantitative'],        aggRole: 'intensive',  domainShape: 'open',    diverging: 'conditional', formatClass: 'unit-suffix', zeroBaseline: 'arbitrary', zeroPad: 0.05 },\n\n    // --- Measure: Proportion ---\n    Percentage:    { t0: 'Measure', t1: 'Proportion', visEncodings: ['quantitative'],      aggRole: 'intensive',  domainShape: 'bounded', diverging: 'none',        formatClass: 'percent',    zeroBaseline: 'contextual', zeroPad: 0 },\n\n    // --- Measure: SignedMeasure ---\n    Profit:             { t0: 'Measure', t1: 'SignedMeasure', visEncodings: ['quantitative'], aggRole: 'signed-additive', domainShape: 'open', diverging: 'conditional', formatClass: 'decimal',          zeroBaseline: 'meaningful', zeroPad: 0 },\n    PercentageChange:   { t0: 'Measure', t1: 'SignedMeasure', visEncodings: ['quantitative'], aggRole: 'intensive',       domainShape: 'open', diverging: 'conditional', formatClass: 'percent',          zeroBaseline: 'contextual', zeroPad: 0.05 },\n    Sentiment:          { t0: 'Measure', t1: 'SignedMeasure', visEncodings: ['quantitative'], aggRole: 'intensive',       domainShape: 'open', diverging: 'inherent',    formatClass: 'decimal',          zeroBaseline: 'meaningful', zeroPad: 0 },\n    Correlation:        { t0: 'Measure', t1: 'SignedMeasure', visEncodings: ['quantitative'], aggRole: 'intensive',       domainShape: 'bounded', diverging: 'inherent', formatClass: 'decimal',          zeroBaseline: 'meaningful', zeroPad: 0 },\n\n    // --- Measure: GenericMeasure ---\n    Count:         { t0: 'Measure', t1: 'GenericMeasure', visEncodings: ['quantitative'],  aggRole: 'additive',   domainShape: 'open',    diverging: 'none',        formatClass: 'integer',    zeroBaseline: 'meaningful', zeroPad: 0 },\n    Number:        { t0: 'Measure', t1: 'GenericMeasure', visEncodings: ['quantitative'],  aggRole: 'additive',   domainShape: 'open',    diverging: 'none',        formatClass: 'decimal',    zeroBaseline: 'meaningful', zeroPad: 0 },\n\n    // --- Discrete ---\n    Rank:          { t0: 'Discrete', t1: 'Rank',  visEncodings: ['ordinal'],               aggRole: 'dimension',  domainShape: 'open',    diverging: 'none',        formatClass: 'integer',    zeroBaseline: 'arbitrary', zeroPad: 0.08 },\n    Score:         { t0: 'Discrete', t1: 'Score', visEncodings: ['quantitative', 'ordinal'], aggRole: 'intensive', domainShape: 'bounded', diverging: 'conditional', formatClass: 'decimal',    zeroBaseline: 'contextual', zeroPad: 0.05 },\n    ID:            { t0: 'Identifier', t1: 'ID',  visEncodings: ['nominal'],               aggRole: 'identifier', domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'arbitrary', zeroPad: 0 },\n\n    // --- Geographic ---\n    Latitude:      { t0: 'Geographic', t1: 'GeoCoordinate', visEncodings: ['quantitative', 'geographic'], aggRole: 'dimension', domainShape: 'fixed', diverging: 'none', formatClass: 'decimal',    zeroBaseline: 'arbitrary', zeroPad: 0.02 },\n    Longitude:     { t0: 'Geographic', t1: 'GeoCoordinate', visEncodings: ['quantitative', 'geographic'], aggRole: 'dimension', domainShape: 'fixed', diverging: 'none', formatClass: 'decimal',    zeroBaseline: 'arbitrary', zeroPad: 0.02 },\n    Country:       { t0: 'Geographic', t1: 'GeoPlace', visEncodings: ['nominal'],         aggRole: 'dimension',  domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n    State:         { t0: 'Geographic', t1: 'GeoPlace', visEncodings: ['nominal'],         aggRole: 'dimension',  domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n    City:          { t0: 'Geographic', t1: 'GeoPlace', visEncodings: ['nominal'],         aggRole: 'dimension',  domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n    Region:        { t0: 'Geographic', t1: 'GeoPlace', visEncodings: ['nominal'],         aggRole: 'dimension',  domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n    Address:       { t0: 'Geographic', t1: 'GeoPlace', visEncodings: ['nominal'],         aggRole: 'dimension',  domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n    ZipCode:       { t0: 'Geographic', t1: 'GeoPlace', visEncodings: ['nominal'],         aggRole: 'identifier', domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n    // --- Categorical: Entity ---\n    Category:      { t0: 'Categorical', t1: 'Entity', visEncodings: ['nominal'],           aggRole: 'dimension',  domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n    Name:          { t0: 'Categorical', t1: 'Entity', visEncodings: ['nominal'],           aggRole: 'dimension',  domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n\n    // --- Categorical: Coded ---\n    Status:        { t0: 'Categorical', t1: 'Coded', visEncodings: ['nominal'],            aggRole: 'dimension',  domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n    Boolean:       { t0: 'Categorical', t1: 'Coded', visEncodings: ['nominal'],            aggRole: 'dimension',  domainShape: 'fixed',   diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n    Direction:     { t0: 'Categorical', t1: 'Coded', visEncodings: ['ordinal', 'nominal'], aggRole: 'dimension',  domainShape: 'cyclic',  diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n\n    // --- Categorical: Binned ---\n    Range:         { t0: 'Categorical', t1: 'Binned', visEncodings: ['ordinal'],           aggRole: 'dimension',  domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n\n    // --- Fallbacks ---\n    Unknown:       { t0: 'Categorical', t1: 'Entity', visEncodings: ['nominal'],           aggRole: 'dimension',  domainShape: 'open',    diverging: 'none',        formatClass: 'plain',      zeroBaseline: 'none', zeroPad: 0 },\n};\n\n/** Default entry for unrecognized types */\nconst UNKNOWN_ENTRY: TypeRegistryEntry = {\n    t0: 'Categorical', t1: 'Entity',\n    visEncodings: ['nominal'],\n    aggRole: 'dimension',\n    domainShape: 'open',\n    diverging: 'none',\n    formatClass: 'plain',\n    zeroBaseline: 'none',\n    zeroPad: 0,\n};\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/** Look up a semantic type in the registry. Falls back to UNKNOWN_ENTRY. */\nexport function getRegistryEntry(semanticType: string): TypeRegistryEntry {\n    return TYPE_REGISTRY[semanticType] ?? UNKNOWN_ENTRY;\n}\n\n/** Check whether a semantic type string is explicitly registered. */\nexport function isRegistered(semanticType: string): boolean {\n    return semanticType in TYPE_REGISTRY;\n}\n\n/**\n * Get all registered type names.\n * Useful for validation or iterating over the type system.\n */\nexport function getRegisteredTypes(): string[] {\n    return Object.keys(TYPE_REGISTRY);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { getRegistryEntry, getRegisteredTypes, isRegistered, type VisCategory } from './type-registry';\nexport type { VisCategory } from './type-registry';\n\n/**\n * =============================================================================\n * SEMANTIC TYPE SYSTEM\n * =============================================================================\n * \n * Semantic types classify data fields for intelligent chart recommendations.\n * Uses strings for flexibility and easy JSON serialization.\n * \n * DESIGN GOALS:\n * 1. Comprehensive: Cover common data types seen in real-world datasets\n * 2. Visualization-aware: Map to Vega-Lite encoding types (Q, O, N, T)\n * 3. Hierarchical: Support generalization via lattice structure\n * 4. Simple: Use strings with helper functions, no complex enums\n * \n * =============================================================================\n * SEMANTIC TYPE LATTICE\n * =============================================================================\n * \n *                           ┌─────────────┐\n *                           │   AnyType   │\n *                           └──────┬──────┘\n *            ┌────────────────────┼────────────────────┐\n *            ▼                    ▼                    ▼\n *     ┌──────────┐         ┌──────────┐         ┌───────-───┐\n *     │ Temporal │         │ Numeric  │         │Categorical│\n *     └────┬─────┘         └────┬─────┘         └─────┬────┘\n *          │                    │                     │\n *    ┌─────┴─────┐        ┌─────┴─────┐         ┌─────┴─────┐\n *    │           │        │           │         │           │\n *  DateTime     Granule    Measure   Discrete    Entity     Coded\n *    │           │        │           │         │           │\n * DateTime    Year     Quantity    Rank      Category   Status\n * Date        Month    Count       Score     Name       Boolean\n * Time        Day      Price       ID                   Direction\n *             Quarter  Percentage\n *             Decade   Amount\n *                      Temperature\n * \n * =============================================================================\n */\n\n// ---------------------------------------------------------------------------\n// All Semantic Types (as string constants)\n// ---------------------------------------------------------------------------\n\n/**\n * All recognized semantic types.\n * Use these constants when comparing or assigning types.\n */\nexport const SemanticTypes = {\n    // =========================================================================\n    // TEMPORAL TYPES - Time-related concepts\n    // =========================================================================\n    \n    // Point-in-time (full timestamp precision)\n    DateTime: 'DateTime',       // Full date and time: \"2024-01-15T14:30:00\"\n    Date: 'Date',               // Date only: \"2024-01-15\"\n    Time: 'Time',               // Time only: \"14:30:00\"\n    Timestamp: 'Timestamp',     // Unix timestamp (seconds or milliseconds since epoch)\n    \n    // Temporal granules (discrete time units, inherently ordered)\n    Year: 'Year',               // \"2024\" (as a time unit, not a measure)\n    Quarter: 'Quarter',         // \"Q1\", \"Q2\", \"2024-Q1\"\n    Month: 'Month',             // \"January\", \"Jan\", 1-12\n    Week: 'Week',               // \"Week 1\", 1-52\n    Day: 'Day',                 // \"Monday\", \"Mon\", 1-31\n    Hour: 'Hour',               // 0-23\n    \n    // Combined temporal\n    YearMonth: 'YearMonth',     // \"2024-01\", \"Jan 2024\"\n    YearQuarter: 'YearQuarter', // \"2024-Q1\"\n    YearWeek: 'YearWeek',       // \"2024-W01\"\n    Decade: 'Decade',           // \"1990s\", \"2000s\"\n    \n    // Temporal duration/span\n    Duration: 'Duration',       // Time span: \"2 hours\", \"3 days\", milliseconds\n    \n    // =========================================================================\n    // NUMERIC MEASURE TYPES - Continuous values for aggregation\n    // =========================================================================\n    \n    Quantity: 'Quantity',       // Generic continuous measure\n    Count: 'Count',             // Discrete count of items\n    Amount: 'Amount',           // Monetary or general amounts\n    Price: 'Price',             // Unit price\n    Percentage: 'Percentage',   // 0-100% or 0-1 ratio\n    Temperature: 'Temperature', // Degrees\n    \n    // Signed measures (can be positive or negative, zero has meaning)\n    Profit: 'Profit',             // Gain/loss, profit/deficit\n    PercentageChange: 'PercentageChange', // Growth rate, change %\n    Sentiment: 'Sentiment',       // Positive/negative sentiment score\n    Correlation: 'Correlation',   // Positive/negative correlation coefficient\n    \n    // =========================================================================\n    // NUMERIC DISCRETE TYPES - Numbers with ordinal/identifier meaning\n    // =========================================================================\n    \n    Rank: 'Rank',               // Position in ordered list: 1st, 2nd, 3rd\n    ID: 'ID',                   // Unique identifier (not for aggregation!)\n    Score: 'Score',             // Rating score: 1-5, 1-10, 0-100\n    \n    // =========================================================================\n    // GEOGRAPHIC TYPES - Location-based data\n    // =========================================================================\n    \n    Latitude: 'Latitude',       // -90 to 90\n    Longitude: 'Longitude',     // -180 to 180\n    Country: 'Country',         // Country name or code\n    State: 'State',             // State/Province\n    City: 'City',               // City name\n    Region: 'Region',           // Geographic region\n    Address: 'Address',         // Street address (geo lookup)\n    ZipCode: 'ZipCode',         // Postal code (geo lookup)\n    \n    // =========================================================================\n    // CATEGORICAL ENTITY TYPES - Named entities\n    // =========================================================================\n    \n    Category: 'Category',       // Discrete category / product / entity class\n    Name: 'Name',               // Generic named entity (person, company, product, etc.)\n    \n    // =========================================================================\n    // CATEGORICAL CODED TYPES - Discrete categories/statuses\n    // =========================================================================\n    \n    Status: 'Status',           // State: \"Active\", \"Pending\", \"Closed\"\n    Boolean: 'Boolean',         // True/False, Yes/No\n    Direction: 'Direction',     // Compass direction: \"N\", \"NE\", \"East\", etc.\n    \n    // =========================================================================\n    // BINNED/RANGE TYPES - Discretized continuous values\n    // =========================================================================\n    \n    Range: 'Range',             // Numeric range, age group, binned values\n    \n    // =========================================================================\n    // FALLBACK TYPES\n    // =========================================================================\n    \n    Number: 'Number',           // Generic number (measure fallback)\n    Unknown: 'Unknown',         // Cannot determine type\n} as const;\n\n// Type for any semantic type string\nexport type SemanticType = typeof SemanticTypes[keyof typeof SemanticTypes];\n\n// ---------------------------------------------------------------------------\n// Visualization Categories  →  defined in type-registry.ts (single source of truth)\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Type Sets for Classification — derived from type-registry.ts\n// ---------------------------------------------------------------------------\n\n// timeseriesXTypes: REMOVED — derived from type-registry.ts via isTimeSeriesType()\n\n/**\n * Types suitable for quantitative encoding (true continuous measures).\n *\n * Derived from the registry: aggRole ∈ {additive, intensive, signed-additive},\n * excluding Score/Rating (t1='Score') which behave as bounded ordinal scales\n * for vis purposes (e.g., 1–5 star rating). This is an intentional vis-level\n * distinction, not a mathematical one.\n */\nexport const measureTypes = new Set<string>(\n    getRegisteredTypes().filter(t => {\n        const e = getRegistryEntry(t);\n        return ['additive', 'intensive', 'signed-additive'].includes(e.aggRole) && e.t1 !== 'Score';\n    })\n);\n\n/** Numeric types that should NOT be used as measures (don't aggregate) */\nexport const nonMeasureNumericTypes = new Set<string>([\n    'Rank', 'ID', 'Score',\n    'Year', 'Month', 'Day', 'Hour',\n    'Latitude', 'Longitude',\n]);\n\n/**\n * Types suitable for categorical color/grouping encoding.\n *\n * Derived from the registry: types that include 'nominal' in visEncodings\n * (at any position — Direction has ['ordinal','nominal']),\n * plus binned types (Range, AgeGroup) which also work as categorical for\n * color/grouping despite having 'ordinal' as their primary encoding.\n * Excludes identifiers (ID) which are nominal but not useful for grouping.\n */\nexport const categoricalTypes = new Set<string>(\n    getRegisteredTypes().filter(t => {\n        const e = getRegistryEntry(t);\n        return (e.visEncodings.includes('nominal') && e.aggRole !== 'identifier') || e.t1 === 'Binned';\n    })\n);\n\n/**\n * Types suitable for ordinal encoding (have inherent order).\n *\n * Derived from the registry: types whose visEncodings include 'ordinal'.\n */\nexport const ordinalTypes = new Set<string>(\n    getRegisteredTypes().filter(t => {\n        const e = getRegistryEntry(t);\n        return e.visEncodings.includes('ordinal');\n    })\n);\n\n// geoTypes, geoCoordinateTypes, geoLocationTypes: REMOVED — derived from type-registry.ts\n// via isGeoType(), isGeoCoordinateType(), isGeoLocationString()\n\n// ---------------------------------------------------------------------------\n// Type Hierarchy — REMOVED\n// ---------------------------------------------------------------------------\n// The typeHierarchy map and its helper functions (getParentType,\n// getAncestorTypes, isSubtypeOf) have been removed. They were unused\n// externally — no consumer ever imported them.\n//\n// The registry's t0/t1 dimensions capture family grouping (e.g., all\n// Amount types share t1='Amount'). If fine-grained parent-child lattice\n// traversal is ever needed in the future, it can be rebuilt from\n// type-registry.ts with an explicit `parent` field per entry.\n// ---------------------------------------------------------------------------\n\n// visCategoryMap: REMOVED — derived from type-registry.ts via getRegistryEntry().visEncodings[0]\n\n// ---------------------------------------------------------------------------\n// Helper Functions\n// ---------------------------------------------------------------------------\n\n/**\n * Get the Vega-Lite visualization category for a semantic type.\n * Derived from the registry's visEncodings[0] (primary encoding).\n * Returns null for unrecognised types so callers can fall back\n * to data-driven inference.\n */\nexport function getVisCategory(semanticType: string): VisCategory | null {\n    // Return null for empty, 'Unknown', or any unregistered type string\n    // so callers fall back to data-driven inference (inferVisCategory).\n    if (!semanticType || !isRegistered(semanticType)) return null;\n    return getRegistryEntry(semanticType).visEncodings[0] ?? null;\n}\n\n\n/**\n * Infer a VisCategory from raw data values when no semantic type is available.\n * Mirrors the DataType → VL encoding type mapping:\n *   number/integer → quantitative, boolean → nominal, date → temporal, string → nominal.\n */\nexport function inferVisCategory(values: any[]): VisCategory {\n    if (values.length === 0) return 'nominal';\n    const isBoolean = (v: any) => v === true || v === false || Object.prototype.toString.call(v) === '[object Boolean]';\n    const isNumber = (v: any) => !isNaN(+v) && !(Object.prototype.toString.call(v) === '[object Date]');\n    // Date.parse is too permissive in V8 — \"FY 2018\", \"hello world 2018\" all parse.\n    // Require the string to start with a digit or a known month-name prefix.\n    const looksLikeDate = (s: string) => /^\\d|^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i.test(s.trim());\n    const isDate = (v: any) => {\n        if (v instanceof Date) return !isNaN(v.getTime());\n        if (typeof v === 'string') return looksLikeDate(v) && !isNaN(Date.parse(v));\n        return !isNaN(Date.parse(v));\n    };\n    const nonNull = values.filter(v => v != null);\n    if (nonNull.length === 0) return 'nominal';\n    if (nonNull.every(isBoolean)) return 'nominal';\n    if (nonNull.every(isNumber)) return 'quantitative';\n    if (nonNull.every(isDate)) return 'temporal';\n    return 'nominal';\n}\n\n/**\n * Check if a semantic type is a true measure (suitable for quantitative encoding).\n */\nexport function isMeasureType(semanticType: string): boolean {\n    return measureTypes.has(semanticType);\n}\n\n/**\n * Check if a semantic type is suitable for time-series X axis.\n * Derived from type-registry: t0 === 'Temporal' but not Duration.\n */\nexport function isTimeSeriesType(semanticType: string): boolean {\n    const entry = getRegistryEntry(semanticType);\n    return entry.t0 === 'Temporal' && entry.t1 !== 'Duration';\n}\n\n/**\n * Check if a semantic type is categorical (suitable for color/grouping).\n */\nexport function isCategoricalType(semanticType: string): boolean {\n    return categoricalTypes.has(semanticType);\n}\n\n/**\n * Check if a semantic type is ordinal (has inherent order).\n */\nexport function isOrdinalType(semanticType: string): boolean {\n    return ordinalTypes.has(semanticType);\n}\n\n/**\n * Check if a semantic type is geographic.\n * Derived from type-registry: t0 === 'Geographic'.\n */\nexport function isGeoType(semanticType: string): boolean {\n    return getRegistryEntry(semanticType).t0 === 'Geographic';\n}\n\n/**\n * Check if a semantic type is a geographic coordinate (lat/lon).\n * Derived from type-registry: t1 === 'GeoCoordinate'.\n */\nexport function isGeoCoordinateType(semanticType: string): boolean {\n    return getRegistryEntry(semanticType).t1 === 'GeoCoordinate';\n}\n\n/**\n * Check if a semantic type is a named geographic location.\n * Derived from type-registry: t1 === 'GeoPlace'.\n */\nexport function isGeoLocationString(semanticType: string): boolean {\n    return getRegistryEntry(semanticType).t1 === 'GeoPlace';\n}\n\n/**\n * Check if a semantic type is numeric but should not be aggregated.\n */\nexport function isNonMeasureNumeric(semanticType: string): boolean {\n    return nonMeasureNumericTypes.has(semanticType);\n}\n\n// ---------------------------------------------------------------------------\n// Zero-Baseline Classification  →  data lives in type-registry.ts (zeroBaseline, zeroPad)\n// ---------------------------------------------------------------------------\n\n/**\n * Classification of whether zero is a meaningful baseline for a semantic type.\n *\n * - `meaningful`: 0 has a real-world interpretation (absence of the measured thing).\n *   Comparisons to zero and ratios between values are meaningful.\n *   Examples: Count, Revenue, Distance, Weight.\n *\n * - `arbitrary`: 0 is either meaningless, doesn't exist, or is an arbitrary\n *   reference point. The data's range is what matters.\n *   Examples: Temperature (0°F is arbitrary), Year (year 0 doesn't exist),\n *   Rank (0th place doesn't exist).\n *\n * - `contextual`: 0 is meaningful but data-fitting may be better when data\n *   is concentrated far from zero and the mark is not bar/area.\n *   Examples: Percentage (0–100% natural, but 48–52% benefits from zoom),\n *   Score (1–5 scale, but 4.2–4.8 benefits from zoom).\n */\nexport type ZeroClass = 'meaningful' | 'arbitrary' | 'contextual';\n\n/**\n * Result of the zero-baseline decision.\n * Encapsulates both the boolean decision and domain padding for non-zero axes.\n */\nexport interface ZeroDecision {\n    /** Whether the axis should include zero */\n    zero: boolean;\n    /**\n     * For non-zero axes: fraction of data range to pad on each side\n     * so edge values aren't crushed against the axis boundary.\n     * e.g. 0.05 = 5% padding on each side.\n     */\n    domainPadFraction: number;\n    /** The zero class that drove this decision */\n    zeroClass: ZeroClass | 'unknown';\n    /**\n     * Whether this is a *forced* (non-debatable) decision:\n     *   - `true`  → mandatory: a length/area mark, data that crosses zero, or a\n     *     zero-meaningful type on a length mark. Including zero is structural.\n     *   - `false` → the engine still has a recommended `zero`, but anchoring at\n     *     zero is at least conceptually a choice.\n     * `forced` records the structural side of the decision; it is NOT the gate\n     * for the UI toggle — see `uncertain` below.\n     */\n    forced: boolean;\n    /**\n     * Whether the zero-vs-fit choice is a *genuine toss-up worth surfacing* to\n     * the user. Hosts read this (via the property `check`) to decide whether to\n     * show the \"Zero X/Y\" toggle at all.\n     *\n     * We deliberately keep this narrow to avoid UI clutter: it is `true` ONLY\n     * for a zero-meaningful field on a position mark whose data sits far enough\n     * from zero that anchoring at zero would noticeably compress the view (a\n     * real zoom-in-vs-anchor tradeoff). Every other case — arbitrary types\n     * (zero is meaningless, just fit the data), contextual types (the engine's\n     * data-range call is confident enough), meaningful types whose data already\n     * spans most of the way to zero (the choice barely changes anything), and\n     * all forced/unknown cases — is `false`, so no toggle is shown and the\n     * engine's `zero` value simply applies. The engine's `zero` remains the\n     * recommended default when the toggle is shown.\n     */\n    uncertain: boolean;\n}\n\n// zeroMeaningfulTypes, zeroArbitraryTypes, zeroContextualTypes, zeroPadMap:\n// REMOVED — now stored as zeroBaseline/zeroPad in type-registry.ts\n\n/**\n * Classify a semantic type's relationship to zero.\n * Derived from the registry's zeroBaseline dimension.\n */\nexport function getZeroClass(semanticType: string): ZeroClass | 'unknown' {\n    const baseline = getRegistryEntry(semanticType).zeroBaseline;\n    if (baseline === 'none') return 'unknown';\n    return baseline;\n}\n\n/**\n * Compute whether a quantitative axis should start at zero, based on\n * semantic type, mark type, channel, and data values.\n *\n * Priority: semantic type > mark type > data range > VL default.\n *\n * This is a pure decision function — it returns a ZeroDecision object\n * without modifying any spec. The caller applies the decision to VL.\n *\n * @param semanticType  The semantic type of the field (e.g. 'Amount', 'Temperature')\n * @param channel       The VL channel ('x', 'y', 'size', etc.)\n * @param markType      The mark type ('bar', 'line', 'point', etc.)\n * @param values        Optional numeric data values for data-range analysis\n */\n/**\n * Above this ratio of dataMin/dataMax, the data band sits far enough above\n * zero that anchoring the axis at zero would leave at least half the axis\n * empty — a big enough gap that \"zoom into the data\" vs \"keep the zero\n * reference\" is a genuine toss-up worth offering as a toggle. Below it, the\n * data already spans most of the way to zero, so including zero barely changes\n * the view and we keep it on silently.\n */\nconst ZERO_BASELINE_GAP_THRESHOLD = 0.5;\n\n/**\n * True when strictly-positive data sits far enough from zero that anchoring at\n * zero would noticeably compress the view (see ZERO_BASELINE_GAP_THRESHOLD).\n * Returns false for empty data or any data that touches/crosses zero (there the\n * baseline is inside the data range, so it is not a debatable gap).\n */\nfunction dataFarFromZero(values?: number[]): boolean {\n    if (!values || values.length === 0) return false;\n    const dataMin = Math.min(...values);\n    const dataMax = Math.max(...values);\n    if (dataMin <= 0 || dataMax <= 0) return false;\n    return dataMin / dataMax >= ZERO_BASELINE_GAP_THRESHOLD;\n}\n\nexport function computeZeroDecision(\n    semanticType: string,\n    channel: string,\n    markType: string,\n    values?: number[],\n): ZeroDecision {\n    const isBarLike = ['bar', 'area', 'rect'].includes(markType);\n    const isScatterMark = markType === 'circle' || markType === 'point';\n    const isPositional = ['x', 'y'].includes(channel);\n    const entry = getRegistryEntry(semanticType);\n    const zeroClass = getZeroClass(semanticType);\n\n    // --- Zero-meaningful types: zero is the conventional baseline ---\n    if (zeroClass === 'meaningful') {\n        // Length marks (bar/area/rect): the baseline is structurally required —\n        // a bar's length is meaningless without zero. Not debatable.\n        if (isBarLike) {\n            return { zero: true, domainPadFraction: 0, zeroClass, forced: true, uncertain: false };\n        }\n        // Scatter (circle/point position): the read is correlation / cloud shape,\n        // not distance from zero — data-fit is the conventional default. Offer\n        // Zero X/Y as an opt-in toggle when the user wants a zero reference.\n        if (isPositional && isScatterMark) {\n            if (values && values.length > 0 && Math.min(...values) <= 0) {\n                return { zero: true, domainPadFraction: 0, zeroClass, forced: true, uncertain: false };\n            }\n            return {\n                zero: false,\n                domainPadFraction: entry.zeroPad || 0.05,\n                zeroClass,\n                forced: false,\n                uncertain: true,\n            };\n        }\n        // Position marks (line/strip): zero is the conventional reference,\n        // so the recommended default is ON. We only *offer* the toggle when the\n        // data sits far enough from zero that anchoring at zero would noticeably\n        // compress the view — a genuine zoom-in-vs-keep-the-reference toss-up.\n        // When the data already spans most of the way to zero, the choice barely\n        // changes anything, so we keep zero on silently and hide the toggle.\n        return {\n            zero: true,\n            domainPadFraction: 0,\n            zeroClass,\n            forced: false,\n            uncertain: dataFarFromZero(values),\n        };\n    }\n\n    // --- Zero-arbitrary types: never zero, apply padding ---\n    if (zeroClass === 'arbitrary') {\n        // Exception: bar/area marks with data that touches/crosses zero —\n        // the baseline is structurally required, so this is forced.\n        if (isBarLike && values && values.length > 0) {\n            const dataMin = Math.min(...values);\n            if (dataMin <= 0) {\n                return { zero: true, domainPadFraction: 0, zeroClass, forced: true, uncertain: false };\n            }\n        }\n        // Strictly away from zero on an arbitrary scale: zero is meaningless\n        // here, so data-fit is simply the right answer — there is nothing to\n        // debate and no toggle is offered.\n        return {\n            zero: false,\n            domainPadFraction: entry.zeroPad || 0.05,\n            zeroClass,\n            forced: false,\n            uncertain: false,\n        };\n    }\n\n    // --- Contextual types: use data range + mark to decide ---\n    if (zeroClass === 'contextual' && values && values.length > 0) {\n        const dataMin = Math.min(...values);\n        const dataMax = Math.max(...values);\n\n        // Data touches/crosses zero → include it (forced: the baseline is\n        // inside the data range).\n        if (dataMin <= 0) {\n            return { zero: true, domainPadFraction: 0, zeroClass, forced: true, uncertain: false };\n        }\n\n        // How far is data from zero?\n        const proximity = dataMax > 0 ? dataMin / dataMax : 0;\n\n        // Close to zero → include it. The engine's data-range call is confident\n        // enough here, so no toggle is offered.\n        if (proximity < 0.3) {\n            return { zero: true, domainPadFraction: 0, zeroClass, forced: false, uncertain: false };\n        }\n\n        // Far from zero + bar/area → still include (bar length integrity, forced).\n        if (isBarLike) {\n            return { zero: true, domainPadFraction: 0, zeroClass, forced: true, uncertain: false };\n        }\n\n        // Far from zero + non-bar → data-fit with padding (engine's call, no toggle).\n        return { zero: false, domainPadFraction: 0.05, zeroClass, forced: false, uncertain: false };\n    }\n\n    // --- No semantic type or unrecognized → no opinion, let VL decide ---\n    // Unknown class is never debatable: we have no basis for a toggle.\n    if (isBarLike && isPositional) {\n        return { zero: true, domainPadFraction: 0, zeroClass: 'unknown', forced: true, uncertain: false };\n    }\n    return { zero: false, domainPadFraction: 0.05, zeroClass: 'unknown', forced: true, uncertain: false };\n}\n\n/**\n * Compute padded domain bounds for a non-zero axis.\n * Pure computation — returns [paddedMin, paddedMax] without modifying any spec.\n *\n * @param values         Numeric data values\n * @param padFraction    Fraction of data range to pad on each side\n * @returns              [paddedMin, paddedMax] or null if padding is not applicable\n */\nexport function computePaddedDomain(\n    values: number[],\n    padFraction: number,\n): [number, number] | null {\n    if (padFraction <= 0 || values.length < 2) return null;\n\n    const dataMin = Math.min(...values);\n    const dataMax = Math.max(...values);\n    const span = dataMax - dataMin;\n    if (span <= 0) return null;\n\n    const padding = span * padFraction;\n    return [dataMin - padding, dataMax + padding];\n}\n\n// ---------------------------------------------------------------------------\n// Color Scheme Recommendations\n// ---------------------------------------------------------------------------\n\nexport type ColorSchemeType = 'categorical' | 'sequential' | 'diverging';\n\nexport interface ColorSchemeRecommendation {\n    scheme: string;\n    type: ColorSchemeType;\n    reason: string;\n    /** For diverging schemes, the recommended midpoint value */\n    domainMid?: number;\n}\n\n// getDivergingMidpoint: REMOVED — superseded by resolveDivergingInfo() in field-semantics.ts\n// which uses a priority chain (unit → type-intrinsic → domain → data) and\n// distinguishes inherent vs conditional diverging.\n\n/**\n * Vega-Lite color schemes organized by use case\n * See: https://vega.github.io/vega/docs/schemes/\n */\nconst colorSchemes = {\n    // Categorical (nominal) - good for distinct categories\n    categorical: {\n        default: 'category10',\n        large: 'category20',\n        pastel: 'pastel1',\n        accent: 'accent',\n        paired: 'paired',      // Good for paired comparisons\n        set1: 'set1',          // Distinct, saturated\n        set2: 'set2',          // Pastel\n        set3: 'set3',          // Larger set\n        tableau10: 'tableau10',\n        tableau20: 'tableau20',\n    },\n    // Sequential - good for ordered/quantitative data\n    sequential: {\n        blues: 'blues',\n        greens: 'greens',\n        oranges: 'oranges',\n        reds: 'reds',\n        purples: 'purples',\n        greys: 'greys',\n        // Multi-hue sequential\n        viridis: 'viridis',\n        inferno: 'inferno',\n        magma: 'magma',\n        plasma: 'plasma',\n        turbo: 'turbo',\n        // Domain-specific\n        yellowGreen: 'yellowgreen',\n        yellowOrangeBrown: 'yelloworangebrown',\n        goldGreen: 'goldgreen',\n        goldOrange: 'goldorange',\n        goldRed: 'goldred',\n    },\n    // Diverging - good for data with meaningful center point\n    diverging: {\n        redBlue: 'redblue',\n        redGrey: 'redgrey',\n        redYellowBlue: 'redyellowblue',\n        redYellowGreen: 'redyellowgreen',\n        pinkYellowGreen: 'pinkyellowgreen',\n        purpleGreen: 'purplegreen',\n        purpleOrange: 'purpleorange',\n        brownBlueGreen: 'brownbluegreen',\n    },\n};\n\n/**\n * Get recommended color scheme based on semantic type and encoding context.\n * \n * @param semanticType - The semantic type of the field\n * @param encodingType - The Vega-Lite encoding type ('nominal', 'ordinal', 'quantitative')\n * @param uniqueValueCount - Number of unique values (for categorical sizing)\n * @param fieldName - Field name (for consistent hashing)\n * @param values - Optional actual data values (for inspecting data range)\n * @param colorHint - Optional classification from resolveColorSchemeHint().\n *        When provided, the hint's type ('diverging'|'sequential'|'categorical')\n *        overrides inline detection, avoiding duplicate diverging logic.\n */\nexport function getRecommendedColorScheme(\n    semanticType: string | undefined,\n    encodingType: 'nominal' | 'ordinal' | 'quantitative' | 'temporal',\n    uniqueValueCount: number = 10,\n    fieldName: string = '',\n    values: any[] = [],\n    colorHint?: { type: 'categorical' | 'sequential' | 'diverging' },\n): ColorSchemeRecommendation {\n    \n    // Helper for consistent scheme selection from array\n    const pickScheme = (schemes: string[], name: string): string => {\n        let hash = 0;\n        for (let i = 0; i < name.length; i++) {\n            hash = ((hash << 5) - hash) + name.charCodeAt(i);\n            hash = hash & hash;\n        }\n        return schemes[Math.abs(hash) % schemes.length];\n    };\n\n    // If no semantic type, use defaults based on encoding type\n    if (!semanticType) {\n        if (encodingType === 'quantitative') {\n            return { scheme: 'viridis', type: 'sequential', reason: 'default for quantitative' };\n        }\n        if (encodingType === 'ordinal') {\n            return { scheme: 'blues', type: 'sequential', reason: 'default for ordinal' };\n        }\n        // nominal/temporal default to categorical — use saturated schemes for readability\n        return { \n            scheme: uniqueValueCount > 10 ? 'tableau20' : 'tableau10', \n            type: 'categorical', \n            reason: 'default for categorical' \n        };\n    }\n\n    // --- Diverging-capable types ---\n    // When a colorHint is provided (from resolveColorSchemeHint), it drives the\n    // diverging/sequential decision. Without a hint, fall back to sequential.\n    // This avoids duplicating the diverging detection logic from field-semantics.ts.\n\n    // Temperature\n    if (semanticType === 'Temperature') {\n        if (colorHint?.type === 'diverging') {\n            return { scheme: 'redblue', type: 'diverging', reason: 'temperature diverging around freezing point' };\n        }\n        return { scheme: 'reds', type: 'sequential', reason: 'temperature single-direction uses sequential' };\n    }\n\n    // Percentage\n    if (semanticType === 'Percentage') {\n        if (colorHint?.type === 'diverging') {\n            return { scheme: 'redblue', type: 'diverging', reason: 'percentage spans positive and negative' };\n        }\n        return { scheme: 'oranges', type: 'sequential', reason: 'percentage all same sign uses sequential' };\n    }\n\n    // Price/Amount\n    if (['Price', 'Amount'].includes(semanticType)) {\n        if (colorHint?.type === 'diverging') {\n            return { scheme: 'redblue', type: 'diverging', reason: 'financial data spans positive and negative' };\n        }\n        return { scheme: 'goldgreen', type: 'sequential', reason: 'financial data uses gold-green' };\n    }\n\n    // Score - evaluation metrics; diverging when hint says so (e.g., domain midpoint)\n    if (semanticType === 'Score') {\n        if (colorHint?.type === 'diverging') {\n            return { scheme: 'redblue', type: 'diverging', reason: 'score/rating diverging around midpoint' };\n        }\n        return { scheme: 'yelloworangebrown', type: 'sequential', reason: 'scores use warm sequential' };\n    }\n\n    // Rank - use single-hue sequential\n    if (semanticType === 'Rank') {\n        return { scheme: 'purples', type: 'sequential', reason: 'ranks use single-hue sequential' };\n    }\n\n    // Ranges - use sequential\n    if (semanticType === 'Range') {\n        return { scheme: 'blues', type: 'sequential', reason: 'range groups use sequential' };\n    }\n\n    // Temporal granules (Year, Month, Quarter, etc.) - sequential for continuity\n    if (ordinalTypes.has(semanticType) && ['Year', 'Quarter', 'Month', 'Week', 'Day', 'Hour', 'Decade'].includes(semanticType)) {\n        return { scheme: 'viridis', type: 'sequential', reason: 'temporal granules use perceptually uniform' };\n    }\n\n    // Geographic locations - use geographic-friendly palettes\n    if (getRegistryEntry(semanticType ?? '').t1 === 'GeoPlace') {\n        if (uniqueValueCount <= 10) {\n            return { scheme: 'set2', type: 'categorical', reason: 'geographic regions use distinct pastels' };\n        }\n        return { scheme: 'tableau20', type: 'categorical', reason: 'many regions use large categorical' };\n    }\n\n    // Status/Boolean - use accent colors for clear distinction\n    if (['Status', 'Boolean'].includes(semanticType)) {\n        return { scheme: 'set1', type: 'categorical', reason: 'status uses high-contrast categorical' };\n    }\n\n    // Categories - use standard categorical\n    if (semanticType === 'Category') {\n        return { \n            scheme: uniqueValueCount > 10 ? 'tableau20' : 'tableau10', \n            type: 'categorical', \n            reason: 'categories use standard categorical' \n        };\n    }\n\n    // Names (persons, companies, products) - use saturated schemes for readability\n    if (semanticType === 'Name') {\n        return { \n            scheme: uniqueValueCount > 8 ? 'tableau20' : 'set2', \n            type: 'categorical', \n            reason: 'names use readable categorical' \n        };\n    }\n\n    // Duration - use sequential (longer = more intense)\n    if (semanticType === 'Duration') {\n        return { scheme: 'oranges', type: 'sequential', reason: 'duration uses intensity-based sequential' };\n    }\n\n    // Quantity/Count/Distance/etc. - general measures\n    // Check colorHint first — signed measures (Profit, Sentiment, Correlation,\n    // PercentageChange) pass through here and should honor their diverging hint.\n    if (measureTypes.has(semanticType)) {\n        if (colorHint?.type === 'diverging') {\n            return { scheme: 'redblue', type: 'diverging', reason: 'measure with diverging nature' };\n        }\n        const sequentialSchemes = ['viridis', 'blues', 'greens', 'reds', 'yelloworangebrown', 'goldgreen'];\n        return { \n            scheme: pickScheme(sequentialSchemes, fieldName), \n            type: 'sequential', \n            reason: 'measures use perceptually uniform sequential' \n        };\n    }\n\n    // Ordinal types not already handled\n    if (ordinalTypes.has(semanticType) || encodingType === 'ordinal') {\n        const ordinalSchemes = ['blues', 'greens', 'purples', 'oranges'];\n        return { \n            scheme: pickScheme(ordinalSchemes, fieldName), \n            type: 'sequential', \n            reason: 'ordinal data uses sequential scheme' \n        };\n    }\n\n    // Default categorical for nominal\n    if (encodingType === 'nominal' || encodingType === 'temporal') {\n        return { \n            scheme: uniqueValueCount > 10 ? 'tableau20' : 'tableau10', \n            type: 'categorical', \n            reason: 'default categorical palette' \n        };\n    }\n\n    // Fallback\n    return { scheme: 'viridis', type: 'sequential', reason: 'universal fallback' };\n}\n\n// getRecommendedColorSchemeWithMidpoint: REMOVED — diverging midpoint is now\n// resolved via resolveDivergingInfo() in field-semantics.ts and applied directly\n// by the caller in resolve-semantics.ts. See resolveChannelSemantics().\n\n// ===========================================================================\n// Canonical Ordinal Sort Orders\n// ===========================================================================\n\n/**\n * Well-known canonical ordinal sequences.\n *\n * Used to detect when data values belong to a known ordinal domain\n * (months, days of the week, quarters, etc.) and sort them in their\n * natural order instead of alphabetically or by a quantitative axis.\n */\n\n/** Full and abbreviated English month names (case-insensitive lookup). */\nconst MONTH_FULL = ['January','February','March','April','May','June','July','August','September','October','November','December'];\nconst MONTH_ABBR3 = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];\nconst MONTH_NUM = ['1','2','3','4','5','6','7','8','9','10','11','12'];\n\n/** Full and abbreviated English day-of-week names. */\nconst DOW_FULL = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];\nconst DOW_ABBR3 = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];\nconst DOW_ABBR2 = ['Mo','Tu','We','Th','Fr','Sa','Su'];\n\n/** Sunday-first variant (US convention). */\nconst DOW_FULL_SUN = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];\nconst DOW_ABBR3_SUN = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];\n\n/** Quarter labels. */\nconst QUARTER_LABELS = ['Q1','Q2','Q3','Q4'];\n\n/** Compass directions — clockwise from North (top of chart). */\nconst COMPASS_8 = ['N','NE','E','SE','S','SW','W','NW'];\nconst COMPASS_8_FULL = ['North','Northeast','East','Southeast','South','Southwest','West','Northwest'];\nconst COMPASS_4 = ['N','E','S','W'];\nconst COMPASS_4_FULL = ['North','East','South','West'];\n\ninterface OrdinalSequence {\n    /** Canonical labels in order */\n    labels: string[];\n    /** Case-insensitive matching */\n    caseInsensitive: boolean;\n}\n\n/** All known ordinal sequences, keyed by semantic type. */\nconst ORDINAL_SEQUENCES: Record<string, OrdinalSequence[]> = {\n    Month: [\n        { labels: MONTH_FULL, caseInsensitive: true },\n        { labels: MONTH_ABBR3, caseInsensitive: true },\n        { labels: MONTH_NUM, caseInsensitive: false },\n    ],\n    Day: [\n        { labels: DOW_FULL, caseInsensitive: true },\n        { labels: DOW_ABBR3, caseInsensitive: true },\n        { labels: DOW_ABBR2, caseInsensitive: true },\n        { labels: DOW_FULL_SUN, caseInsensitive: true },\n        { labels: DOW_ABBR3_SUN, caseInsensitive: true },\n    ],\n    Quarter: [\n        { labels: QUARTER_LABELS, caseInsensitive: true },\n    ],\n    Direction: [\n        { labels: COMPASS_8, caseInsensitive: true },\n        { labels: COMPASS_8_FULL, caseInsensitive: true },\n        { labels: COMPASS_4, caseInsensitive: true },\n        { labels: COMPASS_4_FULL, caseInsensitive: true },\n    ],\n};\n\n/**\n * Build a case-insensitive lookup map from a sequence's labels.\n * Returns map: lowercased label → index.\n */\nfunction buildLookup(seq: OrdinalSequence): Map<string, number> {\n    const m = new Map<string, number>();\n    for (let i = 0; i < seq.labels.length; i++) {\n        const key = seq.caseInsensitive ? seq.labels[i].toLowerCase() : seq.labels[i];\n        m.set(key, i);\n    }\n    return m;\n}\n\n/**\n * Try to match a set of data values against a well-known ordinal sequence.\n *\n * Returns the canonical sort order (subset of the sequence, in order) if\n * enough values match, or `undefined` if no match.\n *\n * Matching rules:\n * - At least 60% of unique data values must be found in the sequence\n * - All matched values are returned in canonical order\n * - Unmatched values are appended at the end (preserving data order)\n *\n * @param values     The data values (strings or numbers) on this channel\n * @param sequences  The candidate sequences for the semantic type\n */\nfunction matchSequence(values: any[], sequences: OrdinalSequence[]): string[] | undefined {\n    const uniqueValues = [...new Set(values.map(v => v != null ? String(v) : ''))].filter(v => v !== '');\n    if (uniqueValues.length === 0) return undefined;\n\n    for (const seq of sequences) {\n        const lookup = buildLookup(seq);\n        const matched: { value: string; index: number }[] = [];\n        const unmatched: string[] = [];\n\n        for (const val of uniqueValues) {\n            const key = seq.caseInsensitive ? val.toLowerCase() : val;\n            const idx = lookup.get(key);\n            if (idx !== undefined) {\n                matched.push({ value: val, index: idx });\n            } else {\n                unmatched.push(val);\n            }\n        }\n\n        // Require at least 60% match rate\n        if (matched.length >= uniqueValues.length * 0.6 && matched.length >= 2) {\n            // Sort matched values by canonical index\n            matched.sort((a, b) => a.index - b.index);\n            const result = matched.map(m => m.value);\n            // Append unmatched at the end\n            result.push(...unmatched);\n            return result;\n        }\n    }\n    return undefined;\n}\n\n/**\n * Infer a canonical ordinal sort order for a field based on its semantic type\n * and data values.\n *\n * Works for:\n * - Month names (full/abbreviated/numeric): Jan, Feb, ... or January, February, ...\n * - Day-of-week names (full/abbreviated): Mon, Tue, ... or Monday, Tuesday, ...\n * - Quarter labels: Q1, Q2, Q3, Q4\n *\n * Falls back to `undefined` if no known sequence is detected, letting the\n * caller use its own default sort logic.\n *\n * @param semanticType  The semantic type of the field (e.g. 'Month', 'Day')\n * @param values        The data values on this channel\n * @returns Sorted unique values in canonical order, or undefined\n */\nexport function inferOrdinalSortOrder(\n    semanticType: string,\n    values: any[],\n): string[] | undefined {\n    // 1. Check by explicit semantic type\n    const sequences = ORDINAL_SEQUENCES[semanticType];\n    if (sequences) {\n        return matchSequence(values, sequences);\n    }\n\n    // 2. Auto-detect: try all sequences if semantic type is generic\n    if (!semanticType || semanticType === 'Category' || semanticType === 'Unknown') {\n        for (const seqs of Object.values(ORDINAL_SEQUENCES)) {\n            const result = matchSequence(values, seqs);\n            if (result) return result;\n        }\n    }\n\n    return undefined;\n}\n\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * =============================================================================\n * REUSABLE DECISION LOGIC\n * =============================================================================\n *\n * Pure decision functions that determine chart layout behavior.\n * These functions take data/config inputs and return decision objects —\n * NO Vega-Lite spec mutation happens here.\n *\n * The separation ensures:\n * 1. Decision logic is testable in isolation\n * 2. Same decisions can drive different output formats (VL, SVG, etc.)\n * 3. Templates can call decision functions without coupling to VL\n *\n * Naming conventions:\n *   - `compute*()` — returns a decision/value from inputs\n *   - `resolve*()` — picks from alternatives (type resolution, etc.)\n *   - `classify*()` — categorizes an input\n * =============================================================================\n */\n\nimport {\n    inferVisCategory,\n    type VisCategory,\n} from './semantic-types';\nimport { getRegistryEntry, isRegistered } from './type-registry';\n\n// ---------------------------------------------------------------------------\n// Encoding Type Resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Result of encoding type resolution.\n * Separates the decision from what gets written into VL.\n */\nexport interface EncodingTypeDecision {\n    /** The resolved VL encoding type */\n    vlType: 'quantitative' | 'ordinal' | 'nominal' | 'temporal';\n    /** The VisCategory that drove the decision */\n    visCategory: VisCategory;\n    /** Whether the type was overridden by channel rules */\n    channelOverride: boolean;\n    /** Whether the type was overridden by cardinality/fraction guard */\n    cardinalityGuard: boolean;\n}\n\n// ---------------------------------------------------------------------------\n// Helpers for encoding type resolution\n// ---------------------------------------------------------------------------\n\n/**\n * Map a VisCategory to the corresponding VL encoding type string.\n * Geographic maps to quantitative since VL uses quantitative for coordinates.\n */\nfunction visCategoryToVLType(vc: VisCategory): 'quantitative' | 'ordinal' | 'nominal' | 'temporal' {\n    switch (vc) {\n        case 'quantitative': return 'quantitative';\n        case 'ordinal': return 'ordinal';\n        case 'temporal': return 'temporal';\n        case 'geographic': return 'quantitative';\n        case 'nominal':\n        default: return 'nominal';\n    }\n}\n\n/**\n * Validate that field values actually parse as dates.\n *\n * @param fromRegistry  If true, uses a looser threshold (≥30%) since the\n *                      semantic type explicitly identified the field as temporal.\n *                      If false (data-inferred), requires ≥50%.\n */\nfunction validateTemporalParsing(\n    data: any[],\n    fieldName: string,\n    fromRegistry: boolean,\n): boolean {\n    const sampleValues = data.map(r => r[fieldName]).slice(0, 15).filter((v: any) => v != null);\n    if (sampleValues.length === 0) return false;\n\n    // Single unique value → not useful as temporal axis (would show a single point)\n    const uniqueValues = new Set(sampleValues.map(String));\n    if (uniqueValues.size <= 1) return false;\n\n    const looksTemporalValue = (val: any): boolean => {\n        if (val instanceof Date) return true;\n        if (typeof val === 'number') {\n            // Year-like integers (1500–2200)\n            if (val >= 1500 && val <= 2200 && val % 1 === 0) return true;\n            // Unix-ms timestamps: 86_400_000 (Jan 2, 1970) to ~year 2103\n            if (val > 86400000 && val < 4200000000000) return true;\n            return false;\n        }\n        if (typeof val === 'string') {\n            const trimmed = val.trim();\n            if (!trimmed) return false;\n            if (/^\\d{4}$/.test(trimmed)) return true;\n            return !Number.isNaN(Date.parse(trimmed));\n        }\n        return false;\n    };\n\n    const passingCount = sampleValues.filter(looksTemporalValue).length;\n    const minFraction = fromRegistry ? 0.3 : 0.5;\n    return passingCount / sampleValues.length >= minFraction;\n}\n\n/**\n * Apply temporal channel-compatibility adjustments, shared by both\n * registry-driven and data-inferred temporal paths.\n */\nfunction resolveTemporalEncoding(\n    visCategory: VisCategory,\n    channel: string,\n    data: any[],\n    fieldName: string,\n    fromRegistry: boolean,\n): EncodingTypeDecision {\n    // Temporal on facet/size channels → ordinal (VL limitation)\n    if (['size', 'column', 'row'].includes(channel)) {\n        return { vlType: 'ordinal', visCategory, channelOverride: true, cardinalityGuard: false };\n    }\n    // Temporal on color with low cardinality → ordinal for distinct colors\n    if (channel === 'color') {\n        const uniqueCount = new Set(data.map(r => r[fieldName])).size;\n        if (uniqueCount <= 12) {\n            return { vlType: 'ordinal', visCategory, channelOverride: true, cardinalityGuard: false };\n        }\n    }\n    // Validate temporal parsing\n    if (!validateTemporalParsing(data, fieldName, fromRegistry)) {\n        return { vlType: 'ordinal', visCategory, channelOverride: false, cardinalityGuard: false };\n    }\n    return { vlType: 'temporal', visCategory, channelOverride: false, cardinalityGuard: false };\n}\n\n/**\n * Apply channel-context guards to an ordinal encoding.\n *\n * Even when the registry says a field is ordinal, channel context may\n * require promoting to quantitative:\n *   - High cardinality on color/group → unreadable legend\n *   - High cardinality on x/y        → bars/lollipops need proportional\n *     spacing and baseline anchoring (y2/x2)\n *   - Fractional values + high cardinality → mis-classified continuous measure\n *\n * @param fromRegistry  Whether the ordinal type came from the registry\n *        (true) or was data-inferred (false). Data-inferred additionally\n *        checks for fractional values (Guard 1).\n */\nfunction applyOrdinalGuards(\n    visCategory: VisCategory,\n    channel: string,\n    data: any[],\n    fieldName: string,\n    fieldValues: any[],\n    fromRegistry: boolean,\n): EncodingTypeDecision {\n    const numericVals = fieldValues.filter(v => v != null && !isNaN(+v)).map(Number);\n    if (numericVals.length > 0) {\n        const uniqueCount = new Set(numericVals).size;\n        const hasFractions = numericVals.some(v => v % 1 !== 0);\n\n        // Guard 1 (data-inferred only): fractional + high-cardinality →\n        // mis-classified continuous measure. Registry types are explicit,\n        // so this guard only applies when the type was inferred from data.\n        if (!fromRegistry && hasFractions && uniqueCount > 20) {\n            return { vlType: 'quantitative', visCategory, channelOverride: false, cardinalityGuard: true };\n        }\n\n        // Guard 2: integer ordinal with high cardinality on color/group →\n        // a discrete legend with 12+ entries is unreadable; promote to\n        // quantitative so VL renders a continuous gradient instead.\n        if (!hasFractions && uniqueCount > 12 && ['color', 'group'].includes(channel)) {\n            return { vlType: 'quantitative', visCategory, channelOverride: true, cardinalityGuard: true };\n        }\n\n        // Guard 3: integer ordinal with high cardinality on position\n        // axes (x, y) → charts like bar/lollipop need a quantitative\n        // axis for proportional length; treating 12+ unique integers\n        // as discrete categories produces an unreadable axis and\n        // prevents baseline anchoring (y2/x2).\n        if (!hasFractions && uniqueCount > 12 && ['x', 'y'].includes(channel)) {\n            return { vlType: 'quantitative', visCategory, channelOverride: true, cardinalityGuard: true };\n        }\n    }\n    return { vlType: 'ordinal', visCategory, channelOverride: false, cardinalityGuard: false };\n}\n\n/**\n * Disambiguate when the registry lists multiple visEncodings for a type.\n *\n * Uses channel context and data characteristics to select the most\n * appropriate encoding from the candidates. Each combination of\n * candidate encodings has dedicated logic:\n *\n *   temporal + ordinal  (Year, YearMonth, Decade, …)\n *   quantitative + ordinal  (Score, Rating)\n *   quantitative + geographic  (Latitude, Longitude)\n *   ordinal + nominal  (Direction)\n */\nfunction disambiguateMultiEncoding(\n    candidates: VisCategory[],\n    channel: string,\n    data: any[],\n    fieldName: string,\n    fieldValues: any[],\n): EncodingTypeDecision {\n    const has = (vc: VisCategory) => candidates.includes(vc);\n\n    // ── Temporal + Ordinal (Year, YearMonth, Decade, etc.) ────────\n    // Time-unit granules. Temporal for continuous time axes (x/y);\n    // ordinal for grouping channels (color, facet, size).\n    if (has('temporal') && has('ordinal')) {\n        return resolveTemporalEncoding('temporal', channel, data, fieldName, true);\n    }\n\n    // ── Quantitative + Ordinal (Score, Rating) ────────────────────\n    // Bounded discrete numerics. Use ordinal for grouping channels\n    // with low cardinality (distinct colors/symbols); quantitative\n    // for position axes (proportional spacing, zero-baseline).\n    if (has('quantitative') && has('ordinal')) {\n        if (['color', 'group'].includes(channel)) {\n            const uniqueCount = new Set(data.map(r => r[fieldName])).size;\n            if (uniqueCount <= 12) {\n                return { vlType: 'ordinal', visCategory: 'ordinal', channelOverride: false, cardinalityGuard: false };\n            }\n            // High-cardinality Score/Rating on color → quantitative gradient\n            return { vlType: 'quantitative', visCategory: 'quantitative', channelOverride: false, cardinalityGuard: true };\n        }\n        if (['column', 'row'].includes(channel)) {\n            return { vlType: 'ordinal', visCategory: 'ordinal', channelOverride: false, cardinalityGuard: false };\n        }\n        // x, y, size → quantitative (proportional axis)\n        return { vlType: 'quantitative', visCategory: 'quantitative', channelOverride: false, cardinalityGuard: false };\n    }\n\n    // ── Quantitative + Geographic (Latitude, Longitude) ───────────\n    // Geographic is for map projections; standard encodings use quantitative.\n    if (has('quantitative') && has('geographic')) {\n        return { vlType: 'quantitative', visCategory: 'quantitative', channelOverride: false, cardinalityGuard: false };\n    }\n\n    // ── Ordinal + Nominal (Direction) ─────────────────────────────\n    // Inherently ordered, but nominal for grouping channels to get\n    // distinct (unordered) colors rather than a sequential scale.\n    if (has('ordinal') && has('nominal')) {\n        if (['color', 'group'].includes(channel)) {\n            return { vlType: 'nominal', visCategory: 'nominal', channelOverride: false, cardinalityGuard: false };\n        }\n        return { vlType: 'ordinal', visCategory: 'ordinal', channelOverride: false, cardinalityGuard: false };\n    }\n\n    // ── Fallback: first candidate ─────────────────────────────────\n    const fallback = candidates[0];\n    return { vlType: visCategoryToVLType(fallback), visCategory: fallback, channelOverride: false, cardinalityGuard: false };\n}\n\n// ---------------------------------------------------------------------------\n// Main API\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve the VL encoding type for a field.\n *\n * Two-stage pipeline:\n *\n * **Stage 1 — Registry-driven** (when semanticType is registered):\n *   - Single visEncoding  → use it directly (with channel adjustments)\n *   - Multiple visEncodings → `disambiguateMultiEncoding()` selects best\n *     option using channel context + data characteristics\n *\n * **Stage 2 — Data-inferred fallback** (no registered semantic type):\n *   - `inferVisCategory()` inspects raw values → VisCategory\n *   - Heuristic guards catch common mis-classifications (e.g., dense\n *     fractional data inferred as ordinal)\n *\n * This is a pure decision — it does NOT mutate any spec.\n *\n * @param semanticType   Semantic type string (e.g. 'Quantity', 'Country')\n * @param fieldValues    Sampled values from the field\n * @param channel        VL channel name (e.g. 'x', 'y', 'color')\n * @param data           Full data table (for computing unique value counts)\n * @param fieldName      Field name (for data lookups)\n */\nexport function resolveEncodingType(\n    semanticType: string,\n    fieldValues: any[],\n    channel: string,\n    data: any[],\n    fieldName: string,\n): EncodingTypeDecision {\n    // ═══════════════════════════════════════════════════════════════════\n    // Stage 1: Registry-driven resolution\n    // ═══════════════════════════════════════════════════════════════════\n    // The registry's visEncodings array is the source of truth.\n    //   - Single encoding  → resolved directly\n    //   - Multiple encodings → disambiguated by channel + data\n    if (semanticType && isRegistered(semanticType)) {\n        const entry = getRegistryEntry(semanticType);\n        const candidates = entry.visEncodings;\n\n        if (candidates.length > 1) {\n            // Multiple encodings listed — disambiguate semantically\n            return disambiguateMultiEncoding(candidates, channel, data, fieldName, fieldValues);\n        }\n\n        // Single encoding — use it directly with channel adjustments\n        const baseType = candidates[0];\n\n        // Guard: if the registry says quantitative but the actual values\n        // are strings (e.g. semantic \"Quantity\" on a binned field like\n        // \"91-95\"), fall back to data-inferred type.  Numeric strings\n        // that parse as numbers (e.g. \"42\") still count as numeric.\n        if (baseType === 'quantitative') {\n            const nonNull = fieldValues.filter(v => v != null);\n            const allNumeric = nonNull.length > 0 &&\n                nonNull.every(v => typeof v === 'number' || (typeof v === 'string' && !isNaN(+v) && v.trim() !== ''));\n            if (!allNumeric) {\n                // Values aren't actually numeric — infer from data instead\n                const inferred = inferVisCategory(fieldValues);\n                return {\n                    vlType: visCategoryToVLType(inferred),\n                    visCategory: inferred,\n                    channelOverride: false,\n                    cardinalityGuard: false,\n                };\n            }\n        }\n\n        if (baseType === 'temporal') {\n            return resolveTemporalEncoding(baseType, channel, data, fieldName, true);\n        }\n        if (baseType === 'ordinal') {\n            return applyOrdinalGuards(baseType, channel, data, fieldName, fieldValues, true);\n        }\n        return {\n            vlType: visCategoryToVLType(baseType),\n            visCategory: baseType,\n            channelOverride: false,\n            cardinalityGuard: false,\n        };\n    }\n\n    // ═══════════════════════════════════════════════════════════════════\n    // Stage 2: Data-inferred fallback\n    // ═══════════════════════════════════════════════════════════════════\n    // No registered semantic type — infer from raw data values, then\n    // apply heuristic guards for common data-inference mis-classifications.\n    const visCategory: VisCategory = inferVisCategory(fieldValues);\n    const channelOverride = false;\n    const cardinalityGuard = false;\n\n    switch (visCategory) {\n        case 'temporal':\n            return resolveTemporalEncoding(visCategory, channel, data, fieldName, false);\n\n        case 'ordinal':\n            return applyOrdinalGuards(visCategory, channel, data, fieldName, fieldValues, false);\n\n        case 'quantitative':\n            return { vlType: 'quantitative', visCategory, channelOverride, cardinalityGuard };\n\n        case 'geographic':\n            return { vlType: 'quantitative', visCategory, channelOverride, cardinalityGuard };\n\n        case 'nominal':\n        default:\n            return { vlType: 'nominal', visCategory, channelOverride, cardinalityGuard };\n    }\n}\n\n// ---------------------------------------------------------------------------\n// Continuous Axis Gas Pressure Model (docs/design-stretch-model.md §2)\n// ---------------------------------------------------------------------------\n\n/**\n * Parameters for the per-axis stretch model (docs/design-stretch-model.md §2).\n *\n * Each axis is stretched independently based on how many distinguishable\n * positions (or series) compete for pixel space along that axis.\n */\nexport interface GasPressureParams {\n    /** Mark cross-section in px² — used as default σ for both axes (default: 30) */\n    markCrossSection: number;\n    /** Per-axis cross-section overrides. When set, the per-axis stretch\n     *  uses these instead of `markCrossSection`.\n     *  Useful for line charts where X needs more stretch than Y. */\n    markCrossSectionX?: number;\n    markCrossSectionY?: number;\n    /** Override X item count for stretch.\n     *  When set, X stretch uses this count (e.g. number of series)\n     *  instead of counting unique X pixel positions. */\n    xItemCountOverride?: number;\n    /** Override Y item count for stretch.\n     *  When set, Y stretch uses this count (e.g. number of series)\n     *  instead of counting unique Y pixel positions. */\n    yItemCountOverride?: number;\n    /** Power-law exponent for continuous stretch (default: 0.3) */\n    elasticity: number;\n    /** Maximum stretch multiplier cap (default: 1.5) */\n    maxStretch: number;\n}\n\n/** Default gas pressure parameters (§2 recommendations). */\nexport const DEFAULT_GAS_PRESSURE_PARAMS: GasPressureParams = {\n    markCrossSection: 30,\n    elasticity: 0.3,\n    maxStretch: 1.5,\n};\n\n/**\n * Result of the per-axis stretch decision.\n */\nexport interface GasPressureDecision {\n    /** Per-axis stretch: X axis (1 = no stretch, capped by maxStretch) */\n    stretchX: number;\n    /** Per-axis stretch: Y axis (1 = no stretch, capped by maxStretch) */\n    stretchY: number;\n    /** Uncapped stretch for X (raw pressure^elasticity, not clipped to maxStretch).\n     *  Used by the layout engine to compute ideal aspect ratio before squeezing. */\n    rawStretchX: number;\n    /** Uncapped stretch for Y (raw pressure^elasticity, not clipped to maxStretch). */\n    rawStretchY: number;\n}\n\n/**\n * Compute per-axis stretch for a continuous 2D axis region.\n *\n * Implements docs/design-stretch-model.md §2: each axis is stretched independently based\n * on how many distinguishable positions (or series) compete for pixel\n * space along that axis.\n *\n * Two modes per axis:\n *   - Positional: count unique pixel positions, σ_1d = √σ.\n *   - Series-count: when xItemCountOverride / yItemCountOverride is set,\n *     use that count directly with σ (not sqrt'd) since it's already 1D.\n *\n * @param xValues      Numeric x-coordinates of data points\n * @param yValues      Numeric y-coordinates of data points\n * @param xDomain      Scale domain [min, max] for x-axis\n * @param yDomain      Scale domain [min, max] for y-axis\n * @param canvasWidth  Base canvas width W₀\n * @param canvasHeight Base canvas height H₀\n * @param params       Gas pressure parameters (optional, uses defaults)\n */\nexport function computeGasPressure(\n    xValues: number[],\n    yValues: number[],\n    xDomain: [number, number],\n    yDomain: [number, number],\n    canvasWidth: number,\n    canvasHeight: number,\n    params: GasPressureParams = DEFAULT_GAS_PRESSURE_PARAMS,\n): GasPressureDecision {\n    const N = xValues.length;\n\n    if (N <= 1 || canvasWidth <= 0 || canvasHeight <= 0) {\n        return { stretchX: 1, stretchY: 1, rawStretchX: 1, rawStretchY: 1 };\n    }\n\n    // Per-axis stretch via unique-position linear packing.\n    // The question for each axis is: \"how many distinguishable positions\n    // compete for pixel space along this axis?\"\n    //\n    // Count unique positions (bucketed to ~1px resolution) along each\n    // axis. Each unique position needs σ_1d ≈ √σ pixels of space.\n    // 1D pressure = uniquePositions × σ_1d / axisDimension.\n    const sigma1dDefault = Math.sqrt(params.markCrossSection); // ~5 px\n\n    /** Returns [cappedStretch, rawStretch] for one axis. */\n    const computeAxisStretch = (values: number[], domain: [number, number], baseDim: number, sigma1d: number): [number, number] => {\n        if (baseDim <= 0 || values.length <= 1) return [1, 1];\n\n        const range = domain[1] - domain[0];\n        if (range <= 0) return [1, 1];\n\n        // Bucket values to ~1px resolution in pixel space\n        const pxPerUnit = baseDim / range;\n        const seen = new Set<number>();\n        for (const v of values) {\n            seen.add(Math.round((v - domain[0]) * pxPerUnit));\n        }\n        const uniquePositions = seen.size;\n\n        // 1D pressure: how many sigma-sized marks fight for baseDim pixels\n        const pressure = (uniquePositions * sigma1d) / baseDim;\n        if (pressure <= 1) return [1, 1];\n        const raw = Math.pow(pressure, params.elasticity);\n        return [Math.min(params.maxStretch, raw), raw];\n    };\n\n    const sigma1dX = params.markCrossSectionX != null ? Math.sqrt(params.markCrossSectionX) : sigma1dDefault;\n    const sigma1dY = params.markCrossSectionY != null ? Math.sqrt(params.markCrossSectionY) : sigma1dDefault;\n\n    // Helper: compute stretch for one axis, using series-count override if set.\n    // When a series override is provided, σ is used directly (not sqrt'd)\n    // because series count is already a 1D concept.\n    /** Returns [cappedStretch, rawStretch] for one axis, with series-count override support. */\n    const computeStretchForAxis = (\n        values: number[], domain: [number, number], baseDim: number,\n        sigma1d: number, sigmaRaw: number, itemCountOverride?: number,\n    ): [number, number] => {\n        if (itemCountOverride != null && sigmaRaw > 0) {\n            const pressure = (itemCountOverride * sigmaRaw) / baseDim;\n            if (pressure <= 1) return [1, 1];\n            const raw = Math.pow(pressure, params.elasticity);\n            return [Math.min(params.maxStretch, raw), raw];\n        }\n        return sigma1d > 0 ? computeAxisStretch(values, domain, baseDim, sigma1d) : [1, 1];\n    };\n\n    const sigmaRawX = params.markCrossSectionX ?? params.markCrossSection;\n    const sigmaRawY = params.markCrossSectionY ?? params.markCrossSection;\n    const [stretchX, rawStretchX] = computeStretchForAxis(xValues, xDomain, canvasWidth, sigma1dX, sigmaRawX, params.xItemCountOverride);\n    const [stretchY, rawStretchY] = computeStretchForAxis(yValues, yDomain, canvasHeight, sigma1dY, sigmaRawY, params.yItemCountOverride);\n\n    return { stretchX, stretchY, rawStretchX, rawStretchY };\n}\n\n// ---------------------------------------------------------------------------\n// Elastic Stretch Computation\n// ---------------------------------------------------------------------------\n\n/**\n * Parameters for elastic axis stretch computation.\n * These control the spring-model behavior from docs/design-stretch-model.md §1.\n */\nexport interface ElasticStretchParams {\n    /** Power-law exponent for stretch (default: 0.5) */\n    elasticity: number;\n    /** Maximum stretch multiplier cap (default: 2) */\n    maxStretch: number;\n    /** Default step size in px per discrete item */\n    defaultStepSize: number;\n    /** Minimum pixels per discrete item (default: 6) */\n    minStep: number;\n}\n\n/**\n * Result of elastic budget computation for a single axis.\n */\nexport interface ElasticBudget {\n    /** Elastic-stretched canvas budget in px */\n    budget: number;\n    /** Stretch multiplier applied (1 = no stretch) */\n    stretchFactor: number;\n}\n\n/**\n * Compute the elastic canvas budget for an axis with N discrete items.\n *\n * When N items at defaultStepSize exceed the base dimension, the axis\n * stretches using a power-law: stretch = min(maxStretch, pressure^elasticity).\n *\n * @param itemCount       Number of discrete items on the axis\n * @param baseDimension   Base canvas size (width or height) in px\n * @param params          Elastic stretch parameters\n */\nexport function computeElasticBudget(\n    itemCount: number,\n    baseDimension: number,\n    params: ElasticStretchParams,\n): ElasticBudget {\n    if (itemCount <= 0) {\n        return { budget: baseDimension, stretchFactor: 1 };\n    }\n    const pressure = (itemCount * params.defaultStepSize) / baseDimension;\n    if (pressure <= 1) {\n        return { budget: baseDimension, stretchFactor: 1 };\n    }\n    const stretchFactor = Math.min(params.maxStretch, Math.pow(pressure, params.elasticity));\n    return {\n        budget: baseDimension * stretchFactor,\n        stretchFactor,\n    };\n}\n\n/**\n * Result of per-axis step computation.\n */\nexport interface AxisStepDecision {\n    /** Computed step size in px per item */\n    step: number;\n    /** Total canvas budget in px */\n    budget: number;\n    /** Number of items this step was computed for */\n    itemCount: number;\n}\n\n/**\n * Compute the step size for a single axis, covering both discrete\n * and continuous-as-discrete (banded) cases.\n *\n * @param nominalCount       Number of discrete (nominal/ordinal) items\n * @param continuousCount    Number of continuous-as-discrete items (banded Q/T)\n * @param baseDimension      Base canvas size (width or height) in px\n * @param params             Elastic stretch parameters\n */\nexport function computeAxisStep(\n    nominalCount: number,\n    continuousCount: number,\n    baseDimension: number,\n    params: ElasticStretchParams,\n): AxisStepDecision {\n    if (nominalCount > 0) {\n        const { budget } = computeElasticBudget(nominalCount, baseDimension, params);\n        return { step: Math.floor(budget / nominalCount), budget, itemCount: nominalCount };\n    }\n    if (continuousCount > 0) {\n        const { budget } = computeElasticBudget(continuousCount, baseDimension, params);\n        return { step: Math.floor(budget / continuousCount), budget, itemCount: continuousCount };\n    }\n    return { step: params.defaultStepSize, budget: baseDimension, itemCount: 0 };\n}\n\n// ---------------------------------------------------------------------------\n// Facet Layout Decisions\n// ---------------------------------------------------------------------------\n\n/**\n * Result of facet layout computation.\n */\nexport interface FacetLayoutDecision {\n    /** Number of facet columns */\n    columns: number;\n    /** Number of facet rows */\n    rows: number;\n    /** Per-subplot width in px */\n    subplotWidth: number;\n    /** Per-subplot height in px */\n    subplotHeight: number;\n}\n\n/**\n * Parameters for facet layout computation.\n */\nexport interface FacetLayoutParams {\n    /** Power-law exponent for facet stretch (default: 0.3) */\n    facetElasticity: number;\n    /** Maximum total stretch multiplier cap (default: 2) */\n    maxStretch: number;\n    /** Minimum subplot size in px (default: 60) */\n    minSubplotSize: number;\n}\n\n/**\n * Compute facet subplot dimensions.\n *\n * @param facetCols       Number of facet columns\n * @param facetRows       Number of facet rows\n * @param baseWidth       Base canvas width in px\n * @param baseHeight      Base canvas height in px\n * @param params          Facet layout parameters\n */\nexport function computeFacetLayout(\n    facetCols: number,\n    facetRows: number,\n    baseWidth: number,\n    baseHeight: number,\n    params: FacetLayoutParams,\n): FacetLayoutDecision {\n    // Minimum subplot dimension — use the caller-supplied parameter\n    // (default 60px) so subplots remain readable.\n    const minContinuousSize = params.minSubplotSize;\n\n    let subplotWidth: number;\n    if (facetCols > 1) {\n        const stretch = Math.min(params.maxStretch, Math.pow(facetCols, params.facetElasticity));\n        subplotWidth = Math.round(Math.max(minContinuousSize, baseWidth * stretch / facetCols));\n    } else {\n        subplotWidth = baseWidth;\n    }\n\n    let subplotHeight: number;\n    if (facetRows > 1) {\n        const stretch = Math.min(params.maxStretch, Math.pow(facetRows, params.facetElasticity));\n        subplotHeight = Math.round(Math.max(minContinuousSize, baseHeight * stretch / facetRows));\n    } else {\n        subplotHeight = baseHeight;\n    }\n\n    return { columns: facetCols, rows: facetRows, subplotWidth, subplotHeight };\n}\n\n// ---------------------------------------------------------------------------\n// Label Sizing Decisions\n// ---------------------------------------------------------------------------\n\n/**\n * Result of label sizing computation for a discrete axis.\n */\nexport interface LabelSizingDecision {\n    /** Font size in px */\n    fontSize: number;\n    /** Max label width in px */\n    labelLimit: number;\n    /** Label rotation angle (undefined = no rotation) */\n    labelAngle?: number;\n    /** Label alignment (for rotated labels) */\n    labelAlign?: string;\n    /** Label baseline (for rotated labels) */\n    labelBaseline?: string;\n}\n\n/**\n * Compute label sizing for a discrete axis based on the effective step size.\n * Pure decision — returns sizing params without modifying any spec.\n *\n * The font descends the **shrink → rotate → cap** ladder from a backend-native\n * base font (`baseFont`), never exceeding it and never dropping below `minFont`:\n *   1. Wide band  → horizontal label at (up to) `baseFont`.\n *   2. Medium band → shrink a little and rotate -45°.\n *   3. Narrow band → shrink more and rotate -90°.\n * `labelLimit` caps the label width so long text is truncated (…) rather than\n * overflowing arbitrarily.\n *\n * @param effectiveStep      Pixels per discrete item\n * @param hasDiscreteItems   Whether the axis has discrete items\n * @param opts               `baseFont` (native ceiling) and `minFont` (floor)\n */\nexport function computeLabelSizing(\n    effectiveStep: number,\n    hasDiscreteItems: boolean,\n    opts?: { baseFont?: number; minFont?: number },\n): LabelSizingDecision {\n    const baseFont = opts?.baseFont ?? 10;\n    const minFont = opts?.minFont ?? 6;\n    const defaultLimit = 100;\n\n    if (!hasDiscreteItems) {\n        return { fontSize: baseFont, labelLimit: defaultLimit };\n    }\n\n    // Shrink lever: font tracks the band step but is bounded by [minFont, baseFont].\n    let fontSize = Math.max(minFont, Math.min(baseFont, effectiveStep - 1));\n    let labelLimit = Math.max(30, Math.min(100, effectiveStep * 8));\n    let labelAngle: number | undefined;\n    let labelAlign: string | undefined;\n    let labelBaseline: string | undefined;\n\n    if (effectiveStep < 10) {\n        // Narrow band → rotate vertical, shrink harder (but keep the ceiling\n        // one notch below base so a 12-native backend still reads ~10 here).\n        labelAngle = -90;\n        fontSize = Math.max(minFont, Math.min(baseFont - 2, effectiveStep));\n        labelLimit = 40;\n        labelAlign = 'right';\n        labelBaseline = 'middle';\n    } else if (effectiveStep < 16) {\n        // Medium band → rotate 45°, shrink slightly.\n        labelAngle = -45;\n        fontSize = Math.max(minFont, Math.min(baseFont - 1, effectiveStep));\n        labelLimit = 60;\n        labelAlign = 'right';\n        labelBaseline = 'top';\n    }\n\n    return { fontSize, labelLimit, labelAngle, labelAlign, labelBaseline };\n}\n\n/**\n * Canvas-adaptive font sizes for headers (axis titles, legend, chart title) and\n * the base for axis tick labels.\n *\n * The per-backend base fonts are the preferred (native) sizes. Fonts render at\n * that base and only **shrink** for genuinely small small-multiple subplots\n * (so dense facets don't overflow); they are never grown above native, matching\n * how the underlying renderers keep fonts constant across canvas sizes.\n *\n * @param minPlotDimension  The smaller of the (sub)plot width/height in px\n * @param opts              Backend-native base font sizes\n */\nexport interface FontSizingDecision {\n    /** Ceiling for axis tick labels (feeds computeLabelSizing `baseFont`). */\n    tickBase: number;\n    /** Header font for axis titles and chart title. */\n    titleFontSize: number;\n    /** Legend entry font (one notch below the title). */\n    legendFontSize: number;\n}\n\nexport function computeFontSizing(\n    minPlotDimension: number,\n    opts?: { baseLabelFontSize?: number; baseTitleFontSize?: number },\n): FontSizingDecision {\n    const baseLabel = opts?.baseLabelFontSize ?? 10;\n    const baseTitle = opts?.baseTitleFontSize ?? 11;\n    // The per-backend base fonts ARE the preferred (native) sizes: native\n    // renderers (Plotly/VL/ECharts) keep tick/title/legend fonts CONSTANT at\n    // every canvas size. So we do NOT grow above base — growth made large\n    // charts render heavy, oversized text. Fonts only SHRINK for genuinely\n    // small small-multiple subplots (minDim < 220) so dense facets don't\n    // overflow; otherwise they render at native base.\n    const minDim = minPlotDimension || 320;\n    const ratio = minDim >= 220 ? 1 : Math.max(0.7, minDim / 220);\n    const atMostNative = (base: number) =>\n        Math.round(Math.max(base - 2, Math.min(base, base * ratio)));\n    const tickBase = atMostNative(baseLabel);\n    const titleFontSize = atMostNative(baseTitle);\n    const legendFontSize = Math.max(baseTitle - 2, titleFontSize - 1);\n    return { tickBase, titleFontSize, legendFontSize };\n}\n\n// ---------------------------------------------------------------------------\n// Overflow Decision\n// ---------------------------------------------------------------------------\n\n/**\n * Result of overflow analysis for a discrete axis.\n */\nexport interface OverflowDecision {\n    /** Whether overflow occurred (more items than can fit) */\n    overflowed: boolean;\n    /** Maximum items to keep */\n    maxToKeep: number;\n    /** Number of items omitted */\n    omittedCount: number;\n}\n\n/**\n * Compute whether a discrete axis overflows and how many items to keep.\n *\n * @param uniqueCount    Number of unique values on the axis\n * @param maxDimension   Maximum canvas dimension (with stretch) in px\n * @param minStepSize    Minimum px per item\n */\nexport function computeOverflow(\n    uniqueCount: number,\n    maxDimension: number,\n    minStepSize: number,\n): OverflowDecision {\n    const maxToKeep = Math.floor(maxDimension / minStepSize);\n    const overflowed = uniqueCount > maxToKeep;\n    return {\n        overflowed,\n        maxToKeep,\n        omittedCount: overflowed ? uniqueCount - maxToKeep : 0,\n    };\n}\n\n// ---------------------------------------------------------------------------\n// Circumference-pressure model for radial charts (§3)\n// ---------------------------------------------------------------------------\n\n/**\n * Parameters for circumference-pressure scaling (spring model on polar axis).\n */\nexport interface CircumferencePressureParams {\n    /** Minimum arc-length (px) each \"effective bar\" needs on the\n     *  circumference — analogous to defaultStepSize in the spring model.\n     *  Default: 45 */\n    minArcPx?: number;\n    /** Minimum chart radius in px. Default: 60 */\n    minRadius?: number;\n    /** Maximum chart radius in px. Caps runaway growth. Default: 400 */\n    maxRadius?: number;\n    /** Power-law exponent for pressure → stretch (same as spring model).\n     *  0.5 = square-root growth. Default: 0.5 */\n    elasticity?: number;\n    /** Per-dimension maximum stretch multiplier cap (matches bar-chart\n     *  default of 2.0).  The effective max stretch on the radius is\n     *  derived from min(baseW, baseH) × maxStretch so that the chart\n     *  never exceeds the cap in either dimension.  Default: 2.0 */\n    maxStretch?: number;\n    /** Per-dimension cap for the width axis. Defaults to `maxStretch`.\n     *  Lets the radius ceiling honor an asymmetric canvas (canvasW/baseW). */\n    maxStretchX?: number;\n    /** Per-dimension cap for the height axis. Defaults to `maxStretch`.\n     *  Lets the radius ceiling honor an asymmetric canvas (canvasH/baseH). */\n    maxStretchY?: number;\n    /** Extra margin outside the chart circle (px) for labels, legend, etc.\n     *  Added to each side when computing canvas dimensions. Default: 20 */\n    margin?: number;\n}\n\n/**\n * Result of circumference pressure computation.\n */\nexport interface CircumferencePressureResult {\n    /** Computed chart radius in px */\n    radius: number;\n    /** Recommended canvas width (px) */\n    canvasW: number;\n    /** Recommended canvas height (px) */\n    canvasH: number;\n}\n\n/**\n * Compute radial chart sizing using the spring model mapped to a polar axis.\n *\n * Treats the circumference as a linear \"bar axis\":\n *   baseCircumference = 2π × baseRadius\n *   pressure = effectiveItemCount × minArcPx / baseCircumference\n *   if pressure > 1:  stretch = min(maxStretch, pressure ^ elasticity)\n *   radius = baseRadius × stretch\n *\n * **effectiveItemCount** varies by chart type:\n *   - Rose / Radar: N categories (uniform slices/spokes)\n *   - Pie: total / minValue — how many of the smallest slice fit in the\n *     full circle.  This captures the worst-case thin slice that needs\n *     minimum arc width.\n *   - Sunburst: same as pie but computed on the outer ring leaves only.\n *\n * Both canvas dimensions grow equally (maintains 1:1 circular aspect).\n *\n * @param effectiveItemCount  Effective number of uniform \"bars\" around\n *                            the circle (see above)\n * @param canvasSize          Base canvas dimensions (from context)\n * @param params              Optional tuning parameters\n */\nexport function computeCircumferencePressure(\n    effectiveItemCount: number,\n    canvasSize: { width: number; height: number },\n    params: CircumferencePressureParams = {},\n): CircumferencePressureResult {\n    const {\n        minArcPx = 45,\n        minRadius = 60,\n        maxRadius = 400,\n        elasticity = 0.5,\n        maxStretch = 2.0,\n        margin = 20,\n    } = params;\n\n    // Per-dimension caps default to the scalar maxStretch (symmetric canvas).\n    const maxStretchX = Math.max(1, params.maxStretchX ?? maxStretch);\n    const maxStretchY = Math.max(1, params.maxStretchY ?? maxStretch);\n\n    const baseW = canvasSize.width;\n    const baseH = canvasSize.height;\n\n    // Base radius: largest circle that fits in the base canvas\n    const baseRadius = Math.max(minRadius,\n        (Math.min(baseW, baseH) / 2) - margin);\n\n    // ── Effective max-stretch on the radius ──────────────────────────\n    // The radius stretch expands the canvas in BOTH x and y equally.\n    // Cap so that neither dimension exceeds its per-dimension budget.\n    const maxCanvasW = baseW * maxStretchX;\n    const maxCanvasH = baseH * maxStretchY;\n    const maxDiameter = Math.min(maxCanvasW, maxCanvasH);\n    const effectiveMaxRadius = Math.min(maxRadius,\n        (maxDiameter - 2 * margin) / 2);\n    const effectiveMaxStretch = Math.max(1, effectiveMaxRadius / baseRadius);\n\n    // Spring model: pressure = items × step / baseDimension\n    const baseCircumference = 2 * Math.PI * baseRadius;\n    const pressure = (effectiveItemCount * minArcPx) / baseCircumference;\n\n    let radius: number;\n    if (pressure <= 1) {\n        // No pressure — base radius is sufficient\n        radius = baseRadius;\n    } else {\n        // Elastic stretch (same power law as bar-chart spring model)\n        const stretch = Math.min(effectiveMaxStretch, Math.pow(pressure, elasticity));\n        radius = Math.round(baseRadius * stretch);\n    }\n\n    // Clamp\n    radius = Math.min(maxRadius, Math.max(minRadius, radius));\n\n    // Canvas = diameter + margins\n    const diameter = 2 * radius + 2 * margin;\n    const canvasW = Math.max(baseW, diameter);\n    const canvasH = Math.max(baseH, diameter);\n\n    return { radius, canvasW, canvasH };\n}\n\n/**\n * Compute effective bar count for variable-width slices (pie / sunburst).\n *\n * If all slices are equal, this returns N (number of slices).\n * If slices vary, this returns `total / minValue` — i.e., how many of the\n * thinnest slice would fill the whole circle.  This is the worst-case\n * pressure that determines whether the chart needs to grow.\n *\n * Capped at 100 to prevent degenerate cases (near-zero slices) from\n * blowing up the radius.\n *\n * @param values  Array of slice values (must be > 0)\n */\nexport function computeEffectiveBarCount(values: number[]): number {\n    if (values.length === 0) return 0;\n    const positiveValues = values.filter(v => v > 0);\n    if (positiveValues.length === 0) return values.length;\n\n    const total = positiveValues.reduce((s, v) => s + v, 0);\n    const minVal = Math.min(...positiveValues);\n\n    // effectiveCount = total / minVal → how many of the smallest slice fill the circle\n    const effective = total / minVal;\n\n    // Cap at 100 to prevent degenerate cases\n    return Math.min(100, effective);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * =============================================================================\n * FIELD SEMANTICS\n * =============================================================================\n *\n * Resolves what a data field *is* by combining its semantic annotation\n * (from LLM or user) with the actual data values. This resolves the\n * one-to-many ambiguities in the type registry (e.g., Score can be\n * quantitative or ordinal depending on cardinality).\n *\n * The entry point is `resolveFieldSemantics()`. It produces a\n * `FieldSemantics` object that captures the field's identity, format,\n * aggregation role, domain, scale hint, and ordering — everything\n * about *what the data represents*, independent of how it will be\n * visualized on any particular channel.\n *\n * Design doc: docs/design-compilation-context.md\n *\n * VL dependency: **None** — pure TypeScript, no rendering library imports.\n * =============================================================================\n */\n\nimport {\n    type VisCategory,\n    getRegistryEntry,\n    isRegistered,\n} from './type-registry';\n\nimport {\n    getZeroClass,\n    inferOrdinalSortOrder,\n    inferVisCategory,\n    type ZeroClass,\n} from './semantic-types';\n\n// Re-export for backward compatibility — consumers can import from here or type-registry\nexport { getRegistryEntry } from './type-registry';\nexport type { TypeRegistryEntry } from './type-registry';\n\n// =============================================================================\n// §1  PUBLIC TYPES\n// =============================================================================\n\n/**\n * Enriched semantic annotation from LLM or user.\n */\nexport interface SemanticAnnotation {\n    /** The T2 semantic type string (e.g., \"Amount\", \"Score\", \"Month\") */\n    semanticType: string;\n\n    /**\n     * Intrinsic domain (value range) of this field's scale.\n     * Only for bounded/scaled types — NOT for open-ended measures.\n     * E.g., [1, 5] for 5-star rating, [0, 100] for score, [-90, 90] for latitude.\n     */\n    intrinsicDomain?: [number, number];\n\n    /** Unit or currency code. E.g., \"USD\", \"°C\", \"kg\" */\n    unit?: string;\n\n    /** Explicit ordinal ordering. E.g., [\"Low\", \"Medium\", \"High\"] */\n    sortOrder?: string[];\n}\n\n/** d3-compatible format specification */\nexport interface FormatSpec {\n    /** d3-format pattern: \",.2f\", \".1%\", \"+.2f\", etc. */\n    pattern?: string;\n    /** Prefix before the number: \"$\", \"€\", \"£\" */\n    prefix?: string;\n    /** Suffix after the number: \"°C\", \"%\", \" kg\" */\n    suffix?: string;\n    /** Whether large values should be abbreviated (1K, 1M, 1B) */\n    abbreviate?: boolean;\n}\n\n/** Domain bounds constraint */\nexport interface DomainConstraint {\n    min?: number;\n    max?: number;\n    /** Whether to hard-clamp values outside the domain */\n    clamp?: boolean;\n}\n\n/** Tick mark constraint */\nexport interface TickConstraint {\n    /** Only show integer tick values */\n    integersOnly?: boolean;\n    /** Exact tick values to show (for small domains like 1–5 rating) */\n    exactTicks?: number[];\n    /** Minimum step between ticks */\n    minStep?: number;\n}\n\n/** Color scheme recommendation from semantic analysis */\nexport interface ColorSchemeHint {\n    /** Whether the field is best shown with sequential, diverging, or categorical colors */\n    type: 'sequential' | 'diverging' | 'categorical';\n    /** For diverging: the midpoint value */\n    divergingMidpoint?: number;\n    /** Whether the field is inherently diverging (always show diverging) vs conditional */\n    inherentlyDiverging?: boolean;\n}\n\n/** Result of diverging midpoint analysis */\nexport interface DivergingInfo {\n    /** The midpoint value where the diverging center sits */\n    midpoint: number;\n    /** Whether this type is always diverging or only when data spans both sides */\n    inherent: boolean;\n    /** Source of the midpoint determination */\n    source: 'unit' | 'type-intrinsic' | 'domain' | 'data';\n}\n\n/**\n * Resolved field semantics — what the data field *is*.\n *\n * Derived from a `SemanticAnnotation` (semantic type + optional metadata)\n * plus actual data values. Resolves the one-to-many ambiguities in the\n * type registry by inspecting the concrete data representation.\n *\n * This is purely about the field’s identity and intrinsic properties —\n * NOT about how it will be visualized on a particular channel.\n * Channel-specific decisions (color scheme, axis reversal, interpolation,\n * tick strategy, stacking, etc.) belong in `ChannelSemantics`.\n *\n * Built once per field per dataset by `resolveFieldSemantics()`.\n */\nexport interface FieldSemantics {\n    // --- Identity ---\n    /** The semantic annotation (normalized from string or object input) */\n    semanticAnnotation: SemanticAnnotation;\n\n    // --- Encoding ---\n    /** Preferred encoding type, disambiguated from registry using data */\n    defaultVisType: VisCategory;\n\n    // --- Formatting ---\n    /** Number format derived from data type and unit (only set when confident) */\n    format?: FormatSpec;\n    /** Tooltip format (typically higher precision than axis format) */\n    tooltipFormat?: FormatSpec;\n\n    // --- Aggregation ---\n    /** Default aggregate function — intrinsic to the field (additive vs intensive) */\n    aggregationDefault?: 'sum' | 'average';\n\n    // --- Scale ---\n    /** Zero-baseline classification (meaningful / arbitrary / bipolar) */\n    zeroClass: ZeroClass | 'unknown';\n    /** Recommended scale type based on data distribution */\n    scaleType?: 'linear' | 'log' | 'sqrt' | 'symlog';\n\n    // --- Domain ---\n    /** Intrinsic domain bounds (from annotation, type-intrinsic, or data-inferred) */\n    domainConstraint?: DomainConstraint;\n\n    // --- Ordering ---\n    /** Canonical ordinal sort order (months, days, etc.) */\n    canonicalOrder?: string[];\n    /** Whether the canonical order is cyclic (wraps around) */\n    cyclic: boolean;\n    /** Default sort direction */\n    sortDirection: 'ascending' | 'descending';\n\n    // --- Histogram ---\n    /** Whether this field’s data distribution benefits from binning */\n    binningSuggested: boolean;\n}\n\n// =============================================================================\n// §2  TYPE REGISTRY  →  see ./type-registry.ts (single source of truth)\n// =============================================================================\n\n/**\n * Extract the semantic type string from a bare string or annotation object.\n * Used when downstream code only needs the type string, not the full annotation.\n */\nexport function toTypeString(input: string | SemanticAnnotation | undefined): string {\n    if (!input) return '';\n    if (typeof input === 'string') return input;\n    return input.semanticType || '';\n}\n\n// =============================================================================\n// §3  ANNOTATION NORMALIZATION\n// =============================================================================\n\n/**\n * Normalize a bare string or enriched annotation object into a\n * consistent SemanticAnnotation.\n *\n * Accepts:\n *   \"Amount\"                                          → { semanticType: \"Amount\" }\n *   { semanticType: \"Score\", intrinsicDomain: [1,5] }  → as-is\n *   undefined / \"\"                                     → { semanticType: \"Unknown\" }\n */\nexport function normalizeAnnotation(\n    input: string | SemanticAnnotation | undefined,\n): SemanticAnnotation {\n    if (!input) return { semanticType: 'Unknown' };\n    if (typeof input === 'string') return { semanticType: input || 'Unknown' };\n    return { ...input, semanticType: input.semanticType || 'Unknown' };\n}\n\n// =============================================================================\n// §4  FORMAT RESOLUTION\n// =============================================================================\n\n/** Map currency codes to display symbols */\nconst CURRENCY_MAP: Record<string, string> = {\n    USD: '$', EUR: '€', GBP: '£', JPY: '¥', CNY: '¥',\n    KRW: '₩', INR: '₹', BRL: 'R$', CAD: 'CA$', AUD: 'A$',\n    CHF: 'CHF', SEK: 'kr', NOK: 'kr', DKK: 'kr',\n};\n\n/**\n * Map common unit strings to suffix display.\n *\n * Limited to a small set of well-known, universally understood units.\n * Unknown/arbitrary annotation.unit values are intentionally excluded\n * to keep axis labels clean and avoid displaying obscure or verbose\n * unit strings on tick marks.\n */\nconst UNIT_SUFFIX_MAP: Record<string, string> = {\n    // Temperature\n    '°C': '°C', '°F': '°F', C: '°C', F: '°F',\n    // Mass\n    kg: ' kg', lb: ' lb',\n    // Distance\n    km: ' km', mi: ' mi', m: ' m', ft: ' ft',\n    // Speed\n    'km/h': ' km/h', mph: ' mph',\n    // Time\n    sec: ' s', min: ' min', hr: ' hr',\n    seconds: ' s', minutes: ' min', hours: ' hr',\n    // Percentage (handled by formatClass, but allow explicit suffix)\n    '%': '%',\n};\n\n/**\n * Detect whether percentage data uses 0–1 (fractional) or 0–100 (whole-number)\n * representation.\n *\n * Values can exceed the intrinsic range (e.g., 155 % growth), so we look at\n * the *majority* of absolute values rather than just the max.\n */\nfunction detectPercentageRepresentation(values: number[]): '0-1' | '0-100' {\n    if (values.length === 0) return '0-100';\n    const abs = values.map(Math.abs);\n    // If the majority of values are ≤ 1, treat as fractional 0–1 representation\n    const countBelow1 = abs.filter(v => v <= 1).length;\n    if (countBelow1 / abs.length >= 0.8) return '0-1';\n    return '0-100';\n}\n\n/**\n * Detect the maximum number of meaningful decimal places in a set of values.\n *\n * Returns 0 for all-integer data, 1 for data like [3.7, 4.2], 2 for [1.25, 3.50], etc.\n * Caps at 4 to avoid floating-point noise (e.g., 0.1 + 0.2 = 0.30000000000000004).\n */\nfunction detectPrecision(values: number[]): number {\n    let maxDecimals = 0;\n    for (const v of values) {\n        if (!Number.isFinite(v)) continue;\n        // Convert to string, trim trailing zeros, count decimal places\n        const s = v.toFixed(10);  // enough digits to detect real precision\n        const dot = s.indexOf('.');\n        if (dot === -1) continue;\n        // Trim trailing zeros\n        let end = s.length - 1;\n        while (end > dot && s[end] === '0') end--;\n        const decimals = end > dot ? end - dot : 0;\n        if (decimals > maxDecimals) maxDecimals = decimals;\n    }\n    return Math.min(maxDecimals, 4);\n}\n\n/**\n * Build a d3-format pattern that matches the detected data precision.\n *\n * @param values  Numeric data values\n * @param useGrouping  Whether to include thousands separator (,)\n * @param signMode  '' = default, '+' = always show sign\n * @returns  Format pattern string like ',d', ',.1f', ',.2f'\n */\nfunction precisionFormat(values: number[], useGrouping = true, signMode: '' | '+' = ''): string {\n    const p = detectPrecision(values);\n    const group = useGrouping ? ',' : '';\n    if (p === 0) return `${signMode}${group}d`;\n    return `${signMode}${group}.${p}f`;\n}\n\n/**\n * Resolve the format specification for a field based on its semantic type,\n * annotation metadata, and data values.\n *\n * Priority: annotation.unit > type-specific defaults\n */\nexport function resolveFormat(\n    semanticType: string,\n    annotation: SemanticAnnotation,\n    values: any[],\n): { format?: FormatSpec; tooltipFormat?: FormatSpec } {\n    const entry = getRegistryEntry(semanticType);\n    const unit = annotation.unit;\n\n    // Resolve currency prefix from annotation.unit\n    const currencyPrefix = unit ? CURRENCY_MAP[unit.toUpperCase()] ?? CURRENCY_MAP[unit] : undefined;\n    // Resolve unit suffix from annotation.unit — only use known units;\n    // unknown units are dropped to avoid polluting tick labels with\n    // obscure or verbose strings.\n    const unitSuffix = unit ? UNIT_SUFFIX_MAP[unit] : undefined;\n\n    const nums = values.filter((v: any) => typeof v === 'number' && !isNaN(v));\n\n    // ─── Policy: only override axis format when the raw number would be\n    // genuinely misleading.  Two cases qualify:\n    //   1. Percent with 0–1 data + intrinsicDomain → representation transform\n    //   2. Currency with a known unit → add currency symbol\n    // Everything else: let VL handle axis formatting natively.\n    // Tooltip format is lower-stakes (transient hover) so we're more liberal.\n\n    switch (entry.formatClass) {\n        case 'currency': {\n            const pfx = currencyPrefix;\n            // Only override axis when we have a known currency symbol;\n            // without it the axis is better left to VL defaults.\n            if (pfx) {\n                const axisPattern = semanticType === 'Price' ? ',.2f' : precisionFormat(nums);\n                return {\n                    format: { pattern: axisPattern, prefix: pfx },\n                    tooltipFormat: { pattern: ',.2f', prefix: pfx },\n                };\n            }\n            return { tooltipFormat: { pattern: ',.2f' } };\n        }\n\n        case 'percent': {\n            // Without intrinsicDomain we can't reliably distinguish 0–1\n            // from 0–100, so defer to VL.\n            if (!annotation.intrinsicDomain) {\n                return { tooltipFormat: { pattern: precisionFormat(nums) } };\n            }\n            const rep = detectPercentageRepresentation(nums);\n            if (rep === '0-1') {\n                // 0–1 fractional → axis must transform (0.45 → \"45%\")\n                const p = detectPrecision(nums);\n                const axisP = Math.max(0, p - 2);\n                const tipP  = Math.min(axisP + 1, 4);\n                return {\n                    format: { pattern: `.${axisP}~%` },\n                    tooltipFormat: { pattern: `.${tipP}%` },\n                };\n            }\n            // Whole-number 0–100: raw numbers are readable as-is.\n            // Axis title conveys \"percentage\"; tooltip adds suffix for clarity.\n            return {\n                tooltipFormat: { pattern: precisionFormat(nums, false), suffix: '%' },\n            };\n        }\n\n        case 'unit-suffix':\n            return {\n                tooltipFormat: unitSuffix\n                    ? { pattern: precisionFormat(nums), suffix: unitSuffix }\n                    : { pattern: precisionFormat(nums) },\n            };\n\n        case 'integer':\n            // Year/Decade: no comma — '2,024' is wrong for a year.\n            // Other integers (Count, Rank, Hour): comma separator aids readability.\n            if (semanticType === 'Year' || semanticType === 'Decade') {\n                return {};\n            }\n            return { tooltipFormat: { pattern: ',d' } };\n\n        case 'decimal':\n            return { tooltipFormat: { pattern: precisionFormat(nums) } };\n\n        case 'plain':\n        default:\n            return {};\n    }\n}\n\n// =============================================================================\n// §5  DEFAULT VIS TYPE\n// =============================================================================\n\n/**\n * Resolve the default Vega-Lite encoding type for a field.\n *\n * When the registry lists multiple candidates (e.g., Score → ['quantitative', 'ordinal']),\n * disambiguate using data statistics (distinct value count).\n */\nexport function resolveDefaultVisType(\n    semanticType: string,\n    values: any[],\n): VisCategory {\n    // For unregistered types, defer entirely to data characteristics\n    if (!isRegistered(semanticType)) {\n        return inferVisCategory(values);\n    }\n\n    const entry = getRegistryEntry(semanticType);\n    const candidates = entry.visEncodings;\n    if (candidates.length === 1) {\n        // Guard: if registry says quantitative but actual values are\n        // strings (e.g. binned ranges like \"91-95\"), defer to data inference.\n        if (candidates[0] === 'quantitative') {\n            const nonNull = values.filter(v => v != null);\n            const allNumeric = nonNull.length > 0 &&\n                nonNull.every(v => typeof v === 'number' || (typeof v === 'string' && !isNaN(+v) && v.trim() !== ''));\n            if (!allNumeric) {\n                return inferVisCategory(values);\n            }\n        }\n        return candidates[0];\n    }\n\n    // Disambiguate between quantitative and ordinal based on distinct count\n    if (candidates.includes('quantitative') && candidates.includes('ordinal')) {\n        const distinct = new Set(values.filter(v => v != null)).size;\n        // Small number of distinct values → ordinal feels more natural\n        return distinct <= 12 ? 'ordinal' : 'quantitative';\n    }\n\n    // Disambiguate between temporal and ordinal\n    if (candidates.includes('temporal') && candidates.includes('ordinal')) {\n        const distinct = new Set(values.filter(v => v != null)).size;\n        // Few values → ordinal (e.g., only 3 years: 2022, 2023, 2024)\n        return distinct <= 6 ? 'ordinal' : 'temporal';\n    }\n\n    // If geographic + quantitative (lat/lon), prefer quantitative for standard charts\n    if (candidates.includes('geographic') && candidates.includes('quantitative')) {\n        return 'quantitative';\n    }\n\n    return candidates[0];\n}\n\n// =============================================================================\n// §6  AGGREGATION DEFAULT\n// =============================================================================\n\n/**\n * Resolve the default aggregation function based on the field's role.\n *\n * - Additive measures → sum (parts sum to a meaningful total)\n * - Intensive measures → average (rates/averages shouldn't be summed)\n * - Signed-additive    → sum (preserves sign semantics)\n * - Dimensions/IDs     → undefined (aggregation not meaningful)\n */\nexport function resolveAggregationDefault(\n    semanticType: string,\n): 'sum' | 'average' | undefined {\n    const entry = getRegistryEntry(semanticType);\n    switch (entry.aggRole) {\n        case 'additive':        return 'sum';\n        case 'signed-additive': return 'sum';\n        case 'intensive':       return 'average';\n        case 'dimension':       return undefined;\n        case 'identifier':      return undefined;\n        default:                return undefined;\n    }\n}\n\n// =============================================================================\n// §7  ZERO-BASELINE CLASSIFICATION\n// =============================================================================\n\n/**\n * Resolve zero-baseline class, enhanced with annotation domain.\n *\n * If annotation provides a domain starting above 0 (e.g., Rating [1, 5]),\n * zero is arbitrary regardless of what the base type says.\n */\nexport function resolveZeroClassFromAnnotation(\n    semanticType: string,\n    domain?: [number, number],\n): ZeroClass | 'unknown' {\n    // If domain starts above zero (e.g., Rating [1,5]), zero is arbitrary\n    if (domain && domain[0] > 0) return 'arbitrary';\n\n    // Delegate to existing classification\n    return getZeroClass(semanticType);\n}\n\n// =============================================================================\n// §8  SCALE TYPE\n// =============================================================================\n\n/**\n * Recommend a scale type based on semantic type and data distribution.\n *\n * Conservative policy — only triggers when ALL of these hold:\n *   1. The semantic type is an additive measure with an open domain and is\n *      not a generic fallback (i.e. Amount, Quantity, Duration — types whose\n *      magnitude is meaningful and can legitimately span many decades).\n *   2. Data spans ≥ 6 orders of magnitude (1,000,000×).\n *   3. At least 10 data points, all non-negative.\n *\n * This intentionally almost never fires on everyday data; it only helps with\n * genuinely wide-range additive measures. When it does not fire the axis stays\n * linear, and the user can still opt into log via the per-axis quick control.\n */\nexport function resolveScaleType(\n    semanticType: string,\n    values: number[],\n): 'linear' | 'log' | 'sqrt' | 'symlog' | undefined {\n    // Only consider log for additive measures with open domains —\n    // these are the types that can legitimately span many orders of magnitude.\n    // (E.g., revenue, population, quantities across different scales.)\n    // Exclude generic fallback types (Number, Unknown) — they just mean\n    // \"we know it's numeric but not what it measures\", so applying\n    // log/symlog would be presumptuous.\n    const entry = getRegistryEntry(semanticType);\n    const eligible = entry.aggRole === 'additive' && entry.domainShape === 'open'\n        && entry.t1 !== 'GenericMeasure';\n    if (!eligible) return undefined;\n\n    if (values.length < 10) return undefined;\n\n    const filtered = values.filter(v => typeof v === 'number' && !isNaN(v) && isFinite(v));\n    if (filtered.length < 10) return undefined;\n\n    const min = Math.min(...filtered);\n    const max = Math.max(...filtered);\n    if (max <= 0 || min === max) return undefined;\n\n    // Only all-positive data — don't auto-log mixed-sign\n    if (min < 0) return undefined;\n\n    // Require ≥ 6 orders of magnitude (1000 000×) — very conservative\n    const positiveMin = Math.min(...filtered.filter(v => v > 0));\n    if (positiveMin > 0 && max / positiveMin >= 1000000) {\n        // If data contains zeros, log(0) = -∞ breaks the scale.\n        // Use symlog (linear near zero, logarithmic for large values)\n        // so zeros remain representable.\n        const hasZeros = filtered.some(v => v === 0);\n        return hasZeros ? 'symlog' : 'log';\n    }\n\n    return undefined;\n}\n\n// =============================================================================\n// §9  DOMAIN CONSTRAINTS\n// =============================================================================\n\n/**\n * Merge an intrinsic (semantic) domain with the actual data range.\n *\n * For **hard** domains (Latitude, Correlation) the intrinsic bounds are\n * physically absolute — data cannot exceed them, so we clamp.\n *\n * For **soft** domains (Percentage, Score, Rating, annotation-supplied)\n * the intrinsic bounds describe the *typical* range but real data can\n * legitimately exceed them (e.g., 155 % growth).  The effective domain\n * is the union: min(intrinsic[0], dataMin) … max(intrinsic[1], dataMax).\n */\nfunction mergeIntrinsicWithData(\n    intrinsic: [number, number],\n    values: any[],\n    hard: boolean,\n): DomainConstraint {\n    if (hard) {\n        return { min: intrinsic[0], max: intrinsic[1], clamp: true };\n    }\n    const nums = values.filter((v: any) => typeof v === 'number' && !isNaN(v));\n    if (nums.length === 0) {\n        return { min: intrinsic[0], max: intrinsic[1], clamp: false };\n    }\n    const dataMin = Math.min(...nums);\n    const dataMax = Math.max(...nums);\n    return {\n        min: Math.min(intrinsic[0], dataMin),\n        max: Math.max(intrinsic[1], dataMax),\n        clamp: false,\n    };\n}\n\n/**\n * Snap-to-bound heuristic for bounded types like Percentage / PercentageChange.\n *\n * Each bound is snapped independently:\n * - If data approaches the intrinsic lower bound → snap min\n * - If data approaches the intrinsic upper bound → snap max\n * - If data exceeds a bound → don't snap that side (let VL auto-extend)\n *\n * Threshold: 25% of the *effective side range*.\n *\n * We err on the side of snapping, because:\n * - Semantic types are opt-in — the bound carries meaning by definition.\n * - A wrong snap (extra white space) is less harmful than a wrong\n *   no-snap (viewer loses semantic reference, differences are\n *   exaggerated and proximity to the bound is hidden).\n * - Only when data is clearly in the interior (> 25% away from each\n *   bound) does the bound stop being a useful reference.\n *\n * When the intrinsic domain straddles zero (lo < 0 < hi), zero acts as a\n * visual baseline (bar charts, contextual zero).  Each bound's threshold\n * is computed relative to its distance from zero — not the full range —\n * so that snapping one side doesn't make values on the other side of zero\n * invisible (e.g., snapping to -100% when data has a tiny +0.2% bar).\n *\n * When the domain doesn't straddle zero (e.g., [0, 100]), the full range\n * is used as the reference.\n *\n * Examples for Percentage [0, 100] (threshold = 25, full range):\n *   20–45%   → snap min=0 only     (20 within 25 of 0; 45 far from 100)\n *   35–65%   → no snap             (both far from edges, in interior)\n *   55–82%   → snap max=100 only   (82 within 25 of 100; 55 far from 0)\n *   15–80%   → snap both [0, 100]  (15 near 0, 80 near 100)\n *   30–130%  → no snap             (130 exceeds 100 → no snap; 30 far from 0)\n *\n * Examples for PercentageChange [-1, 1] (threshold = 0.25 per side):\n *   -0.03 to +0.05 → no snap       (both far from ±0.75)\n *   -0.70 to +0.30 → no snap       (-0.70 > -0.75, not close enough)\n *   -0.80 to +0.30 → snap min=-1   (-0.80 ≤ -0.75; +0.30 < 0.75)\n *   -0.80 to +0.78 → snap both     (both within 0.25 of edges)\n */\nexport function snapToBoundHeuristic(\n    intrinsic: [number, number],\n    values: any[],\n): DomainConstraint | undefined {\n    const nums = values.filter((v: any) => typeof v === 'number' && !isNaN(v));\n    if (nums.length === 0) return undefined;\n\n    const [lo, hi] = intrinsic;\n    const range = hi - lo;\n    if (range <= 0) return undefined;\n\n    const dataMin = Math.min(...nums);\n    const dataMax = Math.max(...nums);\n\n    // When the domain straddles zero, compute each side's threshold relative\n    // to its distance from zero.  This prevents snapping one side from\n    // stretching the axis so wide that values near zero on the other side\n    // become invisible (sub-pixel bars).\n    const zeroInside = lo < 0 && hi > 0;\n    const thresholdLo = 0.25 * (zeroInside ? (0 - lo) : range);\n    const thresholdHi = 0.25 * (zeroInside ? hi       : range);\n\n    let snapMin: number | undefined;\n    let snapMax: number | undefined;\n\n    // Snap lower bound: data min is close to intrinsic lower bound\n    // AND data doesn't go below it (if it does, VL auto-extends)\n    if (dataMin >= lo && dataMin <= lo + thresholdLo) {\n        snapMin = lo;\n    }\n\n    // Snap upper bound: data max is close to intrinsic upper bound\n    // AND data doesn't exceed it\n    if (dataMax <= hi && dataMax >= hi - thresholdHi) {\n        snapMax = hi;\n    }\n\n    if (snapMin === undefined && snapMax === undefined) return undefined;\n\n    return { min: snapMin, max: snapMax, clamp: false };\n}\n\n/**\n * Resolve domain constraints from annotation, type-intrinsic rules, or data.\n *\n * Only truly fixed physical domains (Latitude, Longitude, Correlation)\n * use hard clamping. Bounded types like Percentage use a snap-to-bound\n * heuristic: the axis extends to the theoretical endpoint (e.g., 100%)\n * only when data is close to it, avoiding wasted space when data is\n * concentrated in a small region.\n *\n * Priority: annotation.intrinsicDomain > type-intrinsic > data-inferred\n */\nexport function resolveDomainConstraint(\n    semanticType: string,\n    annotation: SemanticAnnotation,\n    values: any[],\n): DomainConstraint | undefined {\n    const entry = getRegistryEntry(semanticType);\n\n    // 1. Explicit annotation intrinsicDomain\n    if (annotation.intrinsicDomain) {\n        // Proportion (Percentage) and SignedMeasure (PercentageChange, Profit):\n        // use snap-to-bound heuristic on both ends independently.\n        // Don't force the full theoretical range — only snap to a bound\n        // when data approaches it (e.g., 97% → snap to 100%, -0.95 → snap to -1).\n        if (entry.t1 === 'Proportion' || entry.t1 === 'SignedMeasure') {\n            return snapToBoundHeuristic(annotation.intrinsicDomain, values);\n        }\n        // All other types: soft merge (union of intrinsic + data)\n        return mergeIntrinsicWithData(annotation.intrinsicDomain, values, false);\n    }\n\n    // 2. Type-intrinsic hard domains (physically impossible to exceed)\n    if (semanticType === 'Latitude')    return mergeIntrinsicWithData([-90, 90], values, true);\n    if (semanticType === 'Longitude')   return mergeIntrinsicWithData([-180, 180], values, true);\n    if (semanticType === 'Correlation') return mergeIntrinsicWithData([-1, 1], values, true);\n\n    // 3. Percentage without explicit annotation — detect scale and apply snap\n    if (semanticType === 'Percentage') {\n        const nums = values.filter((v: any) => typeof v === 'number' && !isNaN(v));\n        if (nums.length > 0) {\n            const rep = detectPercentageRepresentation(nums);\n            const M = rep === '0-1' ? 1 : 100;\n            return snapToBoundHeuristic([0, M], values);\n        }\n    }\n\n    return undefined;\n}\n\n// =============================================================================\n// §10  TICK CONSTRAINTS\n// =============================================================================\n\n/**\n * Resolve tick constraints based on semantic type and domain.\n *\n * For bounded integer domains (e.g., Rating [1, 5]), generates exact ticks.\n * For integer types (Count, Rank, Year), enforces integer-only ticks.\n */\nexport function resolveTickConstraint(\n    semanticType: string,\n    domain?: [number, number],\n): TickConstraint | undefined {\n    const entry = getRegistryEntry(semanticType);\n\n    if (entry.formatClass === 'integer') {\n        const tc: TickConstraint = { integersOnly: true, minStep: 1 };\n        // If domain provided and span is small, generate exact ticks\n        if (domain) {\n            const span = domain[1] - domain[0];\n            if (span <= 20 && span > 0) {\n                tc.exactTicks = [];\n                for (let i = domain[0]; i <= domain[1]; i++) {\n                    tc.exactTicks.push(i);\n                }\n            }\n        }\n        return tc;\n    }\n\n    // Score with bounded domain → integer ticks ONLY when domain span\n    // indicates meaningful integer steps.  For small spans like [0, 1],\n    // the values are continuous (e.g., outlier_score 0–1) and forcing\n    // integer ticks would remove all intermediate tick marks.\n    if (semanticType === 'Score' && domain) {\n        const span = domain[1] - domain[0];\n        if (span >= 2) {\n            const tc: TickConstraint = { integersOnly: true, minStep: 1 };\n            if (span <= 20) {\n                tc.exactTicks = [];\n                for (let i = domain[0]; i <= domain[1]; i++) {\n                    tc.exactTicks.push(i);\n                }\n            }\n            return tc;\n        }\n    }\n\n    return undefined;\n}\n\n// =============================================================================\n// §11  CANONICAL ORDERING & CYCLIC\n// =============================================================================\n\n/**\n * Resolve the canonical sort order for a field.\n *\n * Priority: annotation.sortOrder > well-known type sequence > auto-detect from data\n */\nexport function resolveCanonicalOrder(\n    semanticType: string,\n    annotation: SemanticAnnotation,\n    values: any[],\n): string[] | undefined {\n    // 1. Explicit annotation sortOrder\n    if (annotation.sortOrder && annotation.sortOrder.length > 0) {\n        return annotation.sortOrder;\n    }\n\n    // 2. Delegate to existing well-known sequence detection\n    return inferOrdinalSortOrder(semanticType, values);\n}\n\n/**\n * Determine whether a field's values form a cyclic (wrap-around) sequence.\n *\n * Derived purely from semantic type — NOT an LLM annotation.\n * Types with domainShape='cyclic' in the registry are cyclic.\n */\nexport function resolveCyclic(semanticType: string): boolean {\n    const entry = getRegistryEntry(semanticType);\n    return entry.domainShape === 'cyclic';\n}\n\n// =============================================================================\n// §12  REVERSED AXIS\n// =============================================================================\n\n/**\n * Whether the axis should be reversed for this field.\n *\n * Rank is the primary case: 1st place should appear at the top of the\n * y-axis.  On the x-axis, rank 1 should stay on the left (no reversal).\n */\nexport function resolveReversed(semanticType: string, channel?: string): boolean {\n    if (semanticType === 'Rank') {\n        // Only reverse on the y-axis (rank 1 at top).\n        // On x-axis, natural left-to-right order is correct.\n        return channel !== 'x';\n    }\n    return false;\n}\n\n// =============================================================================\n// §13  NICE (domain rounding)\n// =============================================================================\n\n/**\n * Whether to apply \"nice\" rounding to scale domain endpoints.\n *\n * Nice is false when:\n * - There's a fixed domain constraint (Rating [1, 5] → axis should show exactly 1–5)\n * - The type has a fixed domain shape (Latitude, Correlation)\n */\nexport function resolveNice(\n    semanticType: string,\n    domainConstraint?: DomainConstraint,\n): boolean {\n    if (domainConstraint?.clamp) return false;\n    if (domainConstraint && domainConstraint.min !== undefined && domainConstraint.max !== undefined) {\n        return false;\n    }\n    const entry = getRegistryEntry(semanticType);\n    if (entry.domainShape === 'fixed') return false;\n    return true;\n}\n\n// =============================================================================\n// §14  DIVERGING & COLOR SCHEME HINT\n// =============================================================================\n\n/**\n * Resolve diverging midpoint information for a field.\n *\n * Priority chain:\n *   1. annotation.unit → type lookup (°C → 0, °F → 32)\n *   2. type-intrinsic midpoint (Sentiment → 0, Correlation → 0)\n *   3. annotation.intrinsicDomain midpoint (Rating [1,5] → 3)\n *   4. data-driven: data spans 0 → midpoint 0\n *\n * Returns undefined if no diverging treatment applies.\n */\nexport function resolveDivergingInfo(\n    semanticType: string,\n    annotation: SemanticAnnotation,\n    values: number[],\n): DivergingInfo | undefined {\n    const entry = getRegistryEntry(semanticType);\n    // Types with diverging='none' don't get diverging treatment\n\n    // 1. Unit-derived (Temperature)\n    if (semanticType === 'Temperature' && annotation.unit) {\n        const unitMidpoints: Record<string, number> = {\n            '°C': 0, '°F': 32, 'K': 273.15, C: 0, F: 32,\n        };\n        const mid = unitMidpoints[annotation.unit];\n        if (mid !== undefined) {\n            return { midpoint: mid, inherent: false, source: 'unit' };\n        }\n    }\n\n    // 3. Type-intrinsic\n    if (entry.diverging === 'inherent') {\n        return { midpoint: 0, inherent: true, source: 'type-intrinsic' };\n    }\n    if (entry.diverging === 'conditional') {\n        return { midpoint: 0, inherent: false, source: 'type-intrinsic' };\n    }\n\n    // 3. Domain-derived midpoint (e.g., Rating [1,5] → 3)\n    if (annotation.intrinsicDomain) {\n        return {\n            midpoint: (annotation.intrinsicDomain[0] + annotation.intrinsicDomain[1]) / 2,\n            inherent: false,\n            source: 'domain',\n        };\n    }\n\n    // 4. Data-driven: if data spans 0, use 0 as midpoint\n    if (values.length > 0) {\n        const min = Math.min(...values);\n        const max = Math.max(...values);\n        if (min < 0 && max > 0) {\n            return { midpoint: 0, inherent: false, source: 'data' };\n        }\n    }\n\n    return undefined;\n}\n\n/**\n * Resolve color scheme hint based on semantic type, diverging analysis,\n * and data values.\n */\nexport function resolveColorSchemeHint(\n    semanticType: string,\n    annotation: SemanticAnnotation,\n    values: any[],\n): ColorSchemeHint {\n    const entry = getRegistryEntry(semanticType);\n    const nums = values.filter((v: any) => typeof v === 'number' && !isNaN(v));\n\n    // Try diverging analysis\n    const divInfo = resolveDivergingInfo(semanticType, annotation, nums);\n    if (divInfo) {\n        const min = nums.length > 0 ? Math.min(...nums) : 0;\n        const max = nums.length > 0 ? Math.max(...nums) : 0;\n        const spansBothSides = min < divInfo.midpoint && max > divInfo.midpoint;\n\n        if (divInfo.inherent || spansBothSides) {\n            return {\n                type: 'diverging',\n                divergingMidpoint: divInfo.midpoint,\n                inherentlyDiverging: divInfo.inherent,\n            };\n        }\n    }\n\n    // Sequential for quantitative, categorical for nominal/ordinal\n    if (entry.visEncodings.includes('quantitative')) {\n        return { type: 'sequential' };\n    }\n    return { type: 'categorical' };\n}\n\n// =============================================================================\n// §15  BINNING SUITABILITY\n// =============================================================================\n\n/**\n * Whether this field benefits from histogram-style binning.\n *\n * False for small bounded domains (Rating 1–5), non-numeric types,\n * and identifiers.\n */\nexport function resolveBinningSuggested(\n    semanticType: string,\n    domain?: [number, number],\n): boolean {\n    const entry = getRegistryEntry(semanticType);\n\n    // Non-quantitative types don't get binned\n    if (!entry.visEncodings.includes('quantitative')) return false;\n\n    // Identifiers/dimensions don't get binned\n    if (entry.aggRole === 'identifier' || entry.aggRole === 'dimension') return false;\n\n    // Year should use temporal axis, not bins\n    if (semanticType === 'Year' || semanticType === 'Decade') return false;\n\n    // Small bounded domains have too few values to bin\n    if (domain && (domain[1] - domain[0]) <= 20) return false;\n\n    // Score with known small range\n    if (semanticType === 'Score' && !domain) return false;\n\n    return true;\n}\n\n// =============================================================================\n// §17  STACKING COMPATIBILITY\n// =============================================================================\n\n/**\n * Whether values of this type can be stacked in a bar/area chart, and how.\n *\n * - 'sum':       Additive measures (parts sum to whole)\n * - 'normalize': Proportions (show 100% breakdown)\n * - false:       Stacking is meaningless (rates, scores, identifiers)\n */\nexport function resolveStackable(\n    semanticType: string,\n): 'sum' | 'normalize' | false {\n    const entry = getRegistryEntry(semanticType);\n\n    switch (entry.aggRole) {\n        case 'additive':        return 'sum';\n        case 'signed-additive': return 'sum';\n        case 'intensive':\n            // Percentage is the exception — normalizable\n            if (semanticType === 'Percentage') return 'normalize';\n            return false;\n        case 'dimension':       return false;\n        case 'identifier':      return false;\n        default:                return false;\n    }\n}\n\n// =============================================================================\n// §18  SORT DIRECTION\n// =============================================================================\n\n/**\n * Default sort direction for this field when used on an axis.\n */\nexport function resolveSortDirection(\n    semanticType: string,\n): 'ascending' | 'descending' {\n    // Rank: show best first\n    if (semanticType === 'Rank') return 'descending';\n    return 'ascending';\n}\n\n// =============================================================================\n// §19  BUILDER: resolveFieldSemantics()\n// =============================================================================\n\n/**\n * Resolve field semantics from annotation + data.\n *\n * This is the sole entry point for data-identity decisions. It resolves\n * the one-to-many ambiguities in the type registry by inspecting the\n * concrete data representation.\n *\n * Visualization-specific decisions (color scheme, axis reversal,\n * interpolation, tick strategy, nice rounding, stacking) are NOT\n * computed here — those belong in `resolveChannelSemantics()`.\n *\n * @param input       The semantic type annotation (string or enriched object)\n * @param fieldName   Column name (used for unit detection heuristics)\n * @param values      Sampled data values from this field\n * @returns           Resolved field semantics\n */\nexport function resolveFieldSemantics(\n    input: string | SemanticAnnotation | undefined,\n    fieldName: string,\n    values: any[],\n): FieldSemantics {\n    // 1. Normalize annotation\n    const annotation = normalizeAnnotation(input);\n    const semanticType = annotation.semanticType;\n\n    // 2. Numeric values (filtered once, reused across resolvers)\n    const numericValues = values\n        .filter((v: any) => typeof v === 'number' && !isNaN(v) && isFinite(v));\n\n    // 3. Resolve field-intrinsic properties\n    const defaultVisType = resolveDefaultVisType(semanticType, values);\n    const { format, tooltipFormat } = resolveFormat(semanticType, annotation, values);\n    let aggregationDefault = resolveAggregationDefault(semanticType);\n    let zeroClass = resolveZeroClassFromAnnotation(semanticType, annotation.intrinsicDomain);\n    const scaleType = resolveScaleType(semanticType, numericValues);\n    const domainConstraint = resolveDomainConstraint(semanticType, annotation, values);\n    const canonicalOrder = resolveCanonicalOrder(semanticType, annotation, values);\n    const cyclic = resolveCyclic(semanticType);\n    let binningSuggested = resolveBinningSuggested(semanticType, annotation.intrinsicDomain);\n    const sortDirection = resolveSortDirection(semanticType);\n\n    // 4. For unregistered types, provide data-driven fallbacks.\n    //    The registry treats unknown types as categorical, but if the data\n    //    is actually numeric, we should behave like a generic measure.\n    if (!isRegistered(semanticType) && defaultVisType === 'quantitative') {\n        // Data looks numeric → treat like Number (GenericMeasure)\n        if (!aggregationDefault) aggregationDefault = 'sum';\n        if (zeroClass === 'unknown') zeroClass = 'meaningful';\n        binningSuggested = true;\n    }\n\n    return {\n        semanticAnnotation: annotation,\n        defaultVisType,\n        format,\n        tooltipFormat,\n        aggregationDefault,\n        zeroClass,\n        scaleType: scaleType ?? undefined,\n        domainConstraint,\n        canonicalOrder,\n        cyclic,\n        sortDirection,\n        binningSuggested,\n    };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * =============================================================================\n * CHANNEL SEMANTICS RESOLVER\n * =============================================================================\n *\n * Stage 2 of the semantic pipeline:\n *   SemanticAnnotation + data → FieldSemantics → **ChannelSemantics**\n *\n * Takes each channel’s field, builds FieldSemantics (stage 1), then adds\n * channel-specific visualization decisions: encoding type, color scheme,\n * temporal format, ordinal sort, tick constraints, axis reversal, nice\n * rounding, interpolation, and stacking.\n *\n * Zero-baseline is NOT resolved here — it requires template mark knowledge\n * and is finalized by the assembler after this function returns.\n *\n * VL dependency: **None**\n * =============================================================================\n */\n\nimport type {\n    ChartEncoding,\n    ChannelSemantics,\n    SemanticResult,\n} from './types';\nimport {\n    getVisCategory,\n    inferVisCategory,\n    getRecommendedColorScheme,\n    inferOrdinalSortOrder,\n} from './semantic-types';\nimport {\n    resolveEncodingType as resolveEncodingTypeDecision,\n} from './decisions';\nimport {\n    resolveFieldSemantics,\n    toTypeString,\n    resolveNice,\n    resolveTickConstraint,\n    resolveReversed,\n    resolveStackable,\n    resolveColorSchemeHint,\n    resolveDivergingInfo,\n    type SemanticAnnotation,\n} from './field-semantics';\n\n// ---------------------------------------------------------------------------\n// Internal helpers (moved from assemble.ts)\n// ---------------------------------------------------------------------------\n\n/** Upper bounds for plausible timestamps (~2099-12-31). */\nconst MAX_TIMESTAMP_SEC = 4102444800;\nconst MAX_TIMESTAMP_MS = 4102444800000;\n\nfunction isLikelyTimestamp(val: number): boolean {\n    if (val >= 1e9 && val <= MAX_TIMESTAMP_SEC) return true;\n    if (val > MAX_TIMESTAMP_SEC && val <= MAX_TIMESTAMP_MS) return true;\n    return false;\n}\n\nfunction timestampToMs(val: number): number {\n    return val <= MAX_TIMESTAMP_SEC ? val * 1000 : val;\n}\n\nfunction looksLikeDateString(s: string): boolean {\n    const t = s.trim();\n    return /^\\d|^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i.test(t);\n}\n\n// ---------------------------------------------------------------------------\n// Temporal field analysis\n// ---------------------------------------------------------------------------\n\ninterface TemporalAnalysis {\n    dates: Date[];\n    same: {\n        month: boolean;\n        day: boolean;\n        hour: boolean;\n        minute: boolean;\n        second: boolean;\n    };\n    sameYear: boolean;\n    sameMonth: boolean;\n    sameDay: boolean;\n}\n\nfunction analyzeTemporalField(fieldValues: any[]): TemporalAnalysis | null {\n    const dates: Date[] = [];\n    let nonNull = 0;\n    for (const v of fieldValues.slice(0, 100)) {\n        if (v == null) continue;\n        nonNull++;\n        const d = v instanceof Date ? v : new Date(v);\n        if (!isNaN(d.getTime())) dates.push(d);\n    }\n    if (dates.length < 2 || dates.length < nonNull * 0.5) return null;\n\n    const monthSet  = new Set(dates.map(d => d.getUTCMonth()));\n    const daySet    = new Set(dates.map(d => d.getUTCDate()));\n    const hourSet   = new Set(dates.map(d => d.getUTCHours()));\n    const minuteSet = new Set(dates.map(d => d.getUTCMinutes()));\n    const secondSet = new Set(dates.map(d => d.getUTCSeconds()));\n    const yearSet   = new Set(dates.map(d => d.getUTCFullYear()));\n\n    const isSmallSpread = (s: Set<number>, maxSpread: number = 1) => {\n        if (s.size <= 1) return true;\n        const arr = [...s];\n        return Math.max(...arr) - Math.min(...arr) <= maxSpread;\n    };\n\n    const same = {\n        month:  monthSet.size  === 1,\n        day:    daySet.size    === 1,\n        hour:   isSmallSpread(hourSet, 1),\n        minute: minuteSet.size === 1,\n        second: secondSet.size === 1,\n    };\n\n    const sameYear  = yearSet.size === 1;\n    const sameMonth = sameYear && same.month;\n    const sameDay   = sameMonth && same.day;\n\n    return { dates, same, sameYear, sameMonth, sameDay };\n}\n\nfunction computeDataVotes(same: TemporalAnalysis['same']): number[] {\n    const votes = [0, 0, 0, 0, 0, 0];\n\n    if (same.second)                                                           votes[5] += 1;\n    if (same.minute && same.second)                                            votes[5] += 1;\n    if (same.hour   && same.minute && same.second)                             votes[5] += 1;\n    if (same.day    && same.hour   && same.minute && same.second)              votes[5] += 2;\n    if (same.month  && same.day    && same.hour   && same.minute && same.second) votes[5] += 3;\n\n    if (same.second)                                                           votes[4] += 1;\n    if (same.minute && same.second)                                            votes[4] += 1;\n    if (same.hour   && same.minute && same.second)                             votes[4] += 1;\n    if (same.day    && same.hour   && same.minute && same.second)              votes[4] += 2;\n    if (!same.month && same.day && same.hour && same.minute && same.second)    votes[4] += 3;\n\n    if (same.second)                                                           votes[3] += 1;\n    if (same.minute && same.second)                                            votes[3] += 1;\n    if (same.hour   && same.minute && same.second)                             votes[3] += 1;\n    if (!same.day && same.hour && same.minute && same.second)                  votes[3] += 3;\n\n    if (same.second)                               votes[2] += 1;\n    if (same.minute && same.second)                votes[2] += 1;\n    if (!same.hour && same.minute && same.second)  votes[2] += 3;\n\n    if (same.second)                    votes[1] += 1;\n    if (!same.minute && same.second)    votes[1] += 3;\n\n    if (!same.second) votes[0] += 4;\n\n    return votes;\n}\n\nconst SEMANTIC_LEVEL: Record<string, number> = {\n    Year:        5, Decade:      5,\n    YearMonth:   4, Month:       4, YearQuarter: 4, Quarter: 4,\n    Date:        3, Day:         3,\n    Hour:        2,\n    DateTime:    1,\n    Timestamp:   0,\n};\n\nfunction pickBestLevel(votes: number[]): { level: number; score: number } {\n    let bestLevel = 0;\n    let bestScore = votes[0];\n    for (let i = 1; i <= 5; i++) {\n        if (votes[i] >= bestScore) {\n            bestScore = votes[i];\n            bestLevel = i;\n        }\n    }\n    return { level: bestLevel, score: bestScore };\n}\n\nfunction levelToFormat(level: number, analysis: TemporalAnalysis): string | null {\n    switch (level) {\n        case 5: return '%Y';\n        case 4: return analysis.sameYear ? '%b' : '%b %Y';\n        case 3: return analysis.sameYear ? '%b %d' : '%b %d, %Y';\n        case 2: return analysis.sameDay  ? '%H:00' : '%b %d %H:00';\n        case 1: return analysis.sameDay  ? '%H:%M' : '%b %d %H:%M';\n        case 0: return analysis.sameDay  ? '%H:%M:%S' : '%b %d %H:%M:%S';\n        default: return null;\n    }\n}\n\n/**\n * Resolve temporal format for a field.\n * Used for both temporal and ordinal-temporal fields.\n */\nfunction resolveTemporalFormat(\n    fieldValues: any[],\n    semanticType: string,\n): string | null {\n    const analysis = analyzeTemporalField(fieldValues);\n    if (!analysis) return null;\n\n    const votes = computeDataVotes(analysis.same);\n    const semLevel = SEMANTIC_LEVEL[semanticType];\n    if (semLevel !== undefined) votes[semLevel] += 3;\n    const { level } = pickBestLevel(votes);\n    return levelToFormat(level, analysis);\n}\n\n// ---------------------------------------------------------------------------\n// Temporal data conversion\n// ---------------------------------------------------------------------------\n\n/**\n * Expand a year string to an unambiguous 4-digit representation.\n *\n * - \"98\" → \"1998\",  \"07\" → \"2007\",  \"00\" → \"2000\"\n * - \"1998\" → \"1998\" (already 4+ digits, pass through)\n * - \"FY 2018\" → \"FY 2018\" (non-numeric, pass through)\n *\n * Two-digit cutoff: 0–49 → 2000s, 50–99 → 1900s (same heuristic JS Date uses).\n */\nfunction expandToFullYear(val: string): string {\n    const trimmed = val.trim();\n    if (/^\\d{2}$/.test(trimmed)) {\n        const n = parseInt(trimmed, 10);\n        return String(n <= 49 ? 2000 + n : 1900 + n);\n    }\n    return val;\n}\n\n/**\n * Convert temporal field values in the data table to canonical string\n * representations for Vega-Lite consumption.\n *\n * This is a data-level concern (not VL-specific) — it ensures consistent\n * date parsing across backends.\n */\nexport function convertTemporalData(\n    data: any[],\n    semanticTypes: Record<string, string | SemanticAnnotation>,\n): any[] {\n    if (data.length === 0) return data;\n\n    const keys = Object.keys(data[0]);\n    const temporalKeys = keys.filter((k: string) => {\n        const st = toTypeString(semanticTypes[k]);\n        const vc = inferVisCategory(data.map(r => r[k]));\n        const stCategory = st ? getVisCategory(st) : null;\n        return vc === 'temporal' || stCategory === 'temporal' || st === 'Decade';\n    });\n\n    if (temporalKeys.length === 0) return data;\n\n    const values = structuredClone(data);\n    return values.map((r: any) => {\n        for (const temporalKey of temporalKeys) {\n            const val = r[temporalKey];\n            const st = toTypeString(semanticTypes[temporalKey]);\n\n            if (typeof val === 'number') {\n                if (st === 'Year' || st === 'Decade') {\n                    r[temporalKey] = `${Math.floor(val)}`;\n                } else if (isLikelyTimestamp(val)) {\n                    r[temporalKey] = new Date(timestampToMs(val)).toISOString();\n                } else {\n                    r[temporalKey] = String(val);\n                }\n            } else if (val instanceof Date) {\n                r[temporalKey] = val.toISOString();\n            } else {\n                // For Year/Decade strings, normalise to 4-digit years so\n                // Vega-Lite parses them unambiguously and doesn't auto-tick\n                // at sub-year intervals (e.g. \"98\" → \"1998\").\n                if ((st === 'Year' || st === 'Decade') && typeof val === 'string') {\n                    r[temporalKey] = expandToFullYear(val);\n                } else {\n                    r[temporalKey] = String(val);\n                }\n            }\n        }\n        return r;\n    });\n}\n\n// ---------------------------------------------------------------------------\n// Public API: resolveChannelSemantics\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve all channel-level semantic decisions.\n *\n * For each channel, builds FieldSemantics (data identity) then layers on\n * channel-specific visualization decisions (color scheme, temporal format,\n * tick constraints, axis reversal, interpolation, etc.).\n *\n * Zero-baseline (cs.zero) is NOT resolved here -- it requires template\n * mark knowledge (bar vs point) that belongs to the assembler.\n * The assembler finalizes zero after calling this function.\n *\n * @param encodings       Channel -> ChartEncoding from user / AI agent\n * @param data            Array of data rows (original, unconverted)\n * @param semanticTypes   Field name -> semantic type string\n * @param convertedData   Pre-converted temporal data (from convertTemporalData).\n *                        If omitted, falls back to data for temporal format detection.\n */\nexport function resolveChannelSemantics(\n    encodings: Record<string, ChartEncoding>,\n    data: any[],\n    semanticTypes: Record<string, string | SemanticAnnotation>,\n    convertedData?: any[],\n): SemanticResult {\n    const result: SemanticResult = {};\n\n    // Use pre-converted temporal data for format detection, or fall back to raw data\n    const temporalData = convertedData ?? data;\n\n    for (const [channel, encoding] of Object.entries(encodings)) {\n        const fieldName = encoding.field;\n        if (!fieldName && encoding.aggregate !== 'count') continue;\n\n        // Handle count aggregate without a field\n        if (!fieldName && encoding.aggregate === 'count') {\n            result[channel] = {\n                field: '_count',\n                semanticAnnotation: { semanticType: 'Count' },\n                type: 'quantitative',\n                aggregationDefault: 'sum',\n            };\n            continue;\n        }\n\n        if (!fieldName) continue;\n\n        const rawAnnotation = semanticTypes[fieldName];\n        const semanticType = typeof rawAnnotation === 'string'\n            ? (rawAnnotation || '')\n            : (rawAnnotation?.semanticType ?? '');\n        const fieldValues = data.map(r => r[fieldName]);\n\n        // Resolve encoding type\n        const typeDecision = resolveEncodingTypeDecision(\n            semanticType, fieldValues, channel, data, fieldName,\n        );\n\n        // Apply explicit type override\n        let resolvedType = typeDecision.vlType;\n        if (encoding.type) {\n            resolvedType = encoding.type;\n        } else if (channel === 'column' || channel === 'row') {\n            if (resolvedType !== 'nominal' && resolvedType !== 'ordinal') {\n                resolvedType = 'nominal';\n            }\n        }\n\n        // ISO date hack\n        if (resolvedType === 'quantitative') {\n            const sampleValues = data.slice(0, 15).filter(r => r[fieldName] != undefined).map(r => r[fieldName]);\n            const isoDateRegex = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})?$/;\n            if (sampleValues.length > 0 && sampleValues.every((val: any) => isoDateRegex.test(`${val}`.trim()))) {\n                resolvedType = 'temporal';\n            }\n        }\n\n        // Build ChannelSemantics entry\n        // Stage 1: resolve field-level semantics (data identity)\n        const fc = resolveFieldSemantics(rawAnnotation, fieldName, fieldValues);\n        const annotation = fc.semanticAnnotation;\n\n        // Stage 2: layer on channel-specific visualization decisions\n        const tickConstraint = resolveTickConstraint(annotation.semanticType, annotation.intrinsicDomain);\n        const reversed = resolveReversed(annotation.semanticType, channel);\n        const nice = resolveNice(annotation.semanticType, fc.domainConstraint);\n        const stackable = resolveStackable(annotation.semanticType);\n\n        const cs: ChannelSemantics = {\n            field: fieldName,\n            semanticAnnotation: annotation,\n            type: resolvedType,\n\n            // From FieldSemantics (data identity)\n            format: fc.format,\n            tooltipFormat: fc.tooltipFormat,\n            aggregationDefault: fc.aggregationDefault,\n            scaleType: fc.scaleType,\n            domainConstraint: fc.domainConstraint,\n            cyclic: fc.cyclic || undefined,\n            sortDirection: fc.sortDirection,\n            binningSuggested: fc.binningSuggested || undefined,\n\n            // Channel-specific visualization decisions\n            nice,\n            tickConstraint,\n            reversed: reversed || undefined,\n            stackable,\n        };\n\n        // Adjust field name for aggregated fields (the derived column is either\n        // computed by applyAggregation or supplied pre-aggregated by the caller)\n        if (encoding.aggregate) {\n            if (encoding.aggregate === 'count') {\n                cs.field = '_count';\n                cs.type = 'quantitative';\n            } else {\n                cs.field = `${fieldName}_${encoding.aggregate}`;\n                cs.type = 'quantitative';\n            }\n        }\n\n        // --- Channel-specific semantic decisions ---\n\n        // Color scheme (color and group channels)\n        if ((channel === 'color' || channel === 'group') && fieldName) {\n            if (encoding.scheme && encoding.scheme !== 'default') {\n                cs.colorScheme = {\n                    scheme: encoding.scheme,\n                    type: 'categorical',\n                    reason: 'explicit user scheme',\n                };\n            } else {\n                const encodingVLType = cs.type as 'nominal' | 'ordinal' | 'quantitative' | 'temporal';\n                // Use design-aligned classification from field-semantics.ts\n                const colorHint = resolveColorSchemeHint(semanticType, annotation, fieldValues);\n                const uniqueValues = [...new Set(fieldValues)];\n                cs.colorScheme = getRecommendedColorScheme(\n                    semanticType, encodingVLType, uniqueValues.length, fieldName,\n                    fieldValues, { type: colorHint.type },\n                );\n                // Apply midpoint from design-aligned diverging analysis\n                if (cs.colorScheme.type === 'diverging' && encodingVLType === 'quantitative') {\n                    const nums = fieldValues.filter((v: any) => typeof v === 'number' && !isNaN(v));\n                    const divInfo = resolveDivergingInfo(semanticType, annotation, nums);\n                    if (divInfo) {\n                        cs.colorScheme.domainMid = divInfo.midpoint;\n                    }\n                }\n            }\n        }\n\n        // Temporal format\n        if (cs.type === 'temporal' || (semanticType && getVisCategory(semanticType) === 'temporal')) {\n            const convertedFieldValues = temporalData.map(r => r[fieldName]);\n            const fmt = resolveTemporalFormat(convertedFieldValues, semanticType);\n            if (fmt) cs.temporalFormat = fmt;\n        }\n\n        // Ordinal sort order (canonical ordering for months, days, quarters, etc.)\n        if (cs.type === 'ordinal' || cs.type === 'nominal') {\n            if (!encoding.sortOrder && !encoding.sortBy) {\n                const ordinalSort = inferOrdinalSortOrder(semanticType, fieldValues);\n                if (ordinalSort) {\n                    cs.ordinalSortOrder = ordinalSort;\n                }\n            }\n        }\n\n        result[channel] = cs;\n    }\n\n    return result;\n}\n\n// Re-export helpers needed by other modules\nexport {\n    analyzeTemporalField,\n    computeDataVotes,\n    pickBestLevel,\n    levelToFormat,\n    looksLikeDateString,\n    SEMANTIC_LEVEL,\n    type TemporalAnalysis,\n};\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * =============================================================================\n * OVERFLOW FILTERING\n * =============================================================================\n *\n * Decides *which* discrete values to keep when there are too many for\n * the available canvas space, then filters the data accordingly.\n *\n * This module does **no layout math**.  Per-channel capacity budgets\n * are computed upstream by `computeChannelBudgets` and passed in as\n * a `ChannelBudgets` object.  This module focuses on:\n *   1. Iterating each discrete channel\n *   2. Applying the overflow strategy (which values to keep)\n *   3. Filtering data rows\n *   4. Producing truncation warnings\n *\n * Runs AFTER computeChannelBudgets and BEFORE computeLayout.\n *\n * VL dependency: **None**\n * =============================================================================\n */\n\nimport type {\n    ChannelSemantics,\n    ChartEncoding,\n    LayoutDeclaration,\n    TruncationWarning,\n    OverflowResult,\n    OverflowStrategy,\n    OverflowStrategyContext,\n    ChannelBudgets,\n} from './types';\nimport type { ChartWarning } from './types';\nimport { inferVisCategory } from './semantic-types';\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Filter data to keep only the values that fit within the canvas.\n *\n * @param channelSemantics  Phase 0 output (field, type per channel)\n * @param declaration       Template layout declaration (resolvedTypes, overflowStrategy)\n * @param encodings         Original user-level encodings (for sort info)\n * @param data              Full data table\n * @param budgets           Per-channel capacity budgets from computeChannelBudgets\n * @param allMarkTypes      Set of all mark types in the template (for connected-mark detection)\n * @returns                 OverflowResult with filtered data, nominal counts, truncations, and warnings\n */\nexport function filterOverflow(\n    channelSemantics: Record<string, ChannelSemantics>,\n    declaration: LayoutDeclaration,\n    encodings: Record<string, ChartEncoding>,\n    data: any[],\n    budgets: ChannelBudgets,\n    allMarkTypes: Set<string>,\n): OverflowResult {\n\n    // --- Build effective channel info from semantics + declaration ---\n\n    const effectiveType = (ch: string): string | undefined =>\n        declaration.resolvedTypes?.[ch] ?? channelSemantics[ch]?.type;\n\n    const effectiveField = (ch: string): string | undefined => {\n        if (channelSemantics[ch]?.field) return channelSemantics[ch].field;\n        return undefined;\n    };\n\n    const isDiscreteType = (t: string | undefined) => t === 'nominal' || t === 'ordinal';\n\n    // --- Filter data ---\n\n    const nominalCounts: Record<string, number> = {\n        x: 0, y: 0, column: 0, row: 0, group: 0,\n    };\n    const truncations: TruncationWarning[] = [];\n    const warnings: ChartWarning[] = [];\n    let filteredData = data;\n\n    // Compute group nominal count\n    const groupField = channelSemantics.group?.field;\n    if (groupField) {\n        nominalCounts.group = new Set(data.map(r => r[groupField])).size;\n    }\n\n    // Strategy context for custom or default overflow\n    const strategyContext: OverflowStrategyContext = {\n        data,\n        channelSemantics,\n        encodings,\n        allMarkTypes,\n    };\n\n    const strategy = declaration.overflowStrategy ?? defaultOverflowStrategy;\n\n    for (const channel of ['x', 'y', 'column', 'row', 'color'] as const) {\n        const fieldName = effectiveField(channel);\n        const type = effectiveType(channel);\n        if (!fieldName) continue;\n\n        // Budget for this channel (Infinity if uncapped)\n        const maxToKeep = budgets.maxValues[channel] ?? Infinity;\n\n        // For non-discrete types on column/row, apply overflow cap —\n        // every unique value becomes a facet panel.\n        if (!isDiscreteType(type)) {\n            if (channel === 'column' || channel === 'row') {\n                const uniqueValues = [...new Set(filteredData.map(r => r[fieldName]))];\n                nominalCounts[channel] = Math.min(uniqueValues.length, maxToKeep);\n\n                if (uniqueValues.length > maxToKeep) {\n                    // For non-discrete facets, keep the first N values (sorted)\n                    const sorted = [...uniqueValues].sort();\n                    const valuesToKeep = sorted.slice(0, maxToKeep);\n\n                    const omittedCount = uniqueValues.length - valuesToKeep.length;\n                    warnings.push({\n                        severity: 'warning',\n                        code: 'overflow',\n                        message: `${omittedCount} of ${uniqueValues.length} values in '${fieldName}' were omitted (showing first ${valuesToKeep.length}).`,\n                        channel,\n                        field: fieldName,\n                    });\n\n                    const keepSet = new Set(valuesToKeep);\n                    filteredData = filteredData.filter(row => keepSet.has(row[fieldName]));\n                }\n            }\n            continue;\n        }\n\n        const uniqueValues = [...new Set(filteredData.map(r => r[fieldName]))];\n        nominalCounts[channel] = Math.min(uniqueValues.length, maxToKeep);\n\n        if (uniqueValues.length > maxToKeep) {\n            const valuesToKeep = strategy(channel, fieldName, uniqueValues, maxToKeep, strategyContext);\n\n            const omittedCount = uniqueValues.length - valuesToKeep.length;\n            const placeholder = `...${omittedCount} items omitted`;\n\n            warnings.push({\n                severity: 'warning',\n                code: 'overflow',\n                message: `${omittedCount} of ${uniqueValues.length} values in '${fieldName}' were omitted (showing first ${valuesToKeep.length} in sort order).`,\n                channel,\n                field: fieldName,\n            });\n\n            truncations.push({\n                severity: 'warning',\n                code: 'overflow',\n                message: `${omittedCount} of ${uniqueValues.length} values in '${fieldName}' were omitted (showing first ${valuesToKeep.length} in sort order).`,\n                channel,\n                field: fieldName,\n                keptValues: valuesToKeep,\n                omittedCount,\n                placeholder,\n            });\n\n            // Filter data rows (except for color — we keep all rows but style the legend)\n            if (channel !== 'color') {\n                filteredData = filteredData.filter(row => valuesToKeep.includes(row[fieldName]));\n            }\n        }\n    }\n\n    return { filteredData, nominalCounts, truncations, warnings };\n}\n\n// ---------------------------------------------------------------------------\n// Default overflow strategy\n// ---------------------------------------------------------------------------\n\n/**\n * Default overflow strategy: decides which discrete values to keep.\n *\n * - User-specified sort: respect it\n * - Canonical semantic order (months, ranks, etc.): keep the first N\n * - Numeric categories: keep the first N numerically\n * - Otherwise preserve data encounter order\n */\nconst defaultOverflowStrategy: OverflowStrategy = (\n    channel, fieldName, uniqueValues, maxToKeep, context,\n) => {\n    const { data, channelSemantics, encodings, allMarkTypes } = context;\n\n    // Determine sort intent from user encodings\n    const encoding = encodings[channel];\n    const sortBy = encoding?.sortBy;\n    const sortOrder = encoding?.sortOrder;\n\n    // Infer sort field and direction\n    let sortField: string | undefined;\n    let sortFieldType: string | undefined;\n    let isDescending = false;\n\n    if (sortBy) {\n        // User explicitly specified sort\n        if (sortBy === 'x' || sortBy === 'y' || sortBy === 'color') {\n            const sortCS = channelSemantics[sortBy];\n            sortField = sortCS?.field;\n            sortFieldType = sortCS?.type;\n            isDescending = sortOrder === 'descending' || (sortOrder !== 'ascending' && sortBy !== channel);\n        } else {\n            // Custom sort list — respect insertion order\n            try {\n                const sortedList = JSON.parse(sortBy);\n                if (Array.isArray(sortedList)) {\n                    const orderedValues = (sortOrder === 'descending') ? sortedList.reverse() : sortedList;\n                    return orderedValues.filter((v: any) => uniqueValues.includes(v)).slice(0, maxToKeep);\n                }\n            } catch {\n                // not a JSON list, fall through\n            }\n            isDescending = sortOrder === 'descending';\n        }\n    }\n\n    // Explicit value sort takes precedence over the category field's own type.\n    if (sortField && sortFieldType === 'quantitative') {\n        let aggregateOp = Math.max;\n        let initialValue = -Infinity;\n        if (allMarkTypes.has('bar') && sortField !== channelSemantics.color?.field) {\n            aggregateOp = (x: number, y: number) => x + y;\n            initialValue = 0;\n        }\n\n        const valueAggregates = new Map<any, number>();\n        for (const row of data) {\n            const fieldValue = row[fieldName];\n            const sortValue = Number(row[sortField] ?? 0);\n            if (valueAggregates.has(fieldValue)) {\n                valueAggregates.set(fieldValue, aggregateOp(valueAggregates.get(fieldValue)!, sortValue));\n            } else {\n                valueAggregates.set(fieldValue, aggregateOp(initialValue, sortValue));\n            }\n        }\n\n        return Array.from(valueAggregates.entries())\n            .map(([value, agg]) => ({ value, agg }))\n            .sort((a, b) => isDescending ? b.agg - a.agg : a.agg - b.agg)\n            .slice(0, maxToKeep)\n            .map(v => v.value);\n    }\n\n    const canonicalOrder = channelSemantics[channel]?.ordinalSortOrder;\n    if (!sortBy && !sortOrder && canonicalOrder?.length) {\n        const present = new Set(uniqueValues);\n        const ordered = canonicalOrder.filter(value => present.has(value));\n        const canonicalValues = new Set(ordered);\n        ordered.push(...uniqueValues.filter(value => !canonicalValues.has(value)));\n        return ordered.slice(0, maxToKeep);\n    }\n\n    // Match the display default for quantitative values treated as discrete.\n    const fieldOriginalType = inferVisCategory(data.map(r => r[fieldName]));\n    if (fieldOriginalType === 'quantitative' || channel === 'color') {\n        return [...uniqueValues].sort((a, b) => Number(a) - Number(b))\n            .slice(0, maxToKeep);\n    }\n\n    // Facet channels: first N\n    if (channel === 'column' || channel === 'row') {\n        return uniqueValues.slice(0, maxToKeep);\n    }\n\n    // Explicit field-order sort follows the displayed label order.\n    if (sortOrder === 'descending') {\n        return [...uniqueValues].sort((a, b) => String(b).localeCompare(String(a), undefined, { numeric: true })).slice(0, maxToKeep);\n    }\n    if (sortOrder === 'ascending') {\n        return [...uniqueValues].sort((a, b) => String(a).localeCompare(String(b), undefined, { numeric: true })).slice(0, maxToKeep);\n    }\n\n    // Default: first N values\n    return uniqueValues.slice(0, maxToKeep);\n};\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * =============================================================================\n * PHASE 1: COMPUTE LAYOUT\n * =============================================================================\n *\n * Determine how big things should be — axis lengths, step sizes,\n * subplot dimensions, label sizing, and overflow truncation — from data\n * density, axis classification, and template-provided tuning knobs.\n *\n * VL dependency: **None**\n *\n * This module reads abstract axis descriptors (AxisLayoutInput) and\n * produces abstract layout numbers (LayoutResult). The same layout\n * engine works regardless of output format.\n *\n * ── Backend Responsibility ──────────────────────────────────────────\n * The LayoutResult is a target-agnostic description of \"how big things\n * should be\".  Each rendering backend (Vega-Lite, ECharts, etc.) MUST:\n *\n *   1. Call computeLayout() once per chart (facet-aware — it already\n *      divides subplot sizes for the facet grid).\n *\n *   2. Translate the LayoutResult into its own rendering format:\n *      - subplotWidth / subplotHeight → plot area size (before margins)\n *      - xStep / yStep → bar widths, band sizes, category spacing\n *      - stepPadding → inter-category gap (barCategoryGap, paddingInner)\n *      - label sizing → font size, rotation, truncation\n *\n *   3. Add its own margins, padding, and chrome (axis labels, titles,\n *      legends, CANVAS_BUFFER) around the subplot area.\n *\n *   4. Handle facet-specific concerns itself:\n *      - Column wrapping (when user specifies column-only, the backend\n *        decides how many columns per visual row and restructures the\n *        panel grid accordingly).\n *      - Per-panel vs shared axis titles.\n *      - Panel positioning and header labels.\n *\n * The layout engine does NOT know about VL encodings, ECharts grid\n * objects, or any rendering-specific structure.\n * =============================================================================\n */\n\nimport type {\n    ChannelSemantics,\n    LayoutDeclaration,\n    LayoutResult,\n    AssembleOptions,\n    ChannelBudgets,\n} from './types';\nimport {\n    computeAxisStep,\n    computeGasPressure,\n    computeLabelSizing,\n    computeFontSizing,\n    DEFAULT_GAS_PRESSURE_PARAMS,\n    type ElasticStretchParams,\n    type GasPressureParams,\n} from './decisions';\nimport { planBandDodge } from './band-dodge';\n\n// ---------------------------------------------------------------------------\n// Short discrete axis labels (align with echarts/templates/bar.ts)\n// ---------------------------------------------------------------------------\n\nconst VL_SHORT_DISCRETE_CATEGORY_COUNT = 4;\nconst VL_SHORT_DISCRETE_LABEL_MAX_LEN = 8;\n\n/** Approximate width (px) of one label character at the given font size. */\nconst APPROX_CHAR_WIDTH_RATIO = 0.62;\n\n/** Distinct label strings for a discrete axis field, plus derived stats. */\ninterface DiscreteLabelStats {\n    count: number;\n    maxLen: number;\n    /** True when every label parses as a finite number (e.g. years, bins, IDs). */\n    allNumeric: boolean;\n}\n\nfunction computeDiscreteLabelStats(\n    field: string | undefined,\n    table: any[],\n): DiscreteLabelStats | null {\n    if (!field) return null;\n    const uniques = new Set<string>();\n    for (const row of table) {\n        const v = row[field];\n        if (v == null || v === '') continue;\n        uniques.add(String(v));\n    }\n    if (uniques.size === 0) return null;\n    const labels = [...uniques];\n    return {\n        count: labels.length,\n        maxLen: Math.max(...labels.map(s => s.length)),\n        allNumeric: labels.every(s => s.trim() !== '' && isFinite(Number(s))),\n    };\n}\n\n/**\n * Few, short category strings → keep axis labels horizontal in Vega-Lite. Used\n * for the Y axis, where banded labels read horizontally in the left margin\n * regardless of band height (so quantitative/numeric labels stay horizontal).\n */\nfunction discreteYAxisShouldUseHorizontalLabels(\n    field: string | undefined,\n    channelType: string | undefined,\n    table: any[],\n): boolean {\n    if (!field) return false;\n    if (channelType === 'quantitative') return true;\n    const stats = computeDiscreteLabelStats(field, table);\n    if (!stats) return false;\n    if (stats.count > VL_SHORT_DISCRETE_CATEGORY_COUNT) return false;\n    return stats.maxLen <= VL_SHORT_DISCRETE_LABEL_MAX_LEN;\n}\n\n// ---------------------------------------------------------------------------\n// Internal types\n// ---------------------------------------------------------------------------\n\ninterface AxisLayoutInput {\n    /** Spring model (banded) or gas pressure (non-banded) */\n    mode: 'banded' | 'non-banded';\n    /** Number of discrete positions (for banded) */\n    itemCount: number;\n    /** Number of sub-items per group (for grouped bars) */\n    subItemsPerGroup?: number;\n    /** Numeric values along this axis (for gas pressure) */\n    values?: number[];\n    /** Data extent [min, max] */\n    domain?: [number, number];\n    /** Number of distinct series (for series-based pressure) */\n    seriesCount?: number;\n}\n\n// ---------------------------------------------------------------------------\n// Stretch caps\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve the per-dimension maximum stretch caps (βx, βy) from options.\n *\n * The assembler derives `maxStretchX`/`maxStretchY` from the spec's\n * `canvasSize / baseSize` ratio (the hard ceiling). When neither is set,\n * both fall back to the scalar `maxStretch` (default {@link DEFAULT_MAX_STRETCH})\n * — the symmetric budget used when the spec pins no `canvasSize`. Each cap is\n * clamped to ≥ 1 (a chart never shrinks below its base under \"stretch\").\n */\nexport function resolveStretchCaps(options: AssembleOptions): { x: number; y: number } {\n    const def = options.maxStretch ?? DEFAULT_MAX_STRETCH;\n    return {\n        x: Math.max(1, options.maxStretchX ?? def),\n        y: Math.max(1, options.maxStretchY ?? def),\n    };\n}\n\n/** Default base (target) chart size in pixels when the spec omits `baseSize`. */\nexport const DEFAULT_BASE_SIZE = { width: 400, height: 320 } as const;\n\n/**\n * Default axis stretch cap used when the spec pins no `canvasSize` ceiling.\n *\n * Bounds how far a chart may grow past its base size (per dimension) under\n * layout pressure. 1.5 keeps growth modest; 2× was found to over-stretch\n * charts in the general (no-ceiling) case.\n */\nexport const DEFAULT_MAX_STRETCH = 1.5;\n\n/**\n * Resolve the effective base (target) size the layout pipeline aims for.\n *\n * Defaults to {@link DEFAULT_BASE_SIZE} when the spec omits `baseSize`, then\n * clamps each dimension to the optional `canvasSize` ceiling. This guarantees\n * the target never exceeds the hard maximum: when a user sets only a (small)\n * `canvasSize` and leaves `baseSize` defaulted — or sets a `baseSize` larger\n * than the ceiling — the chart shrinks to fit the box instead of overflowing\n * it. After clamping, `deriveStretchCaps` yields βx/βy = 1 in any clamped\n * dimension (pure fit-to-box, no growth past the ceiling).\n */\nexport function resolveBaseSize(\n    specBaseSize: { width: number; height: number } | undefined,\n    ceiling: { width: number; height: number } | undefined,\n): { width: number; height: number } {\n    const base = specBaseSize ?? { ...DEFAULT_BASE_SIZE };\n    if (!ceiling) return { width: base.width, height: base.height };\n    return {\n        width: Math.min(base.width, ceiling.width),\n        height: Math.min(base.height, ceiling.height),\n    };\n}\n\n/**\n * Read the user's `facetColumns` chart property (the interactive facet-wrap\n * control) off the RAW chart_spec.chartProperties, returning a clamped integer\n * column count or undefined for auto. Read raw (pre-normalization) because\n * `facetColumns` is a layout-level option, not a per-template mark property, so\n * `normalizeChartProperties` would otherwise drop it as an unknown key.\n */\nexport function resolveFacetColumnsOption(\n    chartProperties: Record<string, any> | undefined,\n): number | undefined {\n    const raw = chartProperties?.facetColumns;\n    if (raw == null) return undefined;\n    const n = Number(raw);\n    return Number.isFinite(n) && n >= 1 ? Math.floor(n) : undefined;\n}\n\n/**\n * Derive per-dimension stretch ceilings (βx, βy) for an assembler.\n *\n * When the spec supplies a hard `canvasSize` ceiling, the caps are the ratio\n * of ceiling to base in each dimension (clamped to ≥ 1). The base passed here\n * is expected to already be clamped to the ceiling (see {@link resolveBaseSize}),\n * so a ceiling smaller than the spec's base resolves to β = 1 (fit-to-box)\n * rather than an overflow. When no ceiling is given, both caps fall back to\n * `options.maxStretch` (or {@link DEFAULT_MAX_STRETCH} when that is unset too),\n * which already reflects any template `paramOverrides`.\n *\n * Assemblers inject the result into `effectiveOptions.maxStretchX/Y` so the\n * whole layout pipeline shares one budget — including faceted grids, whose\n * total size is bounded by the same ceiling.\n */\nexport function deriveStretchCaps(\n    baseSize: { width: number; height: number },\n    ceiling: { width: number; height: number } | undefined,\n    options: AssembleOptions,\n): { maxStretchX: number; maxStretchY: number } {\n    const def = options.maxStretch ?? DEFAULT_MAX_STRETCH;\n    return {\n        maxStretchX: ceiling ? Math.max(1, ceiling.width / baseSize.width) : def,\n        maxStretchY: ceiling ? Math.max(1, ceiling.height / baseSize.height) : def,\n    };\n}\n\n// ---------------------------------------------------------------------------\n// Public API: computeLayout\n// ---------------------------------------------------------------------------\n\n/**\n * Phase 1: Compute layout decisions.\n *\n * Takes channel semantics, template layout declaration, data, canvas size,\n * and assembly options to produce a LayoutResult with step sizes, subplot\n * dimensions, label sizing, and truncation warnings.\n *\n * VL dependency: **None**\n *\n * @param channelSemantics   Phase 0 output\n * @param declaration        Template's layout declaration (axisFlags, resolvedTypes,\n *                           grouping, binnedAxes)\n * @param table              Data rows (post-overflow filtered)\n * @param canvasSize         Target canvas dimensions\n * @param options            Assembly options (merged with template overrides)\n * @param facetGrid          Optional pre-decided facet grid from computeFacetGrid.\n *                           When provided, computeLayout uses these column/row\n *                           counts instead of counting from data — this\n *                           eliminates the circularity between wrapping and\n *                           banded axis sizing.\n */\nexport function computeLayout(\n    channelSemantics: Record<string, ChannelSemantics>,\n    declaration: LayoutDeclaration,\n    table: any[],\n    canvasSize: { width: number; height: number },\n    options: AssembleOptions = {},\n    facetGrid?: { columns: number; rows: number },\n): LayoutResult {\n    const {\n        elasticity: elasticityVal = 0.5,\n        facetElasticity: facetElasticityVal = 0.3,\n        minStep: minStepVal = 6,\n        minSubplotSize: minSubplotVal = 60,\n        stepPadding: stepPaddingVal = 0.1,\n        maintainContinuousAxisRatio = false,\n        continuousMarkCrossSection,\n        facetAspectRatioResistance = 0,\n    } = options;\n\n    // Per-dimension stretch ceilings: βx bounds width-related growth,\n    // βy bounds height-related growth. Both reduce to `maxStretch`\n    // (default 1.5) when the spec sets no explicit `canvasSize` ceiling.\n    const { x: maxStretchX, y: maxStretchY } = resolveStretchCaps(options);\n\n    const defaultChartWidth = canvasSize.width;\n    const defaultChartHeight = canvasSize.height;\n\n    // Facet overhead: fixed (axis labels, titles) + per-panel gap (spacing).\n    const fixW = options.facetFixedPadding?.width ?? 0;\n    const fixH = options.facetFixedPadding?.height ?? 0;\n    const gap = options.facetGap ?? 0;\n\n    const baseRefSize = 300;\n    const sizeRatio = Math.max(defaultChartWidth, defaultChartHeight) / baseRefSize;\n    const baseBandSize = options.defaultBandSize ?? 20;\n    const defaultStepSize = Math.round(baseBandSize * Math.max(1, sizeRatio));\n    // Sparse-expansion ceiling: a band may grow past its base size to fill a\n    // wide plot, but never past maxStepSize. Defaults to the base band, so a\n    // backend that doesn't opt in keeps the old \"cap at base\" behavior.\n    const maxBandSize = Math.max(baseBandSize, options.maxBandSize ?? baseBandSize);\n    const maxStepSize = Math.round(maxBandSize * Math.max(1, sizeRatio));\n\n    const isDiscreteType = (t: string | undefined) => t === 'nominal' || t === 'ordinal';\n\n    // Apply resolved types from template declaration\n    const effectiveTypes: Record<string, string> = {};\n    for (const [ch, cs] of Object.entries(channelSemantics)) {\n        effectiveTypes[ch] = declaration.resolvedTypes?.[ch] || cs.type;\n    }\n\n    // --- Classify axes and count items ---\n    const axisFlags = declaration.axisFlags || {};\n    const xBanded = axisFlags.x?.banded ?? false;\n    const yBanded = axisFlags.y?.banded ?? false;\n\n    const nominalCount: Record<string, number> = {\n        x: 0, y: 0, column: 0, row: 0, group: 0,\n    };\n\n    // Count discrete values per channel\n    for (const channel of ['x', 'y', 'column', 'row', 'color'] as const) {\n        const cs = channelSemantics[channel];\n        if (!cs?.field) continue;\n        const effectiveType = effectiveTypes[channel] || cs.type;\n        if (!isDiscreteType(effectiveType)) continue;\n        const uniqueValues = [...new Set(table.map((r: any) => r[cs.field]))];\n        nominalCount[channel] = uniqueValues.length;\n    }\n\n    // Detect grouping from 'group' channel + discrete axis\n    let groupField: string | undefined = channelSemantics.group?.field;\n    // Some templates (e.g. boxplot) subdivide a band by the COLOR field via an\n    // explicit offset rather than a dedicated 'group' channel. When they opt in,\n    // size the band as a group so total width is budgeted across categories and\n    // each sub-lane shrinks as the subgroup count grows.\n    if (!groupField && declaration.colorActsAsGroup) {\n        const colorCS = channelSemantics.color;\n        const colorType = effectiveTypes.color ?? colorCS?.type;\n        const axisField = isDiscreteType(effectiveTypes.x ?? channelSemantics.x?.type)\n            ? channelSemantics.x?.field\n            : channelSemantics.y?.field;\n        if (colorCS?.field && isDiscreteType(colorType) && colorCS.field !== axisField) {\n            groupField = colorCS.field;\n        }\n    }\n    // Guard: a grouping field that is redundant/nested with the categorical axis\n    // (group == x, or a 1:1 field pair) doesn't actually subdivide any band, so\n    // grouping it would collapse each bar/box to ~1/N of its band. When no band\n    // holds more than one distinct group value (confident-nested; threshold-\n    // independent), suppress grouping so glyphs fill their whole band. Genuine\n    // grouped charts (any band with >1 group value) are untouched.\n    if (groupField) {\n        const groupAxisField = isDiscreteType(effectiveTypes.x ?? channelSemantics.x?.type)\n            ? channelSemantics.x?.field\n            : channelSemantics.y?.field;\n        if (groupAxisField === groupField) {\n            groupField = undefined;  // group == axis: nothing to dodge\n        } else if (groupAxisField && planBandDodge(table, groupAxisField, groupField).maxPerBand <= 1) {\n            groupField = undefined;  // 1:1 / nested with the axis\n        }\n    }\n    let groupAxis: 'x' | 'y' | undefined;\n    if (groupField) {\n        // `local` dodge budgets only `maxPerBand` lanes (declaration.groupLaneCount);\n        // otherwise reserve one lane per global distinct group value.\n        nominalCount.group = declaration.groupLaneCount\n            ?? new Set(table.map((r: any) => r[groupField])).size;\n        if (isDiscreteType(effectiveTypes.x ?? channelSemantics.x?.type)) groupAxis = 'x';\n        else if (isDiscreteType(effectiveTypes.y ?? channelSemantics.y?.type)) groupAxis = 'y';\n    }\n\n    // Total discrete items per axis (grouping multiplies the grouped axis)\n    const xGroupMultiplier = (groupAxis === 'x' && nominalCount.group > 1) ? nominalCount.group : 1;\n    const yGroupMultiplier = (groupAxis === 'y' && nominalCount.group > 1) ? nominalCount.group : 1;\n    const xTotalNominalCount = nominalCount.x * xGroupMultiplier;\n    const yTotalNominalCount = nominalCount.y * yGroupMultiplier;\n\n    // --- Step size hints ---\n    // Minimum group step: the inter-group gap (stepPadding × step) must be\n    // at least MIN_GROUP_GAP_PX pixels so groups are visually separated.\n    const MIN_GROUP_GAP_PX = 3;\n    const xMinGroupStep = xGroupMultiplier > 1 ? Math.max(Math.ceil(MIN_GROUP_GAP_PX / stepPaddingVal), 2 * xGroupMultiplier) : minStepVal;\n    const yMinGroupStep = yGroupMultiplier > 1 ? Math.max(Math.ceil(MIN_GROUP_GAP_PX / stepPaddingVal), 2 * yGroupMultiplier) : minStepVal;\n\n    // (Overflow filtering is now handled by filterOverflow() before\n    //  computeLayout is called. The data passed here is already filtered.)\n\n    // --- Count banded continuous axes ---\n    let xContinuousAsDiscrete = 0;\n    let yContinuousAsDiscrete = 0;\n    for (const axis of ['x', 'y'] as const) {\n        const cs = channelSemantics[axis];\n        if (!cs?.field) continue;\n        const effectiveType = effectiveTypes[axis] || cs.type;\n        if (isDiscreteType(effectiveType)) continue;\n\n        const isBanded = (axis === 'x' ? xBanded : yBanded);\n        // Check for binned from declaration\n        const isBinned = declaration.binnedAxes?.[axis];\n        if (!isBanded && !isBinned) continue;\n\n        let count: number;\n        if (isBinned) {\n            const binDef = declaration.binnedAxes![axis];\n            // Default to 10 bins (Vega-Lite's default maxbins)\n            count = typeof binDef === 'object' && binDef.maxbins\n                ? binDef.maxbins : 10;\n        } else {\n            count = new Set(table.map((r: any) => r[cs.field])).size;\n        }\n        if (count <= 1) continue;\n\n        if (axis === 'x') {\n            xContinuousAsDiscrete = count;\n        } else {\n            yContinuousAsDiscrete = count;\n        }\n    }\n\n    // --- Facet layout ---\n    // Use pre-decided grid from filterOverflow when available.\n    // This avoids the circularity where wrapping depends on subplot\n    // width which depends on facet count which depends on wrapping.\n    let facetCols = 1;\n    let facetRows = 1;\n    if (facetGrid) {\n        facetCols = facetGrid.columns;\n        facetRows = facetGrid.rows;\n    } else {\n        if (nominalCount.column > 0) facetCols = nominalCount.column;\n        if (nominalCount.row > 0) facetRows = nominalCount.row;\n    }\n\n    // --- Facet subplot sizing ---\n    // Log-scale axes need more room so the minor grid lines (1,2,3…9 per\n    // decade) remain legible and act as the visual cue that it's log scale.\n    // Compute the number of orders of magnitude each axis spans; each\n    // decade needs ~40px minimum to avoid a dense wall of grid lines.\n    const LOG_PX_PER_DECADE = 40;\n    let logBoostX = 0;\n    let logBoostY = 0;\n    for (const axis of ['x', 'y'] as const) {\n        const cs = channelSemantics[axis];\n        if (!cs?.field || !cs.scaleType) continue;\n        if (cs.scaleType !== 'log' && cs.scaleType !== 'symlog') continue;\n        const vals = table\n            .map((r: any) => r[cs.field])\n            .filter((v: any) => typeof v === 'number' && v > 0 && isFinite(v));\n        if (vals.length < 2) continue;\n        const decades = Math.log10(Math.max(...vals)) - Math.log10(Math.min(...vals));\n        const needed = Math.ceil(Math.max(1, decades)) * LOG_PX_PER_DECADE;\n        if (axis === 'x') logBoostX = needed;\n        else logBoostY = needed;\n    }\n    const minContinuousSize = Math.max(10, minStepVal);\n    const minContinuousSizeX = Math.max(minContinuousSize, logBoostX);\n    const minContinuousSizeY = Math.max(minContinuousSize, logBoostY);\n\n    let subplotWidth: number;\n    if (facetCols > 1) {\n        const stretch = Math.min(maxStretchX, Math.pow(facetCols, facetElasticityVal));\n        subplotWidth = Math.round(Math.max(minContinuousSizeX,\n            (defaultChartWidth * stretch - fixW) / facetCols - gap));\n    } else {\n        subplotWidth = defaultChartWidth;\n    }\n\n    let subplotHeight: number;\n    if (facetRows > 1) {\n        const stretch = Math.min(maxStretchY, Math.pow(facetRows, facetElasticityVal));\n        subplotHeight = Math.round(Math.max(minContinuousSizeY,\n            (defaultChartHeight * stretch - fixH) / facetRows - gap));\n    } else {\n        subplotHeight = defaultChartHeight;\n    }\n\n    // --- Facet aspect-ratio resistance (non-gas-pressure charts) ---\n    // When faceting compresses one dimension (e.g. width ÷ columns), the\n    // aspect ratio drifts.  Line/area charts are very sensitive to this.\n    // For charts entering the 2D gas pressure path, AR resistance is\n    // handled inside the ideal-then-squeeze logic below. This block\n    // only applies when both axes are NOT continuous-non-banded.\n    const xIsContinuousNonBanded = xTotalNominalCount === 0 && xContinuousAsDiscrete === 0;\n    const yIsContinuousNonBanded = yTotalNominalCount === 0 && yContinuousAsDiscrete === 0;\n    const bothContinuousNonBanded = xIsContinuousNonBanded && yIsContinuousNonBanded;\n\n    if (facetAspectRatioResistance > 0 && !bothContinuousNonBanded\n        && (facetCols > 1 || facetRows > 1)) {\n        const baseAR = defaultChartWidth / defaultChartHeight;\n        const facetAR = subplotWidth / subplotHeight;\n        const arDrift = facetAR / baseAR; // <1 when panel got relatively narrower\n\n        if (arDrift < 1) {\n            // Panel is narrower than base → shrink height to compensate\n            subplotHeight = Math.round(\n                Math.max(minContinuousSizeY, subplotHeight * Math.pow(arDrift, facetAspectRatioResistance)),\n            );\n        } else if (arDrift > 1) {\n            // Panel is wider than base → shrink width to compensate\n            subplotWidth = Math.round(\n                Math.max(minContinuousSizeX, subplotWidth * Math.pow(1 / arDrift, facetAspectRatioResistance)),\n            );\n        }\n    }\n\n    // --- Gas pressure stretch for continuous non-banded axes ---\n    //\n    // Design: per-subplot baseline → pressure → AR blend → fit.\n    //\n    //   Baseline: each subplot gets a fair share of the canvas with\n    //             facet elasticity applied (cols^e / cols).\n    //   Step 1 — Gas pressure measures crowding against the per-subplot\n    //            baseline and produces per-axis raw stretches.\n    //   Step 2 — Decide AR: blend gas-pressure AR (density asymmetry)\n    //            with banking AR (perceptual slope optimization) in\n    //            log space.  Distribute gas-pressure area into the\n    //            blended AR.\n    //   Step 3 — Fit into budget: uniform scale-down so neither axis\n    //            exceeds maxStretch, preserving the AR.\n\n    if (bothContinuousNonBanded) {\n        const xCS = channelSemantics.x;\n        const yCS = channelSemantics.y;\n\n        if (xCS?.field && yCS?.field) {\n            const isTempX = (effectiveTypes.x || xCS.type) === 'temporal';\n            const isTempY = (effectiveTypes.y || yCS.type) === 'temporal';\n\n            const xNumeric: number[] = [];\n            const yNumeric: number[] = [];\n            for (const row of table) {\n                let xv = row[xCS.field];\n                let yv = row[yCS.field];\n                if (xv == null || yv == null) continue;\n                if (isTempX) xv = +new Date(xv);\n                else xv = +xv;\n                if (isTempY) yv = +new Date(yv);\n                else yv = +yv;\n                if (isNaN(xv) || isNaN(yv)) continue;\n                xNumeric.push(xv);\n                yNumeric.push(yv);\n            }\n\n            if (xNumeric.length > 1) {\n                const xMin = Math.min(...xNumeric);\n                const xMax = Math.max(...xNumeric);\n                const yMin = Math.min(...yNumeric);\n                const yMax = Math.max(...yNumeric);\n\n                // Expand to visual domain (include zero when axis starts at zero).\n                const xDomain: [number, number] = [xMin, xMax];\n                const yDomain: [number, number] = [yMin, yMax];\n                if (xCS.zero?.zero) {\n                    if (xDomain[0] > 0) xDomain[0] = 0;\n                    if (xDomain[1] < 0) xDomain[1] = 0;\n                }\n                if (yCS.zero?.zero) {\n                    if (yDomain[0] > 0) yDomain[0] = 0;\n                    if (yDomain[1] < 0) yDomain[1] = 0;\n                }\n\n                // Data-coverage guard: skip banking when zero dominates.\n                const xDataCoverage = (xDomain[1] - xDomain[0]) > 0\n                    ? (xMax - xMin) / (xDomain[1] - xDomain[0]) : 1;\n                const yDataCoverage = (yDomain[1] - yDomain[0]) > 0\n                    ? (yMax - yMin) / (yDomain[1] - yDomain[0]) : 1;\n                const BANKING_COVERAGE_THRESHOLD = 0.2;\n\n                // --- Gas pressure params ---\n                let gasPressureParams: GasPressureParams = DEFAULT_GAS_PRESSURE_PARAMS;\n                if (continuousMarkCrossSection != null) {\n                    if (typeof continuousMarkCrossSection === 'number') {\n                        gasPressureParams = { ...DEFAULT_GAS_PRESSURE_PARAMS, markCrossSection: continuousMarkCrossSection };\n                    } else {\n                        const maxCS = Math.max(continuousMarkCrossSection.x, continuousMarkCrossSection.y);\n                        gasPressureParams = {\n                            ...DEFAULT_GAS_PRESSURE_PARAMS,\n                            markCrossSection: maxCS,\n                            markCrossSectionX: continuousMarkCrossSection.x,\n                            markCrossSectionY: continuousMarkCrossSection.y,\n                            ...(continuousMarkCrossSection.elasticity != null && { elasticity: continuousMarkCrossSection.elasticity }),\n                            ...(continuousMarkCrossSection.maxStretch != null && { maxStretch: continuousMarkCrossSection.maxStretch }),\n                        };\n\n                        if (continuousMarkCrossSection.seriesCountAxis) {\n                            const resolvedAxis = continuousMarkCrossSection.seriesCountAxis === 'auto'\n                                ? 'y' : continuousMarkCrossSection.seriesCountAxis;\n                            const nSeries = countDistinctSeries(channelSemantics, table);\n                            if (resolvedAxis === 'y') {\n                                gasPressureParams.yItemCountOverride = nSeries;\n                            } else {\n                                gasPressureParams.xItemCountOverride = nSeries;\n                            }\n                        }\n                    }\n                }\n\n                // --- Per-subplot baseline canvas ---\n                // Gas pressure must measure crowding against the actual\n                // per-subplot space, not the full canvas.  When faceted,\n                // each subplot gets a share of the canvas that includes\n                // facet elasticity (the same formula used for discrete\n                // axes): `canvas × cols^elasticity / cols`.  This way\n                // 2 columns don't naively halve the space — some stretch\n                // is assumed before gas pressure even kicks in.\n                const perSubplotCanvasW = facetCols > 1\n                    ? Math.max(minContinuousSizeX,\n                        (defaultChartWidth * Math.min(maxStretchX, Math.pow(facetCols, facetElasticityVal)) - fixW)\n                        / facetCols - gap)\n                    : defaultChartWidth;\n                const perSubplotCanvasH = facetRows > 1\n                    ? Math.max(minContinuousSizeY,\n                        (defaultChartHeight * Math.min(maxStretchY, Math.pow(facetRows, facetElasticityVal)) - fixH)\n                        / facetRows - gap)\n                    : defaultChartHeight;\n\n                // --- Gas pressure: per-axis raw stretches ---\n                const idealResult = computeGasPressure(\n                    xNumeric, yNumeric, xDomain, yDomain,\n                    perSubplotCanvasW, perSubplotCanvasH, gasPressureParams,\n                );\n\n                const isConnected = typeof continuousMarkCrossSection === 'object'\n                    && !!continuousMarkCrossSection.seriesCountAxis;\n                const useBanking = xDataCoverage >= BANKING_COVERAGE_THRESHOLD\n                    && yDataCoverage >= BANKING_COVERAGE_THRESHOLD;\n\n                let idealW: number;\n                let idealH: number;\n\n                // Gas pressure's native per-axis dimensions (uncapped).\n                const rawW = perSubplotCanvasW * idealResult.rawStretchX;\n                const rawH = perSubplotCanvasH * idealResult.rawStretchY;\n\n                if (useBanking) {\n                    // ── Step 1: Decide AR ──────────────────────────────\n                    // Blend gas-pressure AR (which axis is more crowded)\n                    // with banking AR (perceptual slope optimization).\n                    const seriesFields: string[] = [];\n                    const colorField = channelSemantics.color?.field;\n                    const detailField = channelSemantics.detail?.field;\n                    if (colorField) seriesFields.push(colorField);\n                    if (detailField && detailField !== colorField) seriesFields.push(detailField);\n\n                    const perPointSeriesKeys: string[] = new Array(xNumeric.length);\n                    if (seriesFields.length === 0) {\n                        perPointSeriesKeys.fill('');\n                    } else {\n                        let idx = 0;\n                        for (const row of table) {\n                            const xv = xCS?.field ? row[xCS.field] : undefined;\n                            const yv = yCS?.field ? row[yCS.field] : undefined;\n                            if (xv == null || yv == null) continue;\n                            const xn = isTempX ? +new Date(xv) : +xv;\n                            const yn = isTempY ? +new Date(yv) : +yv;\n                            if (isNaN(xn) || isNaN(yn)) continue;\n                            perPointSeriesKeys[idx++] = seriesFields\n                                .map(f => String(row[f] ?? '')).join('\\x00');\n                        }\n                    }\n\n                    const bankingAR = computeBankingAR(\n                        xNumeric, yNumeric, xDomain, yDomain,\n                        perPointSeriesKeys, isConnected,\n                    );\n\n                    // ── Step 2: Blend AR + distribute area ────────────\n                    // Gas pressure knows which axis is crowded (per-axis\n                    // stretch).  Banking knows the perceptual ideal AR.\n                    // Blend in log space so both signals contribute:\n                    //   gasAR reflects density asymmetry (X crowded → landscape)\n                    //   bankingAR reflects slope perception\n                    const BANKING_BLEND = 0.5;\n                    const gasAR = rawW / rawH;\n                    const blendedAR = gasAR > 0 && bankingAR > 0\n                        ? Math.exp((1 - BANKING_BLEND) * Math.log(gasAR)\n                            + BANKING_BLEND * Math.log(bankingAR))\n                        : bankingAR;\n\n                    // Total area from gas pressure (capped so subplot\n                    // doesn't blow past per-subplot budget before fit).\n                    const rawArea = rawW * rawH;\n                    const maxArea = perSubplotCanvasW * perSubplotCanvasH * Math.max(maxStretchX, maxStretchY);\n                    const area = Math.min(rawArea, maxArea);\n\n                    idealW = Math.sqrt(area * blendedAR);\n                    idealH = Math.sqrt(area / blendedAR);\n                } else {\n                    // Banking skipped (zero dominates): gas pressure shape.\n                    idealW = rawW;\n                    idealH = rawH;\n                }\n\n                // ── Step 3: Fit into budget, preserving AR ───────────\n                // Hard ceiling per subplot: canvas × maxStretch shared\n                // across facet panels.\n                const availW = facetCols > 1\n                    ? Math.max(minContinuousSizeX, (defaultChartWidth * maxStretchX - fixW) / facetCols - gap)\n                    : defaultChartWidth * maxStretchX;\n                const availH = facetRows > 1\n                    ? Math.max(minContinuousSizeY, (defaultChartHeight * maxStretchY - fixH) / facetRows - gap)\n                    : defaultChartHeight * maxStretchY;\n\n                // Scale down to fit: if either axis exceeds its budget,\n                // shrink both axes by the tighter ratio so neither\n                // exceeds AND the AR is preserved.\n                const scaleX = idealW > availW ? availW / idealW : 1;\n                const scaleY = idealH > availH ? availH / idealH : 1;\n                const fitScale = Math.min(scaleX, scaleY);\n\n                let finalW = idealW * fitScale;\n                let finalH = idealH * fitScale;\n\n                // Enforce minimums (may slightly distort AR at extremes).\n                finalW = Math.max(finalW, minContinuousSizeX);\n                finalH = Math.max(finalH, minContinuousSizeY);\n\n                subplotWidth = Math.round(finalW);\n                subplotHeight = Math.round(finalH);\n            }\n        }\n    } else if (xIsContinuousNonBanded || yIsContinuousNonBanded) {\n        const contAxis = xIsContinuousNonBanded ? 'x' : 'y';\n        const otherAxisHasDiscreteItems = contAxis === 'x'\n            ? (yTotalNominalCount > 0 || yContinuousAsDiscrete > 0)\n            : (xTotalNominalCount > 0 || xContinuousAsDiscrete > 0);\n\n        let seriesStretchApplied = false;\n        if (typeof continuousMarkCrossSection === 'object' && continuousMarkCrossSection.seriesCountAxis) {\n            const resolvedAxis = continuousMarkCrossSection.seriesCountAxis === 'auto'\n                ? contAxis : continuousMarkCrossSection.seriesCountAxis;\n\n            if (resolvedAxis === contAxis) {\n                const sigmaPerSeries = contAxis === 'x'\n                    ? continuousMarkCrossSection.x\n                    : continuousMarkCrossSection.y;\n                const baseDim = contAxis === 'x' ? subplotWidth : subplotHeight;\n                const nSeries = countDistinctSeries(channelSemantics, table);\n                const pressure = (nSeries * sigmaPerSeries) / baseDim;\n\n                const elast = continuousMarkCrossSection.elasticity ?? DEFAULT_GAS_PRESSURE_PARAMS.elasticity;\n                const maxS = continuousMarkCrossSection.maxStretch ?? DEFAULT_GAS_PRESSURE_PARAMS.maxStretch;\n\n                if (pressure > 1) {\n                    const stretch = Math.min(maxS, Math.pow(pressure, elast));\n                    if (contAxis === 'x') {\n                        subplotWidth = Math.round(subplotWidth * stretch);\n                    } else {\n                        subplotHeight = Math.round(subplotHeight * stretch);\n                    }\n                }\n                seriesStretchApplied = true;\n            }\n        }\n\n        if (!seriesStretchApplied && !otherAxisHasDiscreteItems) {\n            const contCS = channelSemantics[contAxis];\n            if (contCS?.field) {\n                const isTemporal = (effectiveTypes[contAxis] || contCS.type) === 'temporal';\n                const contValues: number[] = [];\n                for (const row of table) {\n                    let v = row[contCS.field];\n                    if (v == null) continue;\n                    if (isTemporal) v = +new Date(v);\n                    else v = +v;\n                    if (!isNaN(v)) contValues.push(v);\n                }\n                const sigma1d = Math.sqrt(DEFAULT_GAS_PRESSURE_PARAMS.markCrossSection);\n                const baseDim = contAxis === 'x' ? subplotWidth : subplotHeight;\n                const pressure1d = (contValues.length * sigma1d) / baseDim;\n                if (pressure1d > 1) {\n                    const stretch1d = Math.min(\n                        DEFAULT_GAS_PRESSURE_PARAMS.maxStretch,\n                        Math.pow(pressure1d, DEFAULT_GAS_PRESSURE_PARAMS.elasticity),\n                    );\n                    if (contAxis === 'x') {\n                        subplotWidth = Math.round(subplotWidth * stretch1d);\n                    } else {\n                        subplotHeight = Math.round(subplotHeight * stretch1d);\n                    }\n                }\n            }\n        }\n    }\n\n    // --- Elastic stretch for discrete axes ---\n    // X axis grows under its width budget (βx); Y under its height budget (βy).\n    const elasticParamsX: ElasticStretchParams = {\n        elasticity: elasticityVal,\n        maxStretch: maxStretchX,\n        defaultStepSize,\n        minStep: minStepVal,\n    };\n    const elasticParamsY: ElasticStretchParams = {\n        elasticity: elasticityVal,\n        maxStretch: maxStretchY,\n        defaultStepSize,\n        minStep: minStepVal,\n    };\n\n    const xAxis = computeAxisStep(xTotalNominalCount, xContinuousAsDiscrete, subplotWidth, elasticParamsX);\n    const yAxis = computeAxisStep(yTotalNominalCount, yContinuousAsDiscrete, subplotHeight, elasticParamsY);\n\n    const xIsDiscrete = xTotalNominalCount > 0;\n    const yIsDiscrete = yTotalNominalCount > 0;\n\n    const xHasGrouping = groupAxis === 'x' && nominalCount.group > 0;\n    const yHasGrouping = groupAxis === 'y' && nominalCount.group > 0;\n\n    let xStepSize: number;\n    let yStepSize: number;\n    let xStepUnit: 'item' | 'group' | undefined;\n    let yStepUnit: 'item' | 'group' | undefined;\n\n    if (xIsDiscrete && xHasGrouping) {\n        const itemsPerGroup = nominalCount.group;\n        const defaultGroupStep = itemsPerGroup * maxStepSize;\n        const minGroupStep = Math.max(Math.ceil(MIN_GROUP_GAP_PX / stepPaddingVal), 2 * itemsPerGroup);\n        const groupAxis = computeAxisStep(nominalCount.x, 0, subplotWidth, elasticParamsX);\n        const groupStep = Math.max(minGroupStep, Math.min(defaultGroupStep, groupAxis.step));\n        xStepSize = groupStep;\n        xStepUnit = 'group';\n    } else if (xIsDiscrete) {\n        xStepSize = Math.max(minStepVal, Math.min(maxStepSize, xAxis.step));\n    } else if (xContinuousAsDiscrete > 0) {\n        xStepSize = Math.max(minStepVal, Math.min(maxStepSize, xAxis.step));\n    } else {\n        xStepSize = defaultStepSize;\n    }\n\n    if (yIsDiscrete && yHasGrouping) {\n        const itemsPerGroup = nominalCount.group;\n        const defaultGroupStep = itemsPerGroup * maxStepSize;\n        const minGroupStep = Math.max(Math.ceil(MIN_GROUP_GAP_PX / stepPaddingVal), 2 * itemsPerGroup);\n        const groupAxis = computeAxisStep(nominalCount.y, 0, subplotHeight, elasticParamsY);\n        const groupStep = Math.max(minGroupStep, Math.min(defaultGroupStep, groupAxis.step));\n        yStepSize = groupStep;\n        yStepUnit = 'group';\n    } else if (yIsDiscrete) {\n        yStepSize = Math.max(minStepVal, Math.min(maxStepSize, yAxis.step));\n    } else if (yContinuousAsDiscrete > 0) {\n        yStepSize = Math.max(minStepVal, Math.min(maxStepSize, yAxis.step));\n    } else {\n        yStepSize = defaultStepSize;\n    }\n\n    // --- Banded continuous canvas size ---\n    for (const axis of ['x', 'y'] as const) {\n        const count = axis === 'x' ? xContinuousAsDiscrete : yContinuousAsDiscrete;\n        if (count <= 0) continue;\n        const stepSize = axis === 'x' ? xStepSize : yStepSize;\n        const continuousSize = Math.round(stepSize * (count + 1));\n        if (axis === 'x') {\n            subplotWidth = continuousSize;\n        } else {\n            subplotHeight = continuousSize;\n        }\n    }\n\n    // --- Unified stretch budget ------------------------------------------------\n    // Cap the per-subplot dimensions so total canvas never exceeds\n    // canvasWidth × maxStretch (and canvasHeight × maxStretch).\n    // Formula: effectiveW = W × maxStretch − fixedPad; each panel costs subplot + gap.\n    const maxSubplotW = (defaultChartWidth * maxStretchX - fixW) / facetCols - gap;\n    const maxSubplotH = (defaultChartHeight * maxStretchY - fixH) / facetRows - gap;\n\n    // Clamp step sizes for discrete/banded axes so VL step-based\n    // sizing respects the same budget.\n    // When step unit is 'group', divide by the number of groups (nominalCount)\n    // rather than the total item count (groups × items-per-group).\n    if (xTotalNominalCount > 0) {\n        const divisor = xStepUnit === 'group' ? nominalCount.x : xTotalNominalCount;\n        const cap = Math.max(minStepVal, Math.floor(maxSubplotW / divisor));\n        if (xStepSize > cap) xStepSize = cap;\n    }\n    if (xContinuousAsDiscrete > 0) {\n        const cap = Math.max(minStepVal, Math.floor(maxSubplotW / (xContinuousAsDiscrete + 1)));\n        if (xStepSize > cap) xStepSize = cap;\n    }\n    if (yTotalNominalCount > 0) {\n        const divisor = yStepUnit === 'group' ? nominalCount.y : yTotalNominalCount;\n        const cap = Math.max(minStepVal, Math.floor(maxSubplotH / divisor));\n        if (yStepSize > cap) yStepSize = cap;\n    }\n    if (yContinuousAsDiscrete > 0) {\n        const cap = Math.max(minStepVal, Math.floor(maxSubplotH / (yContinuousAsDiscrete + 1)));\n        if (yStepSize > cap) yStepSize = cap;\n    }\n\n    // Recompute banded subplot size after step clamping.\n    for (const axis of ['x', 'y'] as const) {\n        const count = axis === 'x' ? xContinuousAsDiscrete : yContinuousAsDiscrete;\n        if (count <= 0) continue;\n        const stepSize = axis === 'x' ? xStepSize : yStepSize;\n        if (axis === 'x') subplotWidth = Math.round(stepSize * (count + 1));\n        else subplotHeight = Math.round(stepSize * (count + 1));\n    }\n\n    // --- Nominal discrete subplot sizing ---\n    // For nominal discrete axes, one backend (VL) overrides subplotWidth\n    // with step-based sizing (width:{step:N}), so the subplot dimension\n    // doesn't matter.  Other backends (Chart.js, ECharts) fill the canvas\n    // and divide evenly among categories — for them, the subplot dimension\n    // IS the canvas width.\n    //\n    // Ensure the subplot is at least as wide as canvasSize (the user's\n    // requested chart size) so backends that fill the canvas get generous\n    // bars when there are few categories.  The subplot only exceeds\n    // canvasSize when faceting shrinks it, which is already handled above.\n\n    // Clamp continuous subplot dimensions.\n    subplotWidth = Math.min(subplotWidth, Math.round(maxSubplotW));\n    subplotHeight = Math.min(subplotHeight, Math.round(maxSubplotH));\n\n    // --- Band AR blending ---\n    // When one axis is banded (discrete) and the other is continuous,\n    // each band has a natural AR = continuousSize / stepSize.  If the\n    // actual band AR exceeds the target, blend the subplot AR toward\n    // the target (in log space) to avoid excessively tall/wide bands.\n    const targetBandAR = options.targetBandAR;\n    if (targetBandAR && targetBandAR > 0) {\n        const xIsBanded = xTotalNominalCount > 0 || xContinuousAsDiscrete > 0;\n        const yIsBanded = yTotalNominalCount > 0 || yContinuousAsDiscrete > 0;\n\n        if (xIsBanded && !yIsBanded) {\n            // X is banded, Y is continuous → band AR = subplotHeight / xStepSize\n            const actualBandAR = subplotHeight / xStepSize;\n            if (actualBandAR > targetBandAR) {\n                const idealH = xStepSize * targetBandAR;\n                // Blend: 50/50 between actual and target in log space.\n                const blendedH = Math.exp(\n                    0.5 * Math.log(subplotHeight) + 0.5 * Math.log(idealH));\n                subplotHeight = Math.round(\n                    Math.max(minContinuousSizeY, Math.min(blendedH, subplotHeight)));\n            }\n        } else if (yIsBanded && !xIsBanded) {\n            // Y is banded, X is continuous → band AR = subplotWidth / yStepSize\n            const actualBandAR = subplotWidth / yStepSize;\n            if (actualBandAR > targetBandAR) {\n                const idealW = yStepSize * targetBandAR;\n                const blendedW = Math.exp(\n                    0.5 * Math.log(subplotWidth) + 0.5 * Math.log(idealW));\n                subplotWidth = Math.round(\n                    Math.max(minContinuousSizeX, Math.min(blendedW, subplotWidth)));\n            }\n        }\n    }\n\n    // --- Label sizing ---\n    // A temporal/numeric field used as a BANDED axis (one bar per value) is\n    // \"continuous-as-discrete\": its tick labels sit one-per-band exactly like a\n    // nominal axis, so they must follow the same discrete sizing ladder (shrink\n    // — and rotate when bands are narrow) rather than staying at the full\n    // continuous base font. Otherwise dense date/number bands render oversized\n    // labels that feel too large for their band and crowd together.\n    const xHasDiscreteItems = xTotalNominalCount > 0 || xContinuousAsDiscrete > 0;\n    const yHasDiscreteItems = yTotalNominalCount > 0 || yContinuousAsDiscrete > 0;\n    // Canvas-adaptive fonts: descend the tick ladder from the backend's native\n    // base, and derive header/legend sizes. Scaled by the (sub)plot's smaller\n    // dimension so small multiples shrink and large single views grow subtly.\n    const fontSizing = computeFontSizing(Math.min(subplotWidth, subplotHeight), {\n        baseLabelFontSize: options.baseLabelFontSize,\n        baseTitleFontSize: options.baseTitleFontSize,\n    });\n    const labelOpts = { baseFont: fontSizing.tickBase, minFont: 6 };\n    let xLabel = computeLabelSizing(xStepSize, xHasDiscreteItems, labelOpts);\n    let yLabel = computeLabelSizing(yStepSize, yHasDiscreteItems, labelOpts);\n\n    if (xHasDiscreteItems) {\n        const xf = channelSemantics.x?.field;\n        const xt = effectiveTypes.x || channelSemantics.x?.type;\n        const stats = computeDiscreteLabelStats(xf, table);\n        if (stats) {\n            // Numeric-like labels (declared quantitative, or all values parse as\n            // numbers — years, bins, IDs) compete for the band's width when laid\n            // out horizontally. A continuous field split into many narrow bands\n            // yields many/wide numbers that crowd. Decide horizontal vs. angled\n            // by whether the widest label fits within one band.\n            const numericLike = xt === 'quantitative' || stats.allNumeric;\n            let labelPx = stats.maxLen * xLabel.fontSize * APPROX_CHAR_WIDTH_RATIO;\n            const fewShortStrings = !numericLike\n                && stats.count <= VL_SHORT_DISCRETE_CATEGORY_COUNT\n                && stats.maxLen <= VL_SHORT_DISCRETE_LABEL_MAX_LEN;\n\n            if (fewShortStrings || (numericLike && labelPx <= xStepSize)) {\n                // We want horizontal labels here. But a small number of short\n                // string categories can still collide when the band step is\n                // narrower than the widest label (e.g. box marks declare a tiny\n                // defaultBandSize). Before committing to horizontal, make sure\n                // the label actually fits — widen the band within the stretch\n                // budget if it can, otherwise angle the labels instead of\n                // letting them overlap. (xStepSize is the per-label band width:\n                // the item step when ungrouped, the group step when grouped.)\n                if (labelPx > xStepSize) {\n                    const desiredStep = Math.ceil(labelPx) + 6; // label width + inter-label gap\n                    const cap = Math.max(minStepVal, Math.floor(maxSubplotW / stats.count));\n                    if (desiredStep <= cap) {\n                        xStepSize = Math.max(xStepSize, desiredStep);\n                        xLabel = computeLabelSizing(xStepSize, xHasDiscreteItems, labelOpts);\n                        labelPx = stats.maxLen * xLabel.fontSize * APPROX_CHAR_WIDTH_RATIO;\n                    }\n                }\n\n                if (labelPx <= xStepSize) {\n                    // Fits horizontally (already, or after widening the band).\n                    // Must be explicit: omitting labelAngle leaves VL defaults (e.g. -45° on ordinal).\n                    xLabel = {\n                        ...xLabel,\n                        labelAngle: 0,\n                        labelAlign: 'center',\n                        labelBaseline: 'top',\n                    };\n                } else {\n                    // Even the stretch budget can't fit a wide-enough band →\n                    // angle the labels rather than let them run together.\n                    xLabel = {\n                        ...xLabel,\n                        labelAngle: -45,\n                        labelAlign: 'right',\n                        labelBaseline: 'top',\n                    };\n                }\n            } else if (numericLike && labelPx > xStepSize && xLabel.labelAngle === undefined) {\n                // Numeric labels that don't fit horizontally and weren't already\n                // rotated by step-based sizing (which only rotates at narrow\n                // steps). Without this, VL keeps them horizontal and the numbers\n                // overlap. Rotate to -45°.\n                xLabel = {\n                    ...xLabel,\n                    labelAngle: -45,\n                    labelAlign: 'right',\n                    labelBaseline: 'top',\n                };\n            }\n        }\n    }\n    if (yHasDiscreteItems) {\n        const yf = channelSemantics.y?.field;\n        const yt = effectiveTypes.y || channelSemantics.y?.type;\n        if (discreteYAxisShouldUseHorizontalLabels(yf, yt, table)) {\n            yLabel = {\n                ...yLabel,\n                labelAngle: 0,\n                labelAlign: 'right',\n                labelBaseline: 'middle',\n            };\n        }\n    }\n\n    // Keep tick labels consistent across axes. A continuous value axis stays at\n    // the base font, but a banded axis shrinks its labels as bands tighten — so\n    // the value \"numbers\" can end up visibly larger than the category \"text\".\n    // Unify both tick fonts to the smaller of the two so they read as one size.\n    const unifiedTickFont = Math.min(xLabel.fontSize, yLabel.fontSize);\n    if (xLabel.fontSize !== unifiedTickFont) xLabel = { ...xLabel, fontSize: unifiedTickFont };\n    if (yLabel.fontSize !== unifiedTickFont) yLabel = { ...yLabel, fontSize: unifiedTickFont };\n\n    return {\n        subplotWidth,\n        subplotHeight,\n        xStep: xStepSize,\n        yStep: yStepSize,\n        xStepUnit,\n        yStepUnit,\n        xContinuousAsDiscrete,\n        yContinuousAsDiscrete,\n        xNominalCount: xTotalNominalCount,\n        yNominalCount: yTotalNominalCount,\n        xLabel,\n        yLabel,\n        titleFontSize: fontSizing.titleFontSize,\n        legendFontSize: fontSizing.legendFontSize,\n        stepPadding: stepPaddingVal,\n        facet: (facetCols > 1 || facetRows > 1) ? {\n            columns: facetCols,\n            rows: facetRows,\n            subplotWidth,\n            subplotHeight,\n        } : undefined,\n        effectiveFacetGap: gap,\n        truncations: [],  // Overflow truncations are handled by filterOverflow\n    };\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Count distinct series (color/detail categories) from channel semantics.\n */\nfunction countDistinctSeries(\n    channelSemantics: Record<string, ChannelSemantics>,\n    data: any[],\n): number {\n    const seriesFields: string[] = [];\n    const colorField = channelSemantics.color?.field;\n    const detailField = channelSemantics.detail?.field;\n    if (colorField) seriesFields.push(colorField);\n    if (detailField && detailField !== colorField) seriesFields.push(detailField);\n\n    if (seriesFields.length === 0) return 1;\n\n    const seriesKeys = new Set<string>();\n    for (const row of data) {\n        const key = seriesFields.map(f => String(row[f] ?? '')).join('\\x00');\n        seriesKeys.add(key);\n    }\n    return seriesKeys.size;\n}\n\n/**\n * Compute the ideal aspect ratio for a both-continuous chart.\n *\n * Dispatches to two strategies depending on mark type:\n *\n * - **Scatter / point** (`isConnected = false`): Uses the normalized\n *   standard-deviation ratio of the point cloud — a unit-independent\n *   shape measure.  Dampened 0.3× toward 1.0 so scatter stays near\n *   square.\n *\n * - **Connected marks** (line/area/bump, `isConnected = true`): Uses\n *   multi-scale banking to 45° (Heer & Agrawala 2006).  Slopes are\n *   computed at multiple octave-band smoothing levels and combined via\n *   geometric mean so that trend, periodicity, and noise each\n *   contribute proportionally — avoiding the dense-data failure mode\n *   of Cleveland's single-scale median.\n *\n * @param xValues     Numeric X values\n * @param yValues     Numeric Y values (parallel array)\n * @param xDomain     [min, max] of the visual X axis\n * @param yDomain     [min, max] of the visual Y axis\n * @param seriesKeys  Per-point series key ('' if no series)\n * @param isConnected Whether the mark connects points (line/area vs scatter)\n * @returns Ideal AR (width/height). Clamped to [0.5, 3.0].\n */\nfunction computeBankingAR(\n    xValues: number[],\n    yValues: number[],\n    xDomain: [number, number],\n    yDomain: [number, number],\n    seriesKeys: string[],\n    isConnected: boolean,\n): number {\n    const MIN_AR = 0.5;\n    const MAX_AR = 3.0;\n\n    const xRange = xDomain[1] - xDomain[0];\n    const yRange = yDomain[1] - yDomain[0];\n    if (xRange <= 0 || yRange <= 0) return 1;\n\n    // ── Scatter: σ-ratio ──────────────────────────────────────────────\n    if (!isConnected) {\n        const n = xValues.length;\n        let sumX = 0, sumY = 0;\n        for (let i = 0; i < n; i++) {\n            sumX += (xValues[i] - xDomain[0]) / xRange;\n            sumY += (yValues[i] - yDomain[0]) / yRange;\n        }\n        const meanX = sumX / n;\n        const meanY = sumY / n;\n        let varX = 0, varY = 0;\n        for (let i = 0; i < n; i++) {\n            const dx = (xValues[i] - xDomain[0]) / xRange - meanX;\n            const dy = (yValues[i] - yDomain[0]) / yRange - meanY;\n            varX += dx * dx;\n            varY += dy * dy;\n        }\n        const sdX = Math.sqrt(varX / n);\n        const sdY = Math.sqrt(varY / n);\n        if (sdY <= 0) return MAX_AR;\n        if (sdX <= 0) return MIN_AR;\n\n        const sdRatio = sdX / sdY;\n        const ar = sdRatio > 1\n            ? 1 + (sdRatio - 1) * 0.3\n            : 1 - (1 - sdRatio) * 0.3;\n        return Math.min(MAX_AR, Math.max(MIN_AR, ar));\n    }\n\n    // ── Connected marks: multi-scale banking (Heer & Agrawala 2006) ──\n\n    // Group by series and sort by X.\n    const seriesMap = new Map<string, { x: number; y: number }[]>();\n    for (let i = 0; i < xValues.length; i++) {\n        const key = seriesKeys[i];\n        let arr = seriesMap.get(key);\n        if (!arr) { arr = []; seriesMap.set(key, arr); }\n        arr.push({ x: xValues[i], y: yValues[i] });\n    }\n    for (const pts of seriesMap.values()) {\n        pts.sort((a, b) => a.x - b.x);\n    }\n\n    // Collect per-scale median absolute slopes, then combine with\n    // geometric mean across scales.  Each scale is a box-filter\n    // smoothing at window width 2^k (k = 0, 1, 2, …).\n    // Scale 0 = raw data (Cleveland's original).\n    const scaleMedians: number[] = [];\n\n    // Determine max scale: largest power of 2 that still leaves ≥ 3\n    // points in the longest series after smoothing.\n    let maxSeriesLen = 0;\n    for (const pts of seriesMap.values()) {\n        if (pts.length > maxSeriesLen) maxSeriesLen = pts.length;\n    }\n    const maxScale = Math.max(0, Math.floor(Math.log2(maxSeriesLen)) - 1);\n\n    for (let scale = 0; scale <= maxScale; scale++) {\n        const windowSize = 1 << scale;  // 1, 2, 4, 8, …\n        const absSlopes: number[] = [];\n\n        for (const pts of seriesMap.values()) {\n            // Smooth: non-overlapping bucket averages of `windowSize` points.\n            // The last bucket may be smaller — included as-is.\n            const n = pts.length;\n            if (n < 2) continue;\n\n            const smoothed: { x: number; y: number }[] = [];\n            for (let i = 0; i < n; i += windowSize) {\n                const end = Math.min(i + windowSize, n);\n                let sx = 0, sy = 0;\n                for (let j = i; j < end; j++) {\n                    sx += pts[j].x;\n                    sy += pts[j].y;\n                }\n                const cnt = end - i;\n                smoothed.push({ x: sx / cnt, y: sy / cnt });\n            }\n\n            // Compute slopes between consecutive smoothed points.\n            for (let i = 1; i < smoothed.length; i++) {\n                const dx = (smoothed[i].x - smoothed[i - 1].x) / xRange;\n                const dy = (smoothed[i].y - smoothed[i - 1].y) / yRange;\n                if (dx === 0) continue;\n                absSlopes.push(Math.abs(dy / dx));\n            }\n        }\n\n        if (absSlopes.length === 0) continue;\n\n        // Median absolute slope at this scale.\n        absSlopes.sort((a, b) => a - b);\n        const mid = absSlopes.length >> 1;\n        const median = absSlopes.length % 2 === 1\n            ? absSlopes[mid]\n            : (absSlopes[mid - 1] + absSlopes[mid]) / 2;\n        if (median > 0) {\n            scaleMedians.push(median);\n        }\n    }\n\n    if (scaleMedians.length === 0) return 1;\n\n    // Geometric mean of per-scale median slopes.\n    // This gives equal weight to each octave band: trend (coarse),\n    // periodicity (middle), and noise (fine) all contribute.\n    let logSum = 0;\n    for (const m of scaleMedians) {\n        logSum += Math.log(m);\n    }\n    const combinedSlope = Math.exp(logSum / scaleMedians.length);\n\n    if (combinedSlope <= 0) return MAX_AR;\n\n    // Banking to 45°: display_slope = s_norm × (H/W).\n    // For median |display_slope| = 1:  H/W = 1/median(|s_norm|),\n    // so W/H = median(|s_norm|) = combinedSlope.\n    //\n    // No dampening here — the caller (computeLayout) blends banking AR\n    // with gas-pressure AR at 50/50, which already moderates it.\n    // Applying dampening on top of the blend would double-moderate.\n\n    // Landscape floor for connected marks: time series, line charts,\n    // and area charts are conventionally landscape.  Banking can push\n    // wider (when slopes are steep) but never portrait — the gentle-\n    // slope majority in typical time series would otherwise dominate\n    // the median and produce portrait, compressing the time axis.\n    const ar = Math.max(1.0, combinedSlope);\n    return Math.min(MAX_AR, Math.max(MIN_AR, ar));\n}\n\n// ---------------------------------------------------------------------------\n// Public: computeChannelBudgets\n// ---------------------------------------------------------------------------\n\n/**\n * Compute per-channel maximum values that can fit on the canvas.\n *\n * Uses the **most conservative** assumptions:\n *   - minStep  (smallest px per discrete item)\n *   - minSubplotSize (smallest subplot for continuous axes)\n *   - maxStretch (maximum canvas stretching)\n *\n * This is Step 0c-a in the pipeline — it runs before filterOverflow\n * and produces the budgets that filterOverflow consumes.\n *\n * Pipeline:  computeChannelBudgets → filterOverflow → computeLayout\n *\n * @param channelSemantics  Phase 0 output (field, type per channel)\n * @param declaration       Template layout declaration\n * @param data              Full data table (pre-overflow)\n * @param canvasSize        Target canvas dimensions\n * @param options           Assembly options\n * @returns                 ChannelBudgets with per-channel max-to-keep\n */\nexport function computeChannelBudgets(\n    channelSemantics: Record<string, ChannelSemantics>,\n    declaration: LayoutDeclaration,\n    data: any[],\n    canvasSize: { width: number; height: number },\n    options: AssembleOptions,\n): ChannelBudgets {\n    const {\n        minStep: minStepVal = 6,\n        stepPadding: stepPaddingVal = 0.1,\n        maxColorValues: maxColorVal = 24,\n    } = options;\n\n    const { x: maxStretchX, y: maxStretchY } = resolveStretchCaps(options);\n\n    const fixW = options.facetFixedPadding?.width ?? 0;\n    const fixH = options.facetFixedPadding?.height ?? 0;\n    const gap = options.facetGap ?? 0;\n\n    const isDiscreteType = (t: string | undefined) => t === 'nominal' || t === 'ordinal';\n    const effectiveType = (ch: string): string | undefined =>\n        declaration.resolvedTypes?.[ch] ?? channelSemantics[ch]?.type;\n\n    // --- 1. Facet grid (delegates to computeFacetGrid) ---\n    const facetGrid = computeFacetGrid(\n        channelSemantics, declaration, data, canvasSize, options,\n    );\n    const facetCols = facetGrid?.columns ?? 1;\n    const facetRows = facetGrid?.rows ?? 1;\n\n    // --- 2. Per-subplot budget at maximum stretch ---\n    const maxSubplotW = Math.max(\n        options.minSubplotSize ?? 60,\n        (canvasSize.width * maxStretchX - fixW) / facetCols - gap,\n    );\n    const maxSubplotH = Math.max(\n        options.minSubplotSize ?? 60,\n        (canvasSize.height * maxStretchY - fixH) / facetRows - gap,\n    );\n\n    // --- 3. Grouping detection ---\n    const groupField = channelSemantics.group?.field;\n    let groupCount = 0;\n    let groupAxis: 'x' | 'y' | undefined;\n    if (groupField) {\n        groupCount = new Set(data.map(r => r[groupField])).size;\n        if (isDiscreteType(effectiveType('x'))) groupAxis = 'x';\n        else if (isDiscreteType(effectiveType('y'))) groupAxis = 'y';\n    }\n\n    const xGroupMultiplier = (groupAxis === 'x' && groupCount > 1) ? groupCount : 1;\n    const yGroupMultiplier = (groupAxis === 'y' && groupCount > 1) ? groupCount : 1;\n\n    const MIN_GROUP_GAP_PX = 3;\n    const xMinGroupStep = xGroupMultiplier > 1\n        ? Math.max(Math.ceil(MIN_GROUP_GAP_PX / stepPaddingVal), 2 * xGroupMultiplier)\n        : minStepVal;\n    const yMinGroupStep = yGroupMultiplier > 1\n        ? Math.max(Math.ceil(MIN_GROUP_GAP_PX / stepPaddingVal), 2 * yGroupMultiplier)\n        : minStepVal;\n\n    // --- 4. Per-channel budgets ---\n    let maxXToKeep = Math.floor(maxSubplotW / xMinGroupStep);\n    let maxYToKeep = Math.floor(maxSubplotH / yMinGroupStep);\n\n    // --- 5. Faceted-chart canvas cap ---\n    // When a busy discrete axis makes each subplot wider than the\n    // un-stretched canvas, cap axis items to fit within one canvas\n    // width/height.  This lets subplots be narrower, potentially fitting\n    // more facet columns — reducing overall chart height.\n    //\n    // Example: 70 counties on X × 20 states on column.  Without the cap,\n    // minSubplotWidth = 70 × 6 = 420 → only 1 facet column fits → each\n    // state stacks vertically → excessively tall chart.  With the cap,\n    // X is truncated to floor(400/6) = 66 items, and the facet grid is\n    // re-derived with narrower subplots so more columns fit.\n    if (facetGrid) {\n        const canvasXCap = Math.max(1, Math.floor(canvasSize.width / xMinGroupStep));\n        const canvasYCap = Math.max(1, Math.floor(canvasSize.height / yMinGroupStep));\n\n        if (maxXToKeep > canvasXCap || maxYToKeep > canvasYCap) {\n            maxXToKeep = Math.min(maxXToKeep, canvasXCap);\n            maxYToKeep = Math.min(maxYToKeep, canvasYCap);\n\n            // With tighter axis items, subplots can be narrower, so more\n            // facet columns may fit.  Re-derive the grid for column-only\n            // wrapping (the most affected case).\n            const colField = channelSemantics.column?.field;\n            const rowField = channelSemantics.row?.field;\n            const colCount = colField\n                ? new Set(data.map(r => r[colField])).size : 0;\n\n            if (colCount > 1 && !rowField) {\n                const tighterW = Math.max(\n                    options.minSubplotSize ?? 60,\n                    maxXToKeep * xMinGroupStep,\n                );\n                const totalW = canvasSize.width * maxStretchX - fixW;\n                const totalH = canvasSize.height * maxStretchY - fixH;\n                const revisedMaxCols = Math.max(1, Math.floor(\n                    totalW / (tighterW + gap),\n                ));\n                const revisedMaxRows = Math.max(1, Math.floor(\n                    totalH / ((options.minSubplotSize ?? 60) + gap),\n                ));\n                const maxTotal = revisedMaxCols * revisedMaxRows;\n                const effectiveCount = Math.min(colCount, maxTotal);\n                const visRows = Math.ceil(effectiveCount / revisedMaxCols);\n                const visCols = Math.ceil(effectiveCount / visRows);\n\n                facetGrid.columns = visCols;\n                facetGrid.rows = visRows;\n                facetGrid.maxColumnValues = maxTotal;\n            }\n        }\n    }\n\n    // maxColumnValues already carries the correct semantics for both\n    // column+row (per-dimension cap) and column-only wrapping (total\n    // panel count = grid cols × grid rows).  No multiplication needed.\n    const maxValues: Record<string, number> = {\n        x: maxXToKeep,\n        y: maxYToKeep,\n        column: facetGrid?.maxColumnValues ?? Infinity,\n        row: facetGrid?.maxRowValues ?? Infinity,\n        color: maxColorVal,\n    };\n\n    return { maxValues, facetGrid };\n}\n\n// ---------------------------------------------------------------------------\n// Public: computeFacetGrid\n// ---------------------------------------------------------------------------\n\n/**\n * Decide the facet grid layout (including column-only wrapping).\n *\n * This runs BEFORE filterOverflow and computeLayout.  It:\n *   1. Counts unique column/row values from data.\n *   2. Computes banded-aware minimum subplot dimensions.\n *   3. Computes max columns/rows that fit in the canvas budget.\n *   4. For column-only: wraps into a 2D grid (total panels = cols × rows).\n *   5. For column+row: caps each dimension independently.\n *\n * Returns `undefined` when there are no facet channels.\n *\n * @param channelSemantics  Phase 0 output\n * @param declaration       Template layout declaration\n * @param data              Data rows (pre-overflow — possibly after temporal conversion)\n * @param canvasSize        Target canvas dimensions\n * @param options           Assembly options\n */\nexport function computeFacetGrid(\n    channelSemantics: Record<string, ChannelSemantics>,\n    declaration: LayoutDeclaration,\n    data: any[],\n    canvasSize: { width: number; height: number },\n    options: AssembleOptions,\n): import('./types').FacetGridResult | undefined {\n    const { x: msX, y: msY } = resolveStretchCaps(options);\n    const fixW = options.facetFixedPadding?.width ?? 0;\n    const fixH = options.facetFixedPadding?.height ?? 0;\n    const gap = options.facetGap ?? 0;\n    const minStep = options.minStep ?? 6;\n    const stepPadding = options.stepPadding ?? 0.1;\n    const baseMinSubplot = options.minSubplotSize ?? 60;\n\n    const isDiscreteType = (t: string | undefined) => t === 'nominal' || t === 'ordinal';\n\n    // --- Compute min subplot size per axis ---\n    //\n    // Continuous:  baseMinSubplot (e.g. 60px).\n    //\n    // Discrete (not grouped):\n    //   min(minStep × valueCount, maxDim)\n    //\n    // Discrete (grouped):\n    //   perCategoryStep = max(minStep × groupCount, minGroupStep)\n    //   min(perCategoryStep × valueCount, maxDim)\n    //\n    //   where minGroupStep accounts for the inter-group gap:\n    //     the gap = stepPadding × step, which must be ≥ MIN_GROUP_GAP_PX.\n    //\n    // Always capped at maxDim (full stretched canvas minus fixed overhead)\n    // to guarantee at least 1 facet column/row.\n\n    const maxW = canvasSize.width * msX - fixW;\n    const maxH = canvasSize.height * msY - fixH;\n    const MIN_GROUP_GAP_PX = 3;\n\n    // Grouping detection\n    const groupField = channelSemantics.group?.field;\n    let groupCount = 0;\n    let groupAxis: 'x' | 'y' | undefined;\n    if (groupField) {\n        groupCount = new Set(data.map((r: any) => r[groupField])).size;\n        const xType = declaration.resolvedTypes?.x ?? channelSemantics.x?.type;\n        const yType = declaration.resolvedTypes?.y ?? channelSemantics.y?.type;\n        if (isDiscreteType(xType)) groupAxis = 'x';\n        else if (isDiscreteType(yType)) groupAxis = 'y';\n    }\n\n    let minSubplotWidth = baseMinSubplot;\n    let minSubplotHeight = baseMinSubplot;\n\n    // Log-scale axes need more space for minor grid lines to be legible.\n    const LOG_PX_PER_DECADE_FACET = 40;\n    for (const axis of ['x', 'y'] as const) {\n        const cs = channelSemantics[axis];\n        if (!cs?.field || !cs.scaleType) continue;\n        if (cs.scaleType !== 'log' && cs.scaleType !== 'symlog') continue;\n        const vals = data\n            .map((r: any) => r[cs.field])\n            .filter((v: any) => typeof v === 'number' && v > 0 && isFinite(v));\n        if (vals.length < 2) continue;\n        const decades = Math.log10(Math.max(...vals)) - Math.log10(Math.min(...vals));\n        const needed = Math.ceil(Math.max(1, decades)) * LOG_PX_PER_DECADE_FACET;\n        if (axis === 'x') minSubplotWidth = Math.max(minSubplotWidth, needed);\n        else minSubplotHeight = Math.max(minSubplotHeight, needed);\n    }\n\n    for (const axis of ['x', 'y'] as const) {\n        const cs = channelSemantics[axis];\n        if (!cs?.field) continue;\n\n        const effectiveType = declaration.resolvedTypes?.[axis] ?? cs.type;\n        const isBanded = declaration.axisFlags?.[axis]?.banded === true;\n        if (!isDiscreteType(effectiveType) && !isBanded) continue;\n\n        const valueCount = new Set(data.map((r: any) => r[cs.field])).size;\n        const axisGroupCount = (groupAxis === axis && groupCount > 1) ? groupCount : 1;\n        const maxDim = axis === 'x' ? maxW : maxH;\n\n        let perCategoryStep: number;\n        if (axisGroupCount > 1) {\n            // Grouped: each category needs room for groupCount sub-items\n            // PLUS enough inter-group gap (stepPadding × step ≥ MIN_GROUP_GAP_PX).\n            const minGroupStep = Math.max(\n                Math.ceil(MIN_GROUP_GAP_PX / stepPadding),\n                2 * axisGroupCount,\n            );\n            perCategoryStep = Math.max(minStep * axisGroupCount, minGroupStep);\n        } else {\n            // Ungrouped: one item per category\n            perCategoryStep = minStep;\n        }\n\n        const dataDrivenMin = Math.min(perCategoryStep * valueCount, maxDim);\n        const minDim = Math.max(baseMinSubplot, dataDrivenMin);\n\n        if (axis === 'x') {\n            minSubplotWidth = minDim;\n        } else {\n            minSubplotHeight = minDim;\n        }\n    }\n\n    // --- Continuous axes: AR-based min subplot size ---\n    // When both axes are continuous (non-banded), the expected aspect\n    // ratio tells us which axis needs more room.  The shorter dimension\n    // stays at baseMinSubplot; the longer gets up to ms× (maxStretch)\n    // of the base.  This ensures line charts (landscape AR) get wider\n    // min subplots, so maxFacetColumns is lower → fewer, wider panels.\n    const xIsCont = (() => {\n        const cs = channelSemantics.x;\n        if (!cs?.field) return false;\n        const t = declaration.resolvedTypes?.x ?? cs.type;\n        return !isDiscreteType(t) && !(declaration.axisFlags?.x?.banded === true);\n    })();\n    const yIsCont = (() => {\n        const cs = channelSemantics.y;\n        if (!cs?.field) return false;\n        const t = declaration.resolvedTypes?.y ?? cs.type;\n        return !isDiscreteType(t) && !(declaration.axisFlags?.y?.banded === true);\n    })();\n\n    if (xIsCont && yIsCont) {\n        const xCS = channelSemantics.x;\n        const yCS = channelSemantics.y;\n        if (xCS?.field && yCS?.field) {\n            const isTempX = (declaration.resolvedTypes?.x ?? xCS.type) === 'temporal';\n            const isTempY = (declaration.resolvedTypes?.y ?? yCS.type) === 'temporal';\n            const cmcs = options.continuousMarkCrossSection;\n            const isConn = typeof cmcs === 'object' && !!cmcs.seriesCountAxis;\n\n            const xNum: number[] = [];\n            const yNum: number[] = [];\n            const sKeys: string[] = [];\n            const sFields: string[] = [];\n            // Include facet fields in series keys so banking computes\n            // slopes within each panel, not across panel boundaries.\n            const colF = channelSemantics.column?.field;\n            const rowF = channelSemantics.row?.field;\n            if (colF) sFields.push(colF);\n            if (rowF) sFields.push(rowF);\n            const cf = channelSemantics.color?.field;\n            const df = channelSemantics.detail?.field;\n            if (cf) sFields.push(cf);\n            if (df && df !== cf) sFields.push(df);\n\n            for (const row of data) {\n                const xv = row[xCS.field];\n                const yv = row[yCS.field];\n                if (xv == null || yv == null) continue;\n                const xn = isTempX ? +new Date(xv) : +xv;\n                const yn = isTempY ? +new Date(yv) : +yv;\n                if (isNaN(xn) || isNaN(yn)) continue;\n                xNum.push(xn);\n                yNum.push(yn);\n                sKeys.push(sFields.length > 0\n                    ? sFields.map(f => String(row[f] ?? '')).join('\\x00')\n                    : '');\n            }\n\n            if (xNum.length > 1) {\n                const xMin = Math.min(...xNum);\n                const xMax = Math.max(...xNum);\n                const yMin = Math.min(...yNum);\n                const yMax = Math.max(...yNum);\n                const xDom: [number, number] = [xMin, xMax];\n                const yDom: [number, number] = [yMin, yMax];\n                if (xCS.zero?.zero) {\n                    if (xDom[0] > 0) xDom[0] = 0;\n                    if (xDom[1] < 0) xDom[1] = 0;\n                }\n                if (yCS.zero?.zero) {\n                    if (yDom[0] > 0) yDom[0] = 0;\n                    if (yDom[1] < 0) yDom[1] = 0;\n                }\n\n                const ar = computeBankingAR(xNum, yNum, xDom, yDom, sKeys, isConn);\n\n                // Distribute: shorter side = base, longer side = base × min(ar, ms).\n                if (ar >= 1) {\n                    minSubplotWidth = Math.max(minSubplotWidth,\n                        Math.round(baseMinSubplot * Math.min(ar, msX)));\n                    minSubplotHeight = Math.max(minSubplotHeight, baseMinSubplot);\n                } else {\n                    minSubplotWidth = Math.max(minSubplotWidth, baseMinSubplot);\n                    minSubplotHeight = Math.max(minSubplotHeight,\n                        Math.round(baseMinSubplot * Math.min(1 / ar, msY)));\n                }\n            }\n        }\n    }\n\n    // effectiveW = totalBudget - fixedOverhead; each panel costs (subplot + gap).\n    const effectiveW = maxW;\n    const effectiveH = maxH;\n    const maxFacetColumns = Math.max(1, Math.floor(\n        effectiveW / (minSubplotWidth + gap),\n    ));\n    const maxFacetRows = Math.max(1, Math.floor(\n        effectiveH / (minSubplotHeight + gap),\n    ));\n\n    // Identify column/row fields\n    const colField = channelSemantics.column?.field;\n    const rowField = channelSemantics.row?.field;\n    if (!colField && !rowField) return undefined;\n\n    const colCount = colField\n        ? new Set(data.map((r: any) => r[colField])).size : 0;\n    const rowCount = rowField\n        ? new Set(data.map((r: any) => r[rowField])).size : 0;\n\n    if (colCount === 0 && rowCount === 0) return undefined;\n\n    // Explicit user override: force a specific column count for a column-wrapped\n    // facet (the `facetColumns` chart property). Clamped to [1, colCount]; the\n    // remaining panels wrap into as many rows as needed (all kept, canvas grows).\n    const forcedCols = options.facetColumns != null && options.facetColumns >= 1\n        ? Math.min(Math.max(1, Math.floor(options.facetColumns)), Math.max(1, colCount))\n        : undefined;\n\n    if (colCount > 0 && rowCount === 0) {\n        if (forcedCols != null) {\n            const nRows = Math.ceil(colCount / forcedCols);\n            return {\n                columns: forcedCols,\n                rows: nRows,\n                maxColumnValues: forcedCols * nRows,\n                maxRowValues: Math.max(maxFacetRows, nRows),\n            };\n        }\n        // Column-only.  If all panels fit in one row, use a single row.\n        // Otherwise wrap into a balanced grid: pick the number of rows\n        // that makes the grid as square as possible (cols ≈ rows) while\n        // staying within the max budget per dimension.\n        if (colCount <= maxFacetColumns) {\n            return {\n                columns: colCount,\n                rows: 1,\n                maxColumnValues: colCount,\n                maxRowValues: maxFacetRows,\n            };\n        }\n\n        // Need to wrap.  Use maxFacetColumns as the column count\n        // (fill the width), but reduce columns slightly if it would\n        // produce a widow row (a single orphan panel on the last row).\n        let nCols = maxFacetColumns;\n        let nRows = Math.ceil(colCount / nCols);\n\n        // Check for widow: if last row has only 1 panel, try nCols-1\n        // to redistribute more evenly.  Keep reducing while widow\n        // exists and nCols > 2.\n        while (nCols > 2 && (colCount % nCols) === 1) {\n            nCols--;\n            nRows = Math.ceil(colCount / nCols);\n        }\n\n        const visRows = Math.min(nRows, maxFacetRows);\n        const maxTotal = nCols * visRows;\n\n        return {\n            columns: nCols,\n            rows: visRows,\n            maxColumnValues: maxTotal,\n            maxRowValues: maxFacetRows,\n        };\n    }\n\n    // Column+row or row-only: cap each dimension independently.\n    return {\n        columns: Math.max(1, Math.min(colCount, maxFacetColumns)),\n        rows: Math.max(1, Math.min(rowCount, maxFacetRows)),\n        maxColumnValues: maxFacetColumns,\n        maxRowValues: maxFacetRows,\n    };\n}\n\n// ---------------------------------------------------------------------------\n// Public: computeMinSubplotDimensions\n// ---------------------------------------------------------------------------\n\n/**\n * Compute minimum subplot dimensions considering banded and discrete axes.\n *\n * For banded axes (e.g. temporal x on candlestick), each data point needs\n * `minStep` px, so the subplot minimum can be much larger than the generic\n * `minSubplotSize` (60px).  For discrete axes, the count of unique values\n * drives the minimum similarly.\n *\n * This is used by both filterOverflow (pre-layout) and the assemblers\n * (post-layout) to consistently compute facet column/row caps.\n *\n * @param channelSemantics  Phase 0 output (field, type per channel)\n * @param declaration       Template layout declaration (axisFlags, resolvedTypes)\n * @param data              Data rows\n * @param options           Assembly options ({ minStep, minSubplotSize })\n * @returns                 { minSubplotWidth, minSubplotHeight }\n */\nexport function computeMinSubplotDimensions(\n    channelSemantics: Record<string, ChannelSemantics>,\n    declaration: LayoutDeclaration,\n    data: any[],\n    options: { minStep?: number; minSubplotSize?: number },\n): { minSubplotWidth: number; minSubplotHeight: number } {\n    const minStep = options.minStep ?? 6;\n    const minSubplot = options.minSubplotSize ?? 60;\n\n    let minSubplotWidth = minSubplot;\n    let minSubplotHeight = minSubplot;\n\n    // Log-scale axes need more space so minor grid lines stay legible.\n    const LOG_PX_PER_DECADE_MIN = 40;\n    for (const axis of ['x', 'y'] as const) {\n        const cs = channelSemantics[axis];\n        if (!cs?.field || !cs.scaleType) continue;\n        if (cs.scaleType !== 'log' && cs.scaleType !== 'symlog') continue;\n        const vals = data\n            .map((r: any) => r[cs.field])\n            .filter((v: any) => typeof v === 'number' && v > 0 && isFinite(v));\n        if (vals.length < 2) continue;\n        const decades = Math.log10(Math.max(...vals)) - Math.log10(Math.min(...vals));\n        const needed = Math.ceil(Math.max(1, decades)) * LOG_PX_PER_DECADE_MIN;\n        if (axis === 'x') minSubplotWidth = Math.max(minSubplotWidth, needed);\n        else minSubplotHeight = Math.max(minSubplotHeight, needed);\n    }\n\n    const isDiscreteType = (t: string | undefined) =>\n        t === 'nominal' || t === 'ordinal';\n\n    for (const axis of ['x', 'y'] as const) {\n        const cs = channelSemantics[axis];\n        if (!cs?.field) continue;\n\n        const effectiveType = declaration.resolvedTypes?.[axis] ?? cs.type;\n        const isBanded = declaration.axisFlags?.[axis]?.banded === true;\n        const isDiscrete = isDiscreteType(effectiveType);\n\n        let itemCount = 0;\n        if (isBanded || isDiscrete) {\n            itemCount = new Set(data.map((r: any) => r[cs.field])).size;\n        }\n\n        if (itemCount > 0) {\n            const minDim = Math.max(minSubplot, itemCount * minStep);\n            if (axis === 'x') {\n                minSubplotWidth = Math.max(minSubplotWidth, minDim);\n            } else {\n                minSubplotHeight = Math.max(minSubplotHeight, minDim);\n            }\n        }\n    }\n\n    return { minSubplotWidth, minSubplotHeight };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Static Series Normalization\n *\n * Detects array-valued encodings (static series) in the input spec,\n * validates them, and folds (unpivots) the data into long form so\n * the rest of the pipeline can process it as a standard single-field\n * encoding with a color discriminator.\n *\n * This runs BEFORE Phase 0 (resolveChannelSemantics).\n */\n\nimport type { ChartEncoding, EncodingValue, RawEncodingValue, StaticSeriesMetadata } from './types';\nimport type { SemanticAnnotation } from './field-semantics';\nimport { getVisCategory, inferVisCategory } from './semantic-types';\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\n/** Synthetic column names injected by the fold transform */\nexport const STATIC_SERIES_KEY_COLUMN = '__flint_series_key';\nexport const STATIC_SERIES_VALUE_COLUMN = '__flint_series_value';\n\n/** Channels that may accept array-valued (multi-field) encodings */\nconst MEASURE_CHANNELS = new Set(['x', 'y']);\n\n// ---------------------------------------------------------------------------\n// Shorthand normalization\n// ---------------------------------------------------------------------------\n\n/**\n * Expand the bare-string channel shorthand into a full encoding object.\n *\n * `\"weight\"` → `{ field: \"weight\" }`. Array entries (static series) are\n * expanded element-by-element, so `[\"a\", \"b\"]` → `[{ field: \"a\" }, { field: \"b\" }]`.\n * Non-string values pass through unchanged.\n */\nexport function coerceEncodingValue(value: RawEncodingValue): EncodingValue {\n    if (typeof value === 'string') {\n        return { field: value };\n    }\n    if (Array.isArray(value)) {\n        return value.map((entry) => (typeof entry === 'string' ? { field: entry } : entry));\n    }\n    return value;\n}\n\n/** Normalize a raw channel→value map, expanding any bare-string shorthands. */\nexport function normalizeEncodingShorthand(\n    encodings: Record<string, RawEncodingValue>,\n): Record<string, EncodingValue> {\n    const out: Record<string, EncodingValue> = {};\n    for (const [channel, value] of Object.entries(encodings)) {\n        out[channel] = coerceEncodingValue(value);\n    }\n    return out;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Result of normalizing static series from the input spec.\n */\nexport interface NormalizeStaticSeriesResult {\n    /** Normalized encodings (all single-valued) */\n    encodings: Record<string, ChartEncoding>;\n    /** Folded data (or original if no static series detected) */\n    data: any[];\n    /** Static series metadata (present only when fold was applied) */\n    staticSeries?: StaticSeriesMetadata;\n}\n\n/**\n * Detect, validate, and normalize static series (array-valued encodings).\n *\n * If no array-valued encodings are present, returns the input unchanged.\n * If one is found, validates constraints and returns folded data +\n * rewritten encodings.\n *\n * @throws Error if validation fails (non-quantitative field, conflicting\n *         color binding, multiple array channels, etc.)\n */\nexport function normalizeStaticSeries(\n    rawEncodings: Record<string, RawEncodingValue>,\n    data: any[],\n    semanticTypes: Record<string, string | SemanticAnnotation>,\n): NormalizeStaticSeriesResult {\n    // Expand bare-string channel shorthands (e.g. `{ x: \"weight\" }`) first so\n    // the rest of the pipeline only ever sees full encoding objects.\n    const encodings = normalizeEncodingShorthand(rawEncodings);\n\n    // Find array-valued channels\n    const arrayChannels: { channel: string; entries: ChartEncoding[] }[] = [];\n    for (const [channel, enc] of Object.entries(encodings)) {\n        if (Array.isArray(enc)) {\n            arrayChannels.push({ channel, entries: enc });\n        }\n    }\n\n    // No static series — pass through unchanged\n    if (arrayChannels.length === 0) {\n        return {\n            encodings: encodings as Record<string, ChartEncoding>,\n            data,\n        };\n    }\n\n    // --- Validation ---\n\n    // Only one channel may have an array encoding\n    if (arrayChannels.length > 1) {\n        const channelNames = arrayChannels.map(c => c.channel).join(', ');\n        throw new Error(\n            `Static series (array encoding) found on multiple channels: ${channelNames}. ` +\n            `Only one channel may use array encoding at a time.`\n        );\n    }\n\n    const { channel, entries } = arrayChannels[0];\n\n    // Must be a measure channel\n    if (!MEASURE_CHANNELS.has(channel)) {\n        throw new Error(\n            `Static series (array encoding) is only allowed on measure channels (${[...MEASURE_CHANNELS].join(', ')}), ` +\n            `not \"${channel}\".`\n        );\n    }\n\n    // Must have at least 2 entries\n    if (entries.length < 2) {\n        throw new Error(\n            `Static series requires at least 2 fields, got ${entries.length} on channel \"${channel}\".`\n        );\n    }\n\n    // Each entry must specify a field\n    const fields: string[] = [];\n    for (const entry of entries) {\n        if (!entry.field) {\n            throw new Error(\n                `Each static series entry must have a \"field\" property.`\n            );\n        }\n        fields.push(entry.field);\n    }\n\n    // Duplicate field check\n    const fieldSet = new Set(fields);\n    if (fieldSet.size !== fields.length) {\n        throw new Error(\n            `Static series contains duplicate fields. Each field must be unique.`\n        );\n    }\n\n    // Fields must exist in data columns (if data is available)\n    if (data.length > 0) {\n        const dataColumns = new Set(Object.keys(data[0]));\n        for (const field of fields) {\n            if (!dataColumns.has(field)) {\n                throw new Error(\n                    `Static series field \"${field}\" not found in data columns. ` +\n                    `Available columns: ${[...dataColumns].join(', ')}`\n                );\n            }\n        }\n    }\n\n    // Fields must resolve to quantitative (not nominal/ordinal)\n    for (const entry of entries) {\n        const field = entry.field!;\n        const explicitType = entry.type;\n        if (explicitType === 'nominal' || explicitType === 'ordinal') {\n            throw new Error(\n                `Static series field \"${field}\" has type \"${explicitType}\" — ` +\n                `only quantitative or temporal fields are allowed in static series.`\n            );\n        }\n        // Infer if no explicit type\n        if (!explicitType && data.length > 0) {\n            const semType = semanticTypes[field];\n            const semTypeStr = typeof semType === 'string' ? semType : semType?.semanticType || '';\n            // Try semantic type registry first, then infer from data values\n            const fromRegistry = semTypeStr ? getVisCategory(semTypeStr) : null;\n            const inferred = fromRegistry ?? inferVisCategory(data.map(r => r[field]));\n            if (inferred === 'nominal' || inferred === 'ordinal') {\n                throw new Error(\n                    `Static series field \"${field}\" infers as \"${inferred}\" from data — ` +\n                    `only quantitative or temporal fields are allowed in static series.`\n                );\n            }\n        }\n    }\n\n    // Cannot combine with explicit color field binding\n    const colorEnc = encodings.color;\n    if (colorEnc && !Array.isArray(colorEnc) && colorEnc.field) {\n        throw new Error(\n            `Cannot use static series on \"${channel}\" when the color channel is already bound to ` +\n            `field \"${colorEnc.field}\". Static series implicitly uses the color channel for ` +\n            `series discrimination.`\n        );\n    }\n\n    // --- Fold (unpivot) the data ---\n    const foldedData = foldData(data, fields);\n\n    // --- Rewrite encodings ---\n    const normalizedEncodings: Record<string, ChartEncoding> = {};\n    for (const [ch, enc] of Object.entries(encodings)) {\n        if (ch === channel) {\n            // Replace array with single encoding on the synthetic value column\n            normalizedEncodings[ch] = { field: STATIC_SERIES_VALUE_COLUMN, type: 'quantitative' };\n        } else if (Array.isArray(enc)) {\n            // Shouldn't reach here (validated above), but handle gracefully\n            normalizedEncodings[ch] = enc[0];\n        } else {\n            normalizedEncodings[ch] = enc;\n        }\n    }\n\n    // Add color encoding for the synthetic key column (preserving any user-specified scheme)\n    const colorScheme = (!Array.isArray(colorEnc) && colorEnc?.scheme) ? colorEnc.scheme : undefined;\n    normalizedEncodings.color = {\n        field: STATIC_SERIES_KEY_COLUMN,\n        type: 'nominal',\n        ...(colorScheme ? { scheme: colorScheme } : {}),\n    };\n\n    const metadata: StaticSeriesMetadata = {\n        channel,\n        fields,\n        keyColumn: STATIC_SERIES_KEY_COLUMN,\n        valueColumn: STATIC_SERIES_VALUE_COLUMN,\n    };\n\n    return {\n        encodings: normalizedEncodings,\n        data: foldedData,\n        staticSeries: metadata,\n    };\n}\n\n// ---------------------------------------------------------------------------\n// Internal: fold/unpivot\n// ---------------------------------------------------------------------------\n\n/**\n * Unpivot (fold) wide-format data into long form.\n *\n * Each input row produces N output rows (one per field in `fields`).\n * Non-measure columns are preserved. Two synthetic columns are added:\n * - `__flint_series_key`: the field name (series identifier)\n * - `__flint_series_value`: the value from that field\n *\n * Rows where all fold values are null/undefined are skipped.\n */\nfunction foldData(data: any[], fields: string[]): any[] {\n    const fieldSet = new Set(fields);\n    const result: any[] = [];\n\n    for (const row of data) {\n        // Collect non-fold columns\n        const baseRow: Record<string, any> = {};\n        for (const [key, value] of Object.entries(row)) {\n            if (!fieldSet.has(key)) {\n                baseRow[key] = value;\n            }\n        }\n\n        // Create one row per fold field\n        for (const field of fields) {\n            const value = row[field];\n            // Skip null/undefined values to avoid phantom data points\n            if (value == null) continue;\n            result.push({\n                ...baseRow,\n                [STATIC_SERIES_KEY_COLUMN]: field,\n                [STATIC_SERIES_VALUE_COLUMN]: value,\n            });\n        }\n    }\n\n    return result;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * =============================================================================\n * CHART RECOMMENDATION & ADAPTATION ENGINE\n * =============================================================================\n *\n * Backend-agnostic logic for two chart operations:\n *\n *   1. **Adaptation** — remapping encoding channels when switching chart types\n *      (e.g. Bar→Pie: x→color, y→size because the semantic roles differ).\n *\n *   2. **Recommendation** — suggesting which data fields best fit each\n *      encoding channel for a given chart type, using semantic types,\n *      cardinality constraints, and data-fitness tests.\n *\n * Both functions operate on plain field names (string→string maps) with no\n * UI-layer dependencies.  Backend-specific wrappers (vegalite/recommendation.ts\n * etc.) filter results to channels that actually exist in that backend's\n * template registry.\n *\n * =============================================================================\n */\n\nimport {\n    inferVisCategory,\n    getVisCategory,\n    isMeasureType,\n    isTimeSeriesType,\n    isCategoricalType,\n    isOrdinalType,\n    isGeoType,\n    isGeoCoordinateType,\n    isNonMeasureNumeric,\n} from './semantic-types';\n\n// ============================================================================\n// 1. Semantic Role System (used by adaptation)\n// ============================================================================\n\n/**\n * Semantic role of a channel within a specific chart type.\n */\nexport type SemanticRole =\n    | 'category'\n    | 'measure'\n    | 'measure2'\n    | 'series'\n    | 'facetCol'\n    | 'facetRow'\n    | 'auxiliary'\n    | 'geo'\n    | 'price';\n\ntype ChannelRoleMap = Partial<Record<string, SemanticRole>>;\n\n// ── Chart Families ──────────────────────────────────────────────────────\n\n/** Standard x/y charts: x=category, y=measure, color=series */\nconst FAMILY_XY_STANDARD: ChannelRoleMap = {\n    x: 'category', y: 'measure', color: 'series',\n    opacity: 'auxiliary', size: 'auxiliary', shape: 'auxiliary',\n    detail: 'auxiliary', group: 'series',\n    column: 'facetCol', row: 'facetRow',\n};\n\n/** Horizontal x/y charts (Bar Table, etc.): y=category, x=measure. Same channel\n *  names as standard x/y, but axes are swapped — keeping them as x/y means we\n *  inherit shelf/color/facet plumbing for free, while adaptation knows the\n *  category lives on `y` so switching to/from a vertical bar chart auto-swaps. */\nconst FAMILY_XY_HORIZONTAL: ChannelRoleMap = {\n    y: 'category', x: 'measure', color: 'series',\n    opacity: 'auxiliary', size: 'auxiliary', shape: 'auxiliary',\n    detail: 'auxiliary', group: 'series',\n    column: 'facetCol', row: 'facetRow',\n};\n\n/** Pie-like charts: color=category, size=measure */\nconst FAMILY_PIE: ChannelRoleMap = {\n    color: 'category', size: 'measure',\n    column: 'facetCol', row: 'facetRow',\n};\n\n/** Rose chart: polar radial bar — x=category, y=measure, color=series */\nconst FAMILY_ROSE: ChannelRoleMap = {\n    x: 'category', y: 'measure', color: 'series',\n    column: 'facetCol', row: 'facetRow',\n};\n\n/** Radar chart */\nconst FAMILY_RADAR: ChannelRoleMap = {\n    x: 'category', y: 'measure', color: 'series',\n    column: 'facetCol', row: 'facetRow',\n};\n\n/** Map charts: latitude/longitude = geo */\nconst FAMILY_MAP: ChannelRoleMap = {\n    latitude: 'geo', longitude: 'geo',\n    color: 'series', size: 'auxiliary', opacity: 'auxiliary',\n};\n\n/** Choropleth: id=region (geo), color=measure */\nconst FAMILY_CHOROPLETH: ChannelRoleMap = {\n    id: 'geo', color: 'measure', detail: 'auxiliary',\n};\n\n/** Candlestick: x=category, open/high/low/close=price */\nconst FAMILY_CANDLESTICK: ChannelRoleMap = {\n    x: 'category',\n    open: 'price', high: 'price', low: 'price', close: 'price',\n    column: 'facetCol', row: 'facetRow',\n};\n\n/** Histogram: x=measure (binned) */\nconst FAMILY_HISTOGRAM: ChannelRoleMap = {\n    x: 'measure', color: 'series',\n    column: 'facetCol', row: 'facetRow',\n};\n\n/** Density */\nconst FAMILY_DENSITY: ChannelRoleMap = {\n    x: 'measure', color: 'series',\n    column: 'facetCol', row: 'facetRow',\n};\n\n/** 2-D density (Density Contour): both axes are measures, binned into a joint\n *  distribution — no series channel (colour encodes count). */\nconst FAMILY_DENSITY_2D: ChannelRoleMap = {\n    x: 'measure', y: 'measure2',\n    column: 'facetCol', row: 'facetRow',\n};\n\n/** Heatmap: x=category, y=category, color=measure */\nconst FAMILY_HEATMAP: ChannelRoleMap = {\n    x: 'category', y: 'category', color: 'measure',\n    column: 'facetCol', row: 'facetRow',\n};\n\n/** Gauge: size=measure */\nconst FAMILY_GAUGE: ChannelRoleMap = {\n    size: 'measure', column: 'facetCol',\n};\n\n/** Funnel: y=category, size=measure */\nconst FAMILY_FUNNEL: ChannelRoleMap = {\n    y: 'category', size: 'measure',\n};\n\n/** Treemap / Sunburst */\nconst FAMILY_TREEMAP: ChannelRoleMap = {\n    color: 'category', size: 'measure', detail: 'auxiliary', group: 'auxiliary',\n};\n\n/** Sankey */\nconst FAMILY_SANKEY: ChannelRoleMap = {\n    x: 'category', y: 'category', size: 'measure',\n};\n\n/** Gantt: horizontal interval bar — y=task, x=start, x2=end, color=series */\nconst FAMILY_GANTT: ChannelRoleMap = {\n    y: 'category', x: 'measure', x2: 'measure2', color: 'series',\n    detail: 'auxiliary', column: 'facetCol', row: 'facetRow',\n};\n\n/** Bullet: y=label, x=value (measure), goal=target (measure2) */\nconst FAMILY_BULLET: ChannelRoleMap = {\n    y: 'category', x: 'measure', goal: 'measure2', color: 'series',\n    column: 'facetCol', row: 'facetRow',\n};\n\n// ── Chart → Family lookup ───────────────────────────────────────────────\n\nconst CHART_ROLE_MAP: Record<string, ChannelRoleMap> = {\n    // Axis-based (x/y standard)\n    'Bar Chart': FAMILY_XY_STANDARD,\n    'Pyramid Chart': FAMILY_XY_HORIZONTAL,\n    'Grouped Bar Chart': FAMILY_XY_STANDARD,\n    'Stacked Bar Chart': FAMILY_XY_STANDARD,\n    'Lollipop Chart': FAMILY_XY_STANDARD,\n    'Waterfall Chart': FAMILY_XY_STANDARD,\n    'Gantt Chart': FAMILY_GANTT,\n    'Bullet Chart': FAMILY_BULLET,\n    'Bar Table': FAMILY_XY_HORIZONTAL,\n    'Line Chart': FAMILY_XY_STANDARD,\n    'Bump Chart': FAMILY_XY_STANDARD,\n    'Area Chart': FAMILY_XY_STANDARD,\n    'Streamgraph': FAMILY_XY_STANDARD,\n    'Scatter Plot': FAMILY_XY_STANDARD,\n    'Connected Scatter Plot': FAMILY_XY_STANDARD,\n    'Regression': FAMILY_XY_STANDARD,\n    'Ranged Dot Plot': FAMILY_XY_STANDARD,\n    'Boxplot': FAMILY_XY_STANDARD,\n    'Strip Plot': FAMILY_XY_STANDARD,\n    // Pie-like\n    'Pie Chart': FAMILY_PIE,\n    // Polar\n    'Rose Chart': FAMILY_ROSE,\n    'Radar Chart': FAMILY_RADAR,\n    // Heatmap\n    'Heatmap': FAMILY_HEATMAP,\n    // Histogram / Density\n    'Histogram': FAMILY_HISTOGRAM,\n    'Density Plot': FAMILY_DENSITY,\n    'Density Contour': FAMILY_DENSITY_2D,\n    // Geographic\n    'Map': FAMILY_MAP,\n    'Choropleth': FAMILY_CHOROPLETH,\n    // Financial\n    'Candlestick Chart': FAMILY_CANDLESTICK,\n    // ECharts-only\n    'Gauge Chart': FAMILY_GAUGE,\n    'Funnel Chart': FAMILY_FUNNEL,\n    'Treemap': FAMILY_TREEMAP,\n    'Sunburst Chart': FAMILY_TREEMAP,\n    'Sankey Diagram': FAMILY_SANKEY,\n};\n\n// ── Role helpers ────────────────────────────────────────────────────────\n\nfunction getChannelRole(chartType: string, channel: string): SemanticRole {\n    const roleMap = CHART_ROLE_MAP[chartType];\n    if (roleMap && channel in roleMap) return roleMap[channel]!;\n    if (channel === 'column') return 'facetCol';\n    if (channel === 'row') return 'facetRow';\n    return 'auxiliary';\n}\n\nfunction findChannelsByRole(chartType: string, templateChannels: string[], role: SemanticRole): string[] {\n    return templateChannels.filter(ch => getChannelRole(chartType, ch) === role);\n}\n\n/** Fallback chain when target has no channel with the exact source role. */\nconst FALLBACK_CHAIN: Partial<Record<SemanticRole, SemanticRole[]>> = {\n    measure2: ['measure', 'auxiliary'],\n    series: ['auxiliary'],\n    category: ['series', 'auxiliary'],\n    measure: ['auxiliary'],\n    geo: ['category'],\n    price: ['measure', 'auxiliary'],\n};\n\nconst ROLE_PRIORITY: Record<SemanticRole, number> = {\n    category: 0, measure: 1, series: 2, facetCol: 3, facetRow: 4,\n    measure2: 5, auxiliary: 6, geo: 7, price: 8,\n};\n\n// ============================================================================\n// 2. Adaptation — adapt channel encodings across chart types\n// ============================================================================\n\n/**\n * Adapt encoding channels from one chart type to another.\n *\n * When `data` is provided, uses **recommendation-based adaptation**: re-runs\n * the recommendation engine with a strong preference for the currently-assigned\n * fields, letting the target chart's field-type preferences take effect\n * (e.g. Line Chart prefers temporal on x).  Remaining empty channels are\n * optionally filled from all available fields.\n *\n * When no data is provided, falls back to **structural role-based** adaptation\n * (pure channel remapping by semantic role).\n *\n * @param sourceType      The current chart type name (e.g. \"Bar Chart\")\n * @param targetType      The target chart type name (e.g. \"Pie Chart\")\n * @param targetChannels  Available channels on the target template\n * @param encodings       Current channel→fieldName map (only filled channels)\n * @param data            (optional) Array of data row objects\n * @param semanticTypes   (optional) Field→semantic-type map\n * @returns               New channel→fieldName map for the target\n */\nexport function adaptChannels(\n    sourceType: string,\n    targetType: string,\n    targetChannels: string[],\n    encodings: Record<string, string>,\n    data?: any[],\n    semanticTypes?: Record<string, string>,\n    recommendFn?: RecommendFn,\n): Record<string, string> {\n    // Recommendation-based adaptation when data is available\n    if (data && data.length > 0) {\n        return adaptViaRecommendation(sourceType, targetType, targetChannels, encodings, data, semanticTypes ?? {}, recommendFn ?? getRecommendation);\n    }\n\n    // Fallback: structural role-based adaptation\n    return adaptViaRoles(sourceType, targetType, targetChannels, encodings);\n}\n\n/**\n * Edit-distance-based adaptation: find the minimum-cost mapping from existing\n * field→channel assignments to target chart channels.\n *\n * Cost model (see `assignCost` below):\n *   0    — same channel name AND same semantic role\n *   0.5  — different channel name, same semantic role\n *   1    — same channel name but different role, OR different name + role\n *   1.5  — field is dropped\n *   ∞    — field type is incompatible with target channel\n *\n * No autofill: the result contains at most as many fields as the source had.\n * Empty target channels are left for the user to fill explicitly.\n */\nfunction adaptViaRecommendation(\n    sourceType: string,\n    targetType: string,\n    targetChannels: string[],\n    encodings: Record<string, string>,\n    data: any[],\n    semanticTypes: Record<string, string>,\n    _recommendFn: RecommendFn,\n): Record<string, string> {\n    // --- Pre-process: handle facet channels and filter data ---\n    const FACET_CHANNELS = ['column', 'row'];\n    let facetedData = data;\n    const prePinned: Record<string, string> = {};\n    const prePinnedFields = new Set<string>();\n\n    for (const ch of FACET_CHANNELS) {\n        const field = encodings[ch];\n        if (field && targetChannels.includes(ch)) {\n            prePinned[ch] = field;\n            prePinnedFields.add(field);\n            if (facetedData.length > 0) {\n                const firstVal = facetedData[0][field];\n                facetedData = facetedData.filter(row => row[field] === firstVal);\n            }\n        }\n    }\n\n    const tv = buildTableView(facetedData, semanticTypes);\n\n    // --- Type compatibility check ---\n    const isFieldCompatibleWithRole = (role: SemanticRole, field: string): boolean => {\n        const ft = tv.fieldType[field] ?? 'nominal';\n        const st = tv.fieldSemanticType[field] ?? '';\n        const card = tv.fieldLevels[field]?.length ?? 0;\n        switch (role) {\n            // 'category' is for true discrete axes (nominal/ordinal/temporal).\n            // Quantitative fields — even low-cardinality ones — must NOT\n            // satisfy this role, otherwise a measure can land on the\n            // category axis (e.g. Bar Table y) and push the real discrete\n            // field onto color.\n            case 'category':  return !isQuantitativeField(ft, st) && isDiscreteLike(ft, st, card);\n            case 'measure':   return isQuantitativeField(ft, st);\n            case 'series':    return isDiscreteLike(ft, st, card);\n            case 'geo':       return isGeoCoordinateType(st) || ft === 'quantitative';\n            case 'facetCol':  case 'facetRow': return isDiscreteLike(ft, st, card);\n            case 'auxiliary':  return true;\n            default:          return true;\n        }\n    };\n\n    // --- Cost function for assigning field (from srcCh) to targetCh ---\n    //\n    // Role match is the dominant signal: a field whose role matches the target\n    // channel's role is preferred over a field that merely happens to share the\n    // same channel name.  This is important when swapping between strict\n    // \"category × quantitative\" chart types (Bar, Pie, Heatmap, …) where the\n    // semantic axis assignment of the target should win over channel-name\n    // preservation from the source.\n    const assignCost = (srcCh: string, field: string, targetCh: string): number => {\n        const targetRole = getChannelRole(targetType, targetCh);\n        if (!isFieldCompatibleWithRole(targetRole, field)) return Infinity;\n\n        const srcRole = getChannelRole(sourceType, srcCh);\n\n        // Same channel AND same role → free preservation (e.g. Bar→Stacked Bar x→x)\n        if (srcCh === targetCh && srcRole === targetRole) return 0;\n\n        // Same semantic role, different channel name → small cost\n        //   (e.g. Heatmap.color (measure) → Bar.y (measure))\n        if (srcRole === targetRole) return 0.5;\n\n        // Same channel name but different role → role mismatch is more costly\n        //   than a role-match move; prevents e.g. src.color (series) clobbering\n        //   tgt.color (category) in Pie.\n        if (srcCh === targetCh) return 1;\n\n        // Different role and different name, type-compatible → highest move cost\n        return 1;\n    };\n\n    const COST_DROP = 1.5;  // slightly above move cost to prefer keeping fields\n\n    // --- Collect source entries (excluding pre-pinned facets) ---\n    const entries = Object.entries(encodings)\n        .filter(([ch, f]) => f && !FACET_CHANNELS.includes(ch) && !prePinnedFields.has(f));\n\n    // Available target channels (exclude pre-pinned ones)\n    const availableTargets = targetChannels.filter(ch => !(ch in prePinned));\n\n    // --- Solve minimum-cost assignment via branch-and-bound ---\n    // With typically ≤5 fields and ≤8 channels, this is instant.\n    let bestCost = Infinity;\n    let bestAssignment: Record<string, string> = {};\n\n    const usedTargets = new Set<string>();\n\n    function solve(\n        idx: number,\n        currentCost: number,\n        assignment: Record<string, string>,\n    ): void {\n        if (currentCost >= bestCost) return;  // prune\n\n        if (idx === entries.length) {\n            bestCost = currentCost;\n            bestAssignment = { ...assignment };\n            return;\n        }\n\n        const [srcCh, field] = entries[idx];\n\n        // Option A: assign to each available target channel\n        for (const tch of availableTargets) {\n            if (usedTargets.has(tch)) continue;\n            const cost = assignCost(srcCh, field, tch);\n            if (cost === Infinity) continue;\n\n            usedTargets.add(tch);\n            assignment[tch] = field;\n            solve(idx + 1, currentCost + cost, assignment);\n            delete assignment[tch];\n            usedTargets.delete(tch);\n        }\n\n        // Option B: drop the field\n        solve(idx + 1, currentCost + COST_DROP, assignment);\n    }\n\n    solve(0, 0, {});\n\n    // --- Merge pre-pinned facets + solver result ---\n    //\n    // Intentionally do NOT auto-fill remaining empty target channels via the\n    // recommendation engine: when the user already configured a chart with N\n    // fields and switches type, the adapted chart should also have at most N\n    // fields.  Adding extra fields the user never picked is surprising (e.g.\n    // a 2-encoding Bar Chart turning into a 5-encoding Scatter Plot on type\n    // switch).  Empty channels are left for the user to fill explicitly.\n    const result: Record<string, string> = { ...prePinned, ...bestAssignment };\n\n    return result;\n}\n\n/**\n * Structural role-based adaptation: remap channels by semantic role when no\n * data is available.  Each field keeps its role (category, measure, series…)\n * and is placed into the target channel that has the same role.\n */\nfunction adaptViaRoles(\n    sourceType: string,\n    targetType: string,\n    targetChannels: string[],\n    encodings: Record<string, string>,\n): Record<string, string> {\n    const result: Record<string, string> = {};\n\n    // Collect filled encodings with their semantic roles\n    const filledEncodings: { channel: string; role: SemanticRole; field: string }[] = [];\n    for (const [ch, field] of Object.entries(encodings)) {\n        if (field) {\n            filledEncodings.push({ channel: ch, role: getChannelRole(sourceType, ch), field });\n        }\n    }\n\n    // Sort by priority: category > measure > series > …\n    filledEncodings.sort((a, b) => ROLE_PRIORITY[a.role] - ROLE_PRIORITY[b.role]);\n\n    const assigned = new Set<string>();\n\n    for (const { channel: srcCh, role: srcRole, field } of filledEncodings) {\n        let placed = false;\n\n        // (a) Direct match: same channel name with same role\n        if (targetChannels.includes(srcCh) && !assigned.has(srcCh)) {\n            if (getChannelRole(targetType, srcCh) === srcRole) {\n                result[srcCh] = field;\n                assigned.add(srcCh);\n                placed = true;\n            }\n        }\n\n        if (!placed) {\n            // (b) Role match: find empty target channel with same role\n            placed = tryAssign(srcRole, field, targetType, targetChannels, result, assigned, srcCh);\n        }\n\n        if (!placed) {\n            // (c) Fallback chain\n            const chain = FALLBACK_CHAIN[srcRole];\n            if (chain) {\n                for (const fallbackRole of chain) {\n                    placed = tryAssign(fallbackRole, field, targetType, targetChannels, result, assigned, srcCh);\n                    if (placed) break;\n                }\n            }\n        }\n        // (d) If not placed, encoding is dropped\n    }\n\n    return result;\n}\n\nfunction tryAssign(\n    role: SemanticRole,\n    field: string,\n    targetType: string,\n    targetChannels: string[],\n    result: Record<string, string>,\n    assigned: Set<string>,\n    preferredName?: string,\n): boolean {\n    const candidates = findChannelsByRole(targetType, targetChannels, role)\n        .filter(ch => !assigned.has(ch));\n    if (candidates.length === 0) return false;\n    const best = preferredName && candidates.includes(preferredName)\n        ? preferredName : candidates[0];\n    result[best] = field;\n    assigned.add(best);\n    return true;\n}\n\n// ============================================================================\n// 3. Internal Table View — field classification from data + semantic types\n// ============================================================================\n\nexport interface InternalTableView {\n    names: string[];\n    fieldType: Record<string, string>;\n    fieldSemanticType: Record<string, string>;\n    fieldLevels: Record<string, any[]>;\n    rows: any[];\n    /** Fields the user has already assigned — preferred during pick(). */\n    preferredFields?: Set<string>;\n}\n\n/**\n * Recommendation function signature — used to inject backend-specific\n * chart type handlers into adaptViaRecommendation.\n */\nexport type RecommendFn = (chartType: string, tv: InternalTableView) => Record<string, string>;\n\nexport function buildTableView(data: any[], semanticTypes: Record<string, string>): InternalTableView {\n    const names = data.length > 0 ? Object.keys(data[0]) : [];\n    const fieldType: Record<string, string> = {};\n    const fieldSemanticType: Record<string, string> = {};\n    const fieldLevels: Record<string, any[]> = {};\n\n    for (const name of names) {\n        const values = data.map(r => r[name]);\n        const semanticType = semanticTypes[name] || '';\n        fieldType[name] = (semanticType && getVisCategory(semanticType)) || inferVisCategory(values);\n        fieldSemanticType[name] = semanticType;\n        fieldLevels[name] = [...new Set(data.map(r => r[name]).filter(v => v != null))];\n    }\n\n    return { names, fieldType, fieldSemanticType, fieldLevels, rows: data };\n}\n\n// ============================================================================\n// 4. Preference-Based Assignment Solver\n// ============================================================================\n\n/** Preference tiers for a (channel, field) pair. */\nexport const Pref = { STRONG: 3, OK: 2, WEAK: 1, EXCLUDE: -Infinity } as const;\nexport type PrefScore = number;\n\n/**\n * A scoring function that returns a preference score for a field being\n * assigned to a particular channel.  Return Pref.EXCLUDE to forbid the\n * assignment.\n */\nexport type ChannelPrefFn = (\n    name: string, type: string, semanticType: string,\n    cardinality: number, hasLevels: boolean,\n) => PrefScore;\n\n/**\n * Solve the assignment problem: given N channels each with a preference\n * scoring function, and a set of candidate fields, find the assignment of\n * distinct fields to channels that maximises total score.\n *\n * Returns the best assignment as a Record<channel, fieldName>, or {} if\n * no valid (all-channels-filled) assignment exists.\n *\n * Complexity: O(C! · F^C) where C = number of channels, F = number of\n * fields.  Fine for C ≤ 5 and typical field counts.\n */\nexport function resolveAssignment(\n    tv: InternalTableView,\n    used: Set<string>,\n    channelPrefs: { channel: string; pref: ChannelPrefFn }[],\n): Record<string, string> {\n    // Build the score matrix: scores[channelIdx][fieldIdx]\n    const candidates: string[] = tv.names.filter(n => !used.has(n) && (!isLikelyIdentifierOrRank(n) || tv.preferredFields?.has(n)));\n    const C = channelPrefs.length;\n    const F = candidates.length;\n    if (F < C) return {};\n\n    // Pre-compute all scores\n    const scores: number[][] = [];\n    for (let ci = 0; ci < C; ci++) {\n        scores[ci] = [];\n        for (let fi = 0; fi < F; fi++) {\n            const name = candidates[fi];\n            const type = tv.fieldType[name] ?? 'nominal';\n            const st = tv.fieldSemanticType[name] ?? '';\n            const card = tv.fieldLevels[name]?.length ?? 0;\n            scores[ci][fi] = channelPrefs[ci].pref(name, type, st, card, card > 0);\n        }\n    }\n\n    // Brute-force search over all C-permutations of F fields\n    let bestScore = -Infinity;\n    let bestAssign: number[] | undefined;\n\n    const perm = new Array<number>(C);\n    const usedF = new Uint8Array(F);\n\n    function search(depth: number, totalScore: number) {\n        if (depth === C) {\n            if (totalScore > bestScore) {\n                bestScore = totalScore;\n                bestAssign = [...perm];\n            }\n            return;\n        }\n        for (let fi = 0; fi < F; fi++) {\n            if (usedF[fi]) continue;\n            const s = scores[depth][fi];\n            if (s === -Infinity) continue;            // excluded\n            if (totalScore + s <= bestScore - (C - depth - 1) * Pref.STRONG) continue; // prune\n            perm[depth] = fi;\n            usedF[fi] = 1;\n            search(depth + 1, totalScore + s);\n            usedF[fi] = 0;\n        }\n    }\n\n    search(0, 0);\n\n    if (!bestAssign) return {};\n\n    const result: Record<string, string> = {};\n    for (let ci = 0; ci < C; ci++) {\n        const fieldName = candidates[bestAssign[ci]];\n        result[channelPrefs[ci].channel] = fieldName;\n        used.add(fieldName);\n    }\n    return result;\n}\n\n// ============================================================================\n// 5. Field Classification Utilities (renumbered)\n// ============================================================================\n\nfunction isTemporalField(type: string, semanticType: string): boolean {\n    return type === 'temporal' || isTimeSeriesType(semanticType);\n}\n\nfunction isQuantitativeField(type: string, semanticType: string): boolean {\n    if (isTemporalField(type, semanticType)) return false;\n    if (type !== 'quantitative') return false;\n    if (isNonMeasureNumeric(semanticType)) return false;\n    return isMeasureType(semanticType) || semanticType === '';\n}\n\nfunction isOrdinalField(type: string, semanticType: string, hasLevels: boolean): boolean {\n    if (hasLevels) return true;\n    return isOrdinalType(semanticType);\n}\n\nfunction isCategoricalFieldCheck(type: string, semanticType: string): boolean {\n    if (isTemporalField(type, semanticType)) return false;\n    if (isQuantitativeField(type, semanticType)) return false;\n    return type === 'nominal' || isCategoricalType(semanticType);\n}\n\nfunction isDiscreteLike(type: string, semanticType: string, cardinality: number, maxCard = 50): boolean {\n    if (isCategoricalFieldCheck(type, semanticType)) return true;\n    if (isTemporalField(type, semanticType)) return true;\n    if (isOrdinalType(semanticType)) return true;\n    if (type === 'quantitative' && cardinality > 0 && cardinality <= maxCard) return true;\n    return false;\n}\n\nexport function nameMatches(name: string, patterns: string[]): boolean {\n    const lower = name.toLowerCase();\n    return patterns.some(p => lower === p) || patterns.some(p => lower.includes(p));\n}\n\nfunction isLikelyIdentifierOrRank(name: string): boolean {\n    const lower = name.toLowerCase();\n    const idPatterns = ['rank', 'id', 'index', 'idx', 'row', 'order', 'position', 'pos'];\n    return idPatterns.some(p => lower === p || lower.endsWith('_' + p) || lower.endsWith(p));\n}\n\n// ============================================================================\n// 6. Field Picker Utilities\n// ============================================================================\n\nexport function pick(\n    tv: InternalTableView,\n    used: Set<string>,\n    predicate: (name: string, type: string, semanticType: string, cardinality: number, hasLevels: boolean) => boolean,\n): string | undefined {\n    const candidates: string[] = [];\n    for (const name of tv.names) {\n        if (used.has(name)) continue;\n        const type = tv.fieldType[name] ?? 'nominal';\n        const semanticType = tv.fieldSemanticType[name] ?? '';\n        const cardinality = tv.fieldLevels[name]?.length ?? 0;\n        const hasLevels = cardinality > 0;\n        if (predicate(name, type, semanticType, cardinality, hasLevels)) {\n            candidates.push(name);\n        }\n    }\n    if (candidates.length === 0) return undefined;\n    // Deterministic selection: prefer a field the user already uses, otherwise\n    // the first candidate in table order. Stable, so a given dataset always\n    // yields the same suggestion (no random tie-break).\n    if (tv.preferredFields) {\n        const preferred = candidates.filter(n => tv.preferredFields!.has(n));\n        if (preferred.length > 0) {\n            const chosen = preferred[0];\n            used.add(chosen);\n            return chosen;\n        }\n    }\n    const chosen = candidates[0];\n    used.add(chosen);\n    return chosen;\n}\n\nexport const pickQuantitative = (tv: InternalTableView, u: Set<string>) =>\n    pick(tv, u, (name, ty, st) => isQuantitativeField(ty, st) && (!isLikelyIdentifierOrRank(name) || !!tv.preferredFields?.has(name)));\n\nexport const pickTemporal = (tv: InternalTableView, u: Set<string>) =>\n    pick(tv, u, (_n, ty, st) => isTemporalField(ty, st));\n\nexport const pickNominal = (tv: InternalTableView, u: Set<string>) =>\n    pick(tv, u, (_n, ty, st) => isCategoricalFieldCheck(ty, st));\n\nexport const pickLowCardNominal = (tv: InternalTableView, u: Set<string>, maxCard = 30) =>\n    pick(tv, u, (_n, ty, st, card) => isCategoricalFieldCheck(ty, st) && card > 0 && card <= maxCard);\n\nexport const pickOrdinal = (tv: InternalTableView, u: Set<string>) =>\n    pick(tv, u, (_n, ty, st, _card, hasLevels) => isOrdinalField(ty, st, hasLevels));\n\nexport const pickGeo = (tv: InternalTableView, u: Set<string>) =>\n    pick(tv, u, (_n, _ty, st) => isGeoType(st));\n\nexport const pickDiscrete = (tv: InternalTableView, u: Set<string>) =>\n    pick(tv, u, (name, ty, st, card) => isDiscreteLike(ty, st, card) && (!isLikelyIdentifierOrRank(name) || !!tv.preferredFields?.has(name)));\n\nexport const pickLowCardDiscrete = (tv: InternalTableView, u: Set<string>, maxCard = 30) =>\n    pick(tv, u, (name, ty, st, card) =>\n        isDiscreteLike(ty, st, card, maxCard) && card > 0 && card <= maxCard\n        && (!isLikelyIdentifierOrRank(name) || !!tv.preferredFields?.has(name))\n    );\n\nexport const pickSeriesAxis = (tv: InternalTableView, u: Set<string>) =>\n    pickTemporal(tv, u) ?? pickOrdinal(tv, u) ?? pickNominal(tv, u);\n\nexport const pickQuantitativeByName = (tv: InternalTableView, u: Set<string>, patterns: string[]) =>\n    pick(tv, u, (name, ty, st) => isQuantitativeField(ty, st) && nameMatches(name, patterns));\n\nexport function pickAllQuantitative(tv: InternalTableView, used: Set<string>): string[] {\n    const result: string[] = [];\n    for (const name of tv.names) {\n        if (used.has(name)) continue;\n        const type = tv.fieldType[name] ?? 'nominal';\n        const semanticType = tv.fieldSemanticType[name] ?? '';\n        if (isQuantitativeField(type, semanticType) && (!isLikelyIdentifierOrRank(name) || tv.preferredFields?.has(name))) {\n            result.push(name);\n        }\n    }\n    for (const name of result) used.add(name);\n    return result;\n}\n\n// ============================================================================\n// 7. Data Fitness Tests\n// ============================================================================\n\nexport function hasMultipleValuesPerField(tv: InternalTableView, fieldName: string): boolean {\n    if (!fieldName || !tv.rows || tv.rows.length === 0) return false;\n    const seen = new Set<any>();\n    for (const row of tv.rows) {\n        const val = row[fieldName];\n        if (seen.has(val)) return true;\n        seen.add(val);\n    }\n    return false;\n}\n\nfunction isValidGroupingField(tv: InternalTableView, xField: string, colorField: string): boolean {\n    if (!xField || !colorField || !tv.rows || tv.rows.length === 0) return false;\n    const seen = new Set<string>();\n    for (const row of tv.rows) {\n        const key = `${row[xField]}|||${row[colorField]}`;\n        if (seen.has(key)) return false;\n        seen.add(key);\n    }\n    return true;\n}\n\n/**\n * Deterministic grouping/series selection: choose the lowest-cardinality\n * candidate (fewest distinct values → the most readable legend), breaking ties\n * by table order. Replaces an earlier random tie-break so recommendations are\n * stable and prefer compact color/series encodings.\n */\nfunction lowestCardinality(tv: InternalTableView, candidates: string[]): string {\n    let best = candidates[0];\n    let bestCard = tv.fieldLevels[best]?.length ?? Infinity;\n    for (let i = 1; i < candidates.length; i++) {\n        const card = tv.fieldLevels[candidates[i]]?.length ?? Infinity;\n        if (card < bestCard) { best = candidates[i]; bestCard = card; }\n    }\n    return best;\n}\n\nexport function pickValidGroupingField(\n    tv: InternalTableView, used: Set<string>, xField: string, maxCard = 20,\n): string | undefined {\n    const candidates: string[] = [];\n    for (const name of tv.names) {\n        if (used.has(name)) continue;\n        const type = tv.fieldType[name] ?? 'nominal';\n        const semanticType = tv.fieldSemanticType[name] ?? '';\n        const cardinality = tv.fieldLevels[name]?.length ?? 0;\n        if (!isDiscreteLike(type, semanticType, cardinality, maxCard)) continue;\n        if (cardinality <= 0 || cardinality > maxCard) continue;\n        if (isLikelyIdentifierOrRank(name) && !tv.preferredFields?.has(name)) continue;\n        if (isValidGroupingField(tv, xField, name)) candidates.push(name);\n    }\n    if (candidates.length === 0) return undefined;\n    // Prefer a field the user already uses; otherwise the lowest-cardinality\n    // valid grouping field (fewest colors). Deterministic — no random pick.\n    if (tv.preferredFields) {\n        const preferred = candidates.filter(n => tv.preferredFields!.has(n));\n        if (preferred.length > 0) {\n            const chosen = lowestCardinality(tv, preferred);\n            used.add(chosen);\n            return chosen;\n        }\n    }\n    const chosen = lowestCardinality(tv, candidates);\n    used.add(chosen);\n    return chosen;\n}\n\nexport function isValidLineSeriesData(tv: InternalTableView, xField: string, colorField?: string): boolean {\n    if (!tv.rows || tv.rows.length === 0) return false;\n    const xColorCombinations = new Set<string>();\n    const colorGroupCounts = new Map<string, number>();\n\n    for (const row of tv.rows) {\n        const xVal = row[xField];\n        const colorVal = colorField ? row[colorField] : '__single__';\n        const xColorKey = `${xVal}|||${colorVal}`;\n        if (xColorCombinations.has(xColorKey)) return false;\n        xColorCombinations.add(xColorKey);\n        colorGroupCounts.set(colorVal, (colorGroupCounts.get(colorVal) ?? 0) + 1);\n    }\n\n    let validGroups = 0;\n    let totalGroups = 0;\n    for (const count of colorGroupCounts.values()) {\n        totalGroups++;\n        if (count >= 2) validGroups++;\n    }\n    return totalGroups > 0 && (validGroups / totalGroups) > 0.5;\n}\n\nexport function pickLineChartColorField(\n    tv: InternalTableView, used: Set<string>, xField: string, maxCard = 20,\n): string | undefined {\n    const candidates: string[] = [];\n    for (const name of tv.names) {\n        if (used.has(name)) continue;\n        const type = tv.fieldType[name] ?? 'nominal';\n        const semanticType = tv.fieldSemanticType[name] ?? '';\n        const cardinality = tv.fieldLevels[name]?.length ?? 0;\n        if (!isDiscreteLike(type, semanticType, cardinality, maxCard)) continue;\n        if (cardinality <= 0 || cardinality > maxCard) continue;\n        if (isLikelyIdentifierOrRank(name) && !tv.preferredFields?.has(name)) continue;\n        if (isValidLineSeriesData(tv, xField, name)) candidates.push(name);\n    }\n    if (candidates.length === 0) return undefined;\n    // Prefer a field the user already uses; otherwise the lowest-cardinality\n    // valid series field (fewest lines/colors). Deterministic — no random pick.\n    if (tv.preferredFields) {\n        const preferred = candidates.filter(n => tv.preferredFields!.has(n));\n        if (preferred.length > 0) {\n            const chosen = lowestCardinality(tv, preferred);\n            used.add(chosen);\n            return chosen;\n        }\n    }\n    const chosen = lowestCardinality(tv, candidates);\n    used.add(chosen);\n    return chosen;\n}\n\nfunction calculateMultiplicity(tv: InternalTableView, xField: string, colorField?: string): number {\n    if (!tv.rows || tv.rows.length === 0) return 1;\n    const groups = new Set<string>();\n    for (const row of tv.rows) {\n        const key = colorField ? `${row[xField]}|||${row[colorField]}` : `${row[xField]}`;\n        groups.add(key);\n    }\n    return tv.rows.length / groups.size;\n}\n\nexport function pickBestGroupingField(\n    tv: InternalTableView, used: Set<string>, xField: string, maxMultiplicity = 5,\n): string | undefined {\n    const baseMultiplicity = calculateMultiplicity(tv, xField);\n    if (baseMultiplicity <= 1.0) return undefined;\n\n    let bestField: string | undefined;\n    let bestMultiplicity = baseMultiplicity;\n\n    for (const name of tv.names) {\n        if (used.has(name)) continue;\n        const type = tv.fieldType[name] ?? 'nominal';\n        const semanticType = tv.fieldSemanticType[name] ?? '';\n        const cardinality = tv.fieldLevels[name]?.length ?? 0;\n        if (!isDiscreteLike(type, semanticType, cardinality)) continue;\n        if (isLikelyIdentifierOrRank(name) && !tv.preferredFields?.has(name)) continue;\n\n        const multiplicity = calculateMultiplicity(tv, xField, name);\n        if (multiplicity < bestMultiplicity) {\n            bestMultiplicity = multiplicity;\n            bestField = name;\n            if (multiplicity <= 1.0) break;\n        }\n    }\n\n    if (bestField && bestMultiplicity < baseMultiplicity && bestMultiplicity <= maxMultiplicity) {\n        used.add(bestField);\n        return bestField;\n    }\n    return undefined;\n}\n\n// ============================================================================\n// 8. Per-Chart-Type Recommendation Heuristics\n// ============================================================================\n\n/**\n * Recommend channel→fieldName assignments for a given chart type.\n *\n * Pure logic: takes raw data rows + semantic type annotations, returns\n * a channel→fieldName map.  Backend wrappers filter to valid channels.\n *\n * @param chartType      Chart template name (e.g. \"Bar Chart\")\n * @param data           Array of row objects\n * @param semanticTypes  Field→semantic-type map (e.g. { weight: \"Quantity\" })\n * @returns              channel→fieldName map\n */\nexport function recommendChannels(\n    chartType: string,\n    data: any[],\n    semanticTypes: Record<string, string>,\n    recommendFn?: RecommendFn,\n): Record<string, string> {\n    const fn = recommendFn ?? getRecommendation;\n    return fn(chartType, buildTableView(data, semanticTypes));\n}\n\n/**\n * Core recommendation engine — handles chart types shared across 2+ backends.\n * Backend-specific chart types should be handled in their own recommendation files\n * by extending this function.\n *\n * Exported so that backend wrappers can call it as a fallback in their own\n * extended `getRecommendation` implementations.\n */\nexport function getRecommendation(chartType: string, tv: InternalTableView): Record<string, string> {\n    const used = new Set<string>();\n    const rec: Record<string, string> = {};\n\n    const assign = (channel: string, fieldName: string | undefined) => {\n        if (fieldName) rec[channel] = fieldName;\n    };\n\n    switch (chartType) {\n        case 'Scatter Plot': {\n            const yField = pickQuantitative(tv, used) ?? pickTemporal(tv, used) ?? pickNominal(tv, used);\n            const xField = pickQuantitative(tv, used) ?? pickTemporal(tv, used) ?? pickNominal(tv, used);\n            if (!xField || !yField) return {};\n            assign('x', xField);\n            assign('y', yField);\n            assign('color', pickLowCardNominal(tv, used));\n            break;\n        }\n\n        case 'Bar Chart':\n        case 'Stacked Bar Chart': {\n            const xField = pickDiscrete(tv, used);\n            const yField = pickQuantitative(tv, used);\n            if (!xField || !yField) return {};\n            assign('x', xField);\n            assign('y', yField);\n            if (hasMultipleValuesPerField(tv, xField)) {\n                assign('color', pickBestGroupingField(tv, used, xField));\n            }\n            break;\n        }\n\n        case 'Grouped Bar Chart': {\n            const xField = pickDiscrete(tv, used);\n            const yField = pickQuantitative(tv, used);\n            if (!xField || !yField) return {};\n            const seriesField = pickValidGroupingField(tv, used, xField, 20);\n            if (!seriesField) return {};\n            assign('x', xField);\n            assign('y', yField);\n            // A grouped bar dodges by the `group` channel (not `color`) across\n            // all three backends — assigning `color` here would be dropped by\n            // the Vega-Lite template, leaving an ungrouped bar.\n            assign('group', seriesField);\n            break;\n        }\n\n        case 'Histogram': {\n            const xField = pickQuantitative(tv, used);\n            if (!xField) return {};\n            assign('x', xField);\n            break;\n        }\n\n        case 'Heatmap': {\n            // Semantic-first preference scoring.\n            // 1. Semantic type determines preference (temporal, categorical, measure)\n            // 2. Data type (ty) is a safeguard for compatibility\n            const heatmapResult = resolveAssignment(tv, used, [\n                {\n                    channel: 'x',\n                    pref: (_n, ty, st, card) => {\n                        // Semantic preference\n                        if (isTimeSeriesType(st))                         return Pref.STRONG;\n                        if (isCategoricalType(st))                        return Pref.OK;\n                        if (isOrdinalType(st))                            return Pref.OK;\n                        if (isNonMeasureNumeric(st))                      return Pref.OK;\n                        // Data type safeguard: allow nominal or low-card continuous\n                        if (ty === 'nominal')                             return Pref.OK;\n                        if (ty === 'temporal')                            return Pref.STRONG;\n                        if (ty === 'quantitative' && card > 0 && card <= 50) return Pref.WEAK;\n                        return Pref.EXCLUDE;\n                    },\n                },\n                {\n                    channel: 'y',\n                    pref: (_n, ty, st, card) => {\n                        // Semantic preference\n                        if (isCategoricalType(st))                        return Pref.STRONG;\n                        if (isTimeSeriesType(st))                         return Pref.OK;\n                        if (isOrdinalType(st))                            return Pref.OK;\n                        if (isNonMeasureNumeric(st))                      return Pref.OK;\n                        // Data type safeguard\n                        if (ty === 'nominal')                             return Pref.STRONG;\n                        if (ty === 'temporal')                            return Pref.OK;\n                        if (ty === 'quantitative' && card > 0 && card <= 50) return Pref.WEAK;\n                        return Pref.EXCLUDE;\n                    },\n                },\n                {\n                    channel: 'color',\n                    pref: (_n, ty, st) => {\n                        // Semantic preference: measures are ideal for heatmap color\n                        if (isMeasureType(st))                            return Pref.STRONG;\n                        if (isOrdinalType(st))                            return Pref.OK;\n                        // Data type safeguard: quantitative with no semantic type\n                        if (ty === 'quantitative' && !st)                 return Pref.STRONG;\n                        if (ty === 'temporal')                            return Pref.WEAK;\n                        if (ty === 'nominal')                             return Pref.WEAK;\n                        return Pref.EXCLUDE;\n                    },\n                },\n            ]);\n            if (!heatmapResult['x'] || !heatmapResult['y'] || !heatmapResult['color']) return {};\n            assign('x', heatmapResult['x']);\n            assign('y', heatmapResult['y']);\n            assign('color', heatmapResult['color']);\n            break;\n        }\n\n        case 'Line Chart': {\n            const xField = pickSeriesAxis(tv, used);\n            const yField = pickQuantitative(tv, used);\n            if (!xField || !yField) return {};\n            assign('x', xField);\n            assign('y', yField);\n            if (!isValidLineSeriesData(tv, xField, undefined)) {\n                const colorField = pickLineChartColorField(tv, used, xField, 20)\n                    ?? pickLineChartColorField(tv, used, xField, 200);\n                if (!colorField) return {};\n                assign('color', colorField);\n            }\n            break;\n        }\n\n        case 'Boxplot': {\n            const xField = pickDiscrete(tv, used);\n            const yField = pickQuantitative(tv, used);\n            if (!xField || !yField) return {};\n            assign('x', xField);\n            assign('y', yField);\n            break;\n        }\n\n        case 'Pie Chart': {\n            const sizeField = pickQuantitative(tv, used);\n            const colorField = pickLowCardDiscrete(tv, used, 12);\n            if (!sizeField || !colorField) return {};\n            assign('size', sizeField);\n            assign('color', colorField);\n            break;\n        }\n\n        case 'Area Chart': {\n            const xField = pickSeriesAxis(tv, used);\n            const yField = pickQuantitative(tv, used);\n            if (!xField || !yField) return {};\n            assign('x', xField);\n            assign('y', yField);\n            assign('color', pickLineChartColorField(tv, used, xField, 20));\n            break;\n        }\n\n        case 'Streamgraph': {\n            // Semantic-first preference scoring.\n            // 1. Semantic type determines preference (temporal→x, measure→y, categorical→color)\n            // 2. Data type (ty) is a safeguard for compatibility\n            const streamResult = resolveAssignment(tv, used, [\n                {\n                    channel: 'x',\n                    pref: (_n, ty, st, card) => {\n                        // Semantic preference: temporal types are ideal series axes\n                        if (isTimeSeriesType(st))                            return Pref.STRONG;\n                        if (isOrdinalType(st))                               return Pref.OK;\n                        if (isCategoricalType(st))                           return Pref.OK;\n                        if (isNonMeasureNumeric(st))                         return Pref.OK;\n                        // Data type safeguard\n                        if (ty === 'temporal')                               return Pref.STRONG;\n                        if (ty === 'nominal')                                return Pref.OK;\n                        if (ty === 'quantitative' && card > 0 && card <= 50) return Pref.OK;\n                        return Pref.EXCLUDE;\n                    },\n                },\n                {\n                    channel: 'y',\n                    pref: (_n, ty, st, card) => {\n                        // Semantic preference: true measures are ideal\n                        if (isMeasureType(st))                               return Pref.STRONG;\n                        // Semantic exclusion: temporal / categorical / non-measure\n                        // numeric types should not be used as y-axis measures\n                        if (isTimeSeriesType(st))                            return Pref.EXCLUDE;\n                        if (isCategoricalType(st))                           return Pref.EXCLUDE;\n                        if (isNonMeasureNumeric(st))                         return Pref.EXCLUDE;\n                        // Data type safeguard: quantitative with no semantic type\n                        if (ty === 'quantitative' && !st)\n                            return card > 20 ? Pref.STRONG : Pref.OK;\n                        return Pref.EXCLUDE;\n                    },\n                },\n                {\n                    channel: 'color',\n                    pref: (_n, ty, st, card) => {\n                        // Semantic preference\n                        if (isCategoricalType(st))                           return Pref.STRONG;\n                        if (isOrdinalType(st))                               return Pref.OK;\n                        if (isTimeSeriesType(st))                            return Pref.OK;\n                        // Data type safeguard\n                        if (ty === 'nominal')                                return Pref.STRONG;\n                        if (ty === 'temporal' || ty === 'ordinal')           return Pref.OK;\n                        if (isDiscreteLike(ty, st, card, 20))                return Pref.WEAK;\n                        return Pref.EXCLUDE;\n                    },\n                },\n            ]);\n            if (!streamResult['x'] || !streamResult['y'] || !streamResult['color']) return {};\n            assign('x', streamResult['x']);\n            assign('y', streamResult['y']);\n            assign('color', streamResult['color']);\n            break;\n        }\n\n        case 'Radar Chart': {\n            const xField = pickDiscrete(tv, used) ?? pickLowCardDiscrete(tv, used, 20);\n            const yField = pickQuantitative(tv, used);\n            if (!xField || !yField) return {};\n            assign('x', xField);\n            assign('y', yField);\n            assign('color', pickLowCardDiscrete(tv, used, 20));\n            break;\n        }\n\n        case 'Candlestick Chart': {\n            const xField = pickTemporal(tv, used)\n                ?? pick(tv, used, (name) => nameMatches(name, ['date', 'time', 'day', 'datetime', 'timestamp', 'period']))\n                ?? pickQuantitativeByName(tv, used, ['date', 'time', 'day'])\n                ?? pickDiscrete(tv, used);\n            if (!xField) return {};\n            assign('x', xField);\n            const openField = pickQuantitativeByName(tv, used, ['open']);\n            const highField = pickQuantitativeByName(tv, used, ['high']);\n            const lowField = pickQuantitativeByName(tv, used, ['low']);\n            const closeField = pickQuantitativeByName(tv, used, ['close']);\n            if (openField && highField && lowField && closeField) {\n                assign('open', openField);\n                assign('high', highField);\n                assign('low', lowField);\n                assign('close', closeField);\n            } else {\n                const quants = pickAllQuantitative(tv, used);\n                if (quants.length >= 4) {\n                    assign('open', quants[0]);\n                    assign('high', quants[1]);\n                    assign('low', quants[2]);\n                    assign('close', quants[3]);\n                }\n            }\n            break;\n        }\n\n        default:\n            break;\n    }\n\n    return rec;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * =============================================================================\n * DATA-DRIVEN CHART *TYPE* RECOMMENDATION\n * =============================================================================\n *\n * `recommendChannels` / `getRecommendation` answer \"which fields go on which\n * channels **for a chart type I already picked**\". They do not answer the step\n * that sits *in front* of them: **which chart type should I use at all?**\n *\n * This module fills that gap. Given raw rows + semantic-type annotations it\n * builds a deterministic {@link DataProfile} (how many measures / temporals /\n * categoricals / geographic fields the table has, and their cardinalities) and\n * scores a ranked list of candidate chart types.\n *\n * It reuses the same semantic-type classification the encoders use\n * (`isMeasureType`, `isTimeSeriesType`, `isGeoType`, …) so the two stages agree\n * on what a field *is*; it only adds the type-selection heuristic on top.\n *\n * Typical use (e.g. Data Formulator surfacing suggestions without a model call):\n *\n * ```ts\n * const types = recommendChartTypes(rows, semanticTypes); // [\"Choropleth\", \"Line Chart\", …]\n * const encodings = vlRecommendEncodings(types[0], rows, semanticTypes);\n * ```\n *\n * Backend wrappers (`vlRecommendChartTypes`, …) pass `supportedTypes` so only\n * chart types that backend can actually render are returned, and pair it with\n * their `…RecommendEncodings` to emit type + channels in one step\n * (`…RecommendCharts`).\n *\n * =============================================================================\n */\n\nimport {\n    isMeasureType,\n    isTimeSeriesType,\n    isCategoricalType,\n    isOrdinalType,\n    isGeoCoordinateType,\n    isGeoLocationString,\n    isNonMeasureNumeric,\n} from './semantic-types';\nimport { buildTableView, nameMatches, type InternalTableView } from './recommendation';\n\n// ── Field roles ─────────────────────────────────────────────────────────\n\n/**\n * The role a field plays when choosing a chart type. Mutually exclusive:\n * every field is classified into exactly one role (the most specific one).\n */\nexport type ChartFieldRole =\n    | 'measure'      // true quantitative measure (aggregatable)\n    | 'temporal'     // date / time-granule — a time axis\n    | 'categorical'  // nominal category / entity\n    | 'ordinal'      // ordered discrete (Rank, Range, Score, …)\n    | 'geoPlace'     // named place: Country, State, City, Region …\n    | 'latitude'     // geographic latitude coordinate\n    | 'longitude'    // geographic longitude coordinate\n    | 'identifier'   // row id / index — not useful as a category or measure\n    | 'other';       // unclassified\n\n/** A single field annotated with its data/semantic type, cardinality, and role. */\nexport interface ProfiledField {\n    name: string;\n    /** Vega-Lite-style vis category: 'quantitative' | 'temporal' | 'nominal' | 'ordinal'. */\n    type: string;\n    /** Semantic type annotation (e.g. \"Country\", \"Amount\"), or '' if none. */\n    semanticType: string;\n    /** Number of distinct non-null values. */\n    cardinality: number;\n    role: ChartFieldRole;\n}\n\n/**\n * A deterministic summary of a table's shape, used to rank chart types.\n * The bucketed arrays are views over {@link fields} grouped by role, plus\n * `dimensions` (all category-axis-capable fields: categorical ∪ ordinal ∪\n * geoPlace ∪ temporal).\n */\nexport interface DataProfile {\n    fields: ProfiledField[];\n    measures: ProfiledField[];\n    temporals: ProfiledField[];\n    categoricals: ProfiledField[];\n    ordinals: ProfiledField[];\n    geoPlaces: ProfiledField[];\n    latitudes: ProfiledField[];\n    longitudes: ProfiledField[];\n    identifiers: ProfiledField[];\n    /** Fields usable on a category/discrete axis (categorical ∪ ordinal ∪ geoPlace ∪ temporal). */\n    dimensions: ProfiledField[];\n    rowCount: number;\n}\n\n// Identifier name patterns — strict (exact or `_suffix`) to avoid false hits\n// like \"grid\" / \"valid\" / \"android\". `rank` is intentionally excluded so a\n// Rank field classifies as ordinal (a usable axis) rather than an identifier.\nconst ID_NAME_PATTERNS = ['id', 'index', 'idx', 'row', 'order', 'position', 'pos'];\n\nfunction looksLikeIdentifier(name: string): boolean {\n    const lower = name.toLowerCase();\n    return ID_NAME_PATTERNS.some(p => lower === p || lower.endsWith('_' + p));\n}\n\n/**\n * Classify one field into a single {@link ChartFieldRole}. The order of checks\n * is significant: the most *specific* interpretation wins (geo coordinate →\n * geo place → temporal → identifier → measure → ordinal → categorical).\n */\nfunction classifyRole(name: string, type: string, semanticType: string): ChartFieldRole {\n    const st = semanticType;\n    // Geographic coordinates (Latitude / Longitude): numeric but not measures.\n    if (isGeoCoordinateType(st)) {\n        if (st === 'Latitude' || nameMatches(name, ['latitude', 'lat'])) return 'latitude';\n        if (st === 'Longitude' || nameMatches(name, ['longitude', 'lon', 'lng', 'long'])) return 'longitude';\n        return 'other';\n    }\n    // Named geographic places (Country / State / City / Region / …).\n    if (isGeoLocationString(st)) return 'geoPlace';\n    // Time axis.\n    if (type === 'temporal' || isTimeSeriesType(st)) return 'temporal';\n    // Row identifiers — demoted so they never become a category or measure.\n    if (st === 'ID' || looksLikeIdentifier(name)) return 'identifier';\n    // True quantitative measure (mirrors isQuantitativeField in the encoders).\n    if (type === 'quantitative' && !isNonMeasureNumeric(st) && (isMeasureType(st) || st === '')) {\n        return 'measure';\n    }\n    // Ordered discrete (Rank, Range, Score-as-ordinal, Direction, …).\n    if (isOrdinalType(st)) return 'ordinal';\n    // Plain category.\n    if (type === 'nominal' || isCategoricalType(st)) return 'categorical';\n    return 'other';\n}\n\n/**\n * Build a {@link DataProfile} from raw rows + semantic-type annotations.\n * Deterministic — no random sampling; classification is per-field and\n * order-independent.\n *\n * @param data           Array of row objects.\n * @param semanticTypes  Field → semantic-type map (e.g. `{ Entity: \"Country\" }`).\n */\nexport function profileData(data: any[], semanticTypes: Record<string, string>): DataProfile {\n    const tv: InternalTableView = buildTableView(data, semanticTypes);\n    const fields: ProfiledField[] = tv.names.map(name => ({\n        name,\n        type: tv.fieldType[name] ?? 'nominal',\n        semanticType: tv.fieldSemanticType[name] ?? '',\n        cardinality: tv.fieldLevels[name]?.length ?? 0,\n        role: classifyRole(name, tv.fieldType[name] ?? 'nominal', tv.fieldSemanticType[name] ?? ''),\n    }));\n\n    const by = (r: ChartFieldRole) => fields.filter(f => f.role === r);\n    const categoricals = by('categorical');\n    const ordinals = by('ordinal');\n    const geoPlaces = by('geoPlace');\n    const temporals = by('temporal');\n\n    return {\n        fields,\n        measures: by('measure'),\n        temporals,\n        categoricals,\n        ordinals,\n        geoPlaces,\n        latitudes: by('latitude'),\n        longitudes: by('longitude'),\n        identifiers: by('identifier'),\n        dimensions: [...categoricals, ...ordinals, ...geoPlaces, ...temporals],\n        rowCount: tv.rows.length,\n    };\n}\n\n// ── Scoring ─────────────────────────────────────────────────────────────\n\n/** A ranked chart-type candidate with its score and human-readable reasons. */\nexport interface ChartTypeSuggestion {\n    chartType: string;\n    /** Higher is a better fit. Scores are relative; only the ordering is meaningful. */\n    score: number;\n    reasons: string[];\n}\n\n/** Options for {@link recommendChartTypes} / {@link recommendChartTypesDetailed}. */\nexport interface RecommendChartTypesOptions {\n    /**\n     * Restrict results to these chart-type names (e.g. a backend's template\n     * catalog). Types not in the list are dropped. Omit for all shared types.\n     */\n    supportedTypes?: string[];\n    /** Cap the number of suggestions returned (after ranking). */\n    max?: number;\n}\n\n/**\n * A recommended chart type paired with its recommended channel → field\n * encodings. Returned by the backend one-step recommenders\n * (`vlRecommendCharts`, …) that chain type selection with encoding selection.\n */\nexport interface RecommendedChart {\n    chartType: string;\n    encodings: Record<string, string>;\n}\n\n// Cardinality thresholds for readability gates.\nconst LOW_CARD_SERIES = 12;   // a legend/series stays readable up to ~12 colors\nconst LOW_CARD_AXIS = 25;     // a discrete heatmap axis stays readable up to ~25 bands\nconst PIE_MAX_SLICES = 8;     // a pie is legible only with a handful of slices\n\n/** Semantic types the choropleth base maps can actually render (see map.ts). */\nconst CHOROPLETH_SEMANTIC = new Set(['Country', 'State']);\nconst CHOROPLETH_NAME_HINTS = ['country', 'state', 'province', 'nation'];\n\n/**\n * Score candidate chart types for a data profile. Returns suggestions sorted by\n * descending score; ties keep a stable, priority-ordered arrangement.\n *\n * The rules are curated design heuristics: more *specific* chart types\n * (maps, time series) outrank generic ones (bar) when the data supports them,\n * so a table with a geographic place + a measure surfaces \"Choropleth\" ahead of\n * \"Bar Chart\" without a model call.\n */\nexport function rankChartTypes(profile: DataProfile): ChartTypeSuggestion[] {\n    const {\n        measures, temporals, categoricals, ordinals, geoPlaces,\n        latitudes, longitudes, rowCount,\n    } = profile;\n\n    const catLike = [...categoricals, ...ordinals, ...geoPlaces]; // discrete, non-temporal\n    const dims = profile.dimensions;\n    const lowCardCatLike = catLike.filter(f => f.cardinality >= 2 && f.cardinality <= LOW_CARD_SERIES);\n    const lowCardDims = dims.filter(f => f.cardinality >= 2 && f.cardinality <= LOW_CARD_AXIS);\n    const hasMeasure = measures.length >= 1;\n\n    // Preserve insertion order for stable tie-breaking; keep the max score per type.\n    const order: string[] = [];\n    const acc = new Map<string, { score: number; reasons: string[] }>();\n    const add = (chartType: string, score: number, reason: string) => {\n        const cur = acc.get(chartType);\n        if (!cur) {\n            order.push(chartType);\n            acc.set(chartType, { score, reasons: [reason] });\n        } else {\n            if (score > cur.score) cur.score = score;\n            if (!cur.reasons.includes(reason)) cur.reasons.push(reason);\n        }\n    };\n\n    // ── Geographic (most specific) ──────────────────────────────────────\n    if (latitudes.length >= 1 && longitudes.length >= 1) {\n        add('Map', 96, 'has latitude + longitude coordinates');\n    }\n    const choroGeo = geoPlaces.filter(\n        f => CHOROPLETH_SEMANTIC.has(f.semanticType) || nameMatches(f.name, CHOROPLETH_NAME_HINTS),\n    );\n    if (choroGeo.length >= 1 && hasMeasure) {\n        add('Choropleth', 92, 'has a geographic region field + a measure');\n    }\n\n    // ── Time series ─────────────────────────────────────────────────────\n    if (temporals.length >= 1 && hasMeasure) {\n        add('Line Chart', 88, 'has a time field + a measure (trend over time)');\n        add('Area Chart', 66, 'has a time field + a measure');\n    }\n\n    // ── Correlation (two measures) ──────────────────────────────────────\n    if (measures.length >= 2) {\n        add('Scatter Plot', 84, 'has two or more measures (relationship)');\n    }\n\n    // ── Category + measure (bar) ────────────────────────────────────────\n    if (dims.length >= 1 && hasMeasure) {\n        add('Bar Chart', 80, 'has a category axis + a measure');\n    }\n\n    // ── Single-measure distribution (histogram) ─────────────────────────\n    if (hasMeasure && dims.length === 0) {\n        add('Histogram', 82, 'has a measure with no category (distribution)');\n    }\n\n    // ── Two-category comparison (grouped / stacked / heatmap) ───────────\n    if (catLike.length >= 2 && lowCardCatLike.length >= 1 && hasMeasure) {\n        add('Grouped Bar Chart', 72, 'has two categories + a measure');\n        add('Stacked Bar Chart', 70, 'has two categories + a measure');\n    }\n    if (lowCardDims.length >= 2 && hasMeasure) {\n        add('Heatmap', 74, 'has two discrete fields + a measure (matrix)');\n    }\n\n    // ── Part-to-whole (pie) ─────────────────────────────────────────────\n    if (catLike.length === 1 && temporals.length === 0 && hasMeasure) {\n        const c = catLike[0];\n        const oneRowPerCategory = rowCount <= c.cardinality * 1.5;\n        if (c.cardinality >= 2 && c.cardinality <= PIE_MAX_SLICES && oneRowPerCategory) {\n            add('Pie Chart', 64, 'a few categories that sum to a whole');\n        }\n    }\n\n    // ── Distribution across groups (box / strip) ────────────────────────\n    if (catLike.length >= 1 && hasMeasure && temporals.length === 0) {\n        const smallest = catLike.reduce((a, b) => (b.cardinality < a.cardinality ? b : a));\n        if (smallest.cardinality >= 1 && rowCount >= smallest.cardinality * 2) {\n            add('Boxplot', 58, 'multiple measure values per group (spread)');\n            add('Strip Plot', 52, 'multiple measure values per group');\n        }\n    }\n\n    // ── Count-only fallbacks (dimensions but no measure) ────────────────\n    if (!hasMeasure && dims.length >= 1) {\n        add('Bar Chart', 60, 'categories without a measure (counts)');\n        if (lowCardDims.length >= 2) add('Heatmap', 55, 'two discrete fields (cross-tab counts)');\n    }\n\n    // ── Last-resort fallback ────────────────────────────────────────────\n    if (order.length === 0) {\n        if (measures.length >= 2) add('Scatter Plot', 20, 'fallback for numeric data');\n        else add('Bar Chart', 15, 'fallback');\n    }\n\n    return order\n        .map(chartType => ({ chartType, score: acc.get(chartType)!.score, reasons: acc.get(chartType)!.reasons }))\n        // Stable sort (ES2019+) — equal scores keep priority insertion order.\n        .sort((a, b) => b.score - a.score);\n}\n\n// ── Public API ──────────────────────────────────────────────────────────\n\n/**\n * Recommend candidate chart types for a dataset, with scores and reasons.\n *\n * @param data           Array of row objects.\n * @param semanticTypes  Field → semantic-type map (e.g. `{ Entity: \"Country\" }`).\n * @param options        Optional `supportedTypes` filter and `max` cap.\n * @returns              Ranked {@link ChartTypeSuggestion}s (best first).\n */\nexport function recommendChartTypesDetailed(\n    data: any[],\n    semanticTypes: Record<string, string>,\n    options: RecommendChartTypesOptions = {},\n): ChartTypeSuggestion[] {\n    const profile = profileData(data, semanticTypes);\n    let ranked = rankChartTypes(profile);\n    if (options.supportedTypes) {\n        const allowed = new Set(options.supportedTypes);\n        ranked = ranked.filter(s => allowed.has(s.chartType));\n    }\n    if (options.max != null) ranked = ranked.slice(0, options.max);\n    return ranked;\n}\n\n/**\n * Recommend a ranked list of chart-type names for a dataset (best first).\n *\n * A convenience wrapper over {@link recommendChartTypesDetailed} that drops the\n * scores/reasons. This is the \"type-selection step that sits in front of\"\n * `recommendChannels` — call it first, then feed the chosen type to\n * `…RecommendEncodings` to populate channels.\n *\n * @param data           Array of row objects.\n * @param semanticTypes  Field → semantic-type map.\n * @param options        Optional `supportedTypes` filter and `max` cap.\n * @returns              Ranked chart-type names (best first).\n */\nexport function recommendChartTypes(\n    data: any[],\n    semanticTypes: Record<string, string>,\n    options: RecommendChartTypesOptions = {},\n): string[] {\n    return recommendChartTypesDetailed(data, semanticTypes, options).map(s => s.chartType);\n}\n"]}