@timeplus/vistral 0.1.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.
@@ -0,0 +1,999 @@
1
+ import * as React from 'react';
2
+ import React__default from 'react';
3
+ import { Chart, MarkNode } from '@antv/g2';
4
+
5
+ /**
6
+ * VistralSpec — declarative grammar types for streaming visualizations.
7
+ *
8
+ * These types define a renderer-agnostic specification that can be compiled
9
+ * down to AntV G2 options (or other backends in the future).
10
+ */
11
+ /** Accessor function for computed encodings. */
12
+ type EncodeFn = (datum: Record<string, unknown>) => unknown;
13
+ /** Default maximum number of data items kept in memory for streaming charts. */
14
+ declare const DEFAULT_MAX_ITEMS = 1000;
15
+ /** Streaming data management configuration. */
16
+ interface StreamingSpec {
17
+ /** Maximum number of data items to keep in memory. Default: DEFAULT_MAX_ITEMS (1000) */
18
+ maxItems?: number;
19
+ /** How incoming data is merged with existing data. Default: 'append' */
20
+ mode?: 'append' | 'replace';
21
+ /** Minimum interval (ms) between render updates. Default: 0 */
22
+ throttle?: number;
23
+ }
24
+ /** Temporal bounding — controls how time-windowed data is managed. */
25
+ interface TemporalSpec {
26
+ /** Temporal binding mode. */
27
+ mode: 'axis' | 'frame' | 'key';
28
+ /** Field used for temporal binding. */
29
+ field: string | string[];
30
+ /** Time range in minutes (axis-mode only). */
31
+ range?: number | 'Infinity';
32
+ /** Key field for de-duplication (key-mode only). */
33
+ keyField?: string;
34
+ }
35
+ /** Encoding channels map visual properties to data fields or accessor fns. */
36
+ interface EncodeSpec {
37
+ x?: string | EncodeFn;
38
+ y?: string | EncodeFn;
39
+ color?: string | EncodeFn;
40
+ size?: string | EncodeFn;
41
+ shape?: string | EncodeFn;
42
+ opacity?: string | EncodeFn;
43
+ series?: string | EncodeFn;
44
+ /** Additional custom channels. */
45
+ [channel: string]: string | EncodeFn | undefined;
46
+ }
47
+ /** Scale configuration for a single encoding channel. */
48
+ interface ScaleSpec {
49
+ type?: string;
50
+ domain?: unknown[];
51
+ range?: unknown[];
52
+ nice?: boolean;
53
+ clamp?: boolean;
54
+ padding?: number;
55
+ /** Date/time format mask. */
56
+ mask?: string;
57
+ [option: string]: unknown;
58
+ }
59
+ /** Data or visual transform applied before rendering. */
60
+ interface TransformSpec {
61
+ type: string;
62
+ [option: string]: unknown;
63
+ }
64
+ /** Coordinate system configuration. */
65
+ interface CoordinateSpec {
66
+ type?: string;
67
+ transforms?: Array<{
68
+ type: string;
69
+ [option: string]: unknown;
70
+ }>;
71
+ [option: string]: unknown;
72
+ }
73
+ /** Visual style properties for marks, labels, and annotations. */
74
+ interface StyleSpec {
75
+ fill?: string;
76
+ stroke?: string;
77
+ lineWidth?: number;
78
+ opacity?: number;
79
+ shape?: string;
80
+ [property: string]: unknown;
81
+ }
82
+ /** Label configuration for a mark. */
83
+ interface LabelSpec {
84
+ text?: string | EncodeFn;
85
+ format?: string | ((value: unknown) => string);
86
+ overlapHide?: boolean;
87
+ selector?: string;
88
+ style?: StyleSpec;
89
+ [option: string]: unknown;
90
+ }
91
+ /** Tooltip configuration scoped to a single mark. */
92
+ interface MarkTooltipSpec {
93
+ title?: string | ((datum: Record<string, unknown>) => string);
94
+ items?: TooltipItemSpec[];
95
+ }
96
+ /** A single mark (geometric element) in the visualization. */
97
+ interface MarkSpec {
98
+ type: string;
99
+ encode?: EncodeSpec;
100
+ scales?: Record<string, ScaleSpec>;
101
+ transforms?: TransformSpec[];
102
+ style?: StyleSpec;
103
+ labels?: LabelSpec[];
104
+ tooltip?: MarkTooltipSpec | false;
105
+ animate?: boolean;
106
+ }
107
+ /** Label formatting options for an axis. */
108
+ interface AxisLabelSpec {
109
+ format?: string | ((value: unknown) => string);
110
+ maxLength?: number;
111
+ rotate?: number;
112
+ }
113
+ /** Configuration for a single axis channel. */
114
+ interface AxisChannelSpec {
115
+ title?: string | false;
116
+ grid?: boolean;
117
+ line?: boolean;
118
+ labels?: AxisLabelSpec;
119
+ }
120
+ /** Axis configuration for x and y channels. */
121
+ interface AxesSpec {
122
+ x?: AxisChannelSpec | false;
123
+ y?: AxisChannelSpec | false;
124
+ }
125
+ /** Legend configuration. */
126
+ interface LegendSpec {
127
+ position?: 'top' | 'bottom' | 'left' | 'right';
128
+ interactive?: boolean;
129
+ }
130
+ /** A single item within a tooltip. */
131
+ interface TooltipItemSpec {
132
+ field: string;
133
+ name?: string;
134
+ format?: (value: unknown) => string;
135
+ }
136
+ /** Top-level tooltip configuration. */
137
+ interface TooltipSpec {
138
+ title?: string | ((datum: Record<string, unknown>) => string);
139
+ items?: TooltipItemSpec[];
140
+ }
141
+ /** A reference mark / annotation overlaid on the chart. */
142
+ interface AnnotationSpec {
143
+ type: string;
144
+ value?: unknown;
145
+ style?: StyleSpec;
146
+ label?: string;
147
+ encode?: EncodeSpec;
148
+ }
149
+ /** An interaction behaviour attached to the chart. */
150
+ interface InteractionSpec {
151
+ type: string;
152
+ [option: string]: unknown;
153
+ }
154
+ /**
155
+ * VistralSpec — the top-level declarative specification for a streaming
156
+ * visualization. This is the single object a user hands to the library.
157
+ */
158
+ interface VistralSpec {
159
+ /** Streaming data management. */
160
+ streaming?: StreamingSpec;
161
+ /** Temporal bounding configuration. */
162
+ temporal?: TemporalSpec;
163
+ /** One or more marks (geometric elements) to render. */
164
+ marks: MarkSpec[];
165
+ /** Shared scale definitions (keyed by channel name). */
166
+ scales?: Record<string, ScaleSpec>;
167
+ /** Data transforms applied before mark-level transforms. */
168
+ transforms?: TransformSpec[];
169
+ /** Coordinate system. */
170
+ coordinate?: CoordinateSpec;
171
+ /** Axis configuration. */
172
+ axes?: AxesSpec;
173
+ /** Legend configuration, or false to disable. */
174
+ legend?: LegendSpec | false;
175
+ /** Tooltip configuration, or false to disable. */
176
+ tooltip?: TooltipSpec | false;
177
+ /** Theme name. */
178
+ theme?: 'dark' | 'light';
179
+ /** Annotations overlaid on the chart. */
180
+ annotations?: AnnotationSpec[];
181
+ /** Interaction behaviours. */
182
+ interactions?: InteractionSpec[];
183
+ /** Enable/disable animation globally. */
184
+ animate?: boolean;
185
+ }
186
+
187
+ /**
188
+ * Core types for the stream visualization library
189
+ */
190
+ type ColumnType = 'string' | 'number' | 'datetime' | 'boolean' | 'array' | 'object' | 'int8' | 'int16' | 'int32' | 'int64' | 'uint8' | 'uint16' | 'uint32' | 'uint64' | 'float32' | 'float64' | 'datetime64';
191
+ interface ColumnDefinition {
192
+ name: string;
193
+ type: ColumnType | string;
194
+ nullable?: boolean;
195
+ }
196
+ type DataRow = Record<string, unknown> | unknown[];
197
+ interface StreamDataSource {
198
+ /** Column definitions/schema */
199
+ columns: ColumnDefinition[];
200
+ /** Data rows */
201
+ data: DataRow[];
202
+ /** Whether the data is streaming (continuously updated) */
203
+ isStreaming?: boolean;
204
+ }
205
+ type TemporalMode = 'axis' | 'frame' | 'key';
206
+ interface TemporalConfig {
207
+ /** Temporal binding mode */
208
+ mode: TemporalMode;
209
+ /** Field used for temporal binding */
210
+ field: string | string[];
211
+ /** Time range in minutes (for axis mode only) */
212
+ range?: number | 'Infinity';
213
+ }
214
+ interface ChartConfigBase {
215
+ /** Chart type identifier */
216
+ chartType: string;
217
+ /** Custom color palette */
218
+ colors?: string[];
219
+ /** Temporal binding configuration */
220
+ temporal?: TemporalConfig;
221
+ /** Maximum number of data items to keep for streaming. Defaults to DEFAULT_MAX_ITEMS (1000). */
222
+ maxItems?: number;
223
+ }
224
+ interface TimeSeriesConfig extends ChartConfigBase {
225
+ chartType: 'line' | 'area';
226
+ /** X-axis field (time field) */
227
+ xAxis: string;
228
+ /** Y-axis field (numeric field) */
229
+ yAxis: string;
230
+ /** Color/series grouping field */
231
+ color?: string;
232
+ /** X-axis title */
233
+ xTitle?: string;
234
+ /** Y-axis title */
235
+ yTitle?: string;
236
+ /** Y-axis range */
237
+ yRange?: {
238
+ min?: number | null;
239
+ max?: number | null;
240
+ };
241
+ /** Show data labels */
242
+ dataLabel?: boolean;
243
+ /** Show all labels or just last */
244
+ showAll?: boolean;
245
+ /** Show legend */
246
+ legend?: boolean;
247
+ /** Show gridlines */
248
+ gridlines?: boolean;
249
+ /** Show data points */
250
+ points?: boolean;
251
+ /** Line style */
252
+ lineStyle?: 'curve' | 'straight';
253
+ /** Decimal places */
254
+ fractionDigits?: number;
255
+ /** Unit configuration */
256
+ unit?: {
257
+ position: 'left' | 'right';
258
+ value: string;
259
+ };
260
+ /** X-axis format mask */
261
+ xFormat?: string;
262
+ /** Y-axis tick label max characters */
263
+ yTickLabel?: {
264
+ maxChar: number;
265
+ };
266
+ }
267
+ interface BarColumnConfig extends ChartConfigBase {
268
+ chartType: 'bar' | 'column';
269
+ /** X-axis field */
270
+ xAxis: string;
271
+ /** Y-axis field */
272
+ yAxis: string;
273
+ /** Color/grouping field */
274
+ color?: string;
275
+ /** Group type for multi-series */
276
+ groupType?: 'stack' | 'dodge';
277
+ /** X-axis title */
278
+ xTitle?: string;
279
+ /** Y-axis title */
280
+ yTitle?: string;
281
+ /** Show data labels */
282
+ dataLabel?: boolean;
283
+ /** Show legend */
284
+ legend?: boolean;
285
+ /** Show gridlines */
286
+ gridlines?: boolean;
287
+ /** Decimal places */
288
+ fractionDigits?: number;
289
+ /** Unit configuration */
290
+ unit?: {
291
+ position: 'left' | 'right';
292
+ value: string;
293
+ };
294
+ /** X-axis tick label max characters */
295
+ xTickLabel?: {
296
+ maxChar: number;
297
+ };
298
+ /** Y-axis tick label max characters */
299
+ yTickLabel?: {
300
+ maxChar: number;
301
+ };
302
+ }
303
+ interface SingleValueConfig extends ChartConfigBase {
304
+ chartType: 'singleValue';
305
+ /** Value field */
306
+ yAxis: string;
307
+ /** Font size */
308
+ fontSize?: number;
309
+ /** Value color */
310
+ color?: string;
311
+ /** Decimal places */
312
+ fractionDigits?: number;
313
+ /** Show sparkline */
314
+ sparkline?: boolean;
315
+ /** Sparkline color */
316
+ sparklineColor?: string;
317
+ /** Show delta/change indicator */
318
+ delta?: boolean;
319
+ /** Color for positive changes */
320
+ increaseColor?: string;
321
+ /** Color for negative changes */
322
+ decreaseColor?: string;
323
+ /** Unit configuration */
324
+ unit?: {
325
+ position: 'left' | 'right';
326
+ value: string;
327
+ };
328
+ }
329
+ interface TableConfig extends ChartConfigBase {
330
+ chartType: 'table';
331
+ /** Column styles and visibility */
332
+ tableStyles?: Record<string, {
333
+ name?: string;
334
+ show?: boolean;
335
+ width?: number;
336
+ miniChart?: 'none' | 'sparkline';
337
+ color?: {
338
+ type: 'none' | 'scale' | 'condition';
339
+ colorScale?: string;
340
+ conditions?: Array<{
341
+ operator: 'gt' | 'lt' | 'eq' | 'gte' | 'lte';
342
+ value: number;
343
+ color: string;
344
+ }>;
345
+ };
346
+ }>;
347
+ /** Enable text wrapping */
348
+ tableWrap?: boolean;
349
+ }
350
+ interface OHLCConfig extends ChartConfigBase {
351
+ chartType: 'ohlc' | 'candlestick';
352
+ /** Time field */
353
+ time: string;
354
+ /** Open price field */
355
+ open: string;
356
+ /** High price field */
357
+ high: string;
358
+ /** Low price field */
359
+ low: string;
360
+ /** Close price field */
361
+ close: string;
362
+ /** Bullish candle color */
363
+ bullishColor?: string;
364
+ /** Bearish candle color */
365
+ bearishColor?: string;
366
+ }
367
+ interface GeoChartConfig extends ChartConfigBase {
368
+ chartType: 'geo';
369
+ /** Longitude field name */
370
+ longitude: string;
371
+ /** Latitude field name */
372
+ latitude: string;
373
+ /** Color field for point coloring */
374
+ color?: string;
375
+ /** Size configuration for points */
376
+ size?: {
377
+ key?: string;
378
+ min?: number;
379
+ max?: number;
380
+ };
381
+ /** Initial map center [lat, lng] */
382
+ center?: [number, number];
383
+ /** Initial zoom level (1-18) */
384
+ zoom?: number;
385
+ /** Map tile provider */
386
+ tileProvider?: 'openstreetmap' | 'cartodb-dark' | 'cartodb-light';
387
+ /** Show zoom controls */
388
+ showZoomControl?: boolean;
389
+ /** Show center coordinates */
390
+ showCenterDisplay?: boolean;
391
+ /** Point opacity (0-1) */
392
+ pointOpacity?: number;
393
+ /** Default point color */
394
+ pointColor?: string;
395
+ }
396
+ type ChartConfig = TimeSeriesConfig | BarColumnConfig | SingleValueConfig | TableConfig | OHLCConfig | GeoChartConfig;
397
+ interface ColorPalette {
398
+ label: string;
399
+ values: string[];
400
+ keyColor: number;
401
+ keyColorValue: string;
402
+ }
403
+ interface ColumnStatistics {
404
+ min?: number | {
405
+ value: number;
406
+ };
407
+ max?: number | {
408
+ value: number;
409
+ };
410
+ categories?: Record<string, number>;
411
+ count?: number;
412
+ }
413
+ interface ProcessedDataSource {
414
+ data: DataRow[];
415
+ header: ColumnDefinition[];
416
+ x: {
417
+ index: number;
418
+ values?: string[];
419
+ isTime?: boolean;
420
+ offset?: number;
421
+ min?: number;
422
+ max?: number;
423
+ };
424
+ y: {
425
+ index: number;
426
+ min?: number;
427
+ max?: number;
428
+ };
429
+ z: {
430
+ index: number;
431
+ values: string[];
432
+ };
433
+ xTransform: (value: unknown) => unknown;
434
+ }
435
+
436
+ /**
437
+ * Single Value Chart Component
438
+ * Displays a single metric with optional sparkline and delta indicator
439
+ */
440
+
441
+ interface SingleValueChartProps {
442
+ /** Chart configuration */
443
+ config: SingleValueConfig;
444
+ /** Data source */
445
+ data: StreamDataSource;
446
+ /** Theme */
447
+ theme?: 'dark' | 'light';
448
+ /** Container className */
449
+ className?: string;
450
+ /** Container style */
451
+ style?: React__default.CSSProperties;
452
+ }
453
+ /**
454
+ * Get default configuration for single value chart
455
+ */
456
+ declare function getSingleValueDefaults(columns: {
457
+ name: string;
458
+ type: string;
459
+ }[]): Partial<SingleValueConfig> | null;
460
+ /**
461
+ * Single Value Chart Component
462
+ */
463
+ declare const SingleValueChart: React__default.FC<SingleValueChartProps>;
464
+
465
+ /**
466
+ * Streaming Data Table Component
467
+ * Displays tabular data with streaming update support
468
+ */
469
+
470
+ interface DataTableProps {
471
+ /** Chart configuration */
472
+ config: TableConfig;
473
+ /** Data source */
474
+ data: StreamDataSource;
475
+ /** Theme */
476
+ theme?: 'dark' | 'light';
477
+ /** Container className */
478
+ className?: string;
479
+ /** Container style */
480
+ style?: React__default.CSSProperties;
481
+ /** Callback when configuration changes (e.g., column resize) */
482
+ onConfigChange?: (config: TableConfig) => void;
483
+ /** Max rows to display */
484
+ maxRows?: number;
485
+ }
486
+ /**
487
+ * Get default table configuration
488
+ */
489
+ declare function getTableDefaults(columns: {
490
+ name: string;
491
+ type: string;
492
+ }[]): Partial<TableConfig>;
493
+ /**
494
+ * Streaming Data Table Component
495
+ */
496
+ declare const DataTable: React__default.FC<DataTableProps>;
497
+
498
+ /**
499
+ * Geo Chart Component
500
+ * Displays geographic points on a map with streaming support
501
+ */
502
+
503
+ interface GeoChartProps {
504
+ /** Chart configuration */
505
+ config: GeoChartConfig;
506
+ /** Data source */
507
+ data: StreamDataSource;
508
+ /** Theme */
509
+ theme?: 'dark' | 'light';
510
+ /** Container className */
511
+ className?: string;
512
+ /** Container style */
513
+ style?: React__default.CSSProperties;
514
+ /** Maximum data points for streaming. Defaults to config.maxItems or DEFAULT_MAX_ITEMS. */
515
+ maxItems?: number;
516
+ }
517
+ /**
518
+ * Get default configuration for geo chart
519
+ */
520
+ declare function getGeoChartDefaults(columns: ColumnDefinition[]): Partial<GeoChartConfig> | null;
521
+ /**
522
+ * GeoChart Component
523
+ */
524
+ declare const GeoChart: React__default.FC<GeoChartProps>;
525
+
526
+ /**
527
+ * StreamChart - Universal Streaming Chart Component
528
+ * Automatically renders the appropriate chart based on configuration
529
+ */
530
+
531
+ interface StreamChartProps {
532
+ /** Chart configuration */
533
+ config: ChartConfig;
534
+ /** Data source with columns and data */
535
+ data: StreamDataSource;
536
+ /** Color theme */
537
+ theme?: 'dark' | 'light';
538
+ /** Show data table instead of chart */
539
+ showTable?: boolean;
540
+ /** Container className */
541
+ className?: string;
542
+ /** Container style */
543
+ style?: React__default.CSSProperties;
544
+ /** Callback when configuration changes */
545
+ onConfigChange?: (config: ChartConfig) => void;
546
+ }
547
+ /**
548
+ * StreamChart Component
549
+ *
550
+ * Universal chart component for streaming data visualization.
551
+ * Automatically renders the appropriate chart based on the config.chartType property.
552
+ *
553
+ * @example
554
+ * ```tsx
555
+ * <StreamChart
556
+ * config={{
557
+ * chartType: 'line',
558
+ * xAxis: 'timestamp',
559
+ * yAxis: 'value',
560
+ * legend: true,
561
+ * }}
562
+ * data={{
563
+ * columns: [
564
+ * { name: 'timestamp', type: 'datetime64' },
565
+ * { name: 'value', type: 'float64' },
566
+ * ],
567
+ * data: [...],
568
+ * }}
569
+ * theme="dark"
570
+ * />
571
+ * ```
572
+ */
573
+ declare const StreamChart: React__default.FC<StreamChartProps>;
574
+
575
+ /**
576
+ * VistralChart — a React component that renders any VistralSpec using the
577
+ * Spec Engine and AntV G2.
578
+ *
579
+ * It accepts a declarative `VistralSpec` and an optional `StreamDataSource`,
580
+ * normalises the data, translates the spec to G2 options via `buildG2Options`,
581
+ * and manages the full G2 chart lifecycle (create / update / destroy).
582
+ *
583
+ * Streaming is supported through the imperative `ChartHandle` exposed via
584
+ * `React.forwardRef` — callers can `append`, `replace`, or `clear` data at
585
+ * any time.
586
+ */
587
+
588
+ /** Imperative handle exposed via `ref` on `<VistralChart>`. */
589
+ interface ChartHandle {
590
+ /** Append rows to the internal data buffer and re-render. */
591
+ append: (rows: unknown[][] | Record<string, unknown>[]) => void;
592
+ /** Replace the entire data buffer and re-render. */
593
+ replace: (rows: unknown[][] | Record<string, unknown>[]) => void;
594
+ /** Clear the data buffer and re-render. */
595
+ clear: () => void;
596
+ /** Direct access to the underlying G2 Chart instance (or null). */
597
+ g2: Chart | null;
598
+ }
599
+ /** Props accepted by `<VistralChart>`. */
600
+ interface VistralChartProps {
601
+ /** The declarative spec describing what to render. */
602
+ spec: VistralSpec;
603
+ /** Optional initial / declarative data source. */
604
+ source?: StreamDataSource;
605
+ /** Explicit pixel width (defaults to 100 % of container). */
606
+ width?: number;
607
+ /** Explicit pixel height (defaults to 100 % of container). */
608
+ height?: number;
609
+ /** Additional CSS class for the wrapper div. */
610
+ className?: string;
611
+ /** Additional inline styles for the wrapper div. */
612
+ style?: React__default.CSSProperties;
613
+ /** Called once the chart is ready with its imperative handle. */
614
+ onReady?: (handle: ChartHandle) => void;
615
+ }
616
+ /**
617
+ * `VistralChart` renders a VistralSpec declaratively. It manages the G2
618
+ * chart lifecycle and exposes an imperative `ChartHandle` via ref for
619
+ * streaming updates.
620
+ */
621
+ declare const VistralChart: React__default.ForwardRefExoticComponent<VistralChartProps & React__default.RefAttributes<ChartHandle>>;
622
+
623
+ /**
624
+ * Color palettes for stream visualization
625
+ */
626
+
627
+ declare const singleColorPalettes: ColorPalette[];
628
+ declare const multiColorPalettes: ColorPalette[];
629
+ declare const allPalettes: ColorPalette[];
630
+ declare const DEFAULT_PALETTE: ColorPalette;
631
+ /**
632
+ * Find a color palette by its values array
633
+ */
634
+ declare function findPaletteByValues(values: string[], defaultPalette?: ColorPalette): ColorPalette;
635
+ /**
636
+ * Find a color palette by label
637
+ */
638
+ declare function findPaletteByLabel(label: string, defaultPalette?: ColorPalette): ColorPalette;
639
+ /**
640
+ * Get the key color from a palette with optional opacity
641
+ */
642
+ declare function getPaletteKeyColor(label: string, opacity?: number): string;
643
+ /**
644
+ * Generate colors for a given number of series from a palette
645
+ */
646
+ declare function getSeriesColors(palette: ColorPalette, count: number): string[];
647
+ interface ChartTheme {
648
+ backgroundColor: string;
649
+ textColor: string;
650
+ gridColor: string;
651
+ axisColor: string;
652
+ tooltipBackground: string;
653
+ tooltipTextColor: string;
654
+ fontFamily: string;
655
+ }
656
+ declare const darkTheme: ChartTheme;
657
+ declare const lightTheme: ChartTheme;
658
+ type ThemeName = 'dark' | 'light';
659
+ declare function getTheme(name: ThemeName): ChartTheme;
660
+
661
+ /**
662
+ * Hook to manage AntV G2 chart instance
663
+ */
664
+ declare function useChart(options?: {
665
+ height?: number;
666
+ padding?: number;
667
+ }): {
668
+ chart: Chart | null;
669
+ chartRef: React.RefObject<HTMLDivElement>;
670
+ isMouseOver: boolean;
671
+ activeColor: number;
672
+ setActiveColor: React.Dispatch<React.SetStateAction<number>>;
673
+ };
674
+ /**
675
+ * Hook to process streaming data source
676
+ */
677
+ declare function useDataSource(source: StreamDataSource | null, xKey: string, yKey: string, zKey?: string): ProcessedDataSource | null;
678
+ /**
679
+ * Hook to track streaming data updates
680
+ */
681
+ declare function useStreamingData<T>(initialData: T[], maxItems?: number): {
682
+ data: T[];
683
+ append: (items: T | T[]) => void;
684
+ replace: (items: T[]) => void;
685
+ clear: () => void;
686
+ };
687
+ /**
688
+ * Hook to handle resize detection
689
+ */
690
+ declare function useResizeObserver(callback: (entry: ResizeObserverEntry) => void): React.RefObject<HTMLDivElement>;
691
+ /**
692
+ * Hook to manage chart theme
693
+ */
694
+ declare function useChartTheme(theme?: 'dark' | 'light'): {
695
+ theme: "dark" | "light";
696
+ setTheme: React.Dispatch<React.SetStateAction<"dark" | "light">>;
697
+ toggleTheme: () => void;
698
+ isDark: boolean;
699
+ };
700
+ /**
701
+ * Hook to track last update time
702
+ */
703
+ declare function useLastUpdated(data: unknown[]): Date | null;
704
+ /**
705
+ * Hook for sparkline data management
706
+ */
707
+ declare function useSparklineData(value: number | null, limit?: number): {
708
+ data: {
709
+ value: number;
710
+ }[];
711
+ trend: 'up' | 'down' | 'stable';
712
+ };
713
+ /**
714
+ * Hook to manage chart animation state
715
+ */
716
+ declare function useChartAnimation(enabled?: boolean): {
717
+ isAnimating: boolean;
718
+ startAnimation: () => void;
719
+ stopAnimation: () => void;
720
+ animationEnabled: boolean;
721
+ };
722
+ /**
723
+ * Hook to debounce a value
724
+ */
725
+ declare function useDebouncedValue<T>(value: T, delay?: number): T;
726
+ /**
727
+ * Hook to track previous value
728
+ */
729
+ declare function usePrevious<T>(value: T): T | undefined;
730
+ /**
731
+ * Hook to determine default chart configuration based on data schema
732
+ */
733
+ declare function useAutoConfig(columns: {
734
+ name: string;
735
+ type: string;
736
+ }[]): () => {
737
+ suggestedXAxis: string;
738
+ suggestedYAxis: string;
739
+ suggestedColor: string;
740
+ hasTimeSeries: boolean;
741
+ hasCategorical: boolean;
742
+ };
743
+
744
+ /**
745
+ * Utility functions for stream visualization
746
+ */
747
+
748
+ /**
749
+ * Check if a column type is numeric
750
+ */
751
+ declare function isNumericColumn(type: string): boolean;
752
+ /**
753
+ * Check if a column type is datetime
754
+ */
755
+ declare function isDateTimeColumn(type: string): boolean;
756
+ /**
757
+ * Check if a column type is string
758
+ */
759
+ declare function isStringColumn(type: string): boolean;
760
+ /**
761
+ * Check if a column type is boolean
762
+ */
763
+ declare function isBooleanColumn(type: string): boolean;
764
+ /**
765
+ * Determine automatic time format mask based on domain range
766
+ */
767
+ declare function getTimeMask(domainMin: number | Date, domainMax: number | Date): string;
768
+ /**
769
+ * Clamp a number between min and max values
770
+ */
771
+ declare function clamp(value: number, min: number, max: number): number;
772
+ /**
773
+ * Truncate a string with ellipsis if too long
774
+ */
775
+ declare function truncateWithEllipsis(str: string, maxLength: number): string;
776
+ /**
777
+ * Format a number with locale formatting
778
+ */
779
+ declare function formatNumber(num: number, digits?: number): string;
780
+ /**
781
+ * Format a large number with abbreviation (k, m, b, t)
782
+ */
783
+ declare function abbreviateNumber(num: number, decPlaces?: number): string;
784
+ /**
785
+ * Format duration from milliseconds to human readable
786
+ */
787
+ declare function formatDuration(ms: number): string;
788
+ /**
789
+ * Format bytes to human readable size
790
+ */
791
+ declare function formatBytes(bytes: number, decimals?: number): string;
792
+ /**
793
+ * Debounce function execution
794
+ */
795
+ declare function debounce<T extends (...args: unknown[]) => unknown>(func: T, wait: number): (...args: Parameters<T>) => void;
796
+ /**
797
+ * Get value from a data row by column index or name
798
+ */
799
+ declare function getRowValue(row: DataRow, column: number | string): unknown;
800
+ /**
801
+ * Convert a row to array format if it's an object
802
+ */
803
+ declare function rowToArray(row: DataRow, columns: ColumnDefinition[]): unknown[];
804
+ /**
805
+ * Find column index by name
806
+ */
807
+ declare function findColumnIndex(columns: ColumnDefinition[], name: string): number;
808
+ /**
809
+ * Get filtered columns by type
810
+ */
811
+ declare function getColumnsByType(columns: ColumnDefinition[], filter: 'numeric' | 'datetime' | 'string' | 'boolean' | 'all'): ColumnDefinition[];
812
+ /**
813
+ * Calculate statistics for a numeric column
814
+ */
815
+ declare function calculateColumnStats(data: DataRow[], columnIndex: number): {
816
+ min: number;
817
+ max: number;
818
+ sum: number;
819
+ count: number;
820
+ avg: number;
821
+ };
822
+ /**
823
+ * Get unique values for a column (for categorical data)
824
+ */
825
+ declare function getUniqueValues(data: DataRow[], columnIndex: number): string[];
826
+ /**
827
+ * Parse datetime value to timestamp
828
+ */
829
+ declare function parseDateTime(value: unknown): number;
830
+ /**
831
+ * Process data source into internal format for charts
832
+ */
833
+ declare function processDataSource(source: StreamDataSource, xKey: string, yKey: string, zKey?: string): ProcessedDataSource;
834
+ /**
835
+ * Merge deep objects (like lodash merge)
836
+ */
837
+ declare function mergeDeep<T extends Record<string, unknown>>(target: T, ...sources: Partial<T>[]): T;
838
+ /**
839
+ * Generate unique ID
840
+ */
841
+ declare function generateId(prefix?: string): string;
842
+ /**
843
+ * Filter data by latest timestamp (frame-bound mode)
844
+ * Keeps only rows with the maximum timestamp value
845
+ */
846
+ declare function filterByLatestTimestamp(data: unknown[][], timeIndex: number): unknown[][];
847
+ /**
848
+ * Filter data by unique key (key-bound mode)
849
+ * Keeps only the latest row for each unique key value
850
+ */
851
+ /**
852
+ * Filter data by unique key (key-bound mode)
853
+ * Keeps only the latest row for each unique key value
854
+ */
855
+ declare function filterByKey(data: unknown[][], keyIndex: number | number[]): unknown[][];
856
+ /**
857
+ * Apply temporal filtering based on configuration
858
+ */
859
+ declare function applyTemporalFilter(data: unknown[][], columns: ColumnDefinition[], temporal: TemporalConfig): unknown[][];
860
+
861
+ /**
862
+ * Core chart utilities and base functionality
863
+ */
864
+
865
+ declare const AXIS_HEIGHT_WITH_TITLE = 70;
866
+ declare const AXIS_HEIGHT_WITHOUT_TITLE = 40;
867
+ declare const MAX_LEGEND_ITEMS = 30;
868
+ /**
869
+ * Horizontal axis label transformation configuration
870
+ */
871
+ declare const horizontalAxisLabelConfig: {
872
+ labelAutoHide: {
873
+ type: string;
874
+ keepHeader: boolean;
875
+ keepTail: boolean;
876
+ };
877
+ labelAutoRotate: boolean;
878
+ labelAutoEllipsis: {
879
+ type: string;
880
+ minLength: number;
881
+ maxLength: number;
882
+ };
883
+ };
884
+ /**
885
+ * Vertical axis label transformation configuration
886
+ */
887
+ declare const verticalAxisLabelConfig: {
888
+ transform: {
889
+ margin: number[];
890
+ type: string;
891
+ }[];
892
+ };
893
+ /**
894
+ * Apply color encoding to a chart mark
895
+ */
896
+ declare function applyColorEncoding(node: MarkNode, config: {
897
+ zIndex: number;
898
+ colors: ColorPalette;
899
+ domain?: string[];
900
+ activeIndex?: number;
901
+ }): MarkNode;
902
+ /**
903
+ * Apply legend configuration to a chart mark
904
+ */
905
+ declare function applyLegend(node: MarkNode, enabled: boolean, onItemClick?: (index: number) => void, values?: string[], theme?: 'dark' | 'light'): MarkNode;
906
+ /**
907
+ * Apply data label configuration to a chart mark
908
+ */
909
+ declare function applyDataLabel(node: MarkNode, config: {
910
+ enabled: boolean;
911
+ yIndex: number;
912
+ unit?: {
913
+ position: 'left' | 'right';
914
+ value: string;
915
+ };
916
+ fractionDigits?: number;
917
+ showAll?: boolean;
918
+ textAlign?: 'start' | 'center' | 'end';
919
+ textBaseline?: 'top' | 'middle' | 'bottom' | 'alphabetic';
920
+ }): MarkNode;
921
+ /**
922
+ * Truncate label with ellipsis
923
+ */
924
+ declare function truncateLabel(value: string, maxChar: number | null): string;
925
+ /**
926
+ * Render chart with standard interactions
927
+ */
928
+ declare function renderChart(chart: Chart, theme?: 'dark' | 'light'): Promise<void>;
929
+ /**
930
+ * Configure tooltip for a chart mark
931
+ */
932
+ declare function applyTooltip(node: MarkNode, enabled: boolean, config: {
933
+ xIndex: number;
934
+ yIndex: number;
935
+ zIndex?: number;
936
+ zValues?: string[];
937
+ colors: ColorPalette;
938
+ fractionDigits?: number;
939
+ yLabel?: string;
940
+ }): MarkNode;
941
+ /**
942
+ * Create default chart configuration based on data source
943
+ */
944
+ declare function createDefaultConfig(source: ProcessedDataSource, chartType: string): Record<string, unknown>;
945
+ /**
946
+ * Get theme colors for charts
947
+ */
948
+ declare function getChartThemeColors(theme: 'dark' | 'light'): {
949
+ text: string;
950
+ textSecondary: string;
951
+ line: string;
952
+ gridline: string;
953
+ background: string;
954
+ };
955
+ /**
956
+ * Apply chart theme
957
+ */
958
+ declare function applyChartTheme(chart: Chart, theme?: 'dark' | 'light'): void;
959
+
960
+ /**
961
+ * Config Compilers — bridge between legacy chart configs and VistralSpec.
962
+ *
963
+ * These functions convert the existing high-level chart configuration
964
+ * objects (TimeSeriesConfig, BarColumnConfig) into the declarative
965
+ * VistralSpec grammar.
966
+ */
967
+
968
+ /**
969
+ * Compile a `TimeSeriesConfig` into a `VistralSpec`.
970
+ *
971
+ * Mapping summary:
972
+ * - `chartType` -> mark type ('line' | 'area')
973
+ * - `xAxis` / `yAxis` / `color` -> encode channels
974
+ * - `lineStyle: 'curve'` -> style.shape: 'smooth', else 'line'
975
+ * - Always adds style.connect: true
976
+ * - `points: true` -> adds second point mark (tooltip: false)
977
+ * - `dataLabel: true` -> adds label; if showAll is false, selector: 'last'
978
+ * - area + color -> transforms: [{ type: 'stackY' }]
979
+ * - scales.x: time scale with optional mask from xFormat
980
+ * - scales.y: linear, nice, optional domain from yRange
981
+ * - temporal -> maps to TemporalSpec
982
+ * - streaming: { maxItems: config.maxItems ?? DEFAULT_MAX_ITEMS }
983
+ * - axes, legend, theme, animate configured per defaults
984
+ */
985
+ declare function compileTimeSeriesConfig(config: TimeSeriesConfig, theme?: 'dark' | 'light'): VistralSpec;
986
+ /**
987
+ * Compile a `BarColumnConfig` into a `VistralSpec`.
988
+ *
989
+ * Mapping summary:
990
+ * - mark type is always 'interval'
991
+ * - `chartType 'bar'` -> coordinate: { transforms: [{ type: 'transpose' }] }
992
+ * - `color` set -> transforms: stackY (if groupType==='stack') or dodgeX
993
+ * - `dataLabel: true` -> label with text: yAxis, overlapHide: true
994
+ * - scales: x with padding 0.5, y linear with nice
995
+ * - Same streaming/axes/legend/theme/animate defaults as time series
996
+ */
997
+ declare function compileBarColumnConfig(config: BarColumnConfig, theme?: 'dark' | 'light'): VistralSpec;
998
+
999
+ export { AXIS_HEIGHT_WITHOUT_TITLE, AXIS_HEIGHT_WITH_TITLE, AnnotationSpec, AxesSpec, BarColumnConfig, ChartConfig, ChartConfigBase, ChartHandle, ChartTheme, ColorPalette, ColumnDefinition, ColumnStatistics, ColumnType, CoordinateSpec, DEFAULT_MAX_ITEMS, DEFAULT_PALETTE, DataRow, DataTable, DataTableProps, EncodeFn, EncodeSpec, GeoChart, GeoChartConfig, GeoChartProps, InteractionSpec, LegendSpec, MAX_LEGEND_ITEMS, MarkSpec, OHLCConfig, ProcessedDataSource, ScaleSpec, SingleValueChart, SingleValueChartProps, SingleValueConfig, StreamChart, StreamChartProps, StreamDataSource, StreamingSpec, TableConfig, TemporalConfig, TemporalMode, TemporalSpec, ThemeName, TimeSeriesConfig, TooltipSpec, TransformSpec, VistralChart, VistralChartProps, VistralSpec, abbreviateNumber, allPalettes, applyChartTheme, applyColorEncoding, applyDataLabel, applyLegend, applyTemporalFilter, applyTooltip, calculateColumnStats, clamp, compileBarColumnConfig, compileTimeSeriesConfig, createDefaultConfig, darkTheme, debounce, StreamChart as default, filterByKey, filterByLatestTimestamp, findColumnIndex, findPaletteByLabel, findPaletteByValues, formatBytes, formatDuration, formatNumber, generateId, getChartThemeColors, getColumnsByType, getGeoChartDefaults, getPaletteKeyColor, getRowValue, getSeriesColors, getSingleValueDefaults, getTableDefaults, getTheme, getTimeMask, getUniqueValues, horizontalAxisLabelConfig, isBooleanColumn, isDateTimeColumn, isNumericColumn, isStringColumn, lightTheme, mergeDeep, multiColorPalettes, parseDateTime, processDataSource, renderChart, rowToArray, singleColorPalettes, truncateLabel, truncateWithEllipsis, useAutoConfig, useChart, useChartAnimation, useChartTheme, useDataSource, useDebouncedValue, useLastUpdated, usePrevious, useResizeObserver, useSparklineData, useStreamingData, verticalAxisLabelConfig };