@graphysdk/viz-engine 0.0.1-plugins.3 → 0.0.1-plugins.5

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.
package/dist/index.d.ts CHANGED
@@ -96,7 +96,7 @@ export declare interface AngleExtent {
96
96
  * render-half `draw` lives in the renderer and binds to this definition by import (`defineAnnotationRenderer`).
97
97
  */
98
98
  /** Optional coordinate-count guardrail enforced by the builder; unbounded when omitted. */
99
- declare interface AnnotationArity {
99
+ export declare interface AnnotationArity {
100
100
  min?: number;
101
101
  max?: number;
102
102
  }
@@ -142,7 +142,7 @@ declare interface AnnotationDataPoint {
142
142
  rowValue?: DataValue;
143
143
  }
144
144
 
145
- declare interface AnnotationDef<TParams extends object = object, TType extends string = string> {
145
+ export declare interface AnnotationDef<TParams extends object = object, TType extends string = string> {
146
146
  type: TType;
147
147
  /** Carrier that lets the builder recover `TParams` and merge defaults before a param reaches `draw`. */
148
148
  defaultParams: TParams;
@@ -1114,7 +1114,7 @@ export declare interface CompiledFreeformArrow {
1114
1114
  hasStickerStyle: boolean;
1115
1115
  }
1116
1116
 
1117
- declare interface CompiledGeom {
1117
+ export declare interface CompiledGeom {
1118
1118
  /** The reparameterized dataset (may have new computed variables) */
1119
1119
  data: Dataset;
1120
1120
  /** Any mapping overrides produced by the geom */
@@ -1864,7 +1864,7 @@ declare interface CoordTransformInput {
1864
1864
  * - `'polar'` — Polar coordinates for pie, radar, and radial charts
1865
1865
  * - `'flip'` — Cartesian with x and y axes swapped
1866
1866
  */
1867
- declare type CoordType = 'cartesian' | 'polar' | 'flip';
1867
+ export declare type CoordType = 'cartesian' | 'polar' | 'flip';
1868
1868
 
1869
1869
  declare function count(): CountStatSpec;
1870
1870
 
@@ -1916,6 +1916,9 @@ export declare const createGroupValueReader: (data: Dataset, mapping: AesMapping
1916
1916
 
1917
1917
  export declare const createLabelValueReader: (data: Dataset, mapping: AesMapping) => (observation: Observation) => DataValue;
1918
1918
 
1919
+ /** Opens a {@link MarkTable} builder for a heterogeneous, kind-tagged geom-layout dataset. */
1920
+ export declare function createMarkTable(): MarkTable;
1921
+
1919
1922
  /**
1920
1923
  * Builds a per-observation reader for an `AestheticValue`:
1921
1924
  * - `{ value: X }` → returns `X` for every observation.
@@ -2468,6 +2471,18 @@ declare type DefaultPaletteConfig = {
2468
2471
  type: 'default';
2469
2472
  };
2470
2473
 
2474
+ /**
2475
+ * `TType` is a `const` type parameter so the literal kind name (`'calloutBox'`) survives to the type
2476
+ * level — the registration-typed builder keys `annotation.<kind>(...)` off it, the same way
2477
+ * `createGraphyBuilder` captures a geom's name. `TParams` is recovered from `defaultParams`; annotate or
2478
+ * cast it (`defaultParams: {...} as CalloutBoxParams`) when a param's literal union would otherwise widen.
2479
+ */
2480
+ export declare function defineAnnotation<const TType extends string, TParams extends object = object>(def: {
2481
+ type: TType;
2482
+ defaultParams?: TParams;
2483
+ coordinates?: AnnotationArity;
2484
+ }): AnnotationDef<TParams, TType>;
2485
+
2471
2486
  declare interface DifferenceArrowDimensions {
2472
2487
  /** Gap between the arrow start point and its anchored observation. */
2473
2488
  arrowStartGap: number;
@@ -2584,9 +2599,21 @@ export declare interface ExternalMeasurements {
2584
2599
  footerSize: BoxSize;
2585
2600
  }
2586
2601
 
2602
+ /**
2603
+ * Extracts the constant value from a `{ value }` mapping. Returns undefined for variable mappings.
2604
+ */
2605
+ export declare function extractConstantValue(aestheticValue: AestheticValue | undefined): DataValue | undefined;
2606
+
2587
2607
  /** Flattens a title, subtitle, or caption to plain text for measurement and static renderers. */
2588
2608
  export declare const extractPlainText: (content: TextContent) => string;
2589
2609
 
2610
+ /**
2611
+ * Extracts the variable name from an AestheticValue.
2612
+ * Returns the variable name for string shorthands and { variable } mappings.
2613
+ * Returns null for constant { value } mappings or undefined values.
2614
+ */
2615
+ export declare function extractVariableName(aestheticValue: AestheticValue | undefined): VariableName | null;
2616
+
2590
2617
  declare function filter(options: FilterOptions): FilterTransformInput;
2591
2618
 
2592
2619
  /***************************************************************
@@ -2623,6 +2650,24 @@ export declare function findAxisGuide(guides: CompiledGuides, scaleAestheticKey:
2623
2650
  */
2624
2651
  export declare function findLegendForAesthetic(guides: CompiledGuides, aesthetic: AestheticKey): CompiledLegendGuide | null;
2625
2652
 
2653
+ /**
2654
+ * A gate fixture: a chart authored as plain data — its spec, the custom geom(s) it uses, and the rows —
2655
+ * with no React. The codegen harness's compile and semantic gates load one (authored beside the geom as
2656
+ * `src/<name>.fixture.ts`, exporting a `fixture`) to check that the geom compiles to finite, serialisable
2657
+ * positions and that a synthetic cursor placed on each probed observation resolves hover and a localised
2658
+ * tooltip. It is the rendered chart minus the renderer, so the gates run headlessly.
2659
+ */
2660
+ export declare interface Fixture {
2661
+ /** The custom geom instance(s) to register with the compiler — the same instances the spec uses. */
2662
+ geoms: readonly Geom[];
2663
+ /** The spec rendered in `App.tsx`, built with `createGraphyBuilder` + `pipe`. */
2664
+ spec: SpecInput;
2665
+ /** Rows matching the spec's channels (OHLC for a candlestick, a node/link graph for a sankey, …). */
2666
+ data: Data;
2667
+ /** Observation indices the semantic gate fires a cursor at. Defaults to `[0]` when omitted. */
2668
+ probes?: number[];
2669
+ }
2670
+
2626
2671
  declare interface FlipCoordInput {
2627
2672
  type: 'coord';
2628
2673
  coordType: 'flip';
@@ -2792,7 +2837,7 @@ declare type GenerateTicksOptions = {
2792
2837
  * empty default and keep their typed params through the spec builder's static surface; a custom geom
2793
2838
  * names its params type and declares matching {@link defaultParams}.
2794
2839
  */
2795
- declare abstract class Geom<TParams extends object = object> {
2840
+ export declare abstract class Geom<TParams extends object = object> {
2796
2841
  /**
2797
2842
  * The aesthetics an author must map for this geom. Built-ins list closed aesthetic keys
2798
2843
  * (`['x','y']`); a custom geom may also list open channel names (a box plot's `min`/`q1`/…) that it
@@ -2884,6 +2929,13 @@ declare abstract class Geom<TParams extends object = object> {
2884
2929
  * renderer how to place the annotation.
2885
2930
  */
2886
2931
  resolveAnchorPosition(_observation: Observation, _coordSystem: CoordSystem): AnchorPosition | null;
2932
+ /**
2933
+ * Reparameterizes the stat-transformed data into the shape this geom's geometry needs, the central
2934
+ * hook a custom geom implements. Receives the transformed dataset, effective mapping and geom params;
2935
+ * returns the dataset with any computed position variables added (e.g. a bar's `xMin`/`xMax`/`yMin`
2936
+ * interval), the mapping overrides the geom injects, and any extra tooltip rows it contributes. The
2937
+ * compile pipeline runs this per layer before the position and visual mappers read the result.
2938
+ */
2887
2939
  abstract compile(input: GeomCompilerInput): CompiledGeom;
2888
2940
  /**
2889
2941
  * Validates the layer's mapping against invariants specific to this geom (e.g. a rule needs exactly
@@ -2952,7 +3004,7 @@ declare class GeomCompiler {
2952
3004
  resolveAnchorPosition(geomName: GeomIdentity, observation: Observation, coordSystem: CoordSystem): AnchorPosition | null;
2953
3005
  }
2954
3006
 
2955
- declare interface GeomCompilerInput {
3007
+ export declare interface GeomCompilerInput {
2956
3008
  /** The dataset after stat transformation */
2957
3009
  data: Dataset;
2958
3010
  /** The effective mapping for the layer */
@@ -3020,7 +3072,7 @@ declare class GeomRegistry extends Registry<string, Geom> {
3020
3072
  * data: the `label` is static text and the `variable` names a column, so the rows ride in the
3021
3073
  * serialisable compiled spec.
3022
3074
  */
3023
- declare interface GeomTooltipRow {
3075
+ export declare interface GeomTooltipRow {
3024
3076
  /** The row's label (e.g. "Open"). Static text the geom supplies. */
3025
3077
  label: string;
3026
3078
  /** The data column whose per-observation value the row displays. */
@@ -3244,7 +3296,7 @@ declare type GraphyPaletteVariant = 'default' | 'waterfall';
3244
3296
  * for instance. A geom declares these so the axis guide resolves grid policy from the definition
3245
3297
  * instead of a geom-keyed lookup. Every field absent means the geom imposes no policy.
3246
3298
  */
3247
- declare interface GridPolicy {
3299
+ export declare interface GridPolicy {
3248
3300
  hideGridX?: boolean;
3249
3301
  hideGridY?: boolean;
3250
3302
  hideBorder?: boolean;
@@ -3648,10 +3700,10 @@ export declare class HoverEngine {
3648
3700
  */
3649
3701
  private nonInteractiveLayerIds;
3650
3702
  /**
3651
- * Render-side hit-testers registered per layer for `render-hit-test` (Tier-C) layers, keyed by
3703
+ * Render-side hit-testers registered per layer for `render-hit-test` (geom-layout) layers, keyed by
3652
3704
  * `CompiledLayer.id`. The renderer owns this map and injects it via {@link setHitTesters}; the
3653
3705
  * engine holds the live reference so a plugin mounting or updating its tester is visible at the
3654
- * next `query()` without a re-index. Empty for charts with no Tier-C geom.
3706
+ * next `query()` without a re-index. Empty for charts with no geom-layout geom.
3655
3707
  */
3656
3708
  private hitTesters;
3657
3709
  constructor({ layers, coordSystem }: HoverEngineInput);
@@ -3792,6 +3844,17 @@ declare interface InferredScaleInput {
3792
3844
 
3793
3845
  declare type InferredScaleOptions = ContinuousScaleOptions | DiscreteScaleOptions | DatetimeScaleOptions;
3794
3846
 
3847
+ /**
3848
+ * Recovers where a raw sub-value sits inside an already-scaled interval. Given a raw `[rawLo, rawHi]`
3849
+ * pair that the compiler mapped to the scaled `[scaledLo, scaledHi]` endpoints, returns the scaled
3850
+ * position of `raw` by affine interpolation. The geom-scaled trick a candlestick uses to place its open/close
3851
+ * inside the scaled `[low, high]` wick without re-running the y-scale.
3852
+ *
3853
+ * Exact only when the scale between raw and scaled space is **linear** — both endpoints pin a straight
3854
+ * line every interior value reads off. A degenerate interval (`rawLo === rawHi`) returns `scaledLo`.
3855
+ */
3856
+ export declare function interpolateInScaledInterval(raw: number, rawLo: number, rawHi: number, scaledLo: number, scaledHi: number): number;
3857
+
3795
3858
  /**
3796
3859
  * Curve interpolation method for lines and areas.
3797
3860
  *
@@ -4283,6 +4346,30 @@ declare interface MappingItem {
4283
4346
  mapping: AesMapping;
4284
4347
  }
4285
4348
 
4349
+ /** Declares one mark kind's own columns and the data type of each. */
4350
+ export declare type MarkColumnSchema = Record<string, DataType>;
4351
+
4352
+ /**
4353
+ * Builds one columnar {@link Dataset} from heterogeneous marks discriminated by a `kind` column — *the*
4354
+ * geom-layout dataset shape (node+link, group+leaf, node+edge). Each kind declares its own columns; the union
4355
+ * across kinds forms the dataset's columns, and a row's off-kind columns are filled with `null` **by
4356
+ * construction**, so the null-padding invariant a hand-built builder maintains by hand (and breaks when a
4357
+ * column is omitted from one kind's push) can no longer drift.
4358
+ */
4359
+ declare class MarkTable {
4360
+ /** Column name → declared type, accumulated as the union across every declared kind. */
4361
+ private readonly columnTypes;
4362
+ /** Kind name → the column names that kind owns. */
4363
+ private readonly kindColumns;
4364
+ private readonly rows;
4365
+ /** Declares a mark kind and the columns it carries. Throws if the kind repeats or a column's type conflicts. */
4366
+ kind(name: string, columns: MarkColumnSchema): this;
4367
+ /** Appends one row for a declared kind. Throws if the kind is unknown, or a value misses/overshoots the kind's columns. */
4368
+ push(kind: string, values: Record<string, DataValue>): this;
4369
+ /** Materialises the rows into a {@link Dataset}, null-padding every off-kind column. */
4370
+ toDataset(options: ToDatasetOptions): Dataset;
4371
+ }
4372
+
4286
4373
  declare function mean(): MeanStatSpec;
4287
4374
 
4288
4375
  /**
@@ -4476,7 +4563,7 @@ declare interface PanelConfig {
4476
4563
  }
4477
4564
 
4478
4565
  /**
4479
- * A render-side hit-test a Tier-C geom registers for a `render-hit-test` layer. The engine calls it
4566
+ * A render-side hit-test a geom-layout geom registers for a `render-hit-test` layer. The engine calls it
4480
4567
  * with the cursor in panel `[0, 1]` space using a **top-left origin (y-down)** — the same frame the
4481
4568
  * geom paints in (unit-space SVG / `toPercent`), so the geom can test against its own rendered
4482
4569
  * geometry without re-flipping. It returns the declared identity `key` of the observation under the
@@ -4745,7 +4832,7 @@ declare interface PositionalScaleMethods {
4745
4832
  * derives from. A geom's channels are the manifest the position mapper and coord projection iterate
4746
4833
  * instead of hardcoding the column set.
4747
4834
  */
4748
- declare type PositionChannel = RolePositionChannel | ScalarPositionChannel;
4835
+ export declare type PositionChannel = RolePositionChannel | ScalarPositionChannel;
4749
4836
 
4750
4837
  declare interface PositionChannelBase {
4751
4838
  axis: ChannelAxis;
@@ -4820,6 +4907,32 @@ export declare interface RadiusExtent {
4820
4907
  outerRadius: NumericDataValue;
4821
4908
  }
4822
4909
 
4910
+ /**
4911
+ * Reads an aesthetic value by an open channel name — built-in (`x`, `color`, …) or custom. A custom
4912
+ * geom maps extra channels (a box plot's `q1`/`median`/`q3`, an error bar's bounds) under names outside
4913
+ * the closed {@link AestheticKey} set; those keys ride in the mapping at runtime and are read here
4914
+ * through the one sanctioned widening, so a channel's value is sourced from `aes` rather than `params`.
4915
+ */
4916
+ export declare function readAesthetic(aesMapping: AesMapping, name: string): AestheticValue | undefined;
4917
+
4918
+ /**
4919
+ * Reads an author-named numeric column from an observation with the same null-discipline as the
4920
+ * built-in position/visual readers (`getX`, `getColor`, …): a missing or wrong-typed value is
4921
+ * `null`, never silently coerced to `0`. A custom geom writes its own columns and has no typed
4922
+ * accessor for them; these readers fill that gap without re-deriving the coercion per geom.
4923
+ *
4924
+ * Pass `fallback` to opt into a default for genuinely-missing values; the overload then narrows the
4925
+ * return to `number`, so a geom that wants `0`-on-missing says so explicitly.
4926
+ */
4927
+ export declare function readNumber(observation: Observation, key: string): number | null;
4928
+
4929
+ export declare function readNumber(observation: Observation, key: string, fallback: number): number;
4930
+
4931
+ /** Reads an author-named string column from an observation; missing or wrong-typed is `null` unless a `fallback` is given. */
4932
+ export declare function readString(observation: Observation, key: string): string | null;
4933
+
4934
+ export declare function readString(observation: Observation, key: string, fallback: string): string;
4935
+
4823
4936
  /** A rectangle in pixel coordinates, origin at top-left. */
4824
4937
  export declare interface Rect {
4825
4938
  x: number;
@@ -5181,7 +5294,7 @@ export declare type ScaledAestheticKey = ScaledPositionAestheticKey | ScaledVisu
5181
5294
 
5182
5295
  declare type ScaledPositionAestheticKey = 'x' | 'y' | 'ySecondary';
5183
5296
 
5184
- declare type ScaledVisualAestheticKey = 'color' | 'size' | 'alpha' | 'strokeWidth' | 'lineType';
5297
+ export declare type ScaledVisualAestheticKey = 'color' | 'size' | 'alpha' | 'strokeWidth' | 'lineType';
5185
5298
 
5186
5299
  /**
5187
5300
  * Union type for all possible scale specifications (including inferred, pre-resolution).
@@ -5491,6 +5604,11 @@ declare interface SmoothStatSpec {
5491
5604
 
5492
5605
  declare function sort(options: SortOptions): SortTransformInput;
5493
5606
 
5607
+ /**
5608
+ * Sorts the data by the x variable if it is numeric or temporal.
5609
+ */
5610
+ export declare const sortByXIfContinuous: (data: Dataset, mapping: AesMapping) => Dataset;
5611
+
5494
5612
  /***************************************************************
5495
5613
  * Sort Transform
5496
5614
  ***************************************************************/
@@ -5518,7 +5636,7 @@ export declare interface SourceContent {
5518
5636
  * runtime's index builders, so the descriptor lets the engine dispatch on declared data instead
5519
5637
  * of branching on the geom name.
5520
5638
  *
5521
- * `render-hit-test` is the Tier-C escape hatch: the geom's geometry comes from a layout algorithm,
5639
+ * `render-hit-test` is the geom-layout escape hatch: the geom's geometry comes from a layout algorithm,
5522
5640
  * not from scales, so the compiler cannot build a spatial index from position columns. The geom
5523
5641
  * instead provides a render-side hit-test function (injected per-instance through the renderer),
5524
5642
  * and the engine resolves the observation it returns against the declared identity key. Only the
@@ -5530,7 +5648,7 @@ export declare interface SourceContent {
5530
5648
  * time (no stored cartesian, no Delaunay), staying correct across resizes. Geoms never declare it; a
5531
5649
  * polar coord refines a `points`-natural mark to it during the coord transform.
5532
5650
  */
5533
- declare type SpatialIndexKind = 'buckets' | 'rects' | 'points' | 'arcs' | 'noop' | 'render-hit-test' | 'polar-points';
5651
+ export declare type SpatialIndexKind = 'buckets' | 'rects' | 'points' | 'arcs' | 'noop' | 'render-hit-test' | 'polar-points';
5534
5652
 
5535
5653
  /**
5536
5654
  * A layer's geometry-agnostic hit-test declaration. Pure serialisable data riding in the compiled
@@ -5820,6 +5938,11 @@ export declare interface TextMeasurer {
5820
5938
  measureText: (text: string, font: FontSpec) => MeasuredText;
5821
5939
  }
5822
5940
 
5941
+ declare interface ToDatasetOptions {
5942
+ /** Name of the categorical column that discriminates each row's kind. Must not collide with a declared column. */
5943
+ kindColumn: string;
5944
+ }
5945
+
5823
5946
  /** A chart's semantic content for the hovered observations, in reading order. */
5824
5947
  export declare interface TooltipContent {
5825
5948
  /** Localized main-axis value of the primary's observation. `null` for polar. */
@@ -5957,6 +6080,14 @@ declare type Variable = {
5957
6080
  valueFormat?: ValueFormat;
5958
6081
  };
5959
6082
 
6083
+ /**
6084
+ * The internal dataset variable a channel reads and writes, derived from its axis and open name. The
6085
+ * built-in names (`point`/`lower`/`upper`) resolve to the canonical position columns (`x`, `xMin`, …),
6086
+ * so value readers and renderer recipes stay untouched; any other name resolves to a namespaced column,
6087
+ * so a custom scaled channel never collides with a built-in or another geom's channel.
6088
+ */
6089
+ export declare function variableFor(axis: ChannelAxis, name: string): string;
6090
+
5960
6091
  /** A map of variable names to their type and values. */
5961
6092
  declare type VariableMap = Record<VariableName, Variable>;
5962
6093