@@ -12,6 +12,7 @@ export default class Graph {
12
12
hours = 24 ,
13
13
points = 1 ,
14
14
aggregateFuncName = 'avg' ,
15
+ valueMultipler = 1 ,
15
16
groupBy = 'interval' ,
16
17
smoothing = true ,
17
18
logarithmic = false ,
@@ -38,6 +39,7 @@ export default class Graph {
38
39
this . points = points ;
39
40
this . hours = hours ;
40
41
this . aggregateFuncName = aggregateFuncName ;
42
+ this . _valueMultipler = valueMultipler ;
41
43
this . _calcPoint = aggregateFuncMap [ aggregateFuncName ] || this . _average ;
42
44
this . _smoothing = smoothing ;
43
45
this . _logarithmic = logarithmic ;
@@ -74,8 +76,9 @@ export default class Graph {
74
76
histGroups . length = requiredNumOfPoints ;
75
77
76
78
this . coords = this . _calcPoints ( histGroups ) ;
77
- this . min = Math . min ( ...this . coords . map ( item => Number ( item [ V ] ) ) ) ;
78
- this . max = Math . max ( ...this . coords . map ( item => Number ( item [ V ] ) ) ) ;
79
+ this . min = this . _scale ( Math . min ( ...this . coords . map ( item => Number ( item [ V ] ) ) ) ) ;
80
+ this . max = this . _scale ( Math . max ( ...this . coords . map ( item => Number ( item [ V ] ) ) ) ) ;
81
+ if ( this . min > this . max ) [ this . min , this . max ] = [ this . max , this . min ] ;
79
82
}
80
83
81
84
_reducer ( res , item ) {
@@ -107,14 +110,19 @@ export default class Graph {
107
110
return coords ;
108
111
}
109
112
113
+ _scale ( value ) {
114
+ return this . _valueMultipler * value ;
115
+ }
116
+
110
117
_calcY ( coords ) {
111
118
// account for logarithmic graph
112
119
const max = this . _logarithmic ? Math . log10 ( Math . max ( 1 , this . max ) ) : this . max ;
113
120
const min = this . _logarithmic ? Math . log10 ( Math . max ( 1 , this . min ) ) : this . min ;
114
121
115
122
const yRatio = ( ( max - min ) / this . height ) || 1 ;
116
123
const coords2 = coords . map ( ( coord ) => {
117
- const val = this . _logarithmic ? Math . log10 ( Math . max ( 1 , coord [ V ] ) ) : coord [ V ] ;
124
+ const val = this . _logarithmic
125
+ ? Math . log10 ( Math . max ( 1 , this . _scale ( coord [ V ] ) ) ) : this . _scale ( coord [ V ] ) ;
118
126
const coordY = this . height - ( ( val - min ) / yRatio ) + this . margin [ Y ] * 2 ;
119
127
return [ coord [ X ] , coordY , coord [ V ] ] ;
120
128
} ) ;
0 commit comments