@@ -181,73 +181,74 @@ export function getChartType(index: number): 'log' | 'linear' {
181
181
return index === 0 ? 'linear' : 'log'
182
182
}
183
183
184
- export function trimSteps ( series : Indicator [ ] , min : number , max : number , smoothRange : number = 0 ) : Indicator [ ] {
185
- smoothRange /= 2 // remove half from each end
186
- return < Indicator [ ] > series . map ( s => {
187
- let res = { ...s }
184
+ /**
185
+ * Smooths and trims all charts in the current and base series.
186
+ *
187
+ * @param {Indicator[] } series - The current series of data.
188
+ * @param {Indicator[] } baseSeries - The base series of data for comparison.
189
+ * @param {number } smoothValue - The value to be used for smoothing the data.
190
+ * @param {number[] } stepRange - The range of steps to be considered for trimming.
191
+ */
192
+ export function smoothAndTrimAllCharts ( series : Indicator [ ] , baseSeries : Indicator [ ] , smoothValue : number , stepRange : number [ ] ) {
193
+ let [ smoothWindow , smoothRange ] = getSmoothWindow ( series ?? [ ] ,
194
+ baseSeries ?? [ ] , smoothValue )
195
+
196
+ if ( series != null ) {
197
+ series = series . map ( ( s , i ) => {
198
+ s . series = smoothSeries ( s . series , smoothWindow [ 0 ] [ i ] )
199
+ return s
200
+ } )
201
+ trimSteps ( series , stepRange [ 0 ] , stepRange [ 1 ] , smoothRange )
202
+ }
188
203
204
+ if ( baseSeries != null ) {
205
+ baseSeries = baseSeries . map ( ( s , i ) => {
206
+ s . series = smoothSeries ( s . series , smoothWindow [ 1 ] [ i ] )
207
+ return s
208
+ } )
209
+ trimSteps ( baseSeries , stepRange [ 0 ] , stepRange [ 1 ] , smoothRange )
210
+ }
211
+ }
212
+
213
+ export function trimSteps ( series : Indicator [ ] , min : number , max : number , smoothRange : number = 0 ) {
214
+ smoothRange /= 2 // remove half from each end
215
+ series . forEach ( s => {
216
+ let localSmoothRange = smoothRange
189
217
if ( s . series . length <= 2 ) {
190
- smoothRange = 0
218
+ localSmoothRange = 0
191
219
} else {
192
- let trimStepCount = smoothRange / ( s . series [ 1 ] . step - s . series [ 0 ] . step )
220
+ let trimStepCount = localSmoothRange / ( s . series [ 1 ] . step - s . series [ 0 ] . step )
193
221
if ( trimStepCount < 1 ) {
194
- smoothRange = 0
222
+ localSmoothRange = 0
195
223
}
196
224
}
197
225
198
- res . series = [ ]
199
-
200
226
let localMin = min
201
227
let localMax = max
202
228
203
229
if ( localMin == - 1 ) {
204
230
localMin = s . series [ 0 ] . step
205
231
}
206
- localMin = Math . max ( localMin , s . series [ 0 ] . step + smoothRange )
232
+ localMin = Math . max ( localMin , s . series [ 0 ] . step + localSmoothRange )
207
233
208
234
if ( localMax == - 1 ) {
209
235
localMax = s . series [ s . series . length - 1 ] . step
210
236
}
211
- localMax = Math . min ( localMax , s . series [ s . series . length - 1 ] . step - smoothRange )
237
+ localMax = Math . min ( localMax , s . series [ s . series . length - 1 ] . step - localSmoothRange )
238
+
239
+ let minIndex = s . series . length - 1
240
+ let maxIndex = 0
212
241
213
242
for ( let i = 0 ; i < s . series . length ; i ++ ) {
214
243
let p = s . series [ i ]
215
244
if ( p . step >= localMin && p . step <= localMax ) {
216
- res . series . push ( p )
217
- }
218
- }
219
-
220
- return res
221
- } )
222
- }
223
-
224
- export function trimStepsOfPoints ( series : PointValue [ ] [ ] , min : number , max : number , smoothRange : number = 0 ) : PointValue [ ] [ ] {
225
- smoothRange /= 2 // remove half from each end
226
- return series . map ( s => {
227
- let res = [ ]
228
- let start = 1e9 , end = - 1
229
- let localMin = min
230
- let localMax = max
231
-
232
- if ( localMin == - 1 ) {
233
- localMin = s [ 0 ] . step
234
- }
235
- localMin = Math . max ( localMin , s [ 0 ] . step + smoothRange )
236
-
237
- if ( localMax == - 1 ) {
238
- localMax = s [ s . length - 1 ] . step
239
- }
240
- localMax = Math . min ( localMax , s [ s . length - 1 ] . step - smoothRange )
241
- for ( let i = 0 ; i < s . length ; i ++ ) {
242
- let p = s [ i ]
243
- if ( ( p . step >= localMin || localMin == - 1 ) && ( p . step <= localMax || localMax == - 1 ) ) {
244
- start = Math . min ( start , i )
245
- end = Math . max ( end , i )
246
- res . push ( p )
245
+ minIndex = Math . min ( i , minIndex )
246
+ maxIndex = Math . max ( i , maxIndex )
247
247
}
248
248
}
249
249
250
- return res
250
+ s . lowTrimIndex = minIndex
251
+ s . highTrimIndex = maxIndex
251
252
} )
252
253
}
253
254
0 commit comments