@@ -68,7 +68,7 @@ var attrs = exports.attributes = {
6868 } ,
6969 func : {
7070 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' ] ,
7272 dflt : 'first' ,
7373 role : 'info' ,
7474 editType : 'calc' ,
@@ -87,7 +87,8 @@ var attrs = exports.attributes = {
8787 '*median* will return the average of the two central values if there is' ,
8888 'an even count. *mode* will return the first value to reach the maximum' ,
8989 '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.'
9192 ] . join ( ' ' )
9293 } ,
9394 funcmode : {
@@ -348,6 +349,20 @@ function getAggregateFunction(opts, conversions) {
348349 return ( out === - Infinity ) ? BADNUM : c2d ( out ) ;
349350 } ;
350351
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+
351366 case 'median' :
352367 return function ( array , indices ) {
353368 var sortCalc = [ ] ;
0 commit comments