@graphysdk/viz-engine 0.0.1-experimental.0 → 0.0.1-experimental.1

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
@@ -16,7 +16,11 @@
16
16
  * @packageDocumentation
17
17
  */
18
18
 
19
+ import { Area } from 'd3-shape';
20
+ import { CurveFactory } from 'd3-shape';
19
21
  import { internal } from 'arquero';
22
+ import { Line } from 'd3-shape';
23
+ import { Translator } from '@graphysdk/i18n';
20
24
 
21
25
  /** Maps each visual channel (x, y, color, size, ...) to a data column or constant value. */
22
26
  export declare interface AesMapping {
@@ -259,6 +263,11 @@ export declare interface AreaGeomParams {
259
263
  missingValues: MissingValuesType;
260
264
  }
261
265
 
266
+ export declare interface AreaPathGenerators {
267
+ lineGenerator: Line<Observation>;
268
+ areaGenerator: Area<Observation>;
269
+ }
270
+
262
271
  /** One end of a freeform arrow, positioned as a fraction of the plot rect (0..1) so it re-flows on resize. */
263
272
  export declare interface ArrowEndpoint {
264
273
  /** 0..1 of plot width. */
@@ -627,6 +636,13 @@ declare interface BuildLayerYValueFormatterInput {
627
636
  locale: Locale;
628
637
  }
629
638
 
639
+ /**
640
+ * Builds the SVG arc path for a polar bar (pie / donut slice).
641
+ *
642
+ * Returns `null` for an empty slice (no angular span or no radius) that d3 cannot render.
643
+ */
644
+ export declare const buildPolarBarArcPath: (input: PolarBarArcInput) => string | null;
645
+
630
646
  /**
631
647
  * Pure projection of `(compiled, hover)` into the tooltip's `{ header, rows }`. Pure (no I/O, no
632
648
  * mutation) — safe to memoize on its input.
@@ -2014,6 +2030,18 @@ declare interface CountStatSpec {
2014
2030
  /** Reader for the raw value behind a layer's `alpha` mapping. */
2015
2031
  export declare const createAlphaValueReader: (data: Dataset, mapping: AesMapping) => RawValueReader;
2016
2032
 
2033
+ /**
2034
+ * Builds the d3 area + top-line generators for an area layer.
2035
+ *
2036
+ * The `mainAxis === 'y'` branch is structural: d3-area exposes two separate APIs —
2037
+ * `.x(main).y0(crossMin).y1(crossMax)` for vertical fills and `.y(main).x0(crossMin).x1(crossMax)`
2038
+ * for horizontal fills — there is no orientation-agnostic setter. After `coord.flip()` has run,
2039
+ * `POSITION_VARIABLES.x` holds the measure (fill bound) and `POSITION_VARIABLES.y` the band
2040
+ * center, so the flipped branch reads `xMin`/`xMax` as the fill bounds and `y` as the main-axis
2041
+ * position.
2042
+ */
2043
+ export declare const createAreaPathGenerators: (coordSystem: CartesianCoordSystem, params: AreaGeomParams) => AreaPathGenerators;
2044
+
2017
2045
  /** Reader for the raw value behind a layer's `color` mapping. */
2018
2046
  export declare const createColorValueReader: (data: Dataset, mapping: AesMapping) => RawValueReader;
2019
2047
 
@@ -2038,9 +2066,19 @@ export declare function createEmptyHighlight(geom: GeomName): CompiledLayerHighl
2038
2066
  /** Reader for the raw value behind a layer's `group` mapping. */
2039
2067
  export declare const createGroupValueReader: (data: Dataset, mapping: AesMapping) => RawValueReader;
2040
2068
 
2069
+ /**
2070
+ * The single structural model of a headline item's rows and segments. Both the measurer (which sizes
2071
+ * each segment without a DOM) and the JSX (which paints them) read this, so a layout change — a new
2072
+ * row, a reordered segment — lands in one place and the two can't drift. Styling and font pixels are
2073
+ * resolved by each consumer from the roles; this model carries only structure, text, and gaps.
2074
+ */
2075
+ export declare const createHeadlineItemRows: (item: FormattedHeadlineItem) => HeadlineRow[];
2076
+
2041
2077
  /** Reader for the raw value behind a layer's `label` mapping. */
2042
2078
  export declare const createLabelValueReader: (data: Dataset, mapping: AesMapping) => RawValueReader;
2043
2079
 
2080
+ export declare const createLinePathGenerator: (params: LineGeomParams) => Line<Observation>;
2081
+
2044
2082
  /**
2045
2083
  * Builds a per-observation reader for an `AestheticValue`:
2046
2084
  * - `{ value: X }` → returns `X` for every observation.
@@ -2082,6 +2120,8 @@ export declare const createSizeValueReader: (data: Dataset, mapping: AesMapping)
2082
2120
  */
2083
2121
  export declare function createSpec(...items: Array<AesMapping | SpecItem>): SpecInput;
2084
2122
 
2123
+ export declare const createStableKeyGenerator: (data: Dataset, mapping: AesMapping, layerId: string) => ((observation: Observation) => string);
2124
+
2085
2125
  /** Reader for the raw value behind a layer's `strokeWidth` mapping. */
2086
2126
  export declare const createStrokeWidthValueReader: (data: Dataset, mapping: AesMapping) => RawValueReader;
2087
2127
 
@@ -2543,6 +2583,9 @@ export declare const DEFAULT_FONT_STYLE = "normal";
2543
2583
  */
2544
2584
  export declare const DEFAULT_FONT_WEIGHT = 500;
2545
2585
 
2586
+ /** Stroke width used when a line/area layer leaves `lineWidth` on `'auto'` and the observation carries none. */
2587
+ export declare const DEFAULT_LINE_WIDTH = 2;
2588
+
2546
2589
  /** Locale used when a consumer does not specify one. */
2547
2590
  export declare const DEFAULT_LOCALE: Locale;
2548
2591
 
@@ -2771,7 +2814,7 @@ export declare interface FontSpec {
2771
2814
  * Every field on the result is render-verbatim (see {@link FormattedHeadlineItem}); the renderer adds
2772
2815
  * only the arrow/colour implied by the trend `direction`. Returns null when there is no headline.
2773
2816
  */
2774
- export declare const formatHeadline: ({ headline, show, numberFormat, parsingLocale, formattingLocale, }: FormatHeadlineInput) => FormattedHeadline | null;
2817
+ export declare const formatHeadline: ({ headline, show, numberFormat, parsingLocale, formattingLocale, t, }: FormatHeadlineInput) => FormattedHeadline | null;
2775
2818
 
2776
2819
  /** Inputs to {@link formatHeadline}. `formattingLocale` overrides `parsingLocale` for display when the two differ. */
2777
2820
  export declare interface FormatHeadlineInput {
@@ -2785,6 +2828,7 @@ export declare interface FormatHeadlineInput {
2785
2828
  * ('en-GB', 'en-US', 'ar', 'pt-PT'); a `duration` figure always formats in English regardless.
2786
2829
  */
2787
2830
  formattingLocale?: Locale;
2831
+ t: Translator;
2788
2832
  }
2789
2833
 
2790
2834
  /**
@@ -3035,6 +3079,17 @@ export declare function getAlpha(observation: Observation): NumericDataValue;
3035
3079
  */
3036
3080
  export declare function getAngleExtent(observation: Observation): AngleExtent;
3037
3081
 
3082
+ /**
3083
+ * Normalized data-space bounds for a bar observation in [0, 1]² with origin at the top-left
3084
+ * (matches SVG conventions used by overlay renderers). Negative values flip the rect upside-down
3085
+ * so callers don't need to know whether the bar grows up or down from its baseline.
3086
+ *
3087
+ * `mainAxis` selects which data axis separates bars (bar length runs along the cross axis). For
3088
+ * `'x'` bars grow vertically; for `'y'` (flipped) they grow horizontally and the cross-axis
3089
+ * extent can be negative for negative values.
3090
+ */
3091
+ export declare const getBarRectBounds: (mainAxis: MainAxis, observation: Observation) => Rect | null;
3092
+
3038
3093
  /**
3039
3094
  * Reads the resolved color string from an observation.
3040
3095
  *
@@ -3046,6 +3101,10 @@ export declare function getColor(observation: Observation): string | undefined;
3046
3101
  /** Reads the coordinate lying on the cross axis of the coord system. */
3047
3102
  export declare function getCrossAxisCoordinate(mainAxis: MainAxis, point: XYPoint): number;
3048
3103
 
3104
+ export declare const getCurve: (interpolate: InterpolateType) => CurveFactory;
3105
+
3106
+ export declare const getDashArray: (lineType: LineStyleType) => string | undefined;
3107
+
3049
3108
  /**
3050
3109
  * Returns pixel dimensions for a difference arrow at the requested size.
3051
3110
  *
@@ -3064,6 +3123,10 @@ export declare const getDifferenceArrowDimensions: (size: DifferenceArrowSize, t
3064
3123
  */
3065
3124
  export declare const getGroup: (observation: Observation) => CategoricalDataValue;
3066
3125
 
3126
+ export declare function getHoverGuideLineProps(coordSystem: CartesianCoordSystem, primary: XYPoint): HoverGuideLineProps;
3127
+
3128
+ export declare function getHoverGuideRectProps(coordSystem: CartesianCoordSystem, scales: CompiledSpec['scales'], primary: HoverHit): HoverGuideRectProps | null;
3129
+
3067
3130
  /**
3068
3131
  * Reads the resolved line type (stroke style) from an observation.
3069
3132
  * Falls back to `'solid'` when no `lineType` variable was derived.
@@ -3101,6 +3164,8 @@ export declare function getRadiusExtent(observation: Observation): RadiusExtent;
3101
3164
  */
3102
3165
  export declare function getSize(observation: Observation): NumericDataValue;
3103
3166
 
3167
+ export declare const getStablePolarBarKeyGenerator: () => ((observation: Observation, index: number) => string);
3168
+
3104
3169
  /**
3105
3170
  * Reads the resolved stroke width value from an observation, in pixels.
3106
3171
  *
@@ -3431,6 +3496,21 @@ declare type GuideConfig = Pick<ConfigSpec, 'axes' | 'legend' | 'headline' | 'pa
3431
3496
  /** Geometric shape an axis traces: a straight line, a full circle, or a spoke from the centre. */
3432
3497
  declare type GuideGeometry = 'linear' | 'circular' | 'radial';
3433
3498
 
3499
+ /** Gap between the swatch and its group label, in pixels. */
3500
+ export declare const HEADLINE_SWATCH_GAP = 4;
3501
+
3502
+ /** Side length of the colour swatch in a headline group row, in pixels. */
3503
+ export declare const HEADLINE_SWATCH_SIZE = 12;
3504
+
3505
+ /** Gap between trend segments (arrow, percentage, reference), in pixels. */
3506
+ export declare const HEADLINE_TREND_GAP = 4;
3507
+
3508
+ /** Side length of the trend arrow icon, in pixels. */
3509
+ export declare const HEADLINE_TREND_ICON_SIZE = 12;
3510
+
3511
+ /** Gap between the value figure and its observation label, in pixels. */
3512
+ export declare const HEADLINE_VALUE_LABEL_GAP = 4;
3513
+
3434
3514
  /**
3435
3515
  * Comparison reference for trend indicator
3436
3516
  * - 'previous': Compare to preceding data point
@@ -3475,6 +3555,9 @@ declare interface HeadlineConfig {
3475
3555
  position: HeadlinePosition;
3476
3556
  }
3477
3557
 
3558
+ /** Which font token a text segment renders at: the large figure or the smaller chrome. */
3559
+ export declare type HeadlineFontRole = 'value' | 'label';
3560
+
3478
3561
  declare interface HeadlineGroupSwatch {
3479
3562
  color: string;
3480
3563
  shape: SwatchShape;
@@ -3570,6 +3653,32 @@ export declare interface HeadlinePlacement {
3570
3653
  */
3571
3654
  export declare type HeadlinePosition = 'above' | 'center';
3572
3655
 
3656
+ export declare interface HeadlineRow {
3657
+ role: HeadlineRowRole;
3658
+ gap: number;
3659
+ segments: HeadlineSegment[];
3660
+ ariaLabel?: string;
3661
+ }
3662
+
3663
+ /** Which row a segment stacks into, aligned with the renderer's CSS class names. */
3664
+ export declare type HeadlineRowRole = 'valueRow' | 'trendRow' | 'groupRow';
3665
+
3666
+ export declare type HeadlineSegment = {
3667
+ kind: 'text';
3668
+ textRole: HeadlineTextRole;
3669
+ fontRole: HeadlineFontRole;
3670
+ text: string;
3671
+ trendDirection?: HeadlineTrendDirection;
3672
+ } | {
3673
+ kind: 'swatch';
3674
+ swatch: HeadlineSwatch;
3675
+ size: number;
3676
+ } | {
3677
+ kind: 'trendArrow';
3678
+ direction: HeadlineTrendDirection;
3679
+ size: number;
3680
+ };
3681
+
3573
3682
  /**
3574
3683
  * Display mode for headline numbers
3575
3684
  * - 'total': Sum of all values
@@ -3589,6 +3698,11 @@ export declare type HeadlineShow = 'total' | 'average' | 'current' | 'conversion
3589
3698
  */
3590
3699
  export declare type HeadlineSize = 'auto' | 'small' | 'medium' | 'large';
3591
3700
 
3701
+ declare type HeadlineSwatch = NonNullable<FormattedHeadlineItem['swatch']>;
3702
+
3703
+ /** Which styled span a text segment maps to (drives its CSS class and colour). */
3704
+ export declare type HeadlineTextRole = 'value' | 'observation' | 'label' | 'trendPercentage' | 'trendReference';
3705
+
3592
3706
  /**
3593
3707
  * Direction of a headline's trend, and the SOLE source of the comparison's sign — drive both the
3594
3708
  * arrow and the colour off it, since `percentage` is unsigned. `flat` is neutral, so render it
@@ -3827,6 +3941,22 @@ export declare interface HoverEngineInput {
3827
3941
  coordSystem: CoordSystem;
3828
3942
  }
3829
3943
 
3944
+ /** SVG `<line>` endpoints for the continuous-composition rule. */
3945
+ declare interface HoverGuideLineProps {
3946
+ x1: string | number;
3947
+ x2: string | number;
3948
+ y1: string | number;
3949
+ y2: string | number;
3950
+ }
3951
+
3952
+ /** SVG `<rect>` attributes for the bar-composition band rect. */
3953
+ declare interface HoverGuideRectProps {
3954
+ x: string | number;
3955
+ y: string | number;
3956
+ width: string | number;
3957
+ height: string | number;
3958
+ }
3959
+
3830
3960
  /**
3831
3961
  * A single hit returned by the hover engine.
3832
3962
  *
@@ -3979,6 +4109,17 @@ export declare const isLookupValueFormat: (valueFormat: ValueFormat) => valueFor
3979
4109
 
3980
4110
  export declare const isNumericValueFormat: (valueFormat: ValueFormat) => valueFormat is NumericValueFormat | CurrencyValueFormat;
3981
4111
 
4112
+ /**
4113
+ * Whether a string is safe to assign to an `href`. Allows http, https, and
4114
+ * mailto; rejects javascript:, data:, vbscript:, and any other scheme that
4115
+ * could execute code or load arbitrary content.
4116
+ *
4117
+ * Leading control characters (NUL, tab, newline, etc.) are stripped before
4118
+ * the scheme check because the browser ignores them when parsing href, so
4119
+ * `\tjavascript:alert(1)` would otherwise sneak past a naive prefix test.
4120
+ */
4121
+ export declare const isSafeUrl: (input: unknown) => input is string;
4122
+
3982
4123
  /**
3983
4124
  * True for positions that accumulate values along an axis (`'stack'` and `'fill'`).
3984
4125
  *
@@ -4822,6 +4963,13 @@ declare interface PointPosition {
4822
4963
  y: number;
4823
4964
  }
4824
4965
 
4966
+ export declare interface PolarBarArcInput {
4967
+ startAngle: number;
4968
+ endAngle: number;
4969
+ innerRadius: number;
4970
+ outerRadius: number;
4971
+ }
4972
+
4825
4973
  declare interface PolarCoordInput {
4826
4974
  type: 'coord';
4827
4975
  coordType: 'polar';
@@ -5006,6 +5154,10 @@ export declare type Predicate = VariablePredicate | LogicalPredicate;
5006
5154
  */
5007
5155
  export declare const prefixInternalVariable: (name: string) => string;
5008
5156
 
5157
+ export declare const prepareAreaObservations: (observations: Observation[], missingValues: AreaGeomParams["missingValues"]) => Observation[];
5158
+
5159
+ export declare const prepareLineObservations: (observations: Observation[], missingValues: LineGeomParams["missingValues"]) => Observation[];
5160
+
5009
5161
  declare interface QuantitativeScaleMethods {
5010
5162
  /**
5011
5163
  * Continuous (numeric) scale. Supports `transform`, `reverse`, `nice`, `zero`, `domainMin`, `domainMax`.
@@ -5033,6 +5185,10 @@ export declare interface RadiusExtent {
5033
5185
  /** Resolves one observation's raw, type-filtered value for an aesthetic. */
5034
5186
  declare type RawValueReader = (observation: Observation) => DataValue;
5035
5187
 
5188
+ export declare function readXExtent(primary: HoverHit): number | null;
5189
+
5190
+ export declare function readYExtent(primary: HoverHit): number | null;
5191
+
5036
5192
  /**
5037
5193
  * A rectangle in pixel coordinates, origin at top-left. Every rect on a {@link GraphLayout} is measured
5038
5194
  * from the chart CONTAINER top-left (with {@link LAYOUT_PADDING} already included), never panel- or
@@ -5195,6 +5351,8 @@ export declare interface ResolveHeadlinePlacementInput {
5195
5351
  /** Source of a layer's segment y value: `yRaw` when stacked, user's y mapping otherwise. */
5196
5352
  export declare function resolveSegmentYSource(position: PositionType, mapping: AesMapping): AestheticValue;
5197
5353
 
5354
+ export declare const resolveStrokeWidth: (observation: Observation, params: AreaGeomParams | LineGeomParams) => number;
5355
+
5198
5356
  /**
5199
5357
  * Resolves the Y scale aesthetic based on the layer's `yScaleType` axis assignment.
5200
5358
  *
@@ -6034,6 +6192,22 @@ export declare interface TooltipRow {
6034
6192
  key: string;
6035
6193
  }
6036
6194
 
6195
+ /** Formats a normalized [0,1] value as a CSS percentage string for SVG positioning. */
6196
+ export declare const toPercent: (value: number) => string;
6197
+
6198
+ /**
6199
+ * Converts a normalized [0,1] x-coordinate to viewBox coordinate (identity transform).
6200
+ * Used inside nested SVGs with viewBox="0 0 1 1".
6201
+ */
6202
+ export declare function toViewBoxX(normalized: number): number;
6203
+
6204
+ /**
6205
+ * Converts a normalized [0,1] y-coordinate to viewBox coordinate (Y-inverted).
6206
+ * SVG y=0 is at the top, but data y=0 is at the bottom, so we invert.
6207
+ * Used inside nested SVGs with viewBox="0 0 1 1".
6208
+ */
6209
+ export declare function toViewBoxY(normalized: number): number;
6210
+
6037
6211
  /** Factories for data transforms applied before charting (reshape, filter, sort, aggregate, constant). */
6038
6212
  export declare const transform: {
6039
6213
  reshape: typeof reshape;