13
13
/**
14
14
* Error bar computing function generator
15
15
*
16
- * N.B. This function does not clean the dataPt entries, non -numeric
17
- * entries result in undefined * error*
16
+ * N.B. The generated function does not clean the dataPt entries. Non -numeric
17
+ * entries result in undefined error magnitudes.
18
18
*
19
19
* @param {object } opts error bar attributes
20
20
*
21
21
* @return {function } :
22
- * @param {numeric } dataVal error magnitude in the negative direction
22
+ * @param {numeric } dataPt data point from where to compute the error magnitude
23
23
* @param {number } index index of dataPt in its corresponding data array
24
24
* @return {array }
25
25
* - error[0] : error magnitude in the negative direction
@@ -46,20 +46,20 @@ module.exports = function makeComputeError(opts) {
46
46
}
47
47
}
48
48
else {
49
- var value = opts . value ,
50
- valueminus = opts . valueminus ;
49
+ var computeErrorValue = makeComputeErrorValue ( type , opts . value ) ,
50
+ computeErrorValueMinus = makeComputeErrorValue ( type , opts . valueminus ) ;
51
51
52
- if ( symmetric || valueminus === undefined ) {
52
+ if ( symmetric || opts . valueminus === undefined ) {
53
53
return function computeError ( dataPt ) {
54
- var val = getErrorVal ( type , dataPt , value ) ;
54
+ var val = computeErrorValue ( dataPt ) ;
55
55
return [ val , val ] ;
56
56
} ;
57
57
}
58
58
else {
59
59
return function computeError ( dataPt ) {
60
60
return [
61
- getErrorVal ( type , dataPt , valueminus ) ,
62
- getErrorVal ( type , dataPt , value )
61
+ computeErrorValueMinus ( dataPt ) ,
62
+ computeErrorValue ( dataPt )
63
63
] ;
64
64
} ;
65
65
}
@@ -70,13 +70,25 @@ module.exports = function makeComputeError(opts) {
70
70
* Compute error bar magnitude (for all types except data)
71
71
*
72
72
* @param {string } type error bar type
73
- * @param {numeric } dataPt
74
- * data point from where to compute the error magnitude
75
- * @param {numeric } [value] error bar value
73
+ * @param {numeric } value error bar value
76
74
*
75
+ * @return {function } :
76
+ * @param {numeric } dataPt
77
77
*/
78
- function getErrorVal ( type , dataPt , value ) {
79
- if ( type === 'percent' ) return Math . abs ( dataPt * value / 100 ) ;
80
- if ( type === 'constant' ) return Math . abs ( value ) ;
81
- if ( type === 'sqrt' ) return Math . sqrt ( Math . abs ( dataPt ) ) ;
78
+ function makeComputeErrorValue ( type , value ) {
79
+ if ( type === 'percent' ) {
80
+ return function ( dataPt ) {
81
+ return Math . abs ( dataPt * value / 100 ) ;
82
+ } ;
83
+ }
84
+ if ( type === 'constant' ) {
85
+ return function ( ) {
86
+ return Math . abs ( value ) ;
87
+ } ;
88
+ }
89
+ if ( type === 'sqrt' ) {
90
+ return function ( dataPt ) {
91
+ return Math . sqrt ( Math . abs ( dataPt ) ) ;
92
+ } ;
93
+ }
82
94
}
0 commit comments