@@ -205,7 +205,7 @@ function getSmoothWindow(currentSeries: Indicator[], baseSeries: Indicator[], sm
205
205
maxRange = Math . max ( maxRange , s . series [ s . series . length - 1 ] . step - s . series [ 0 ] . step )
206
206
}
207
207
}
208
- if ( maxRange == Number . MIN_SAFE_INTEGER ) {
208
+ if ( maxRange == Number . MIN_SAFE_INTEGER ) { // all single points. -> can't smooth
209
209
let stepRange = [ [ ] , [ ] ]
210
210
for ( let s of currentSeries ) {
211
211
stepRange [ 0 ] . push ( 1 )
@@ -216,28 +216,26 @@ function getSmoothWindow(currentSeries: Indicator[], baseSeries: Indicator[], sm
216
216
return [ stepRange , 0 ]
217
217
}
218
218
219
- let smoothRange = mapRange ( smoothValue , 1 , 100 , 1 , maxRange )
219
+ let smoothRange = mapRange ( smoothValue , 1 , 100 , 1 , 2 * maxRange )
220
220
221
221
let stepRange = [ [ ] , [ ] ]
222
+
222
223
for ( let s of currentSeries ) {
223
- if ( smoothValue == 100 ) { // hardcode to max range in case not range due to step inconsistencies
224
- stepRange [ 0 ] . push ( s . series . length )
225
- } else if ( s . series . length >= 2 && ! s . is_summary ) {
224
+ if ( s . series . length >= 2 && ! s . is_summary ) {
226
225
let stepGap = s . series [ 1 ] . step - s . series [ 0 ] . step
227
- let numSteps = Math . max ( 1 , Math . floor ( smoothRange / stepGap ) )
226
+ let numSteps = Math . max ( 1 , Math . ceil ( smoothRange / stepGap ) )
228
227
stepRange [ 0 ] . push ( numSteps )
229
- } else {
228
+ } else { // can't smooth - just a single point
230
229
stepRange [ 0 ] . push ( 1 )
231
230
}
232
231
}
232
+
233
233
for ( let s of baseSeries ) {
234
- if ( smoothValue == 100 ) {
235
- stepRange [ 1 ] . push ( s . series . length )
236
- } else if ( s . series . length >= 2 && ! s . is_summary ) {
234
+ if ( s . series . length >= 2 && ! s . is_summary ) {
237
235
let stepGap = s . series [ 1 ] . step - s . series [ 0 ] . step
238
- let numSteps = Math . max ( 1 , Math . floor ( smoothRange / stepGap ) )
236
+ let numSteps = Math . max ( 1 , Math . ceil ( smoothRange / stepGap ) )
239
237
stepRange [ 1 ] . push ( numSteps )
240
- } else {
238
+ } else { // can't smooth - just a single point
241
239
stepRange [ 1 ] . push ( 1 )
242
240
}
243
241
}
@@ -248,9 +246,6 @@ function getSmoothWindow(currentSeries: Indicator[], baseSeries: Indicator[], sm
248
246
function smoothSeries ( series : PointValue [ ] , windowSize : number ) : PointValue [ ] {
249
247
let result : PointValue [ ] = [ ]
250
248
windowSize = ~ ~ windowSize
251
- if ( series . length < windowSize ) {
252
- windowSize = series . length
253
- }
254
249
let extraWindow = windowSize / 2
255
250
extraWindow = ~ ~ extraWindow
256
251
@@ -278,18 +273,14 @@ function smoothSeries(series: PointValue[], windowSize: number): PointValue[] {
278
273
279
274
function trimSteps ( series : Indicator [ ] , min : number , max : number , smoothWindow : number [ ] , trimSmoothEnds : boolean = true ) {
280
275
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
- }
276
+ let localSmoothWindow = Math . floor ( smoothWindow [ i ] / 2 ) // remove half from each end
277
+
286
278
if ( s . series . length <= 1 ) {
287
279
localSmoothWindow = 0
288
280
} else if ( smoothWindow [ i ] >= s . series . length ) {
289
281
localSmoothWindow = Math . floor ( s . series . length / 2 )
290
282
}
291
283
292
-
293
284
let localMin = min
294
285
let localMax = max
295
286
@@ -308,8 +299,8 @@ function trimSteps(series: Indicator[], min: number, max: number, smoothWindow:
308
299
( s . series . length % 2 == 0 && localSmoothWindow != 0 ? 1 : 0 ) ] . step ) // get the mid value for even length series
309
300
}
310
301
311
- localMin = Math . floor ( localMin - 1 )
312
- localMax = Math . ceil ( localMax + 1 )
302
+ localMin = Math . floor ( localMin ) - 0.5
303
+ localMax = Math . ceil ( localMax ) + 0.5
313
304
314
305
let minIndex = s . series . length - 1
315
306
let maxIndex = 0
0 commit comments