@@ -93,36 +93,6 @@ export function toDate(time: number) {
93
93
return new Date ( time * 1000 )
94
94
}
95
95
96
- function smoothSeries ( series : PointValue [ ] , windowSize : number ) : PointValue [ ] {
97
- let result : PointValue [ ] = [ ]
98
- windowSize = ~ ~ windowSize
99
- if ( series . length < windowSize ) {
100
- windowSize = series . length
101
- }
102
- let extraWindow = windowSize / 2
103
- extraWindow = ~ ~ extraWindow
104
-
105
-
106
- let count = 0
107
- let total = 0
108
-
109
- for ( let i = 0 ; i < series . length + extraWindow ; i ++ ) {
110
- let j = i - extraWindow
111
- if ( i < series . length ) {
112
- total += series [ i ] . value
113
- count ++
114
- }
115
- if ( j - extraWindow - 1 >= 0 ) {
116
- total -= series [ j - extraWindow - 1 ] . value
117
- count --
118
- }
119
- if ( j >= 0 ) {
120
- result . push ( { step : series [ j ] . step , value : series [ j ] . value , smoothed : total / count , lastStep : series [ j ] . lastStep } )
121
- }
122
- }
123
- return result
124
- }
125
-
126
96
export function fillPlotPreferences ( series : Indicator [ ] , currentPlotIdx : number [ ] = [ ] ) {
127
97
if ( currentPlotIdx . length != 0 ) {
128
98
if ( currentPlotIdx . length == series . length ) {
@@ -213,57 +183,6 @@ export function smoothAndTrimAllCharts(series: Indicator[], baseSeries: Indicato
213
183
}
214
184
}
215
185
216
- function trimSteps ( series : Indicator [ ] , min : number , max : number , smoothWindow : number [ ] , trimSmoothEnds : boolean = true ) {
217
- series . forEach ( ( s , i ) => {
218
- let localSmoothWindow = smoothWindow [ i ] / 2 // remove half from each end
219
- localSmoothWindow = Math . floor ( localSmoothWindow )
220
- if ( localSmoothWindow < 0 ) {
221
- localSmoothWindow = 0
222
- }
223
- if ( s . series . length <= 1 ) {
224
- localSmoothWindow = 0
225
- } else if ( smoothWindow [ i ] >= s . series . length ) {
226
- localSmoothWindow = Math . floor ( s . series . length / 2 )
227
- }
228
-
229
-
230
- let localMin = min
231
- let localMax = max
232
-
233
- if ( localMin == - 1 ) {
234
- localMin = s . series [ 0 ] . step
235
- }
236
- if ( trimSmoothEnds ) {
237
- localMin = Math . max ( localMin , s . series [ localSmoothWindow ] . step )
238
- }
239
-
240
- if ( localMax == - 1 ) {
241
- localMax = s . series [ s . series . length - 1 ] . step
242
- }
243
- if ( trimSmoothEnds ) {
244
- localMax = Math . min ( localMax , s . series [ s . series . length - 1 - localSmoothWindow +
245
- ( s . series . length % 2 == 0 && localSmoothWindow != 0 ? 1 : 0 ) ] . step ) // get the mid value for even length series
246
- }
247
-
248
- localMin = Math . floor ( localMin - 1 )
249
- localMax = Math . ceil ( localMax + 1 )
250
-
251
- let minIndex = s . series . length - 1
252
- let maxIndex = 0
253
-
254
- for ( let i = 0 ; i < s . series . length ; i ++ ) {
255
- let p = s . series [ i ]
256
- if ( p . step >= localMin && p . step <= localMax ) {
257
- minIndex = Math . min ( i , minIndex )
258
- maxIndex = Math . max ( i , maxIndex )
259
- }
260
- }
261
-
262
- s . lowTrimIndex = minIndex
263
- s . highTrimIndex = maxIndex
264
- } )
265
- }
266
-
267
186
/**
268
187
* Calculates the smooth window size for each series in the current and base series.
269
188
* The smooth window size is determined based on the minimum range of steps in the series and the provided smooth value.
@@ -274,7 +193,7 @@ function trimSteps(series: Indicator[], min: number, max: number, smoothWindow:
274
193
* @returns {[number[][], number] } - Returns an array of smooth window sizes for each series. and the smooth window size in steps.
275
194
* (ret[0] = smooth window for current series, ret[1] = smooth window for base series
276
195
*/
277
- export function getSmoothWindow ( currentSeries : Indicator [ ] , baseSeries : Indicator [ ] , smoothValue : number ) : [ number [ ] [ ] , number ] {
196
+ function getSmoothWindow ( currentSeries : Indicator [ ] , baseSeries : Indicator [ ] , smoothValue : number ) : [ number [ ] [ ] , number ] {
278
197
let maxRange : number = Number . MIN_SAFE_INTEGER
279
198
for ( let s of currentSeries ) {
280
199
if ( s . series . length > 1 && ! s . is_summary ) {
@@ -326,6 +245,88 @@ export function getSmoothWindow(currentSeries: Indicator[], baseSeries: Indicato
326
245
return [ stepRange , smoothRange ]
327
246
}
328
247
248
+ function smoothSeries ( series : PointValue [ ] , windowSize : number ) : PointValue [ ] {
249
+ let result : PointValue [ ] = [ ]
250
+ windowSize = ~ ~ windowSize
251
+ if ( series . length < windowSize ) {
252
+ windowSize = series . length
253
+ }
254
+ let extraWindow = windowSize / 2
255
+ extraWindow = ~ ~ extraWindow
256
+
257
+
258
+ let count = 0
259
+ let total = 0
260
+
261
+ for ( let i = 0 ; i < series . length + extraWindow ; i ++ ) {
262
+ let j = i - extraWindow
263
+ if ( i < series . length ) {
264
+ total += series [ i ] . value
265
+ count ++
266
+ }
267
+ if ( j - extraWindow - 1 >= 0 ) {
268
+ total -= series [ j - extraWindow - 1 ] . value
269
+ count --
270
+ }
271
+ if ( j >= 0 ) {
272
+ result . push ( { step : series [ j ] . step , value : series [ j ] . value , smoothed : total / count , lastStep : series [ j ] . lastStep } )
273
+ }
274
+ }
275
+ return result
276
+ }
277
+
278
+
279
+ function trimSteps ( series : Indicator [ ] , min : number , max : number , smoothWindow : number [ ] , trimSmoothEnds : boolean = true ) {
280
+ series . forEach ( ( s , i ) => {
281
+ let localSmoothWindow = smoothWindow [ i ] / 2 // remove half from each end
282
+ localSmoothWindow = Math . floor ( localSmoothWindow )
283
+ if ( localSmoothWindow < 0 ) {
284
+ localSmoothWindow = 0
285
+ }
286
+ if ( s . series . length <= 1 ) {
287
+ localSmoothWindow = 0
288
+ } else if ( smoothWindow [ i ] >= s . series . length ) {
289
+ localSmoothWindow = Math . floor ( s . series . length / 2 )
290
+ }
291
+
292
+
293
+ let localMin = min
294
+ let localMax = max
295
+
296
+ if ( localMin == - 1 ) {
297
+ localMin = s . series [ 0 ] . step
298
+ }
299
+ if ( trimSmoothEnds ) {
300
+ localMin = Math . max ( localMin , s . series [ localSmoothWindow ] . step )
301
+ }
302
+
303
+ if ( localMax == - 1 ) {
304
+ localMax = s . series [ s . series . length - 1 ] . step
305
+ }
306
+ if ( trimSmoothEnds ) {
307
+ localMax = Math . min ( localMax , s . series [ s . series . length - 1 - localSmoothWindow +
308
+ ( s . series . length % 2 == 0 && localSmoothWindow != 0 ? 1 : 0 ) ] . step ) // get the mid value for even length series
309
+ }
310
+
311
+ localMin = Math . floor ( localMin - 1 )
312
+ localMax = Math . ceil ( localMax + 1 )
313
+
314
+ let minIndex = s . series . length - 1
315
+ let maxIndex = 0
316
+
317
+ for ( let i = 0 ; i < s . series . length ; i ++ ) {
318
+ let p = s . series [ i ]
319
+ if ( p . step >= localMin && p . step <= localMax ) {
320
+ minIndex = Math . min ( i , minIndex )
321
+ maxIndex = Math . max ( i , maxIndex )
322
+ }
323
+ }
324
+
325
+ s . lowTrimIndex = minIndex
326
+ s . highTrimIndex = maxIndex
327
+ } )
328
+ }
329
+
329
330
// Default smoothing function from backend
330
331
function meanAngle ( smoothed : PointValue [ ] , aspectRatio : number ) {
331
332
let xRange = smoothed [ smoothed . length - 1 ] . lastStep - smoothed [ 0 ] . lastStep
0 commit comments