@jigonzalez930209/scichart-engine 0.1.0

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,102 @@
1
+ import { Bounds } from '../types';
2
+ import { Scale } from '../scales';
3
+
4
+ export interface OverlayTheme {
5
+ /** Background color (usually transparent) */
6
+ background: string;
7
+ /** Axis line color */
8
+ axisColor: string;
9
+ /** Tick mark color */
10
+ tickColor: string;
11
+ /** Label text color */
12
+ labelColor: string;
13
+ /** Grid line color */
14
+ gridColor: string;
15
+ /** Cursor line color */
16
+ cursorColor: string;
17
+ /** Font family */
18
+ fontFamily: string;
19
+ /** Base font size */
20
+ fontSize: number;
21
+ }
22
+ export declare const DEFAULT_THEME: OverlayTheme;
23
+ export interface AxisConfig {
24
+ /** Axis label (e.g., 'E / V') */
25
+ label?: string;
26
+ /** Tick values to draw */
27
+ ticks?: number[];
28
+ /** Format function for tick labels */
29
+ tickFormat?: (value: number) => string;
30
+ /** Show grid lines */
31
+ showGrid?: boolean;
32
+ }
33
+ export interface CursorState {
34
+ /** Cursor enabled */
35
+ enabled: boolean;
36
+ /** Cursor X position in pixels */
37
+ x: number;
38
+ /** Cursor Y position in pixels */
39
+ y: number;
40
+ /** Show crosshair */
41
+ crosshair: boolean;
42
+ /** Tooltip text */
43
+ tooltip?: string;
44
+ }
45
+ /**
46
+ * Canvas Overlay manages the 2D rendering layer
47
+ */
48
+ export declare class CanvasOverlay {
49
+ private canvas;
50
+ private ctx;
51
+ private dpr;
52
+ private theme;
53
+ private readonly MARGIN;
54
+ constructor(parentElement: HTMLElement, theme?: Partial<OverlayTheme>);
55
+ /**
56
+ * Resize the overlay canvas
57
+ */
58
+ resize(): void;
59
+ /**
60
+ * Get the plot area (excluding margins)
61
+ */
62
+ getPlotArea(): {
63
+ x: number;
64
+ y: number;
65
+ width: number;
66
+ height: number;
67
+ };
68
+ /**
69
+ * Clear the overlay
70
+ */
71
+ clear(): void;
72
+ /**
73
+ * Render axes
74
+ */
75
+ renderAxes(bounds: Bounds, xAxis?: AxisConfig, yAxis?: AxisConfig, xScale?: Scale, yScale?: Scale): void;
76
+ private renderGrid;
77
+ private renderXAxis;
78
+ private renderYAxis;
79
+ private renderXAxisLabel;
80
+ private renderYAxisLabel;
81
+ /**
82
+ * Render cursor/crosshair
83
+ */
84
+ renderCursor(cursor: CursorState): void;
85
+ /**
86
+ * Render tooltip
87
+ */
88
+ renderTooltip(x: number, y: number, text: string): void;
89
+ /**
90
+ * Render FPS counter (debug)
91
+ */
92
+ renderFPS(fps: number, frameTime: number): void;
93
+ private dataToPixelX;
94
+ private dataToPixelY;
95
+ private generateTicks;
96
+ private formatNumber;
97
+ private formatScientific;
98
+ /**
99
+ * Destroy the overlay
100
+ */
101
+ destroy(): void;
102
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Overlay module exports
3
+ */
4
+ export { CanvasOverlay, DEFAULT_THEME, type OverlayTheme, type AxisConfig, type CursorState, } from './CanvasOverlay';
@@ -0,0 +1,60 @@
1
+ import { CSSProperties } from 'react';
2
+ import { UseSciChartOptions } from './useSciChart';
3
+ import { ZoomOptions, CursorOptions, Bounds } from '../types';
4
+ import { Chart } from '../core/Chart';
5
+
6
+ export interface SciChartSeries {
7
+ id: string;
8
+ x: Float32Array | Float64Array;
9
+ y: Float32Array | Float64Array;
10
+ color?: string;
11
+ width?: number;
12
+ visible?: boolean;
13
+ }
14
+ export interface SciChartProps extends UseSciChartOptions {
15
+ /** Series data to display */
16
+ series?: SciChartSeries[];
17
+ /** Zoom state (controlled) */
18
+ zoom?: ZoomOptions;
19
+ /** Callback when zoom changes */
20
+ onZoomChange?: (bounds: Bounds) => void;
21
+ /** Cursor configuration */
22
+ cursor?: CursorOptions;
23
+ /** Container width */
24
+ width?: number | string;
25
+ /** Container height */
26
+ height?: number | string;
27
+ /** Additional class name */
28
+ className?: string;
29
+ /** Additional styles */
30
+ style?: CSSProperties;
31
+ /** Debug mode - shows FPS counter */
32
+ debug?: boolean;
33
+ }
34
+ export interface SciChartRef {
35
+ /** Get the chart instance */
36
+ getChart: () => Chart | null;
37
+ /** Reset zoom to show all data */
38
+ resetZoom: () => void;
39
+ /** Get current bounds */
40
+ getBounds: () => Bounds | null;
41
+ }
42
+ /**
43
+ * SciChart React Component
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * <SciChart
48
+ * series={[
49
+ * { id: 'cv-1', x: potentialData, y: currentData, color: '#ff0055' }
50
+ * ]}
51
+ * xAxis={{ label: 'E / V' }}
52
+ * yAxis={{ label: 'I / A' }}
53
+ * height={400}
54
+ * cursor={{ enabled: true, snap: true }}
55
+ * onZoomChange={(bounds) => console.log('Zoom:', bounds)}
56
+ * />
57
+ * ```
58
+ */
59
+ export declare const SciChart: import('react').ForwardRefExoticComponent<SciChartProps & import('react').RefAttributes<SciChartRef>>;
60
+ export default SciChart;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * React bindings for SciChart Engine
3
+ */
4
+ export { SciChart, type SciChartProps, type SciChartRef, type SciChartSeries } from './SciChart';
5
+ export { useSciChart, type UseSciChartOptions, type UseSciChartReturn } from './useSciChart';
@@ -0,0 +1,56 @@
1
+ import { RefObject } from 'react';
2
+ import { Chart, ChartOptions } from '../core/Chart';
3
+ import { SeriesOptions, SeriesUpdateData, ZoomOptions, Bounds } from '../types';
4
+
5
+ export interface UseSciChartOptions extends Omit<ChartOptions, "container"> {
6
+ /** Auto-resize on container changes */
7
+ autoResize?: boolean;
8
+ }
9
+ export interface UseSciChartReturn {
10
+ /** Chart instance (null until initialized) */
11
+ chart: Chart | null;
12
+ /** Whether the chart is ready */
13
+ isReady: boolean;
14
+ /** Error during initialization */
15
+ error: Error | null;
16
+ /** Current view bounds */
17
+ bounds: Bounds | null;
18
+ /** Add a series */
19
+ addSeries: (options: SeriesOptions) => void;
20
+ /** Update series data */
21
+ updateSeries: (id: string, data: SeriesUpdateData) => void;
22
+ /** Remove a series */
23
+ removeSeries: (id: string) => void;
24
+ /** Set zoom range */
25
+ zoom: (options: ZoomOptions) => void;
26
+ /** Reset zoom to show all data */
27
+ resetZoom: () => void;
28
+ }
29
+ /**
30
+ * React hook for using SciChart Engine
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * function MyChart() {
35
+ * const canvasRef = useRef<HTMLCanvasElement>(null);
36
+ * const { chart, isReady, addSeries, zoom } = useSciChart(canvasRef, {
37
+ * xAxis: { label: 'E / V' },
38
+ * yAxis: { label: 'I / A' }
39
+ * });
40
+ *
41
+ * useEffect(() => {
42
+ * if (isReady) {
43
+ * addSeries({
44
+ * id: 'cv-1',
45
+ * type: 'line',
46
+ * data: { x: xData, y: yData },
47
+ * style: { color: '#ff0055' }
48
+ * });
49
+ * }
50
+ * }, [isReady]);
51
+ *
52
+ * return <canvas ref={canvasRef} />;
53
+ * }
54
+ * ```
55
+ */
56
+ export declare function useSciChart(containerRef: RefObject<HTMLDivElement>, options?: UseSciChartOptions): UseSciChartReturn;
@@ -0,0 +1,69 @@
1
+ import { Bounds, SeriesStyle } from '../types';
2
+
3
+ export interface NativeSeriesRenderData {
4
+ id: string;
5
+ buffer: WebGLBuffer;
6
+ count: number;
7
+ style: SeriesStyle;
8
+ visible: boolean;
9
+ type: "line" | "scatter" | "line+scatter";
10
+ }
11
+ export interface NativeRenderOptions {
12
+ bounds: Bounds;
13
+ backgroundColor?: [number, number, number, number];
14
+ }
15
+ export declare class NativeWebGLRenderer {
16
+ private canvas;
17
+ private gl;
18
+ private dpr;
19
+ private lineProgram;
20
+ private pointProgram;
21
+ private buffers;
22
+ private bufferSizes;
23
+ private isInitialized;
24
+ constructor(canvas: HTMLCanvasElement);
25
+ private createShader;
26
+ private createProgram;
27
+ get available(): boolean;
28
+ /**
29
+ * Create or update a buffer with interleaved X,Y data
30
+ */
31
+ createBuffer(id: string, data: Float32Array): void;
32
+ /**
33
+ * Get a buffer by ID
34
+ */
35
+ getBuffer(id: string): WebGLBuffer | undefined;
36
+ /**
37
+ * Delete a buffer
38
+ */
39
+ deleteBuffer(id: string): void;
40
+ /**
41
+ * Calculate uniforms for the current viewport
42
+ */
43
+ private calculateUniforms;
44
+ /**
45
+ * Render a frame
46
+ */
47
+ render(series: NativeSeriesRenderData[], options: NativeRenderOptions): void;
48
+ private renderLine;
49
+ private renderPoints;
50
+ /**
51
+ * Handle resize
52
+ */
53
+ resize(): void;
54
+ /**
55
+ * Get WebGL limits (for debugging)
56
+ */
57
+ getLimits(): {
58
+ maxTextureSize: any;
59
+ maxViewportDims: any;
60
+ renderer: any;
61
+ vendor: any;
62
+ };
63
+ /**
64
+ * Destroy and cleanup
65
+ */
66
+ destroy(): void;
67
+ }
68
+ export declare function parseColor(color: string): [number, number, number, number];
69
+ export declare function interleaveData(x: Float32Array | Float64Array | number[], y: Float32Array | Float64Array | number[]): Float32Array;
@@ -0,0 +1,61 @@
1
+ import { Bounds, SeriesStyle } from '../types';
2
+
3
+ export interface SeriesRenderData {
4
+ id: string;
5
+ buffer: WebGLBuffer;
6
+ count: number;
7
+ style: SeriesStyle;
8
+ visible: boolean;
9
+ type: 'line' | 'scatter';
10
+ }
11
+ export interface RenderOptions {
12
+ bounds: Bounds;
13
+ backgroundColor?: [number, number, number, number];
14
+ }
15
+ /**
16
+ * Common interface for all WebGL renderer implementations
17
+ */
18
+ export interface IWebGLRenderer {
19
+ /** Check if WebGL is available and initialized */
20
+ readonly available: boolean;
21
+ /**
22
+ * Create or update a GPU buffer with interleaved X,Y data
23
+ * @param id - Unique buffer identifier
24
+ * @param data - Interleaved Float32Array [x0, y0, x1, y1, ...]
25
+ */
26
+ createBuffer(id: string, data: Float32Array): void;
27
+ /**
28
+ * Get a buffer by ID
29
+ */
30
+ getBuffer(id: string): WebGLBuffer | undefined;
31
+ /**
32
+ * Delete a buffer and free GPU memory
33
+ */
34
+ deleteBuffer(id: string): void;
35
+ /**
36
+ * Render a frame with all visible series
37
+ */
38
+ render(series: SeriesRenderData[], options: RenderOptions): void;
39
+ /**
40
+ * Handle canvas resize
41
+ */
42
+ resize(): void;
43
+ /**
44
+ * Get WebGL capabilities/limits
45
+ */
46
+ getLimits(): Record<string, unknown>;
47
+ /**
48
+ * Cleanup and destroy all GPU resources
49
+ */
50
+ destroy(): void;
51
+ }
52
+ /**
53
+ * Create a WebGL renderer (Native WebGL)
54
+ *
55
+ * @param canvas - Target canvas element
56
+ */
57
+ export declare function createRenderer(canvas: HTMLCanvasElement): IWebGLRenderer;
58
+ /**
59
+ * Create a renderer synchronously (native only)
60
+ */
61
+ export { NativeWebGLRenderer as createNativeRenderer } from './NativeWebGLRenderer';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Renderer module exports
3
+ */
4
+ export { NativeWebGLRenderer, interleaveData, parseColor, type NativeSeriesRenderData, type NativeRenderOptions, } from './NativeWebGLRenderer';
5
+ export { type IWebGLRenderer, type SeriesRenderData, type RenderOptions, createRenderer, createNativeRenderer, } from './RendererInterface';
6
+ export * from './shaders';
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Line Vertex Shader
3
+ *
4
+ * Transforms 2D points from data space to clip space using uniforms.
5
+ * This allows zoom/pan without recreating vertex buffers.
6
+ */
7
+ export declare const lineVertexShader = "\nprecision highp float;\n\n// Attributes (per-vertex data)\nattribute vec2 position;\n\n// Uniforms (constant across all vertices)\nuniform vec2 uScale; // Zoom factor [scaleX, scaleY]\nuniform vec2 uTranslate; // Pan offset [translateX, translateY]\nuniform vec2 uResolution; // Canvas size in pixels\n\n// Varying (passed to fragment shader)\nvarying float vAlpha;\n\nvoid main() {\n // Transform position: apply scale and translate\n vec2 pos = position * uScale + uTranslate;\n\n // pos is now in normalized device coordinates (-1 to 1)\n gl_Position = vec4(pos, 0.0, 1.0);\n\n // Pass alpha for potential fading effects\n vAlpha = 1.0;\n}\n";
8
+ /**
9
+ * Line Fragment Shader
10
+ *
11
+ * Simple solid color output with configurable opacity.
12
+ */
13
+ export declare const lineFragmentShader = "\nprecision highp float;\n\n// Uniforms\nuniform vec4 uColor; // RGBA color\n\n// Varying from vertex shader\nvarying float vAlpha;\n\nvoid main() {\n gl_FragColor = vec4(uColor.rgb, uColor.a * vAlpha);\n}\n";
14
+ /**
15
+ * Antialiased Line Vertex Shader
16
+ *
17
+ * For thick lines with proper antialiasing, we need to expand
18
+ * lines into quads and compute distance from line center.
19
+ */
20
+ export declare const lineAAVertexShader = "\nprecision highp float;\n\nattribute vec2 position;\nattribute vec2 normal; // Perpendicular to line direction\nattribute float miter; // Miter length for joins\n\nuniform vec2 uScale;\nuniform vec2 uTranslate;\nuniform vec2 uResolution;\nuniform float uLineWidth;\n\nvarying vec2 vNormal;\nvarying float vLineWidth;\n\nvoid main() {\n // Transform position\n vec2 pos = position * uScale + uTranslate;\n\n // Convert to screen space for line width calculation\n vec2 screenPos = (pos * 0.5 + 0.5) * uResolution;\n\n // Offset by line width in screen space\n float halfWidth = uLineWidth * 0.5;\n screenPos += normal * halfWidth * miter;\n\n // Convert back to clip space\n pos = (screenPos / uResolution) * 2.0 - 1.0;\n\n gl_Position = vec4(pos, 0.0, 1.0);\n\n vNormal = normal;\n vLineWidth = uLineWidth;\n}\n";
21
+ /**
22
+ * Antialiased Line Fragment Shader
23
+ *
24
+ * Uses distance-based antialiasing for smooth edges.
25
+ */
26
+ export declare const lineAAFragmentShader = "\nprecision highp float;\n\nuniform vec4 uColor;\nuniform float uLineWidth;\n\nvarying vec2 vNormal;\nvarying float vLineWidth;\n\nvoid main() {\n // Distance from line center (0 at center, 1 at edge)\n float dist = length(vNormal);\n\n // Smooth step for antialiasing\n float aa = 1.0 / uLineWidth;\n float alpha = 1.0 - smoothstep(1.0 - aa, 1.0, dist);\n\n gl_FragColor = vec4(uColor.rgb, uColor.a * alpha);\n}\n";
27
+ /**
28
+ * Point/Scatter Vertex Shader
29
+ *
30
+ * Renders data points as squares/circles.
31
+ */
32
+ export declare const pointVertexShader = "\nprecision highp float;\n\nattribute vec2 position;\n\nuniform vec2 uScale;\nuniform vec2 uTranslate;\nuniform float uPointSize;\n\nvoid main() {\n vec2 pos = position * uScale + uTranslate;\n gl_Position = vec4(pos, 0.0, 1.0);\n gl_PointSize = uPointSize;\n}\n";
33
+ /**
34
+ * Point/Scatter Fragment Shader
35
+ *
36
+ * Renders circular points with smooth edges.
37
+ */
38
+ export declare const pointFragmentShader = "\nprecision highp float;\n\nuniform vec4 uColor;\n\nvoid main() {\n // Distance from point center\n vec2 coord = gl_PointCoord - vec2(0.5);\n float dist = length(coord);\n\n // Discard outside circle\n if (dist > 0.5) discard;\n\n // Smooth edge\n float alpha = 1.0 - smoothstep(0.4, 0.5, dist);\n\n gl_FragColor = vec4(uColor.rgb, uColor.a * alpha);\n}\n";
39
+ /**
40
+ * Heatmap Vertex Shader (for future density plots)
41
+ */
42
+ export declare const heatmapVertexShader = "\nprecision highp float;\n\nattribute vec2 position;\nattribute float value;\n\nuniform vec2 uScale;\nuniform vec2 uTranslate;\n\nvarying float vValue;\n\nvoid main() {\n vec2 pos = position * uScale + uTranslate;\n gl_Position = vec4(pos, 0.0, 1.0);\n vValue = value;\n}\n";
43
+ /**
44
+ * Heatmap Fragment Shader
45
+ *
46
+ * Maps values to colors using a colormap.
47
+ */
48
+ export declare const heatmapFragmentShader = "\nprecision highp float;\n\nuniform float uMinValue;\nuniform float uMaxValue;\nuniform sampler2D uColormap;\n\nvarying float vValue;\n\nvoid main() {\n float normalized = (vValue - uMinValue) / (uMaxValue - uMinValue);\n normalized = clamp(normalized, 0.0, 1.0);\n\n vec4 color = texture2D(uColormap, vec2(normalized, 0.5));\n gl_FragColor = color;\n}\n";
49
+ export declare const Shaders: {
50
+ line: {
51
+ vertex: string;
52
+ fragment: string;
53
+ };
54
+ lineAA: {
55
+ vertex: string;
56
+ fragment: string;
57
+ };
58
+ point: {
59
+ vertex: string;
60
+ fragment: string;
61
+ };
62
+ heatmap: {
63
+ vertex: string;
64
+ fragment: string;
65
+ };
66
+ };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Scale interface and implementations
3
+ *
4
+ * Scales transform data values to pixel coordinates and vice versa.
5
+ */
6
+ export interface Scale {
7
+ /** Data domain [min, max] */
8
+ domain: [number, number];
9
+ /** Pixel range [min, max] */
10
+ range: [number, number];
11
+ /** Scale type identifier */
12
+ type: "linear" | "log";
13
+ /** Set the domain */
14
+ setDomain(min: number, max: number): void;
15
+ /** Set the range */
16
+ setRange(min: number, max: number): void;
17
+ /** Transform data value to pixel */
18
+ transform(value: number): number;
19
+ /** Transform pixel to data value */
20
+ invert(pixel: number): number;
21
+ /** Generate nice tick values */
22
+ ticks(count?: number): number[];
23
+ }
24
+ /**
25
+ * Linear scale - proportional mapping
26
+ */
27
+ export declare class LinearScale implements Scale {
28
+ domain: [number, number];
29
+ range: [number, number];
30
+ readonly type: "linear";
31
+ setDomain(min: number, max: number): void;
32
+ setRange(min: number, max: number): void;
33
+ transform(value: number): number;
34
+ invert(pixel: number): number;
35
+ ticks(count?: number): number[];
36
+ }
37
+ /**
38
+ * Logarithmic scale - for exponential data
39
+ */
40
+ export declare class LogScale implements Scale {
41
+ domain: [number, number];
42
+ range: [number, number];
43
+ readonly type: "log";
44
+ private base;
45
+ setDomain(min: number, max: number): void;
46
+ setRange(min: number, max: number): void;
47
+ transform(value: number): number;
48
+ invert(pixel: number): number;
49
+ ticks(count?: number): number[];
50
+ }
51
+ /**
52
+ * Factory function to create scale by type
53
+ */
54
+ export declare function createScale(type: "linear" | "log"): Scale;