@@ -21,7 +21,7 @@ Two downsampling methods are currently supported, description of both can be fou
2121
2222Downsampling a series of data points using either of these looks like this:
2323
24- ```
24+ ``` typescript
2525// ES6
2626import { LTOB , LTTB } from " downsample" ;
2727
@@ -30,11 +30,11 @@ var LTOB = require("downsample").LTOB;
3030var LTTB = require (" downsample" ).LTTB ;
3131
3232// The number of target data points, 100 for example
33- const numPointsInDownsampledData = 100;
33+ const numPointsInDownsampledData: number = 100 ;
3434
3535// See the API docs for supported input data formats
36- const data = [ ... ];
37- const downsampledDataLTOB = LTOB(data, numPointsInDownsampledData);
36+ const data: DataPoint [] = [ ... ];
37+ const downsampledDataLTOB: DataPoint [] = LTOB (data , numPointsInDownsampledData );
3838
3939// downsampledDataLTOB now contains data downsampled to contain
4040// no more than numPointsInDownsampledData data points.
@@ -45,4 +45,46 @@ const downsampledDataLTOB = LTOB(data, numPointsInDownsampledData);
4545
4646## API
4747
48- * Work in progress, please see src/methods/LTOB.ts for a simple TypeScript API*
48+ ### DataPoint type
49+
50+ Represents a data point in the input data array. Two formats are currently supported:
51+
52+ ` TupleDataPoint ` is an array tuple of a ` number ` or a ` Date ` representing
53+ the independent variable (e.g. time) and a ` number ` representing the value:
54+
55+ ``` typescript
56+ const numericTupleDataPoint: TupleDataPoint = [1 , 152.2 ];
57+
58+ const dateTupleDataPoint: TupleDataPoint = [new Date (), 45.1 ];
59+ ```
60+
61+ ` XYDataPoint ` is an object hash with ` x ` property representing
62+ the independent variable (e.g. time) and an ` y ` property the value:
63+
64+ ``` typescript
65+ const numericXYDataPoint: XYDataPoint = { x: 1 , y: 152.2 };
66+
67+ const dateXYDataPoint: XYDataPoint = { x: new Date (), y: 152.2 };
68+ ```
69+
70+ ### downsample.LTOB< ; T extends DataPoint> ; (data: T[ ] , desiredLength: number): T[ ]
71+
72+ Implementation of ` Largest triangle one bucket ` downsampling method.
73+
74+ ` data: DataPoint[] ` is the input array. This array should be sorted by the independent variable
75+ otherwise the results will be unpredictable.
76+
77+ ` desiredLength: number ` is the length of the downsampled array.
78+
79+ This function will throw an error if the ` desiredLength ` is negative.
80+
81+ ### downsample.LTTB< ; T extends DataPoint> ; (data: T[ ] , desiredLength: number): T[ ]
82+
83+ Implementation of ` Largest triangle three buckets ` downsampling method.
84+
85+ ` data: DataPoint[] ` is the input array. This array should be sorted by the independent variable
86+ otherwise the results will be unpredictable.
87+
88+ ` desiredLength: number ` is the length of the downsampled array.
89+
90+ This function will throw an error if the ` desiredLength ` is negative.
0 commit comments