@@ -4,14 +4,14 @@ import {DeleteButton, SaveButton, ToggleButton} from "../../../components/button
4
4
import { LineChart } from "../../../components/charts/lines/chart"
5
5
import { SparkLines } from "../../../components/charts/spark_lines/chart"
6
6
import {
7
- getChartType
7
+ getChartType , getSmoother
8
8
} from "../../../components/charts/utils"
9
9
import { NumericRangeField } from "../../../components/input/numeric_range_field"
10
10
import { Loader } from "../../../components/loader"
11
11
import { Slider } from "../../../components/input/slider"
12
12
import { UserMessages } from "../../../components/user_messages"
13
13
import { NetworkError } from "../../../network"
14
- import { TwoSidedExponentialAverage } from "../../../components/charts/smoothing/two_sided_exponential_average"
14
+ import { SmoothingType } from "../../../components/charts/smoothing/smoothing_base" ;
15
15
16
16
interface ViewWrapperOpt {
17
17
dataStore : MetricDataStore
@@ -36,6 +36,7 @@ export interface MetricDataStore {
36
36
focusSmoothed : boolean
37
37
stepRange : number [ ]
38
38
smoothValue : number
39
+ smoothFunction : string
39
40
40
41
isUnsaved : boolean
41
42
}
@@ -100,6 +101,19 @@ namespace ChangeHandlers {
100
101
}
101
102
}
102
103
104
+ export class SmoothFunctionHandler extends ChangeHandlerBase {
105
+ private readonly value : string
106
+
107
+ constructor ( wrapper : ViewWrapper , value : string ) {
108
+ super ( wrapper )
109
+ this . value = value
110
+ }
111
+
112
+ protected handleChange ( ) {
113
+ this . wrapper . dataStore . smoothFunction = this . value
114
+ }
115
+ }
116
+
103
117
export class ToggleChangeHandler extends ChangeHandlerBase {
104
118
private readonly idx : number
105
119
private readonly isBase : boolean
@@ -153,6 +167,7 @@ export class ViewWrapper {
153
167
private readonly focusButton : ToggleButton
154
168
private readonly smoothSlider : Slider
155
169
private readonly deleteButton : DeleteButton
170
+ private readonly leftSmoothButton : ToggleButton
156
171
private sparkLines : SparkLines
157
172
158
173
public dataStore : MetricDataStore
@@ -226,6 +241,22 @@ export class ViewWrapper {
226
241
parent : this . constructor . name ,
227
242
onButtonClick : this . onDelete
228
243
} )
244
+ this . leftSmoothButton = new ToggleButton ( {
245
+ onButtonClick : ( ) => {
246
+ let value : string
247
+ if ( this . dataStore . smoothFunction === SmoothingType . LEFT_EXPONENTIAL ) {
248
+ value = SmoothingType . EXPONENTIAL
249
+ } else {
250
+ value = SmoothingType . LEFT_EXPONENTIAL
251
+ }
252
+ let changeHandler = new ChangeHandlers . SmoothFunctionHandler ( this ,
253
+ value )
254
+ changeHandler . change ( )
255
+ } ,
256
+ text : 'Left' ,
257
+ isToggled : this . dataStore . smoothFunction === SmoothingType . LEFT_EXPONENTIAL ,
258
+ parent : this . constructor . name
259
+ } )
229
260
}
230
261
231
262
public clear ( ) {
@@ -316,13 +347,13 @@ export class ViewWrapper {
316
347
}
317
348
318
349
private smoothSeries ( ) {
319
- let [ series , baseSeries ] = ( new TwoSidedExponentialAverage ( {
350
+ let [ series , baseSeries ] = getSmoother ( this . dataStore . smoothFunction , {
320
351
indicators : this . dataStore . series . concat ( this . dataStore . baseSeries ?? [ ] ) ?? [ ] ,
321
352
smoothValue : this . dataStore . smoothValue ,
322
353
min : this . dataStore . stepRange [ 0 ] ,
323
354
max : this . dataStore . stepRange [ 1 ] ,
324
355
currentIndicatorLength : this . dataStore . series . length
325
- } ) ) . smoothAndTrim ( )
356
+ } ) . smoothAndTrim ( )
326
357
327
358
this . dataStore . series = series
328
359
this . dataStore . baseSeries = baseSeries
@@ -350,6 +381,7 @@ export class ViewWrapper {
350
381
this . scaleButton . isToggled = this . dataStore . chartType > 0
351
382
this . focusButton . isToggled = this . dataStore . focusSmoothed
352
383
this . smoothSlider . value = this . dataStore . smoothValue
384
+ this . leftSmoothButton . isToggled = this . dataStore . smoothFunction === SmoothingType . LEFT_EXPONENTIAL
353
385
354
386
this . optionRowContainer . innerHTML = ''
355
387
this . optionRowContainer . classList . add ( 'chart-options' )
@@ -366,6 +398,7 @@ export class ViewWrapper {
366
398
$ ( 'div' , '.button-row' , $ => {
367
399
$ ( 'span.key' , 'Smoothing:' )
368
400
this . smoothSlider . render ( $ )
401
+ this . leftSmoothButton . render ( $ )
369
402
} )
370
403
} )
371
404
}
0 commit comments