( data: ReadonlyArray<DataPoint>, sampling: SeriesSampling, samplingThreshold: number )
| 110 | } |
| 111 | |
| 112 | export function sampleSeriesDataPoints( |
| 113 | data: ReadonlyArray<DataPoint>, |
| 114 | sampling: SeriesSampling, |
| 115 | samplingThreshold: number |
| 116 | ): ReadonlyArray<DataPoint> { |
| 117 | const threshold = clampTargetPoints(samplingThreshold); |
| 118 | |
| 119 | // Disabled or already under threshold: keep original reference (avoid extra allocations). |
| 120 | if (sampling === 'none') return data; |
| 121 | if (!(threshold > 0)) return data; |
| 122 | if (data.length <= threshold) return data; |
| 123 | |
| 124 | switch (sampling) { |
| 125 | case 'lttb': |
| 126 | return lttbSample(data, threshold); |
| 127 | case 'average': |
| 128 | return sampleByBuckets(data, threshold, 'average'); |
| 129 | case 'max': |
| 130 | return sampleByBuckets(data, threshold, 'max'); |
| 131 | case 'min': |
| 132 | return sampleByBuckets(data, threshold, 'min'); |
| 133 | default: { |
| 134 | // Defensive for JS callers / widened types. |
| 135 | return data; |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 |
no test coverage detected