scichart-engine 1.0.1 → 1.1.2

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,74 @@
1
+ /**
2
+ * Fast Fourier Transform (FFT) Implementation
3
+ *
4
+ * Provides:
5
+ * - FFT for spectral analysis
6
+ * - Inverse FFT
7
+ * - Power spectrum
8
+ * - Frequency bins calculation
9
+ */
10
+ /** Complex number representation */
11
+ export interface Complex {
12
+ re: number;
13
+ im: number;
14
+ }
15
+ /** FFT Result */
16
+ export interface FFTResult {
17
+ /** Frequency bins in Hz (if sample rate provided) or normalized */
18
+ frequency: Float32Array;
19
+ /** Magnitude spectrum */
20
+ magnitude: Float32Array;
21
+ /** Phase spectrum in radians */
22
+ phase: Float32Array;
23
+ /** Full complex spectrum */
24
+ complex: Complex[];
25
+ }
26
+ /** Power spectrum result */
27
+ export interface PowerSpectrumResult {
28
+ /** Frequency bins */
29
+ frequency: Float32Array;
30
+ /** Power values (magnitude squared) */
31
+ power: Float32Array;
32
+ /** Power in dB */
33
+ powerDb: Float32Array;
34
+ }
35
+ /**
36
+ * Compute FFT using Cooley-Tukey algorithm
37
+ * Input length must be a power of 2
38
+ */
39
+ export declare function fft(input: Float32Array | Float64Array | number[]): Complex[];
40
+ /**
41
+ * Compute inverse FFT
42
+ */
43
+ export declare function ifft(spectrum: Complex[]): Float32Array;
44
+ /**
45
+ * Find next power of 2
46
+ */
47
+ export declare function nextPowerOf2(n: number): number;
48
+ /**
49
+ * Compute full FFT analysis with frequencies and magnitudes
50
+ */
51
+ export declare function analyzeSpectrum(data: Float32Array | Float64Array | number[], sampleRate?: number): FFTResult;
52
+ /**
53
+ * Compute power spectrum
54
+ */
55
+ export declare function powerSpectrum(data: Float32Array | Float64Array | number[], sampleRate?: number): PowerSpectrumResult;
56
+ /**
57
+ * Find dominant frequency in signal
58
+ */
59
+ export declare function dominantFrequency(data: Float32Array | Float64Array | number[], sampleRate?: number, minFrequency?: number): {
60
+ frequency: number;
61
+ magnitude: number;
62
+ };
63
+ /**
64
+ * Apply Hanning window to data
65
+ */
66
+ export declare function hanningWindow(data: Float32Array | Float64Array): Float32Array;
67
+ /**
68
+ * Apply Hamming window to data
69
+ */
70
+ export declare function hammingWindow(data: Float32Array | Float64Array): Float32Array;
71
+ /**
72
+ * Apply Blackman window to data
73
+ */
74
+ export declare function blackmanWindow(data: Float32Array | Float64Array): Float32Array;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Digital Filters Implementation
3
+ *
4
+ * Provides:
5
+ * - Low-pass filter
6
+ * - High-pass filter
7
+ * - Band-pass filter
8
+ * - Band-stop (notch) filter
9
+ * - Butterworth filter
10
+ * - Moving average (for smoothing)
11
+ * - Savitzky-Golay filter
12
+ */
13
+ export type FilterType = 'lowpass' | 'highpass' | 'bandpass' | 'bandstop';
14
+ export interface FilterOptions {
15
+ /** Cutoff frequency in Hz (or normalized 0-1) */
16
+ cutoff: number;
17
+ /** Second cutoff for bandpass/bandstop filters */
18
+ cutoffHigh?: number;
19
+ /** Sample rate in Hz (default: 1.0 for normalized) */
20
+ sampleRate?: number;
21
+ /** Filter order (default: 2) */
22
+ order?: number;
23
+ }
24
+ export interface ButterworthOptions extends FilterOptions {
25
+ /** Filter type */
26
+ type: FilterType;
27
+ }
28
+ /**
29
+ * Apply a simple low-pass FIR filter
30
+ */
31
+ export declare function lowPassFilter(data: Float32Array | Float64Array, cutoffHz: number, sampleRate: number, order?: number): Float32Array;
32
+ /**
33
+ * Apply a simple high-pass FIR filter
34
+ */
35
+ export declare function highPassFilter(data: Float32Array | Float64Array, cutoffHz: number, sampleRate: number, order?: number): Float32Array;
36
+ /**
37
+ * Apply a band-pass FIR filter
38
+ */
39
+ export declare function bandPassFilter(data: Float32Array | Float64Array, lowCutoffHz: number, highCutoffHz: number, sampleRate: number, order?: number): Float32Array;
40
+ /**
41
+ * Apply a band-stop (notch) FIR filter
42
+ */
43
+ export declare function bandStopFilter(data: Float32Array | Float64Array, lowCutoffHz: number, highCutoffHz: number, sampleRate: number, order?: number): Float32Array;
44
+ /**
45
+ * Apply Butterworth filter (IIR)
46
+ */
47
+ export declare function butterworth(data: Float32Array | Float64Array, options: ButterworthOptions): Float32Array;
48
+ /**
49
+ * Exponential moving average filter
50
+ */
51
+ export declare function exponentialMovingAverage(data: Float32Array | Float64Array, alpha?: number): Float32Array;
52
+ /**
53
+ * Gaussian smoothing filter
54
+ */
55
+ export declare function gaussianSmooth(data: Float32Array | Float64Array, sigma?: number): Float32Array;
56
+ /**
57
+ * Savitzky-Golay smoothing filter
58
+ */
59
+ export declare function savitzkyGolay(data: Float32Array | Float64Array, windowSize?: number, polynomialOrder?: number): Float32Array;
60
+ /**
61
+ * Median filter (good for spike removal)
62
+ */
63
+ export declare function medianFilter(data: Float32Array | Float64Array, windowSize?: number): Float32Array;
@@ -2,7 +2,7 @@
2
2
  * Data Analysis module exports
3
3
  *
4
4
  * General-purpose utilities for data formatting, cycle detection,
5
- * peak detection, and data validation.
5
+ * peak detection, data validation, FFT, filters, and statistics.
6
6
  */
7
7
  export { formatWithPrefix, formatValue, formatScientific, getBestPrefix, detectCycles, generateCycleColors, detectPeaks, validateData, calculateStats, movingAverage, downsampleLTTB, subtractBaseline, } from './utils';
8
8
  export { solveLinearSystem, calculateR2, integrate, derivative, cumulativeIntegral, } from './math';
@@ -10,3 +10,9 @@ export { fitData, } from './fitting';
10
10
  export type { CycleInfo, Peak, PrefixInfo, ValidationResult, DataStats, } from './utils';
11
11
  export type { FitType, FitOptions, FitResult, } from './fitting';
12
12
  export * from './contours';
13
+ export { fft, ifft, analyzeSpectrum, powerSpectrum, dominantFrequency, hanningWindow, hammingWindow, blackmanWindow, nextPowerOf2, } from './fft';
14
+ export type { Complex, FFTResult, PowerSpectrumResult, } from './fft';
15
+ export { lowPassFilter, highPassFilter, bandPassFilter, bandStopFilter, butterworth, exponentialMovingAverage, gaussianSmooth, savitzkyGolay, medianFilter, } from './filters';
16
+ export type { FilterType, FilterOptions, ButterworthOptions, } from './filters';
17
+ export { crossCorrelation, autoCorrelation, detectAnomalies, trapezoidalIntegration, simpsonsIntegration, cumulativeIntegration as cumulativeIntegral2, tTest, } from './statistics';
18
+ export type { CorrelationResult, AnomalyResult, AnomalyOptions, TTestResult, } from './statistics';
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Advanced Statistical Analysis
3
+ *
4
+ * Provides:
5
+ * - Cross-correlation
6
+ * - Auto-correlation
7
+ * - Anomaly detection
8
+ * - Statistical tests
9
+ * - Numerical integration (Simpson, trapezoidal)
10
+ */
11
+ /** Cross-correlation result */
12
+ export interface CorrelationResult {
13
+ /** Correlation values at each lag */
14
+ correlation: Float32Array;
15
+ /** Lag values */
16
+ lags: Float32Array;
17
+ /** Maximum correlation value */
18
+ maxCorrelation: number;
19
+ /** Lag at maximum correlation */
20
+ lagAtMax: number;
21
+ }
22
+ /**
23
+ * Compute cross-correlation between two signals
24
+ */
25
+ export declare function crossCorrelation(signal1: Float32Array | Float64Array, signal2: Float32Array | Float64Array, maxLag?: number): CorrelationResult;
26
+ /**
27
+ * Compute auto-correlation of a signal
28
+ */
29
+ export declare function autoCorrelation(signal: Float32Array | Float64Array, maxLag?: number): CorrelationResult;
30
+ /** Anomaly detection result */
31
+ export interface AnomalyResult {
32
+ /** Indices of anomalous points */
33
+ indices: number[];
34
+ /** Anomaly scores for all points */
35
+ scores: Float32Array;
36
+ /** Threshold used for detection */
37
+ threshold: number;
38
+ }
39
+ /** Anomaly detection options */
40
+ export interface AnomalyOptions {
41
+ /** Detection method */
42
+ method?: 'zscore' | 'mad' | 'iqr' | 'isolation';
43
+ /** Threshold multiplier (default: 3 for zscore, 2.5 for mad, 1.5 for iqr) */
44
+ threshold?: number;
45
+ /** Window size for local anomaly detection (default: use global) */
46
+ windowSize?: number;
47
+ }
48
+ /**
49
+ * Detect anomalies in a signal
50
+ */
51
+ export declare function detectAnomalies(data: Float32Array | Float64Array, options?: AnomalyOptions): AnomalyResult;
52
+ /**
53
+ * Trapezoidal integration
54
+ */
55
+ export declare function trapezoidalIntegration(y: Float32Array | Float64Array, x?: Float32Array | Float64Array | number): number;
56
+ /**
57
+ * Simpson's rule integration (requires odd number of points)
58
+ */
59
+ export declare function simpsonsIntegration(y: Float32Array | Float64Array, x?: Float32Array | Float64Array | number): number;
60
+ /**
61
+ * Cumulative integration (returns running integral)
62
+ */
63
+ export declare function cumulativeIntegration(y: Float32Array | Float64Array, x?: Float32Array | Float64Array | number): Float32Array;
64
+ /** T-test result */
65
+ export interface TTestResult {
66
+ /** T-statistic */
67
+ tStatistic: number;
68
+ /** Degrees of freedom */
69
+ degreesOfFreedom: number;
70
+ /** Approximate p-value (two-tailed) */
71
+ pValue: number;
72
+ /** Whether the difference is significant at 0.05 level */
73
+ significant: boolean;
74
+ }
75
+ /**
76
+ * Two-sample t-test (Welch's t-test)
77
+ */
78
+ export declare function tTest(sample1: Float32Array | Float64Array | number[], sample2: Float32Array | Float64Array | number[]): TTestResult;
@@ -1,10 +1,12 @@
1
1
  import { ChartTheme } from '../theme';
2
+ import { InteractionMode } from './InteractionManager';
2
3
 
3
4
  export interface ChartControlsCallbacks {
4
5
  onResetZoom: () => void;
5
6
  onSetType: (type: "line" | "scatter" | "line+scatter") => void;
6
7
  onToggleSmoothing: () => void;
7
8
  onTogglePan: (active: boolean) => void;
9
+ onSetMode: (mode: InteractionMode) => void;
8
10
  onExport: () => void;
9
11
  onAutoScale: () => void;
10
12
  onToggleLegend: (visible: boolean) => void;
@@ -15,7 +17,7 @@ export declare class ChartControls {
15
17
  private callbacks;
16
18
  private theme;
17
19
  private isSmoothing;
18
- private isPanMode;
20
+ private currentMode;
19
21
  private isLegendVisible;
20
22
  private currentType;
21
23
  constructor(parent: HTMLElement, theme: ChartTheme, callbacks: ChartControlsCallbacks);
@@ -2,7 +2,7 @@ import { Bounds } from '../types';
2
2
 
3
3
  export interface AxisLayout {
4
4
  id: string;
5
- position: 'left' | 'right';
5
+ position: "left" | "right";
6
6
  offset: number;
7
7
  }
8
8
  export interface InteractionCallbacks {
@@ -16,6 +16,19 @@ export interface InteractionCallbacks {
16
16
  } | null) => void;
17
17
  onCursorMove: (x: number, y: number) => void;
18
18
  onCursorLeave: () => void;
19
+ onPointClick?: (pixelX: number, pixelY: number, ctrlKey: boolean, shiftKey: boolean) => void;
20
+ onBoxSelect?: (rect: {
21
+ x: number;
22
+ y: number;
23
+ width: number;
24
+ height: number;
25
+ } | null, additive: boolean) => void;
26
+ onBoxSelectUpdate?: (pixelX: number, pixelY: number) => void;
27
+ onBoxSelectStart?: (pixelX: number, pixelY: number) => void;
28
+ /** Called when any drag operation starts (pan, box zoom, box select) */
29
+ onDragStart?: () => void;
30
+ /** Called when any drag operation ends */
31
+ onDragEnd?: () => void;
19
32
  }
20
33
  export interface PlotAreaGetter {
21
34
  (): {
@@ -31,6 +44,7 @@ export interface BoundsGetter {
31
44
  export interface AxisLayoutGetter {
32
45
  (): AxisLayout[];
33
46
  }
47
+ export type InteractionMode = 'pan' | 'boxZoom' | 'select';
34
48
  export declare class InteractionManager {
35
49
  private container;
36
50
  private callbacks;
@@ -40,9 +54,10 @@ export declare class InteractionManager {
40
54
  private isDragging;
41
55
  private panningAxisId?;
42
56
  private isBoxSelecting;
57
+ private isBoxZooming;
43
58
  private selectionStart;
44
59
  private lastMousePos;
45
- private isPanMode;
60
+ private mode;
46
61
  private boundWheel;
47
62
  private boundMouseDown;
48
63
  private boundMouseMove;
@@ -54,7 +69,19 @@ export declare class InteractionManager {
54
69
  constructor(container: HTMLElement, callbacks: InteractionCallbacks, getPlotArea: PlotAreaGetter, getBounds: BoundsGetter, getAxesLayout: AxisLayoutGetter);
55
70
  private attachListeners;
56
71
  private detachListeners;
72
+ /**
73
+ * Set the interaction mode
74
+ * @deprecated Use setMode instead
75
+ */
57
76
  setPanMode(enabled: boolean): void;
77
+ /**
78
+ * Set the interaction mode: 'pan', 'boxZoom', or 'select'
79
+ */
80
+ setMode(mode: InteractionMode): void;
81
+ /**
82
+ * Get the current interaction mode
83
+ */
84
+ getMode(): InteractionMode;
58
85
  private handleWheel;
59
86
  private handleMouseDown;
60
87
  private handleMouseMove;
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Animation Engine
3
+ *
4
+ * Provides smooth, performant animations for chart transitions
5
+ * including zoom, pan, data updates, and custom animations.
6
+ */
7
+ export type EasingFunction = (t: number) => number;
8
+ export declare const easings: {
9
+ /** Linear easing - constant speed */
10
+ readonly linear: (t: number) => number;
11
+ /** Ease in - starts slow, accelerates */
12
+ readonly easeIn: (t: number) => number;
13
+ /** Ease out - starts fast, decelerates */
14
+ readonly easeOut: (t: number) => number;
15
+ /** Ease in-out - slow start and end */
16
+ readonly easeInOut: (t: number) => number;
17
+ /** Cubic ease out - smoother deceleration */
18
+ readonly easeOutCubic: (t: number) => number;
19
+ /** Cubic ease in-out */
20
+ readonly easeInOutCubic: (t: number) => number;
21
+ /** Spring-like bounce at the end */
22
+ readonly spring: (t: number) => number;
23
+ /** Elastic overshoot */
24
+ readonly elastic: (t: number) => number;
25
+ /** Bounce effect */
26
+ readonly bounce: (t: number) => number;
27
+ };
28
+ export type EasingName = keyof typeof easings;
29
+ export interface AnimationOptions {
30
+ /** Duration in milliseconds */
31
+ duration: number;
32
+ /** Easing function name or custom function */
33
+ easing?: EasingName | EasingFunction;
34
+ /** Callback on each frame with progress 0-1 */
35
+ onUpdate: (progress: number) => void;
36
+ /** Callback when animation completes */
37
+ onComplete?: () => void;
38
+ /** Callback if animation is cancelled */
39
+ onCancel?: () => void;
40
+ }
41
+ export interface AnimationHandle {
42
+ /** Unique animation ID */
43
+ id: string;
44
+ /** Cancel the animation */
45
+ cancel: () => void;
46
+ /** Promise that resolves when animation completes */
47
+ promise: Promise<void>;
48
+ /** Whether animation is currently running */
49
+ isRunning: () => boolean;
50
+ }
51
+ export interface BoundsAnimation {
52
+ /** Target X range [min, max] */
53
+ xRange?: [number, number];
54
+ /** Target Y range [min, max] */
55
+ yRange?: [number, number];
56
+ /** Duration in ms (default: 300) */
57
+ duration?: number;
58
+ /** Easing function (default: 'easeOutCubic') */
59
+ easing?: EasingName | EasingFunction;
60
+ }
61
+ export declare class AnimationEngine {
62
+ private animations;
63
+ private frameId;
64
+ private idCounter;
65
+ private isDestroyed;
66
+ /**
67
+ * Start a new animation
68
+ */
69
+ animate(options: AnimationOptions): AnimationHandle;
70
+ /**
71
+ * Animate numeric value interpolation
72
+ */
73
+ interpolate(from: number, to: number, options: Omit<AnimationOptions, 'onUpdate'> & {
74
+ onUpdate: (value: number) => void;
75
+ }): AnimationHandle;
76
+ /**
77
+ * Animate bounds transition
78
+ */
79
+ animateBounds(current: {
80
+ xMin: number;
81
+ xMax: number;
82
+ yMin: number;
83
+ yMax: number;
84
+ }, target: BoundsAnimation, onUpdate: (bounds: {
85
+ xMin: number;
86
+ xMax: number;
87
+ yMin: number;
88
+ yMax: number;
89
+ }) => void, onComplete?: () => void): AnimationHandle;
90
+ /**
91
+ * Cancel a specific animation
92
+ */
93
+ cancel(id: string): void;
94
+ /**
95
+ * Cancel all running animations
96
+ */
97
+ cancelAll(): void;
98
+ /**
99
+ * Check if any animations are running
100
+ */
101
+ isAnimating(): boolean;
102
+ /**
103
+ * Get number of active animations
104
+ */
105
+ getActiveCount(): number;
106
+ /**
107
+ * Destroy the animation engine
108
+ */
109
+ destroy(): void;
110
+ private ensureLoop;
111
+ private tick;
112
+ }
113
+ export interface ChartAnimationConfig {
114
+ /** Enable all animations */
115
+ enabled: boolean;
116
+ /** Zoom animation settings */
117
+ zoom: {
118
+ enabled: boolean;
119
+ duration: number;
120
+ easing: EasingName;
121
+ };
122
+ /** Pan animation settings */
123
+ pan: {
124
+ enabled: boolean;
125
+ duration: number;
126
+ easing: EasingName;
127
+ };
128
+ /** Data update animation settings */
129
+ dataUpdate: {
130
+ enabled: boolean;
131
+ duration: number;
132
+ easing: EasingName;
133
+ };
134
+ /** Series entry animation */
135
+ seriesEntry: {
136
+ enabled: boolean;
137
+ duration: number;
138
+ easing: EasingName;
139
+ };
140
+ /** Auto-scale animation */
141
+ autoScale: {
142
+ enabled: boolean;
143
+ duration: number;
144
+ easing: EasingName;
145
+ };
146
+ }
147
+ export declare const DEFAULT_ANIMATION_CONFIG: ChartAnimationConfig;
148
+ /**
149
+ * Merge user config with defaults
150
+ */
151
+ export declare function mergeAnimationConfig(config?: Partial<ChartAnimationConfig>): ChartAnimationConfig;
152
+ export declare function getSharedAnimationEngine(): AnimationEngine;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Animation Module
3
+ *
4
+ * Exports animation utilities for smooth chart transitions.
5
+ */
6
+ export { AnimationEngine, easings, DEFAULT_ANIMATION_CONFIG, mergeAnimationConfig, getSharedAnimationEngine, type AnimationOptions, type AnimationHandle, type BoundsAnimation, type ChartAnimationConfig, type EasingFunction, type EasingName, } from './AnimationEngine';
@@ -0,0 +1,53 @@
1
+ import { Bounds, ZoomOptions, AxisOptions, ChartEventMap } from '../../types';
2
+ import { Scale } from '../../scales';
3
+ import { EventEmitter } from '../EventEmitter';
4
+ import { AnimationEngine, ChartAnimationConfig, AnimationHandle } from '../animation';
5
+
6
+ export interface AnimatedNavigationContext {
7
+ viewBounds: Bounds;
8
+ yScales: Map<string, Scale>;
9
+ yAxisOptionsMap: Map<string, AxisOptions>;
10
+ xAxisOptions: AxisOptions;
11
+ primaryYAxisId: string;
12
+ getPlotArea: () => {
13
+ x: number;
14
+ y: number;
15
+ width: number;
16
+ height: number;
17
+ };
18
+ events: EventEmitter<ChartEventMap>;
19
+ requestRender: () => void;
20
+ series: Map<string, {
21
+ isVisible(): boolean;
22
+ getBounds(): Bounds | null;
23
+ getYAxisId(): string | undefined;
24
+ getType(): string;
25
+ }>;
26
+ animationEngine: AnimationEngine;
27
+ animationConfig: ChartAnimationConfig;
28
+ }
29
+ /**
30
+ * Apply animated zoom to the chart
31
+ */
32
+ export declare function applyAnimatedZoom(ctx: AnimatedNavigationContext, options: ZoomOptions & {
33
+ animate?: boolean;
34
+ }): AnimationHandle | null;
35
+ /**
36
+ * Apply animated auto-scale to fit all data
37
+ */
38
+ export declare function applyAnimatedAutoScale(ctx: AnimatedNavigationContext, animate?: boolean): AnimationHandle | null;
39
+ /**
40
+ * Animate to specific bounds
41
+ */
42
+ export declare function animateToBounds(ctx: AnimatedNavigationContext, targetBounds: Partial<Bounds>, options?: {
43
+ duration?: number;
44
+ easing?: string;
45
+ }): AnimationHandle;
46
+ /**
47
+ * Check if any navigation animation is running
48
+ */
49
+ export declare function isNavigationAnimating(): boolean;
50
+ /**
51
+ * Cancel all navigation animations
52
+ */
53
+ export declare function cancelNavigationAnimations(): void;