spectraview 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.
- package/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +158 -0
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +504 -0
- package/dist/index.d.ts +504 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/package.json +99 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as d3_scale from 'd3-scale';
|
|
3
|
+
import { ScaleLinear } from 'd3-scale';
|
|
4
|
+
import { ZoomTransform } from 'd3-zoom';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Core type definitions for SpectraView.
|
|
8
|
+
*
|
|
9
|
+
* @module types
|
|
10
|
+
*/
|
|
11
|
+
/** Supported spectral technique types. */
|
|
12
|
+
type SpectrumType = "IR" | "Raman" | "NIR" | "UV-Vis" | "fluorescence" | "other";
|
|
13
|
+
/** A single spectrum dataset. */
|
|
14
|
+
interface Spectrum {
|
|
15
|
+
/** Unique identifier. */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Display label. */
|
|
18
|
+
label: string;
|
|
19
|
+
/** X-axis values (wavenumbers, wavelengths, Raman shift, etc.). */
|
|
20
|
+
x: Float64Array | number[];
|
|
21
|
+
/** Y-axis values (absorbance, transmittance, intensity, etc.). */
|
|
22
|
+
y: Float64Array | number[];
|
|
23
|
+
/** X-axis unit (e.g., "cm⁻¹", "nm"). */
|
|
24
|
+
xUnit?: string;
|
|
25
|
+
/** Y-axis unit (e.g., "Absorbance", "Transmittance"). */
|
|
26
|
+
yUnit?: string;
|
|
27
|
+
/** Spectral technique type. */
|
|
28
|
+
type?: SpectrumType;
|
|
29
|
+
/** Rendering color (CSS color string). */
|
|
30
|
+
color?: string;
|
|
31
|
+
/** Whether this spectrum is visible. */
|
|
32
|
+
visible?: boolean;
|
|
33
|
+
/** Arbitrary metadata from file headers. */
|
|
34
|
+
meta?: Record<string, string | number>;
|
|
35
|
+
}
|
|
36
|
+
/** A detected peak in a spectrum. */
|
|
37
|
+
interface Peak {
|
|
38
|
+
/** X-axis position. */
|
|
39
|
+
x: number;
|
|
40
|
+
/** Y-axis position. */
|
|
41
|
+
y: number;
|
|
42
|
+
/** Optional display label (e.g., wavenumber annotation). */
|
|
43
|
+
label?: string;
|
|
44
|
+
/** Associated spectrum ID. */
|
|
45
|
+
spectrumId?: string;
|
|
46
|
+
}
|
|
47
|
+
/** A selected x-axis region. */
|
|
48
|
+
interface Region {
|
|
49
|
+
/** Start X value. */
|
|
50
|
+
xStart: number;
|
|
51
|
+
/** End X value. */
|
|
52
|
+
xEnd: number;
|
|
53
|
+
/** Optional display label. */
|
|
54
|
+
label?: string;
|
|
55
|
+
/** Optional fill color. */
|
|
56
|
+
color?: string;
|
|
57
|
+
}
|
|
58
|
+
/** Current zoom/pan view state. */
|
|
59
|
+
interface ViewState {
|
|
60
|
+
/** Visible x-axis domain [min, max]. */
|
|
61
|
+
xDomain: [number, number];
|
|
62
|
+
/** Visible y-axis domain [min, max]. */
|
|
63
|
+
yDomain: [number, number];
|
|
64
|
+
}
|
|
65
|
+
/** Theme configuration. */
|
|
66
|
+
type Theme = "light" | "dark";
|
|
67
|
+
/** Display mode for multiple spectra. */
|
|
68
|
+
type DisplayMode = "overlay";
|
|
69
|
+
/** Margin configuration for the chart area. */
|
|
70
|
+
interface Margin {
|
|
71
|
+
top: number;
|
|
72
|
+
right: number;
|
|
73
|
+
bottom: number;
|
|
74
|
+
left: number;
|
|
75
|
+
}
|
|
76
|
+
/** Props for the main SpectraView component. */
|
|
77
|
+
interface SpectraViewProps {
|
|
78
|
+
/** Array of spectra to display. */
|
|
79
|
+
spectra: Spectrum[];
|
|
80
|
+
/** Width in pixels. */
|
|
81
|
+
width?: number;
|
|
82
|
+
/** Height in pixels. */
|
|
83
|
+
height?: number;
|
|
84
|
+
/** Reverse X axis (standard for IR wavenumber). */
|
|
85
|
+
reverseX?: boolean;
|
|
86
|
+
/** Show grid lines. */
|
|
87
|
+
showGrid?: boolean;
|
|
88
|
+
/** Show crosshair on hover. */
|
|
89
|
+
showCrosshair?: boolean;
|
|
90
|
+
/** Show toolbar controls. */
|
|
91
|
+
showToolbar?: boolean;
|
|
92
|
+
/** Peak markers to display. */
|
|
93
|
+
peaks?: Peak[];
|
|
94
|
+
/** Highlighted regions. */
|
|
95
|
+
regions?: Region[];
|
|
96
|
+
/** X-axis label override. */
|
|
97
|
+
xLabel?: string;
|
|
98
|
+
/** Y-axis label override. */
|
|
99
|
+
yLabel?: string;
|
|
100
|
+
/** Display mode for multiple spectra. */
|
|
101
|
+
displayMode?: DisplayMode;
|
|
102
|
+
/** Chart margins. */
|
|
103
|
+
margin?: Partial<Margin>;
|
|
104
|
+
/** Theme. */
|
|
105
|
+
theme?: Theme;
|
|
106
|
+
/** Custom CSS class name. */
|
|
107
|
+
className?: string;
|
|
108
|
+
/** Callback when user clicks a peak marker. */
|
|
109
|
+
onPeakClick?: (peak: Peak) => void;
|
|
110
|
+
/** Callback when zoom/pan state changes. */
|
|
111
|
+
onViewChange?: (view: ViewState) => void;
|
|
112
|
+
/** Callback when crosshair position changes. */
|
|
113
|
+
onCrosshairMove?: (x: number, y: number) => void;
|
|
114
|
+
}
|
|
115
|
+
/** Internal resolved configuration (defaults merged with user props). */
|
|
116
|
+
interface ResolvedConfig {
|
|
117
|
+
width: number;
|
|
118
|
+
height: number;
|
|
119
|
+
reverseX: boolean;
|
|
120
|
+
showGrid: boolean;
|
|
121
|
+
showCrosshair: boolean;
|
|
122
|
+
showToolbar: boolean;
|
|
123
|
+
displayMode: DisplayMode;
|
|
124
|
+
margin: Margin;
|
|
125
|
+
theme: Theme;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
declare function SpectraView(props: SpectraViewProps): react_jsx_runtime.JSX.Element;
|
|
129
|
+
|
|
130
|
+
interface SpectrumCanvasProps {
|
|
131
|
+
/** Spectra to render. */
|
|
132
|
+
spectra: Spectrum[];
|
|
133
|
+
/** X-axis scale (already zoomed). */
|
|
134
|
+
xScale: ScaleLinear<number, number>;
|
|
135
|
+
/** Y-axis scale (already zoomed). */
|
|
136
|
+
yScale: ScaleLinear<number, number>;
|
|
137
|
+
/** Canvas width in pixels. */
|
|
138
|
+
width: number;
|
|
139
|
+
/** Canvas height in pixels. */
|
|
140
|
+
height: number;
|
|
141
|
+
/** ID of the currently highlighted spectrum. */
|
|
142
|
+
highlightedId?: string;
|
|
143
|
+
}
|
|
144
|
+
declare function SpectrumCanvas({ spectra, xScale, yScale, width, height, highlightedId, }: SpectrumCanvasProps): react_jsx_runtime.JSX.Element;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Default color palette for rendering multiple spectra.
|
|
148
|
+
*
|
|
149
|
+
* Colors are chosen for good contrast on both light and dark backgrounds,
|
|
150
|
+
* and are distinguishable for common forms of color blindness.
|
|
151
|
+
*/
|
|
152
|
+
/** Default spectrum color palette (10 colors). */
|
|
153
|
+
declare const SPECTRUM_COLORS: readonly ["#2563eb", "#dc2626", "#16a34a", "#9333ea", "#ea580c", "#0891b2", "#be185d", "#854d0e", "#4f46e5", "#65a30d"];
|
|
154
|
+
/** Theme color definition. */
|
|
155
|
+
interface ThemeColors {
|
|
156
|
+
background: string;
|
|
157
|
+
axisColor: string;
|
|
158
|
+
gridColor: string;
|
|
159
|
+
tickColor: string;
|
|
160
|
+
labelColor: string;
|
|
161
|
+
crosshairColor: string;
|
|
162
|
+
regionFill: string;
|
|
163
|
+
regionStroke: string;
|
|
164
|
+
tooltipBg: string;
|
|
165
|
+
tooltipBorder: string;
|
|
166
|
+
tooltipText: string;
|
|
167
|
+
}
|
|
168
|
+
/** Light theme colors. */
|
|
169
|
+
declare const LIGHT_THEME: ThemeColors;
|
|
170
|
+
/** Dark theme colors. */
|
|
171
|
+
declare const DARK_THEME: ThemeColors;
|
|
172
|
+
/**
|
|
173
|
+
* Get the color for a spectrum at the given index.
|
|
174
|
+
*
|
|
175
|
+
* Cycles through the palette if index exceeds palette length.
|
|
176
|
+
*/
|
|
177
|
+
declare function getSpectrumColor(index: number): string;
|
|
178
|
+
/**
|
|
179
|
+
* Get theme colors for the given theme name.
|
|
180
|
+
*/
|
|
181
|
+
declare function getThemeColors(theme: "light" | "dark"): ThemeColors;
|
|
182
|
+
|
|
183
|
+
interface AxisLayerProps {
|
|
184
|
+
/** X-axis scale (already zoomed). */
|
|
185
|
+
xScale: ScaleLinear<number, number>;
|
|
186
|
+
/** Y-axis scale (already zoomed). */
|
|
187
|
+
yScale: ScaleLinear<number, number>;
|
|
188
|
+
/** Plot area width (excluding margins). */
|
|
189
|
+
width: number;
|
|
190
|
+
/** Plot area height (excluding margins). */
|
|
191
|
+
height: number;
|
|
192
|
+
/** X-axis label. */
|
|
193
|
+
xLabel?: string;
|
|
194
|
+
/** Y-axis label. */
|
|
195
|
+
yLabel?: string;
|
|
196
|
+
/** Show grid lines. */
|
|
197
|
+
showGrid?: boolean;
|
|
198
|
+
/** Theme colors. */
|
|
199
|
+
colors: ThemeColors;
|
|
200
|
+
}
|
|
201
|
+
declare function AxisLayer({ xScale, yScale, width, height, xLabel, yLabel, showGrid, colors, }: AxisLayerProps): react_jsx_runtime.JSX.Element;
|
|
202
|
+
|
|
203
|
+
interface PeakMarkersProps {
|
|
204
|
+
/** Peaks to display. */
|
|
205
|
+
peaks: Peak[];
|
|
206
|
+
/** X-axis scale (zoomed). */
|
|
207
|
+
xScale: ScaleLinear<number, number>;
|
|
208
|
+
/** Y-axis scale (zoomed). */
|
|
209
|
+
yScale: ScaleLinear<number, number>;
|
|
210
|
+
/** Theme colors. */
|
|
211
|
+
colors: ThemeColors;
|
|
212
|
+
/** Callback when a peak is clicked. */
|
|
213
|
+
onPeakClick?: (peak: Peak) => void;
|
|
214
|
+
}
|
|
215
|
+
declare function PeakMarkers({ peaks, xScale, yScale, colors, onPeakClick, }: PeakMarkersProps): react_jsx_runtime.JSX.Element;
|
|
216
|
+
|
|
217
|
+
interface RegionSelectorProps {
|
|
218
|
+
/** Existing regions to display. */
|
|
219
|
+
regions: Region[];
|
|
220
|
+
/** X-axis scale (zoomed). */
|
|
221
|
+
xScale: ScaleLinear<number, number>;
|
|
222
|
+
/** Plot area height. */
|
|
223
|
+
height: number;
|
|
224
|
+
/** Theme colors. */
|
|
225
|
+
colors: ThemeColors;
|
|
226
|
+
}
|
|
227
|
+
declare function RegionSelector({ regions, xScale, height, colors, }: RegionSelectorProps): react_jsx_runtime.JSX.Element;
|
|
228
|
+
|
|
229
|
+
/** Position data for the crosshair. */
|
|
230
|
+
interface CrosshairPosition {
|
|
231
|
+
/** Pixel x coordinate within the plot area. */
|
|
232
|
+
px: number;
|
|
233
|
+
/** Pixel y coordinate within the plot area. */
|
|
234
|
+
py: number;
|
|
235
|
+
/** Data-space x value. */
|
|
236
|
+
dataX: number;
|
|
237
|
+
/** Data-space y value. */
|
|
238
|
+
dataY: number;
|
|
239
|
+
}
|
|
240
|
+
interface CrosshairProps {
|
|
241
|
+
/** Current crosshair position, or null when not hovering. */
|
|
242
|
+
position: CrosshairPosition | null;
|
|
243
|
+
/** Plot area width. */
|
|
244
|
+
width: number;
|
|
245
|
+
/** Plot area height. */
|
|
246
|
+
height: number;
|
|
247
|
+
/** Theme colors. */
|
|
248
|
+
colors: ThemeColors;
|
|
249
|
+
}
|
|
250
|
+
declare function Crosshair({ position, width, height, colors, }: CrosshairProps): react_jsx_runtime.JSX.Element | null;
|
|
251
|
+
|
|
252
|
+
interface ToolbarProps {
|
|
253
|
+
/** Zoom in handler. */
|
|
254
|
+
onZoomIn: () => void;
|
|
255
|
+
/** Zoom out handler. */
|
|
256
|
+
onZoomOut: () => void;
|
|
257
|
+
/** Reset zoom handler. */
|
|
258
|
+
onReset: () => void;
|
|
259
|
+
/** Whether the view is currently zoomed. */
|
|
260
|
+
isZoomed: boolean;
|
|
261
|
+
/** Theme. */
|
|
262
|
+
theme: Theme;
|
|
263
|
+
}
|
|
264
|
+
declare function Toolbar({ onZoomIn, onZoomOut, onReset, isZoomed, theme, }: ToolbarProps): react_jsx_runtime.JSX.Element;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Hook for zoom and pan behavior backed by d3-zoom.
|
|
268
|
+
*
|
|
269
|
+
* Provides smooth mouse wheel zoom, click-drag pan, and double-click
|
|
270
|
+
* reset. Works with both the SVG overlay and Canvas data layers.
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
interface ZoomPanState {
|
|
274
|
+
/** Current d3 zoom transform. */
|
|
275
|
+
transform: ZoomTransform;
|
|
276
|
+
/** Whether the view is currently zoomed (not at identity). */
|
|
277
|
+
isZoomed: boolean;
|
|
278
|
+
}
|
|
279
|
+
interface UseZoomPanOptions {
|
|
280
|
+
/** Width of the plot area (excluding margins). */
|
|
281
|
+
plotWidth: number;
|
|
282
|
+
/** Height of the plot area (excluding margins). */
|
|
283
|
+
plotHeight: number;
|
|
284
|
+
/** Base x-scale (unzoomed). */
|
|
285
|
+
xScale: ScaleLinear<number, number>;
|
|
286
|
+
/** Base y-scale (unzoomed). */
|
|
287
|
+
yScale: ScaleLinear<number, number>;
|
|
288
|
+
/** Maximum zoom factor. */
|
|
289
|
+
scaleExtent?: [number, number];
|
|
290
|
+
/** Whether zoom/pan is enabled. */
|
|
291
|
+
enabled?: boolean;
|
|
292
|
+
/** Callback when the view changes. */
|
|
293
|
+
onViewChange?: (xDomain: [number, number], yDomain: [number, number]) => void;
|
|
294
|
+
}
|
|
295
|
+
interface UseZoomPanReturn {
|
|
296
|
+
/** Ref to attach to the interaction overlay element. */
|
|
297
|
+
zoomRef: React.RefObject<SVGRectElement | null>;
|
|
298
|
+
/** Current zoom/pan state. */
|
|
299
|
+
state: ZoomPanState;
|
|
300
|
+
/** Zoomed (rescaled) x-scale. */
|
|
301
|
+
zoomedXScale: ScaleLinear<number, number>;
|
|
302
|
+
/** Zoomed (rescaled) y-scale. */
|
|
303
|
+
zoomedYScale: ScaleLinear<number, number>;
|
|
304
|
+
/** Reset zoom to initial view. */
|
|
305
|
+
resetZoom: () => void;
|
|
306
|
+
/** Zoom in by a fixed step. */
|
|
307
|
+
zoomIn: () => void;
|
|
308
|
+
/** Zoom out by a fixed step. */
|
|
309
|
+
zoomOut: () => void;
|
|
310
|
+
}
|
|
311
|
+
declare function useZoomPan(options: UseZoomPanOptions): UseZoomPanReturn;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Peak detection for spectral data.
|
|
315
|
+
*
|
|
316
|
+
* Uses a simple local-maxima algorithm with prominence filtering,
|
|
317
|
+
* suitable for identifying peaks in IR, Raman, and NIR spectra.
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
interface PeakDetectionOptions {
|
|
321
|
+
/** Minimum prominence relative to the signal range. */
|
|
322
|
+
prominence?: number;
|
|
323
|
+
/** Minimum distance between peaks in data points. */
|
|
324
|
+
minDistance?: number;
|
|
325
|
+
/** Maximum number of peaks to return (sorted by prominence). */
|
|
326
|
+
maxPeaks?: number;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Detect peaks in a 1D signal using local maxima with prominence filtering.
|
|
330
|
+
*
|
|
331
|
+
* @param x - X-axis values (wavenumbers, wavelengths, etc.)
|
|
332
|
+
* @param y - Y-axis values (absorbance, intensity, etc.)
|
|
333
|
+
* @param options - Detection parameters
|
|
334
|
+
* @returns Array of detected peaks sorted by x position
|
|
335
|
+
*/
|
|
336
|
+
declare function detectPeaks(x: Float64Array | number[], y: Float64Array | number[], options?: PeakDetectionOptions): Peak[];
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Hook for automatic peak detection in spectral data.
|
|
340
|
+
*
|
|
341
|
+
* Wraps the peak detection algorithm with React state management
|
|
342
|
+
* and recalculates when spectra or options change.
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
interface UsePeakPickingOptions extends PeakDetectionOptions {
|
|
346
|
+
/** Whether peak picking is enabled. */
|
|
347
|
+
enabled?: boolean;
|
|
348
|
+
/** Only detect peaks for these spectrum IDs (all if not specified). */
|
|
349
|
+
spectrumIds?: string[];
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Automatically detect peaks across one or more spectra.
|
|
353
|
+
*
|
|
354
|
+
* @param spectra - Array of spectra to analyze
|
|
355
|
+
* @param options - Peak detection configuration
|
|
356
|
+
* @returns Array of detected peaks with associated spectrum IDs
|
|
357
|
+
*/
|
|
358
|
+
declare function usePeakPicking(spectra: Spectrum[], options?: UsePeakPickingOptions): Peak[];
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Hook for managing spectrum data loading and state.
|
|
362
|
+
*
|
|
363
|
+
* Handles file loading (drag-and-drop, file input), parsing,
|
|
364
|
+
* and managing the collection of loaded spectra.
|
|
365
|
+
*/
|
|
366
|
+
|
|
367
|
+
interface UseSpectrumDataReturn {
|
|
368
|
+
/** Currently loaded spectra. */
|
|
369
|
+
spectra: Spectrum[];
|
|
370
|
+
/** Whether a file is currently being loaded. */
|
|
371
|
+
loading: boolean;
|
|
372
|
+
/** Last error message, if any. */
|
|
373
|
+
error: string | null;
|
|
374
|
+
/** Load spectra from a File object (detects format from extension). */
|
|
375
|
+
loadFile: (file: File) => Promise<void>;
|
|
376
|
+
/** Load spectra from a raw text string with explicit format. */
|
|
377
|
+
loadText: (text: string, format: "jcamp" | "csv" | "json") => Promise<void>;
|
|
378
|
+
/** Add a spectrum directly. */
|
|
379
|
+
addSpectrum: (spectrum: Spectrum) => void;
|
|
380
|
+
/** Remove a spectrum by ID. */
|
|
381
|
+
removeSpectrum: (id: string) => void;
|
|
382
|
+
/** Toggle a spectrum's visibility. */
|
|
383
|
+
toggleVisibility: (id: string) => void;
|
|
384
|
+
/** Clear all loaded spectra. */
|
|
385
|
+
clear: () => void;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Hook for loading and managing spectral data.
|
|
389
|
+
*/
|
|
390
|
+
declare function useSpectrumData(initialSpectra?: Spectrum[]): UseSpectrumDataReturn;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Hook for exporting the spectrum view as PNG, SVG, or CSV data.
|
|
394
|
+
*/
|
|
395
|
+
|
|
396
|
+
interface UseExportReturn {
|
|
397
|
+
/** Export the canvas as a PNG data URL. */
|
|
398
|
+
exportPng: (canvas: HTMLCanvasElement, filename?: string) => void;
|
|
399
|
+
/** Export visible spectra as CSV text. */
|
|
400
|
+
exportCsv: (spectra: Spectrum[], filename?: string) => void;
|
|
401
|
+
/** Export visible spectra as JSON. */
|
|
402
|
+
exportJson: (spectra: Spectrum[], filename?: string) => void;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Hook for exporting spectrum data and visualizations.
|
|
406
|
+
*/
|
|
407
|
+
declare function useExport(): UseExportReturn;
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* JCAMP-DX parser for spectral data.
|
|
411
|
+
*
|
|
412
|
+
* Wraps the `jcampconverter` npm package (optional peer dependency)
|
|
413
|
+
* to parse .dx, .jdx, and .jcamp files into Spectrum objects.
|
|
414
|
+
*
|
|
415
|
+
* If jcampconverter is not installed, a lightweight built-in parser
|
|
416
|
+
* handles basic AFFN (ASCII Free Format Numeric) JCAMP-DX files.
|
|
417
|
+
*/
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Parse a JCAMP-DX string into Spectrum objects.
|
|
421
|
+
*
|
|
422
|
+
* Uses jcampconverter if available, otherwise falls back to the built-in
|
|
423
|
+
* parser for basic AFFN format files.
|
|
424
|
+
*
|
|
425
|
+
* @param text - Raw JCAMP-DX file content
|
|
426
|
+
* @returns Array of parsed Spectrum objects
|
|
427
|
+
*/
|
|
428
|
+
declare function parseJcamp(text: string): Promise<Spectrum[]>;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* CSV/TSV parser for spectral data.
|
|
432
|
+
*
|
|
433
|
+
* Handles comma, tab, and semicolon delimiters with automatic detection.
|
|
434
|
+
* Supports files with or without header rows.
|
|
435
|
+
*/
|
|
436
|
+
|
|
437
|
+
interface CsvParseOptions {
|
|
438
|
+
/** Column delimiter (auto-detected if not provided). */
|
|
439
|
+
delimiter?: string;
|
|
440
|
+
/** Zero-based index of the x-value column. */
|
|
441
|
+
xColumn?: number;
|
|
442
|
+
/** Zero-based index of the y-value column. */
|
|
443
|
+
yColumn?: number;
|
|
444
|
+
/** Whether the first row is a header. */
|
|
445
|
+
hasHeader?: boolean;
|
|
446
|
+
/** Label for the parsed spectrum. */
|
|
447
|
+
label?: string;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Parse a CSV/TSV string into a Spectrum object.
|
|
451
|
+
*
|
|
452
|
+
* @param text - Raw CSV/TSV text content
|
|
453
|
+
* @param options - Parsing configuration
|
|
454
|
+
* @returns Parsed Spectrum
|
|
455
|
+
* @throws Error if the data cannot be parsed
|
|
456
|
+
*/
|
|
457
|
+
declare function parseCsv(text: string, options?: CsvParseOptions): Spectrum;
|
|
458
|
+
/**
|
|
459
|
+
* Parse a CSV string containing multiple y-columns into multiple spectra.
|
|
460
|
+
*
|
|
461
|
+
* The first column is treated as x-values, and each subsequent column
|
|
462
|
+
* becomes a separate spectrum.
|
|
463
|
+
*/
|
|
464
|
+
declare function parseCsvMulti(text: string, options?: Omit<CsvParseOptions, "xColumn" | "yColumn">): Spectrum[];
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* JSON parser for spectral data.
|
|
468
|
+
*
|
|
469
|
+
* Supports multiple JSON formats commonly used for spectral data exchange.
|
|
470
|
+
*/
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Parse a JSON string into one or more Spectrum objects.
|
|
474
|
+
*
|
|
475
|
+
* Handles both single spectrum objects and arrays of spectra.
|
|
476
|
+
* Supports flexible key names (x/wavenumbers, y/intensities, etc.).
|
|
477
|
+
*
|
|
478
|
+
* @param text - Raw JSON string
|
|
479
|
+
* @returns Array of parsed Spectrum objects
|
|
480
|
+
* @throws Error if the JSON cannot be parsed or has invalid structure
|
|
481
|
+
*/
|
|
482
|
+
declare function parseJson(text: string): Spectrum[];
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Compute the x-axis extent across all visible spectra.
|
|
486
|
+
*/
|
|
487
|
+
declare function computeXExtent(spectra: Spectrum[]): [number, number];
|
|
488
|
+
/**
|
|
489
|
+
* Compute the y-axis extent across all visible spectra with padding.
|
|
490
|
+
*/
|
|
491
|
+
declare function computeYExtent(spectra: Spectrum[]): [number, number];
|
|
492
|
+
/**
|
|
493
|
+
* Create an x-axis scale.
|
|
494
|
+
*
|
|
495
|
+
* When `reverseX` is true, the domain is reversed so higher wavenumbers
|
|
496
|
+
* appear on the left (standard IR convention).
|
|
497
|
+
*/
|
|
498
|
+
declare function createXScale(domain: [number, number], width: number, margin: Margin, reverseX: boolean): d3_scale.ScaleLinear<number, number, never>;
|
|
499
|
+
/**
|
|
500
|
+
* Create a y-axis scale (always low values at bottom, high at top).
|
|
501
|
+
*/
|
|
502
|
+
declare function createYScale(domain: [number, number], height: number, margin: Margin): d3_scale.ScaleLinear<number, number, never>;
|
|
503
|
+
|
|
504
|
+
export { AxisLayer, Crosshair, type CrosshairPosition, type CrosshairProps, type CsvParseOptions, DARK_THEME, type DisplayMode, LIGHT_THEME, type Margin, type Peak, type PeakDetectionOptions, PeakMarkers, type Region, RegionSelector, type ResolvedConfig, SPECTRUM_COLORS, SpectraView, type SpectraViewProps, type Spectrum, SpectrumCanvas, type SpectrumType, type Theme, Toolbar, type UseExportReturn, type UsePeakPickingOptions, type UseSpectrumDataReturn, type UseZoomPanOptions, type UseZoomPanReturn, type ViewState, type ZoomPanState, computeXExtent, computeYExtent, createXScale, createYScale, detectPeaks, getSpectrumColor, getThemeColors, parseCsv, parseCsvMulti, parseJcamp, parseJson, useExport, usePeakPicking, useSpectrumData, useZoomPan };
|