@graphysdk/viz-engine 0.0.1-plugins.0 → 0.0.1-plugins.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1283 +0,0 @@
1
- import { internal } from 'arquero';
2
-
3
- declare interface AesMapping {
4
- x?: AestheticValue;
5
- y?: AestheticValue;
6
- label?: AestheticValue;
7
- color?: AestheticValue;
8
- size?: AestheticValue;
9
- alpha?: AestheticValue;
10
- group?: AestheticValue;
11
- strokeWidth?: AestheticValue;
12
- lineType?: AestheticValue;
13
- }
14
-
15
- export declare type AestheticKey = keyof AesMapping;
16
-
17
- /**
18
- * Aesthetic value can be:
19
- * - string (shorthand for { variable: string })
20
- * - { variable: string } (explicit variable mapping)
21
- * - { value: DataValue } (constant value applied to every observation)
22
- */
23
- declare type AestheticValue = string | VariableMapping | ValueMapping;
24
-
25
- /***************************************************************
26
- * Aggregate Transform
27
- ***************************************************************/
28
- declare interface AggregateOperation {
29
- /** The aggregation function to apply. */
30
- op: AggregationFunction;
31
- /** The variable to aggregate. */
32
- variableName: VariableName;
33
- /** The name of the output variable. */
34
- as: VariableName;
35
- }
36
-
37
- declare interface AggregateOptions {
38
- /** Variables to group by before aggregating. */
39
- groupby: VariableName[];
40
- /** Aggregation operations to apply per group. */
41
- operations: AggregateOperation[];
42
- }
43
-
44
- declare interface AggregateTransformInput {
45
- type: 'transform';
46
- transformType: 'aggregate';
47
- options: AggregateOptions;
48
- }
49
-
50
- /** A function that aggregates a variable's values. */
51
- declare type AggregationFunction = 'count' | 'sum' | 'mean' | 'median' | 'mode' | 'min' | 'max';
52
-
53
- /** A record of variable names and their aggregations. */
54
- declare type AggregationInput = Record<VariableName, {
55
- variableName: VariableName;
56
- aggregation: AggregationFunction;
57
- }>;
58
-
59
- /**
60
- * Where an annotation anchored to an observation sits, in normalised panel space `[0, 1]²`, plus the
61
- * render discriminant the annotation renderer dispatches on. A geom computes this from an observation
62
- * under a coord system (`Geom.resolveAnchorPosition`); the annotations compiler resolves anchors through
63
- * the definition rather than branching on geom name.
64
- */
65
- declare interface AnchorPosition {
66
- x: number;
67
- y: number;
68
- geom: 'bar' | 'line' | 'polar-bar';
69
- }
70
-
71
- /**
72
- * The compile-half definition of a custom annotation kind (ADR-035).
73
- *
74
- * It carries **no compile logic** — coordinate resolution is generic for every kind — and exists only
75
- * so the registration-typed builder (`createGraphyBuilder({ annotations })`) can type `annotation.<kind>({
76
- * params })` from `TParams`, merge `defaultParams`, and enforce the optional coordinate arity. The
77
- * render-half `draw` lives in the renderer and binds to this definition by import (`defineAnnotationRenderer`).
78
- */
79
- /** Optional coordinate-count guardrail enforced by the builder; unbounded when omitted. */
80
- export declare interface AnnotationArity {
81
- min?: number;
82
- max?: number;
83
- }
84
-
85
- /**
86
- * A single coordinate for a custom annotation (ADR-035). One of three whole-coordinate modes — a
87
- * data-domain value scaled through the chart's scales, a raw [0,1] unit fraction of the panel, or a
88
- * snap to an existing observation. Per-axis mixing (x in one mode, y in another) is a deliberate
89
- * non-goal until a consumer needs it.
90
- */
91
- export declare type AnnotationCoordinateInput = {
92
- data: {
93
- x: DataValue;
94
- y: DataValue;
95
- };
96
- } | {
97
- unit: {
98
- x: number;
99
- y: number;
100
- };
101
- } | {
102
- observation: ObservationAnchorInput;
103
- };
104
-
105
- export declare interface AnnotationDef<TParams extends object = object, TType extends string = string> {
106
- type: TType;
107
- /** Carrier that lets the builder recover `TParams` and merge defaults before a param reaches `draw`. */
108
- defaultParams: TParams;
109
- coordinates?: AnnotationArity;
110
- }
111
-
112
- /** Whether a custom annotation paints behind the geoms (background) or on top (foreground). */
113
- export declare type AnnotationZOrder = 'background' | 'foreground';
114
-
115
- /**
116
- * Area-specific parameters (same rendering knobs as line, but fills under the curve)
117
- */
118
- declare interface AreaGeomParams {
119
- lineWidth: number | 'auto';
120
- interpolate: InterpolateType;
121
- missingValues: MissingValuesType;
122
- }
123
-
124
- /**
125
- * Maps each positional aesthetic to its axis orientation.
126
- * The guide compiler uses this to determine where axes are placed
127
- * and what geometry they use (e.g., linear vs circular grid lines).
128
- */
129
- declare interface AxisMapping {
130
- x: {
131
- position: AxisPosition;
132
- geometry: GuideGeometry;
133
- };
134
- y: {
135
- position: AxisPosition;
136
- geometry: GuideGeometry;
137
- };
138
- }
139
-
140
- declare type AxisPosition = 'left' | 'right' | 'top' | 'bottom';
141
-
142
- /**
143
- * Bar/Column-specific parameters
144
- */
145
- declare type BarGeomParams = Record<string, never>;
146
-
147
- /**
148
- * Discriminated union of the built-in resolved layer specs, keyed on `geom`. All properties are fully
149
- * resolved — no optionals. The `Extract`-based per-geom params views read from this closed union.
150
- */
151
- declare type BuiltinLayerSpec = {
152
- [G in GeomName]: LayerSpecOf<G>;
153
- }[GeomName];
154
-
155
- /**
156
- * Cartesian coordinate system - standard x/y plot. Also used for flipped coordinates (flip is
157
- * an axis-assignment variant, not a different geometric paradigm).
158
- */
159
- declare interface CartesianCoordSystem {
160
- type: 'cartesian';
161
- /**
162
- * The data-space axis that is the main (independent) one. `'x'` for standard cartesian (bars
163
- * rise, X ticks on the horizontal axis); `'y'` for `coord.flip()` (bars extend, Y ticks on the
164
- * horizontal axis). Consumers that need to branch on flip read this; the runtime `coord/axes`
165
- * helpers turn it into main/cross accessors so the branch lives in one place.
166
- */
167
- mainAxis: MainAxis;
168
- /** Axis orientation metadata for the guide compiler */
169
- axisMapping: AxisMapping;
170
- }
171
-
172
- declare interface CategoricalValueFormat {
173
- type: 'text';
174
- }
175
-
176
- /**
177
- * The spatial axis a position channel binds to. Selects the scale (`x` → the x scale, `y` → the
178
- * primary or secondary y scale) and is the axis flip swaps and polar projects.
179
- */
180
- declare type ChannelAxis = 'x' | 'y';
181
-
182
- /** Comparison operators for declarative filtering. */
183
- declare type ComparisonOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte';
184
-
185
- export declare interface CompiledGeom {
186
- /** The reparameterized dataset (may have new computed variables) */
187
- data: Dataset;
188
- /** Any mapping overrides produced by the geom */
189
- mapping: AesMapping;
190
- /**
191
- * Extra single-observation tooltip rows this geom contributes (e.g. OHLC). The compiler derives
192
- * each row's display format from its column and the renderer materialises the values for the
193
- * hovered observation. Omit when the geom adds no detail rows; the standard one-row-per-series
194
- * tooltip applies.
195
- */
196
- tooltipRows?: GeomTooltipRow[];
197
- }
198
-
199
- /***************************************************************
200
- * Constant Transform
201
- ***************************************************************/
202
- declare interface ConstantOptions {
203
- /** The name of the new variable. */
204
- variableName: VariableName;
205
- /** The type of the new variable. */
206
- type: DataType;
207
- /** The constant value to assign to every observation. */
208
- value: DataValue;
209
- }
210
-
211
- declare interface ConstantTransformInput {
212
- type: 'transform';
213
- transformType: 'constant';
214
- options: ConstantOptions;
215
- }
216
-
217
- /**
218
- * Render-ready coordinate system (discriminated union).
219
- * Discriminates on geometric paradigm: cartesian plane vs polar projection.
220
- */
221
- declare type CoordSystem = CartesianCoordSystem | PolarCoordSystem;
222
-
223
- /**
224
- * Coordinate system type for transforming geometric positions.
225
- *
226
- * - `'cartesian'` — Standard x/y Cartesian plane
227
- * - `'polar'` — Polar coordinates for pie, radar, and radial charts
228
- * - `'flip'` — Cartesian with x and y axes swapped
229
- */
230
- export declare type CoordType = 'cartesian' | 'polar' | 'flip';
231
-
232
- /**
233
- * Resolved count stat spec.
234
- */
235
- declare interface CountStatSpec {
236
- type: 'count';
237
- }
238
-
239
- /** Opens a {@link MarkTable} builder for a heterogeneous, kind-tagged Tier-C dataset. */
240
- export declare function createMarkTable(): MarkTable;
241
-
242
- /** Three letter ISO string representing the currency */
243
- declare type CurrencyIso = 'aed' | 'aud' | 'bdt' | 'bhd' | 'brl' | 'cad' | 'chf' | 'clp' | 'cny' | 'cop' | 'czk' | 'dkk' | 'egp' | 'eur' | 'gbp' | 'hkd' | 'huf' | 'idr' | 'ils' | 'inr' | 'jpy' | 'krw' | 'kwd' | 'mxn' | 'myr' | 'ngn' | 'nok' | 'nzd' | 'php' | 'pkr' | 'pln' | 'qar' | 'ron' | 'rub' | 'sar' | 'sek' | 'sgd' | 'thb' | 'try' | 'twd' | 'usd' | 'vnd' | 'zar';
244
-
245
- declare interface CurrencyValueFormat {
246
- type: 'currency';
247
- iso: CurrencyIso;
248
- }
249
-
250
- /**
251
- * A custom (registered) annotation instance. `type` names the registered kind (resolves the render-side
252
- * `draw`); `coordinates` resolve to targets at compile time; `params` is opaque at the spec level — the
253
- * registration-typed builder types it from the annotation definition. `zOrder` overrides the kind's
254
- * declared default.
255
- */
256
- export declare interface CustomAnnotationInput {
257
- id?: string;
258
- type: string;
259
- coordinates: AnnotationCoordinateInput[];
260
- params?: Record<string, unknown>;
261
- zOrder?: AnnotationZOrder;
262
- }
263
-
264
- /** A resolved layer spec for a custom-registered geom — the generic resolver's output shape. */
265
- declare interface CustomLayerSpec extends LayerSpecBase {
266
- geom: string;
267
- params: Record<string, unknown>;
268
- }
269
-
270
- /**
271
- * Resolved data-labels config carried per-layer.
272
- */
273
- declare interface DataLabelsConfig {
274
- /**
275
- * Whether to show data labels on the layer.
276
- * @default false
277
- */
278
- showDataLabels: boolean;
279
- /**
280
- * The format to use for the data labels.
281
- * @default 'absolute'
282
- */
283
- format: 'absolute' | 'percentage';
284
- /**
285
- * Whether to show stack totals on the layer.
286
- * @default false
287
- */
288
- showStackTotals: boolean;
289
- /**
290
- * Whether to show category labels on the layer.
291
- * @default false
292
- */
293
- showCategoryLabels: boolean;
294
- /**
295
- * The source of the data labels.
296
- * @default { variable: POSITION_VARIABLES.yRaw }
297
- */
298
- labelSource: AestheticValue;
299
- }
300
-
301
- /**
302
- * An immutable, columnar dataset. Uses Arquero internally for filtering, grouping and aggregation.
303
- *
304
- * Data is organised as **variables** (columns) and **observations** (rows). The values of each variable are typed and must match the variable's {@link DataType}. Missing values are represented as `null`.
305
- *
306
- * All transformation methods (filter, orderBy, addVariable etc.) return a new instance.
307
- *
308
- * @example
309
- * const data = new Dataset({
310
- * age: { type: 'numeric', values: [25, 30, 35, null] },
311
- * name: { type: 'categorical', values: ['John', 'Jane', 'Jim', 'Joanna'] },
312
- * });
313
- *
314
- * data.filter('age', 'gt', 30).print();
315
- */
316
- export declare class Dataset {
317
- private table;
318
- private variableMetadata;
319
- /**
320
- * Constructs a new dataset from typed columnar input.
321
- * @param variables - A record mapping variable names to their type and values.
322
- *
323
- * @example
324
- * const data = new Dataset({
325
- * age: { type: 'numeric', values: [25, 30, 35] },
326
- * name: { type: 'categorical', values: ['John', 'Jane', 'Jim'] },
327
- * });
328
- */
329
- constructor(variables?: VariableMap);
330
- /* Excluded from this release type: fromTrusted */
331
- /**
332
- * Returns the number of observations in the dataset.
333
- */
334
- size(): number;
335
- /**
336
- * Returns the names of all variables in the dataset.
337
- */
338
- getVariableNames(): VariableName[];
339
- /**
340
- * Returns true if the dataset has the given variable.
341
- */
342
- hasVariable(variable: VariableName): boolean;
343
- /**
344
- * Adds a new variable to the dataset. The variable's `valueFormat` is resolved in this order:
345
- * 1. explicit `valueFormat` argument,
346
- * 2. the existing variable's format (when overwriting an existing variable — e.g. a stack
347
- * position adjuster rewriting the user's y),
348
- * 3. a type-based default (`numeric → decimal`, `categorical → text`, `temporal → date`).
349
- */
350
- addVariable(variable: VariableName, type: DataType, values: DataValue[], valueFormat?: ValueFormat): Dataset;
351
- /**
352
- * Adds a new constant variable to the dataset. Format resolution follows {@link addVariable}.
353
- */
354
- addConstantVariable(variable: VariableName, type: DataType, value: DataValue, valueFormat?: ValueFormat): Dataset;
355
- /**
356
- * Derives a new variable based on existing variables, using a table expression. If `valueFormat`
357
- * is omitted, a type-based default is used.
358
- */
359
- deriveVariable(variable: VariableName, type: DataType, expression: (observation: Observation, rowIndex: number) => DataValue, valueFormat?: ValueFormat): Dataset;
360
- /**
361
- * Renames a variable.
362
- */
363
- renameVariable(oldName: VariableName, newName: VariableName): Dataset;
364
- /**
365
- * Selects a subset of variables from the dataset.
366
- */
367
- selectVariables(...variables: VariableName[]): Dataset;
368
- /**
369
- * Returns the type of a variable.
370
- */
371
- getType(variable: VariableName): DataType;
372
- /**
373
- * Returns the value format of a variable. Every variable carries a format — either explicitly
374
- * supplied at construction (via `Variable.valueFormat` or an `addVariable`-family `valueFormat`
375
- * argument) or a type-based default.
376
- */
377
- getValueFormat(variable: VariableName): ValueFormat;
378
- /**
379
- * Groups the variable names by their type.
380
- */
381
- groupVariableNamesByType(): GroupedVariableNames;
382
- /**
383
- * Returns the values of a given variable.
384
- *
385
- * @param options.type - The expected type of the values. If provided, the return type is narrowed to the matching concrete type and a runtime check ensures the variable actually carries that type.
386
- * @param options.skipNulls - Whether to skip null values. Defaults to `false`.
387
- * @param options.distinct - Whether to remove duplicate values from the result. Defaults to `false`.
388
- */
389
- getValues(variable: VariableName, options: GetValuesOptions & {
390
- type: 'numeric';
391
- skipNulls?: false;
392
- }): Array<number | null>;
393
- getValues(variable: VariableName, options: GetValuesOptions & {
394
- type: 'categorical';
395
- skipNulls?: false;
396
- }): Array<string | null>;
397
- getValues(variable: VariableName, options: GetValuesOptions & {
398
- type: 'temporal';
399
- skipNulls?: false;
400
- }): Array<Date | null>;
401
- getValues(variable: VariableName, options: GetValuesOptions & {
402
- type: 'numeric';
403
- skipNulls: true;
404
- }): number[];
405
- getValues(variable: VariableName, options: GetValuesOptions & {
406
- type: 'categorical';
407
- skipNulls: true;
408
- }): string[];
409
- getValues(variable: VariableName, options: GetValuesOptions & {
410
- type: 'temporal';
411
- skipNulls: true;
412
- }): Date[];
413
- getValues(variable: VariableName, options?: GetValuesOptions): DataValue[];
414
- /**
415
- * Filters the dataset using a declarative predicate.
416
- */
417
- filter(variableName: VariableName, operator: ComparisonOperator, value: DataValue): Dataset;
418
- /**
419
- * Returns a dataset filtered to rows where `mask[i] === 1`. Underlying column
420
- * storage is shared with the parent — values are not copied. The mask length
421
- * must equal `size()`.
422
- */
423
- filterByMask(mask: Uint8Array): Dataset;
424
- /**
425
- * Orders the dataset by a variable, in ascending (default) or descending order.
426
- */
427
- orderBy(variable: VariableName, direction?: 'asc' | 'desc'): Dataset;
428
- /**
429
- * Returns the first observation in the dataset.
430
- */
431
- getFirst(): Observation | null;
432
- /**
433
- * Returns the last observation in the dataset.
434
- */
435
- getLast(): Observation | null;
436
- /**
437
- * Returns the last observation matching a predicate, scanning backwards from the end.
438
- */
439
- findLast(predicate: (observation: Observation) => boolean): Observation | null;
440
- /**
441
- * Groups the dataset by one or more variables.
442
- */
443
- groupBy(...variables: VariableName[]): GroupBy;
444
- /**
445
- * Aggregates the dataset.
446
- */
447
- rollup(aggregations: AggregationInput): Dataset;
448
- /**
449
- * Reshapes data from wide to long format by collapsing multiple numeric variables
450
- * into key–value pairs.
451
- *
452
- * ```
453
- * ┌─────────┬──────┬──────┬──────┐ ┌─────────┬──────┬─────┐
454
- * │ country │ 2020 │ 2021 │ 2022 │ │ country │ year │ gdp │
455
- * ├─────────┼──────┼──────┼──────┤ ───► ├─────────┼──────┼─────┤
456
- * │ US │ 100 │ 110 │ 120 │ │ US │ 2020 │ 100 │
457
- * │ UK │ 200 │ 210 │ 220 │ │ US │ 2021 │ 110 │
458
- * └─────────┴──────┴──────┴──────┘ │ US │ 2022 │ 120 │
459
- * │ UK │ 2020 │ 200 │
460
- * │ UK │ 2021 │ 210 │
461
- * │ UK │ 2022 │ 220 │
462
- * └─────────┴──────┴─────┘
463
- * ```
464
- *
465
- * @param keep - Variables to carry through unchanged. Defaults to all
466
- * categorical and temporal variables.
467
- * @param reshape - Numeric variables to collapse into rows. Defaults to all
468
- * numeric variables.
469
- * @param keyName - Name of the new variable whose values are the
470
- * original variable names (default: 'key').
471
- * @param valueName - Name of the new variable whose values are the
472
- * original values of the variables to reshape (default: 'value').
473
- * @throws If `keyName` or `valueName` conflicts with a variable in `keep`.
474
- * @throws If any variable in `reshape` is not numeric.
475
- *
476
- * @example
477
- * const reshaped = data.reshapeFromWideToLong({
478
- * keep: ['country'],
479
- * reshape: ['2020', '2021'],
480
- * keyName: 'year',
481
- * valueName: 'gdp',
482
- * });
483
- */
484
- reshapeFromWideToLong({ keep, reshape, keyName, valueName, }?: {
485
- keep?: VariableName[];
486
- reshape?: VariableName[];
487
- keyName?: VariableName;
488
- valueName?: VariableName;
489
- }): Dataset;
490
- /**
491
- * Prints the dataset to the console.
492
- */
493
- print(): void;
494
- /**
495
- * Returns an iterator over the observations in the dataset.
496
- */
497
- [Symbol.iterator](): Iterator<Observation>;
498
- /**
499
- * Resolves a freshly-added variable's `valueFormat`: explicit > existing (overwrite) > type-default.
500
- */
501
- private resolveAddedVariableFormat;
502
- /**
503
- * Parses the variable map into a table and variable metadata.
504
- */
505
- private parseVariableMap;
506
- /**
507
- * Normalizes raw values into typed values.
508
- */
509
- private normalizeRawValues;
510
- /**
511
- * Skips nulls when retrieving values from a variable.
512
- */
513
- private skipNulls;
514
- /**
515
- * Returns distinct values.
516
- */
517
- private getDistinctValues;
518
- }
519
-
520
- /** The type of a variable's values. Internally, numeric values are stored as numbers, dates as Date objects and categorical values as strings. */
521
- declare type DataType = 'numeric' | 'categorical' | 'temporal';
522
-
523
- /** The smallest unit of data in the dataset. `null` represents a missing value. */
524
- declare type DataValue = number | string | Date | null;
525
-
526
- /**
527
- * `TType` is a `const` type parameter so the literal kind name (`'calloutBox'`) survives to the type
528
- * level — the registration-typed builder keys `annotation.<kind>(...)` off it, the same way
529
- * `createGraphyBuilder` captures a geom's name. `TParams` is recovered from `defaultParams`; annotate or
530
- * cast it (`defaultParams: {...} as CalloutBoxParams`) when a param's literal union would otherwise widen.
531
- */
532
- export declare function defineAnnotation<const TType extends string, TParams extends object = object>(def: {
533
- type: TType;
534
- defaultParams?: TParams;
535
- coordinates?: AnnotationArity;
536
- }): AnnotationDef<TParams, TType>;
537
-
538
- /** A value format with no inner lookups. Lookup cases and fallbacks are constrained to this so a `lookup` cannot nest another `lookup` at the type level. */
539
- declare type ExplicitValueFormat = TemporalValueFormat | NumericValueFormat | CurrencyValueFormat | CategoricalValueFormat;
540
-
541
- /**
542
- * Extracts the constant value from a `{ value }` mapping. Returns undefined for variable mappings.
543
- */
544
- export declare function extractConstantValue(aestheticValue: AestheticValue | undefined): DataValue | undefined;
545
-
546
- /**
547
- * Extracts the variable name from an AestheticValue.
548
- * Returns the variable name for string shorthands and { variable } mappings.
549
- * Returns null for constant { value } mappings or undefined values.
550
- */
551
- export declare function extractVariableName(aestheticValue: AestheticValue | undefined): VariableName | null;
552
-
553
- /***************************************************************
554
- * Filter Transform
555
- ***************************************************************/
556
- declare interface FilterOptions {
557
- /** The variable to filter on. */
558
- variableName: VariableName;
559
- /** The comparison operator. */
560
- operator: ComparisonOperator;
561
- /** The value to compare against. */
562
- value: DataValue;
563
- }
564
-
565
- declare interface FilterTransformInput {
566
- type: 'transform';
567
- transformType: 'filter';
568
- options: FilterOptions;
569
- }
570
-
571
- /**
572
- * Base class for geoms that turn observations into visual marks (points, bars, lines etc).
573
- *
574
- * `TParams` is the geom's parameter type — the single source of truth the registration-typed builder
575
- * reads to type `geom.<name>({ params })` and to default missing params. Built-ins leave it at the
576
- * empty default and keep their typed params through the spec builder's static surface; a custom geom
577
- * names its params type and declares matching {@link defaultParams}.
578
- */
579
- export declare abstract class Geom<TParams extends object = object> {
580
- /**
581
- * The aesthetics an author must map for this geom. Built-ins list closed aesthetic keys
582
- * (`['x','y']`); a custom geom may also list open channel names (a box plot's `min`/`q1`/…) that it
583
- * binds to scales through its {@link positionChannels}, so the registration-typed builder accepts and
584
- * types them as `aes` keys instead of forcing the bindings into `params`.
585
- */
586
- readonly requiredAesthetics: readonly string[];
587
- /**
588
- * The params merged in by the registration-typed builder before a missing key would reach the geom.
589
- * The default is empty; a custom geom overrides it with its definition's defaults, which doubles as
590
- * the carrier that lets the builder recover `TParams` from the registered instance.
591
- */
592
- readonly defaultParams: TParams;
593
- /**
594
- * The position channels this geom produces. The position mapper and coord projection iterate this
595
- * manifest instead of a hardcoded column set, so a geom's geometry is described by what it declares.
596
- */
597
- readonly positionChannels: readonly PositionChannel[];
598
- /**
599
- * The visual aesthetics this geom encodes (color, size, …). The visual mapper and legend iterate
600
- * this declaration instead of a hardcoded set, so a geom's visual surface is described by what it
601
- * declares. The default is the full vocabulary; a geom narrows it to the aesthetics it actually
602
- * paints, and a custom aesthetic extends it (decision 10).
603
- */
604
- readonly visualAesthetics: readonly ScaledVisualAestheticKey[];
605
- /**
606
- * The swatch shape that evokes this geom's on-canvas mark in the legend and tooltip — its
607
- * cartesian-natural shape. A polar coord refines a `square` mark to a `slice` (pie/donut wedge)
608
- * at read time. Decoupled from `GeomName` so guides paint by what a geom declares, not its name.
609
- */
610
- readonly swatchShape: SwatchShape;
611
- /**
612
- * How this geom composes highlight matches above its base render, or `null` to opt out of
613
- * highlighting. Read at layer compile and stamped onto `CompiledLayer.highlight.strategy`.
614
- * Declared per geom so core resolves it from the definition, not a geom-keyed lookup.
615
- */
616
- readonly highlightStrategy: HighlightStrategy | null;
617
- /**
618
- * The spatial structure this geom's marks present for hit-testing — its cartesian-natural kind.
619
- * Stamped onto `CompiledLayer.spatialMap`; a polar coord refines it to `arcs`. Declared per geom
620
- * so the runtime builds the matching index from data, not by branching on the geom name.
621
- */
622
- readonly spatialKind: SpatialIndexKind;
623
- /**
624
- * Positions for which this geom supports direct (inline) series labels in the legend. Empty when
625
- * the geom never shows them. The legend reads this from the definition, not a geom-keyed lookup.
626
- */
627
- readonly directLabelPositions: readonly PositionType[];
628
- /**
629
- * Grid/border visibility overrides this geom requests per coord type (e.g. a bar hides the
630
- * categorical-axis grid). Empty when the geom imposes none. The axis guide reads these.
631
- */
632
- readonly gridPolicies: Partial<Record<CoordType, GridPolicy>>;
633
- /**
634
- * How this geom derives each observation's stable identity key: `'index'` (position by row, so
635
- * marks morph smoothly on enter/exit) or `'fields'` (x value plus resolved series). The identity
636
- * compiler reads this from the definition, not a geom-name check.
637
- */
638
- readonly identityKeyStrategy: 'index' | 'fields';
639
- /**
640
- * The coord types under which this geom has meaningful semantics. The layer validator rejects a
641
- * layer whose coord is absent from this set (e.g. a rule has no polar interpretation). Declared per
642
- * geom so the validator resolves support from the definition, not a geom-name check.
643
- */
644
- readonly supportedCoordTypes: readonly CoordType[];
645
- /**
646
- * Whether a non-stacked layer of this geom carries a layer-wide grand total (the signed sum of `y`,
647
- * the pie/donut headline figure). The summarise stage runs the grand-total summariser only for geoms
648
- * that declare this, so eligibility lives on the definition rather than a geom-name gate.
649
- */
650
- readonly emitsGrandTotal: boolean;
651
- /**
652
- * Whether a stacked layer of this geom carries per-x stack totals (the share-of-stack denominator).
653
- * The summarise stage runs the stack-totals summariser only for geoms that declare this, so a stacked
654
- * area (which writes the same interval columns) is excluded by declaration, not by a geom-name gate.
655
- */
656
- readonly emitsStackTotals: boolean;
657
- /**
658
- * Whether a layer of this geom contributes a per-group headline figure. The headline guide builds a
659
- * per-group strip only when an eligible geom is present, reading this from the definition rather than
660
- * a membership list of geom names (so a reference-line geom, which is an annotation, opts out).
661
- */
662
- readonly supportsPerGroupHeadline: boolean;
663
- abstract readonly type: GeomIdentity;
664
- /**
665
- * Where an annotation anchored to the given observation sits, in normalised panel space, or `null`
666
- * when this geom does not support anchoring (the default). The annotations compiler resolves anchors
667
- * through this method rather than branching on geom name; the returned `geom` discriminant tells the
668
- * renderer how to place the annotation.
669
- */
670
- resolveAnchorPosition(_observation: Observation, _coordSystem: CoordSystem): AnchorPosition | null;
671
- abstract compile(input: GeomCompilerInput): CompiledGeom;
672
- /**
673
- * Validates the layer's mapping against invariants specific to this geom (e.g. a rule needs exactly
674
- * one numeric axis). Returns the issues found; omit the method when the geom imposes no mapping
675
- * invariant. The layer validator dispatches here instead of branching on geom name.
676
- */
677
- validateMapping?(input: GeomMappingValidationInput): ValidationIssue[];
678
- }
679
-
680
- /**
681
- * The built-in geometric marks. The single source for both the {@link GeomName} type and the runtime
682
- * {@link BUILTIN_GEOM_NAMES} set used to tell a built-in name from a custom registration.
683
- *
684
- * - `'point'` — Scatter-style dot marks
685
- * - `'line'` — Connected line marks
686
- * - `'area'` — Filled area marks
687
- * - `'bar'` — Rectangular bar marks
688
- * - `'rule'` — Horizontal or vertical reference line at a constant value
689
- */
690
- declare const GEOM_NAMES: readonly ["point", "line", "area", "bar", "rule"];
691
-
692
- export declare interface GeomCompilerInput {
693
- /** The dataset after stat transformation */
694
- data: Dataset;
695
- /** The effective mapping for the layer */
696
- mapping: AesMapping;
697
- /** Geom-specific params */
698
- params: LayerSpec['params'];
699
- }
700
-
701
- /**
702
- * Open geom identity: the built-in vocabulary plus any custom registration's `type`. The layer types,
703
- * the compiled layer, and the geom registry key on this so a registered custom geom is a first-class
704
- * mark; the built-in literals stay for autocomplete. Core never *decides* on the name (the decisions
705
- * live on the geom definition) — this is purely the identity a layer carries.
706
- */
707
- declare type GeomIdentity = GeomName | (string & {});
708
-
709
- /**
710
- * Input to a geom's mapping validation. The validator resolves the stat-computed aesthetics and the
711
- * effective mapping, so the geom only expresses its own invariant (e.g. a rule needs exactly one
712
- * numeric axis) without reaching for a registry.
713
- */
714
- declare interface GeomMappingValidationInput {
715
- /** Layer id, for issue attribution. */
716
- layerId: string;
717
- /** The effective mapping: spec mapping merged with the layer's. */
718
- mapping: AesMapping;
719
- /** Aesthetics a stat computes at compile time, so a missing literal there is not an error. */
720
- computedVariables: ReadonlySet<AestheticKey>;
721
- }
722
-
723
- /** A built-in geom's name — the default vocabulary the spec builder offers out of the box. */
724
- export declare type GeomName = (typeof GEOM_NAMES)[number];
725
-
726
- /**
727
- * Maps each geom type name to its resolved parameter type.
728
- */
729
- declare interface GeomParamsMap {
730
- point: PointGeomParams;
731
- line: LineGeomParams;
732
- area: AreaGeomParams;
733
- bar: BarGeomParams;
734
- rule: RuleGeomParams;
735
- }
736
-
737
- /**
738
- * One extra tooltip row a geom contributes for the hovered observation — a named reading of a data
739
- * column the standard one-row-per-series tooltip would not surface on its own. An OHLC candle, for
740
- * instance, declares four (open/high/low/close); the compiler derives each row's display format from
741
- * the column and the renderer materialises the values for the observation under the cursor. Pure
742
- * data: the `label` is static text and the `variable` names a column, so the rows ride in the
743
- * serialisable compiled spec.
744
- */
745
- export declare interface GeomTooltipRow {
746
- /** The row's label (e.g. "Open"). Static text the geom supplies. */
747
- label: string;
748
- /** The data column whose per-observation value the row displays. */
749
- variable: VariableName;
750
- }
751
-
752
- declare interface GetValuesOptions {
753
- /** The expected type of the values. */
754
- type?: DataType;
755
- /** Whether to skip null values. Defaults to `false`. */
756
- skipNulls?: boolean;
757
- /** Whether to return distinct values. Defaults to `false`. */
758
- distinct?: boolean;
759
- }
760
-
761
- /**
762
- * Grid/border visibility a geom requests per coord type — a bar hides the categorical-axis grid,
763
- * for instance. A geom declares these so the axis guide resolves grid policy from the definition
764
- * instead of a geom-keyed lookup. Every field absent means the geom imposes no policy.
765
- */
766
- export declare interface GridPolicy {
767
- hideGridX?: boolean;
768
- hideGridY?: boolean;
769
- hideBorder?: boolean;
770
- }
771
-
772
- /**
773
- * A group by operation on a dataset. This is returned when calling `new Dataset(...).groupBy(...)`.
774
- */
775
- declare class GroupBy {
776
- private groupedBy;
777
- private grouped;
778
- private variableMetadata;
779
- constructor(groupedBy: VariableName[], grouped: Table, variableMetadata: VariableMetadata);
780
- /**
781
- * Iterates over each group.
782
- */
783
- forEach(callback: (group: Dataset, groupKey: string, groupIndex: number) => void): void;
784
- /**
785
- * Aggregates the variables in each group.
786
- */
787
- rollup(aggregations: AggregationInput): Dataset;
788
- /**
789
- * Computes the group key based on the first value of the grouped variable. If multiple variables are grouped, returns a composite key.
790
- */
791
- private getStableKey;
792
- }
793
-
794
- /** A map of variable names grouped by their type. */
795
- declare type GroupedVariableNames = {
796
- [key in DataType]: VariableName[];
797
- };
798
-
799
- declare type GuideGeometry = 'linear' | 'circular' | 'radial';
800
-
801
- /**
802
- * How a geom composes highlight matches above its base render. Declared per geom on the geom
803
- * definition and stamped onto `CompiledLayer.highlight.strategy` by the layer compiler.
804
- *
805
- * - `'observation-rerender'`: matched observations re-render through the same plugin against a
806
- * filtered sub-dataset. Used by per-observation surface geoms (bar, rule).
807
- * - `'overlay-anchor'`: series-scope matches go through the matched re-render pass;
808
- * data-point / x-value-scope matches surface as a dot + value label at the plugin's
809
- * reported anchor. Used by line, area, point.
810
- */
811
- export declare type HighlightStrategy = 'observation-rerender' | 'overlay-anchor';
812
-
813
- /**
814
- * Resolved identity stat spec.
815
- */
816
- declare interface IdentityStatSpec {
817
- type: 'identity';
818
- }
819
-
820
- /**
821
- * Recovers where a raw sub-value sits inside an already-scaled interval. Given a raw `[rawLo, rawHi]`
822
- * pair that the compiler mapped to the scaled `[scaledLo, scaledHi]` endpoints, returns the scaled
823
- * position of `raw` by affine interpolation. The Tier-B trick a candlestick uses to place its open/close
824
- * inside the scaled `[low, high]` wick without re-running the y-scale.
825
- *
826
- * Exact only when the scale between raw and scaled space is **linear** — both endpoints pin a straight
827
- * line every interior value reads off. A degenerate interval (`rawLo === rawHi`) returns `scaledLo`.
828
- */
829
- export declare function interpolateInScaledInterval(raw: number, rawLo: number, rawHi: number, scaledLo: number, scaledHi: number): number;
830
-
831
- /**
832
- * Curve interpolation method for lines and areas.
833
- *
834
- * - `'linear'` — Straight segments between points
835
- * - `'catmull-rom'` — Smooth spline through points
836
- */
837
- declare type InterpolateType = 'linear' | 'catmull-rom';
838
-
839
- /**
840
- * Any resolved layer spec: a built-in or a custom registration. All properties are fully resolved.
841
- */
842
- declare type LayerSpec = BuiltinLayerSpec | CustomLayerSpec;
843
-
844
- declare interface LayerSpecBase {
845
- type: 'layer';
846
- id: string;
847
- mapping: AesMapping;
848
- stat: StatSpec;
849
- position: PositionType;
850
- yScaleType: YScaleType;
851
- transforms: TransformInput[];
852
- interactive: boolean;
853
- dataLabels: DataLabelsConfig;
854
- }
855
-
856
- declare type LayerSpecOf<G extends GeomName> = LayerSpecBase & {
857
- geom: G;
858
- params: GeomParamsMap[G];
859
- };
860
-
861
- /**
862
- * Line-specific parameters
863
- */
864
- declare interface LineGeomParams {
865
- lineWidth: number | 'auto';
866
- /**
867
- * Interpolation method to use for the line.
868
- * @default 'linear'
869
- */
870
- interpolate: InterpolateType;
871
- /**
872
- * How to handle missing (NULL/undefined) values.
873
- * @default 'gap'
874
- */
875
- missingValues: MissingValuesType;
876
- }
877
-
878
- /**
879
- * Stroke style for line rendering.
880
- *
881
- * - `'solid'` — Continuous unbroken stroke
882
- * - `'dashed'` — Repeating dash pattern
883
- * - `'dotted'` — Repeating dot pattern
884
- */
885
- declare type LineStyleType = 'solid' | 'dashed' | 'dotted';
886
-
887
- /**
888
- * A value format that switches on a peer variable's value. Produced by transforms whose output is
889
- * structurally observation-dependent (see `reshapeFromWideToLong`).
890
- */
891
- declare interface LookupValueFormat {
892
- type: 'lookup';
893
- /** Peer variable whose stringified value selects the case. */
894
- byVariable: VariableName;
895
- /** Case format keyed by `getStableKey(observation[byVariable])`. */
896
- cases: Record<string, ExplicitValueFormat>;
897
- /** Format used when an observation isn't available, or its case-key is absent from `cases`. */
898
- fallback: ExplicitValueFormat;
899
- }
900
-
901
- /** The data-space axis a `CartesianCoordSystem` uses as the main (independent) axis. */
902
- declare type MainAxis = 'x' | 'y';
903
-
904
- /** Declares one mark kind's own columns and the data type of each. */
905
- export declare type MarkColumnSchema = Record<string, DataType>;
906
-
907
- /**
908
- * Builds one columnar {@link Dataset} from heterogeneous marks discriminated by a `kind` column — *the*
909
- * Tier-C dataset shape (node+link, group+leaf, node+edge). Each kind declares its own columns; the union
910
- * across kinds forms the dataset's columns, and a row's off-kind columns are filled with `null` **by
911
- * construction**, so the null-padding invariant a hand-built builder maintains by hand (and breaks when a
912
- * column is omitted from one kind's push) can no longer drift.
913
- */
914
- declare class MarkTable {
915
- /** Column name → declared type, accumulated as the union across every declared kind. */
916
- private readonly columnTypes;
917
- /** Kind name → the column names that kind owns. */
918
- private readonly kindColumns;
919
- private readonly rows;
920
- /** Declares a mark kind and the columns it carries. Throws if the kind repeats or a column's type conflicts. */
921
- kind(name: string, columns: MarkColumnSchema): this;
922
- /** Appends one row for a declared kind. Throws if the kind is unknown, or a value misses/overshoots the kind's columns. */
923
- push(kind: string, values: Record<string, DataValue>): this;
924
- /** Materialises the rows into a {@link Dataset}, null-padding every off-kind column. */
925
- toDataset(options: ToDatasetOptions): Dataset;
926
- }
927
-
928
- /**
929
- * Resolved mean stat spec.
930
- */
931
- declare interface MeanStatSpec {
932
- type: 'mean';
933
- }
934
-
935
- /**
936
- * Strategy for handling null/undefined values in lines and areas.
937
- *
938
- * - `'zero'` — Replace missing values with zero
939
- * - `'gap'` — Leave a visible gap where values are missing
940
- * - `'connect'` — Skip missing values and connect adjacent valid points
941
- */
942
- declare type MissingValuesType = 'zero' | 'gap' | 'connect';
943
-
944
- declare interface NumericValueFormat {
945
- type: 'decimal' | 'integer' | 'percentage' | 'duration';
946
- }
947
-
948
- /** A single row of data, mapping every variable name to the value in that row. */
949
- declare type Observation = Record<VariableName, DataValue>;
950
-
951
- /** Points at a single observation by its anchor value and series. */
952
- declare interface ObservationAnchorInput {
953
- /** Pick a specific layer when multiple share the same `(anchorValue, groupValue)` pair. */
954
- layerIndex?: number;
955
- /** Value on the main axis (x in cartesian, y in flipped). */
956
- anchorValue: DataValue;
957
- /** Series identity (the `group` aesthetic value). */
958
- groupValue: DataValue;
959
- }
960
-
961
- /**
962
- * Point-specific parameters
963
- */
964
- declare interface PointGeomParams {
965
- size: number;
966
- }
967
-
968
- /**
969
- * Polar coordinate system - for pie charts, radar charts, etc.
970
- * Angular params (theta, startAngle) are consumed by the compiler during coordTransform.
971
- * `innerRadius` is also exposed here so the renderer can recover the donut hole geometry
972
- * (e.g. to place a centred headline) without reaching into per-observation radii.
973
- */
974
- declare interface PolarCoordSystem {
975
- type: 'polar';
976
- /** Axis orientation metadata for the guide compiler */
977
- axisMapping: AxisMapping;
978
- /** Donut hole radius as a fraction of the outer radius (0-1). 0 for a full pie. */
979
- innerRadius: number;
980
- }
981
-
982
- /**
983
- * One position channel a geom declares: where it sits ({@link ChannelAxis}, {@link PositionChannelRole}),
984
- * how its raw column maps to a position ({@link PositionValueKind}), and an open identity its column
985
- * derives from. A geom's channels are the manifest the position mapper and coord projection iterate
986
- * instead of hardcoding the column set.
987
- */
988
- export declare type PositionChannel = RolePositionChannel | ScalarPositionChannel;
989
-
990
- declare interface PositionChannelBase {
991
- axis: ChannelAxis;
992
- valueKind: PositionValueKind;
993
- }
994
-
995
- /**
996
- * Position adjustment for overlapping geometries.
997
- *
998
- * - `'stack'` — Stack geometries on top of each other (e.g. stacked bar chart)
999
- * - `'dodge'` — Place geometries side by side (e.g. grouped bar chart)
1000
- * - `'identity'` — No adjustment, use raw positions (e.g. scatter plot, allows overlapping)
1001
- * - `'fill'` — Normalize stacks to fill 100% of the axis (e.g. 100% stacked bar chart)
1002
- */
1003
- export declare type PositionType = 'stack' | 'dodge' | 'identity' | 'fill';
1004
-
1005
- /**
1006
- * How a channel's raw column becomes a scaled position.
1007
- * - `value` — the column holds data-domain values mapped directly through the scale.
1008
- * - `bandOffset` — the column holds fractional offsets around the scaled axis point, sized by the
1009
- * scale's bandwidth (a bar's left/right edges relative to its band centre).
1010
- */
1011
- declare type PositionValueKind = 'value' | 'bandOffset';
1012
-
1013
- /**
1014
- * Reads an aesthetic value by an open channel name — built-in (`x`, `color`, …) or custom. A custom
1015
- * geom maps extra channels (a box plot's `q1`/`median`/`q3`, an error bar's bounds) under names outside
1016
- * the closed {@link AestheticKey} set; those keys ride in the mapping at runtime and are read here
1017
- * through the one sanctioned widening, so a channel's value is sourced from `aes` rather than `params`.
1018
- */
1019
- export declare function readAesthetic(aesMapping: AesMapping, name: string): AestheticValue | undefined;
1020
-
1021
- /**
1022
- * Reads an author-named numeric column from an observation with the same null-discipline as the
1023
- * built-in position/visual readers (`getX`, `getColor`, …): a missing or wrong-typed value is
1024
- * `null`, never silently coerced to `0`. A custom geom writes its own columns and has no typed
1025
- * accessor for them; these readers fill that gap without re-deriving the coercion per geom.
1026
- *
1027
- * Pass `fallback` to opt into a default for genuinely-missing values; the overload then narrows the
1028
- * return to `number`, so a geom that wants `0`-on-missing says so explicitly.
1029
- */
1030
- export declare function readNumber(observation: Observation, key: string): number | null;
1031
-
1032
- export declare function readNumber(observation: Observation, key: string, fallback: number): number;
1033
-
1034
- /** Reads an author-named string column from an observation; missing or wrong-typed is `null` unless a `fallback` is given. */
1035
- export declare function readString(observation: Observation, key: string): string | null;
1036
-
1037
- export declare function readString(observation: Observation, key: string, fallback: string): string;
1038
-
1039
- /***************************************************************
1040
- * Reshape Transform
1041
- ***************************************************************/
1042
- declare interface ReshapeOptions {
1043
- /**
1044
- * Numeric variables to collapse into rows.
1045
- * Defaults to all numeric variables
1046
- * */
1047
- reshape?: VariableName[];
1048
- /**
1049
- * Variables to carry through unchanged.
1050
- * Defaults to all categorical/temporal variables
1051
- * */
1052
- keep?: VariableName[];
1053
- /**
1054
- * Name of the output column containing the original variable names.
1055
- * @default 'key'
1056
- * */
1057
- keyName?: VariableName;
1058
- /**
1059
- * Name of the output column containing the original values.
1060
- * @default 'value'
1061
- * */
1062
- valueName?: VariableName;
1063
- }
1064
-
1065
- declare interface ReshapeTransformInput {
1066
- type: 'transform';
1067
- transformType: 'reshape';
1068
- options: ReshapeOptions;
1069
- }
1070
-
1071
- /**
1072
- * A custom annotation's coordinate resolved to normalized panel space, in **top-left [0,1]** — the
1073
- * space the draw function paints in. `observation` is attached only for a snap-to-observation
1074
- * coordinate (so the draw can read the bound row's columns); unit/data targets are synthetic points.
1075
- */
1076
- export declare interface ResolvedTarget {
1077
- x: number;
1078
- y: number;
1079
- mode: 'data' | 'unit' | 'observation';
1080
- observation?: Observation;
1081
- }
1082
-
1083
- /**
1084
- * A structural channel — the per-axis anchor (`point`) or one end of an interval (`lower`/`upper`).
1085
- * Its {@link PositionChannel.name | name} defaults to the role, so the canonical position columns
1086
- * (`x`, `xMin`, `yMax`, …) are preserved and a geom declares `{ axis, role, valueKind }` with no name.
1087
- */
1088
- declare interface RolePositionChannel extends PositionChannelBase {
1089
- role: 'point' | 'lower' | 'upper';
1090
- /** Open identity override; defaults to {@link role}. Built-ins omit it to keep canonical columns. */
1091
- name?: string;
1092
- }
1093
-
1094
- /**
1095
- * Rule-specific parameters.
1096
- */
1097
- declare interface RuleGeomParams {
1098
- /** Stroke color; falls back to a theme token. */
1099
- color?: string;
1100
- strokeWidth: number;
1101
- lineType: LineStyleType;
1102
- /** Optional inline text label rendered alongside the line. */
1103
- label?: string;
1104
- labelPosition: RuleLabelPosition;
1105
- }
1106
-
1107
- /**
1108
- * Where the optional inline label is anchored along a reference line.
1109
- */
1110
- declare type RuleLabelPosition = 'start' | 'end';
1111
-
1112
- /**
1113
- * A standalone scaled value on an axis, identified by an open {@link ScalarPositionChannel.name | name}.
1114
- * Always `value`-kind — a lone value has no band to offset against. Its column is namespaced from the
1115
- * name, so two geoms' scalars never collide and neither freezes an internal column (the decision-9
1116
- * litmus): a box plot declares `q1`/`median`/`q3`, an error bar its CI bounds, and the position mapper
1117
- * scales each through the axis scale exactly as it scales an interval bound.
1118
- */
1119
- declare interface ScalarPositionChannel extends PositionChannelBase {
1120
- role: 'scalar';
1121
- valueKind: 'value';
1122
- name: string;
1123
- /**
1124
- * The mapping key this channel sources its raw values from. When set, the position mapper reads
1125
- * `mapping[aes]`'s column and scales it in place — so the value is authored as `aes` (a box plot's
1126
- * `q1`), not hand-copied from `params`. When omitted, the channel reads the column the geom wrote
1127
- * under {@link variableFor}`(axis, name)` (a geom that computes the value itself).
1128
- */
1129
- aes?: string;
1130
- }
1131
-
1132
- export declare type ScaledVisualAestheticKey = 'color' | 'size' | 'alpha' | 'strokeWidth' | 'lineType';
1133
-
1134
- /**
1135
- * Regression methods supported by the `smooth` stat.
1136
- */
1137
- declare type SmoothMethod = 'linear' | 'loess' | 'exponential' | 'logarithmic' | 'quadratic' | 'power' | 'polynomial';
1138
-
1139
- /**
1140
- * Resolved smooth (regression) stat spec.
1141
- */
1142
- declare interface SmoothStatSpec {
1143
- type: 'smooth';
1144
- method: SmoothMethod;
1145
- /** Polynomial order — only meaningful when `method: 'polynomial'`. */
1146
- order: number;
1147
- /** LOESS bandwidth — only meaningful when `method: 'loess'`. */
1148
- bandwidth: number;
1149
- }
1150
-
1151
- /**
1152
- * Sorts the data by the x variable if it is numeric or temporal.
1153
- */
1154
- export declare const sortByXIfContinuous: (data: Dataset, mapping: AesMapping) => Dataset;
1155
-
1156
- /***************************************************************
1157
- * Sort Transform
1158
- ***************************************************************/
1159
- declare interface SortOptions {
1160
- /** The variable to sort by. */
1161
- variableName: VariableName;
1162
- /** Sort direction. @default 'asc' */
1163
- direction?: 'asc' | 'desc';
1164
- }
1165
-
1166
- declare interface SortTransformInput {
1167
- type: 'transform';
1168
- transformType: 'sort';
1169
- options: SortOptions;
1170
- }
1171
-
1172
- /**
1173
- * The kind of spatial structure a geom presents for hit-testing. Each value selects one of the
1174
- * runtime's index builders, so the descriptor lets the engine dispatch on declared data instead
1175
- * of branching on the geom name.
1176
- *
1177
- * `render-hit-test` is the Tier-C escape hatch: the geom's geometry comes from a layout algorithm,
1178
- * not from scales, so the compiler cannot build a spatial index from position columns. The geom
1179
- * instead provides a render-side hit-test function (injected per-instance through the renderer),
1180
- * and the engine resolves the observation it returns against the declared identity key. Only the
1181
- * kind rides in the compiled spec — the closure never crosses the serialisable boundary.
1182
- */
1183
- export declare type SpatialIndexKind = 'buckets' | 'rects' | 'points' | 'arcs' | 'noop' | 'render-hit-test';
1184
-
1185
- /**
1186
- * Discriminated union of all resolved stat specs (post-resolution).
1187
- */
1188
- declare type StatSpec = IdentityStatSpec | CountStatSpec | SmoothStatSpec | MeanStatSpec;
1189
-
1190
- /**
1191
- * Visual signature of a geom's mark, decoupled from `GeomName` because legends and tooltips care
1192
- * only about the shape that best evokes the on-canvas mark, not the geom's spec-level identity.
1193
- *
1194
- * - `square` → a filled rect (bar)
1195
- * - `line` → a horizontal stroke
1196
- * - `area` → a filled region with a stroke accent
1197
- * - `circle` → a point
1198
- * - `slice` → a pie / donut wedge (a `square` mark refined under polar coords)
1199
- */
1200
- export declare type SwatchShape = 'square' | 'line' | 'circle' | 'area' | 'slice';
1201
-
1202
- declare type Table = internal.ColumnTable;
1203
-
1204
- declare interface TemporalValueFormat {
1205
- type: 'datetime' | 'time' | 'date' | 'year' | 'quarter' | 'month_year' | 'month' | 'weekly_date_range_with_year' | 'weekly_date_range' | 'day_month';
1206
- /** Template string representing how values of this type have been formatted. ie. dd-mm-yyyy */
1207
- dateFormat?: string;
1208
- }
1209
-
1210
- declare interface ToDatasetOptions {
1211
- /** Name of the categorical column that discriminates each row's kind. Must not collide with a declared column. */
1212
- kindColumn: string;
1213
- }
1214
-
1215
- /***************************************************************
1216
- * Transform Input
1217
- ***************************************************************/
1218
- declare type TransformInput = ReshapeTransformInput | FilterTransformInput | SortTransformInput | AggregateTransformInput | ConstantTransformInput;
1219
-
1220
- /**
1221
- * Shared validation types used across compiler stages.
1222
- *
1223
- * Each validation stage (e.g. {@link LayerValidator}, the pre-pass in {@link ScaleCompiler}) collects
1224
- * {@link ValidationIssue}s and throws a single {@link SpecValidationError} at the end of its stage.
1225
- */
1226
- declare type ValidationCode = 'UNKNOWN_VARIABLE' | 'INCOMPATIBLE_TYPE' | 'MISSING_AESTHETIC' | 'INVALID_RULE_MAPPING' | 'UNSUPPORTED_COORD';
1227
-
1228
- declare interface ValidationIssue {
1229
- code: ValidationCode;
1230
- message: string;
1231
- layerId?: string;
1232
- aesthetic?: string;
1233
- }
1234
-
1235
- declare type ValueFormat = ExplicitValueFormat | LookupValueFormat;
1236
-
1237
- /**
1238
- * Constant mapping - a literal value applied to every observation.
1239
- * Analogous to Vega-Lite's `{datum: X}` / ggplot2's `aes(color = "literal")`.
1240
- */
1241
- declare interface ValueMapping {
1242
- value: DataValue;
1243
- }
1244
-
1245
- /** A column of a variable in the dataset. When `valueFormat` is omitted, the Dataset assigns a type-based default (`numeric → decimal`, `categorical → text`, `temporal → date`). */
1246
- declare type Variable = {
1247
- type: DataType;
1248
- values: DataValue[];
1249
- valueFormat?: ValueFormat;
1250
- };
1251
-
1252
- /**
1253
- * The internal dataset variable a channel reads and writes, derived from its axis and open name. The
1254
- * built-in names (`point`/`lower`/`upper`) resolve to the canonical position columns (`x`, `xMin`, …),
1255
- * so value readers and renderer recipes stay untouched; any other name resolves to a namespaced column,
1256
- * so a custom scaled channel never collides with a built-in or another geom's channel.
1257
- */
1258
- export declare function variableFor(axis: ChannelAxis, name: string): string;
1259
-
1260
- /** A map of variable names to their type and values. */
1261
- declare type VariableMap = Record<VariableName, Variable>;
1262
-
1263
- /**
1264
- * Variable mapping - references a column in the data
1265
- */
1266
- declare interface VariableMapping {
1267
- variable: string;
1268
- }
1269
-
1270
- declare type VariableMetadata = Record<VariableName, {
1271
- type: DataType;
1272
- valueFormat: ValueFormat;
1273
- }>;
1274
-
1275
- /** A type alias for variable names. */
1276
- declare type VariableName = string;
1277
-
1278
- /**
1279
- * Which Y axis a layer binds to.
1280
- */
1281
- declare type YScaleType = 'primary' | 'secondary';
1282
-
1283
- export { }