@@ -68,7 +68,7 @@ var attrs = exports.attributes = {
68
68
} ,
69
69
func : {
70
70
valType : 'enumerated' ,
71
- values : [ 'count' , 'sum' , 'avg' , 'median' , 'mode' , 'rms' , 'stddev' , 'min' , 'max' , 'first' , 'last' , 'change' ] ,
71
+ values : [ 'count' , 'sum' , 'avg' , 'median' , 'mode' , 'rms' , 'stddev' , 'min' , 'max' , 'first' , 'last' , 'change' , 'range' ] ,
72
72
dflt : 'first' ,
73
73
role : 'info' ,
74
74
editType : 'calc' ,
@@ -87,7 +87,8 @@ var attrs = exports.attributes = {
87
87
'*median* will return the average of the two central values if there is' ,
88
88
'an even count. *mode* will return the first value to reach the maximum' ,
89
89
'count, in case of a tie.' ,
90
- '*change* will return the difference between the first and last linked value.'
90
+ '*change* will return the difference between the first and last linked values.' ,
91
+ '*range* will return the difference between the min and max linked values.'
91
92
] . join ( ' ' )
92
93
} ,
93
94
funcmode : {
@@ -348,6 +349,20 @@ function getAggregateFunction(opts, conversions) {
348
349
return ( out === - Infinity ) ? BADNUM : c2d ( out ) ;
349
350
} ;
350
351
352
+ case 'range' :
353
+ return function ( array , indices ) {
354
+ var min = Infinity ;
355
+ var max = - Infinity ;
356
+ for ( var i = 0 ; i < indices . length ; i ++ ) {
357
+ var vi = d2c ( array [ indices [ i ] ] ) ;
358
+ if ( vi !== BADNUM ) {
359
+ min = Math . min ( min , vi ) ;
360
+ max = Math . max ( max , vi ) ;
361
+ } ;
362
+ }
363
+ return ( max === - Infinity || min === Infinity ) ? BADNUM : c2d ( max - min ) ;
364
+ } ;
365
+
351
366
case 'median' :
352
367
return function ( array , indices ) {
353
368
var sortCalc = [ ] ;
0 commit comments