Skip to content

Commit d20f32f

Browse files
authored
docs: improve JSDoc across 10 files (#373)
- Add missing JSDoc to zeroShift, matrixAutoCorrelation, matrixBoxPlot - Document sorted-rows invariant on matrixBoxPlot - Add interface property docs to MatrixBoxPlot - Trim verbose xyEquallySpaced prose; fix stub from/to/variant descriptions - Fix xGetFromToIndex descriptions that wrongly cited xyIntegration; add @default for from/to - Fix truncated centerX description in xHistogram; add @default for logBaseX/logBaseY/absolute - Add algorithm property JSDoc and fix stray character in xPadding - Add zones property JSDoc to XYExtractOptions - Fix mangled magnitudeMode description in reimAutoPhaseCorrection; add @returns - Fix copy-pasted wrong descriptions on nbRows/nbColumns in matrixCreateEmpty
1 parent fdd4414 commit d20f32f

10 files changed

Lines changed: 60 additions & 35 deletions

src/matrix/matrixAutoCorrelation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import type { DoubleMatrix } from 'cheminfo-types';
22

33
import { xCorrelation } from '../x/index.ts';
44

5+
/**
6+
* Correlates every column of a matrix against a single reference column.
7+
* @param matrix - 2D matrix with at least 2 rows
8+
* @param index - column index used as the reference signal. Defaults to `0`.
9+
* @returns array of Pearson correlations, one value per column
10+
*/
511
export function matrixAutoCorrelation(
612
matrix: DoubleMatrix,
713
index = 0,

src/matrix/matrixBoxPlot.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
import type { DoubleArray, DoubleMatrix } from 'cheminfo-types';
22

33
export interface MatrixBoxPlot {
4+
/** First quartile for each column. */
45
q1: Float64Array;
6+
/** Median for each column. */
57
median: Float64Array;
8+
/** Third quartile for each column. */
69
q3: Float64Array;
10+
/** Minimum value for each column (taken from the first row of the sorted matrix). */
711
min: Float64Array;
12+
/** Maximum value for each column (taken from the last row of the sorted matrix). */
813
max: Float64Array;
914
}
1015

16+
/**
17+
* Computes per-column box-plot statistics (min, Q1, median, Q3, max) for a matrix.
18+
* The matrix rows must be sorted in ascending order — results will be wrong otherwise.
19+
* Requires at least 5 rows.
20+
* @param matrix - 2D matrix whose rows are sorted in ascending order
21+
* @returns per-column box-plot statistics
22+
*/
1123
export function matrixBoxPlot(matrix: DoubleMatrix): MatrixBoxPlot {
1224
const nbRows = matrix.length;
1325
const nbColumns = matrix[0].length;

src/matrix/matrixCreateEmpty.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ export interface MatrixCreateEmptyOptions<
1010
ArrayConstructorType extends NumberArrayConstructor = Float64ArrayConstructor,
1111
> {
1212
/**
13-
* Matrix from which to extract nbRows and nbColumns
13+
* Reference matrix used to derive default row and column counts.
1414
*/
1515
matrix?: DoubleMatrix;
1616

1717
/**
18-
* Matrix from which to extract nbRows and nbColumns
18+
* Number of rows in the new matrix.
1919
* @default matrix.length || 1
2020
*/
2121
nbRows?: number;
2222

2323
/**
24-
* Matrix from which to extract nbRows and nbColumns
24+
* Number of columns in the new matrix.
2525
* @default matrix[0].length || 1
2626
*/
2727
nbColumns?: number;

src/reim/reimAutoPhaseCorrection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { reimPhaseCorrection } from './reimPhaseCorrection.ts';
88

99
export interface AutoPhaseCorrectionOptions {
1010
/**
11-
* if true it uses magnitude spectrum.boolean
11+
* If true, uses the magnitude spectrum to detect baseline regions.
1212
* @default true
1313
*/
1414
magnitudeMode?: boolean;
@@ -48,6 +48,7 @@ export interface AutoPhaseCorrectionOptions {
4848
* correction algorithm for high-resolution NMR data. 10.1002/mrc.4586
4949
* @param data - complex spectrum
5050
* @param options - options
51+
* @returns phased spectrum together with the zero- and first-order correction angles (ph0, ph1) in degrees
5152
*/
5253

5354
export function reimAutoPhaseCorrection(

src/reim/zeroShift.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { xRotate } from '../x/index.ts';
22

3+
/**
4+
* Circular shift that moves the zero-frequency component to the center of the array (FFT shift).
5+
* For the inverse, the shift is reversed to restore the original layout.
6+
* @param data - input array
7+
* @param inverse - if true, shifts by ceil(n/2) instead of floor(n/2) to undo a previous zeroShift
8+
* @returns shifted array
9+
*/
310
export function zeroShift(
411
data: Float64Array,
512
inverse?: boolean,

src/x/xGetFromToIndex.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ import { xFindClosestIndex } from './xFindClosestIndex.ts';
44

55
export interface XGetFromToIndexOptions {
66
/**
7-
* First point for xyIntegration
7+
* Start index (0-based, clamped to array bounds). Takes precedence over `from`.
88
* @default 0
99
*/
1010
fromIndex?: number;
1111

1212
/**
13-
* Last point for xyIntegration
13+
* End index (0-based, clamped to array bounds). Takes precedence over `to`.
1414
* @default x.length-1
1515
*/
1616
toIndex?: number;
1717

1818
/**
19-
* First value for xyIntegration in the X scale
19+
* Start value in the x scale; resolved to the nearest index.
20+
* @default x[0]
2021
*/
2122
from?: number;
2223

2324
/**
24-
* Last value for xyIntegration in the X scale
25+
* End value in the x scale; resolved to the nearest index.
26+
* @default x[x.length-1]
2527
*/
2628
to?: number;
2729
}

src/x/xHistogram.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { xMinValue } from './xMinValue.ts';
99

1010
export interface XHistogramOptions {
1111
/**
12-
* Center the X value. We will enlarge the first and
12+
* Center each slot's x value at the mid-point of the bin rather than at the left edge.
1313
* @default true
1414
*/
1515
centerX?: boolean;
@@ -27,17 +27,20 @@ export interface XHistogramOptions {
2727
nbSlots?: number;
2828

2929
/**
30-
* We can first apply a log on x axis
30+
* Apply log base transformation to input x values before binning.
31+
* @default undefined
3132
*/
3233
logBaseX?: number;
3334

3435
/**
35-
* We can apply a log on the resulting histogram
36+
* Apply log base transformation to the resulting histogram y counts.
37+
* @default undefined
3638
*/
3739
logBaseY?: number;
3840

3941
/**
40-
* Take the absolute value
42+
* Take the absolute value of each input element before binning.
43+
* @default false
4144
*/
4245
absolute?: boolean;
4346

src/x/xPadding.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ export interface XPaddingOptions {
1515
* @default 0
1616
*/
1717
value?: number;
18+
/**
19+
* Padding strategy: `value` fills with a constant, `duplicate` repeats the first/last element, `circular` wraps the array.
20+
* @default undefined
21+
*/
1822
algorithm?: 'value' | 'duplicate' | 'circular';
1923
}
2024

2125
/**
22-
* This function pads an array
23-
*s
26+
* Pads an array symmetrically on both sides.
2427
* @param array - the array that will be padded
2528
* @param options - options
29+
* @returns padded Float64Array
2630
*/
2731
export function xPadding(
2832
array: NumberArray,

src/xy/xyEquallySpaced.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import { xyCheck } from './xyCheck.ts';
99

1010
export interface XYEquallySpacedOptions {
1111
/**
12-
* from
12+
* Start of the output x range.
1313
* @default x[0]
1414
*/
1515
from?: number;
1616

1717
/**
18-
* to
18+
* End of the output x range.
1919
* @default x[x.length-1]
2020
*/
2121
to?: number;
2222

2323
/**
24-
* variant
24+
* `slot` averages y values within each bin; `smooth` uses the trapezoidal integral divided by the step size.
2525
* @default 'smooth'
2626
*/
2727
variant?: 'slot' | 'smooth';
@@ -46,25 +46,11 @@ export interface XYEquallySpacedOptions {
4646
}
4747

4848
/**
49-
* Function that returns a Number array of equally spaced numberOfPoints
50-
* containing a representation of intensities of the spectra arguments x
51-
* and y.
52-
*
53-
* The options parameter contains an object in the following form:
54-
* from: starting point
55-
* to: last point
56-
* numberOfPoints: number of points between from and to
57-
* variant: "slot" or "smooth" - smooth is the default option
58-
*
59-
* The slot variant consist that each point in an array is calculated
60-
* averaging the existing points between the slot that belongs to the current
61-
* value. The smooth variant is the same but takes the integral of the range
62-
* of the slot and divide by the step size between two points in an array.
63-
*
64-
* If exclusions zone are present, zones are ignored !
65-
* @param data - object containing 2 properties x and y
49+
* Resample a spectrum to equally spaced x points.
50+
* When `exclusions` are provided they take precedence and `zones` is ignored.
51+
* @param data - object containing x and y arrays
6652
* @param options - options
67-
* @returns new object with x / y array with the equally spaced data.
53+
* @returns resampled spectrum with equally spaced x values
6854
*/
6955

7056
export function xyEquallySpaced(

src/xy/xyExtract.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { zonesNormalize } from '../zones/index.ts';
55
import { xyCheck } from './xyCheck.ts';
66

77
export interface XYExtractOptions {
8+
/**
9+
* Ranges to keep; points outside all zones are discarded.
10+
* @default []
11+
*/
812
zones?: FromTo[];
913
}
1014

0 commit comments

Comments
 (0)