public/js/barchart/barchart.js
/**
   * Aggregates several results in one.
   *
   * The deep copy will perform on the base and structure of the first Stats item of the `data` argument if no
   * `aggregate` argument is provided.
   *
   * @param {Array.<Stats>} data Series of Stats elements we want to compact in one Stats object
   * @param {Object=} aggregate Structure in which we aggregates the `data`
   * @returns <Stats> Compacted Stats object
   */
Aggregates several results in one.
The deep copy will perform on the base and structure of the first Stats item of the `data` argument if no
`aggregate` argument is provided.

@param {Array.} data Series of Stats elements we want to compact in one Stats object
@param {Object=} aggregate Structure in which we aggregates the `data`
@returns  Compacted Stats object
Aggregates several results in one . The deep copy will perform on the base and structure of the first Stats item of the ` data ` argument if no ` aggregate ` argument is provided . @param { Array . } data Series of Stats elements we want to compact in one Stats object @param { Object = } aggregate Structure in which we aggregates the ` data ` @returns Compacted Stats object
function aggregateStatsData(data, aggregate){
    if(arguments.length === 1){
      aggregate = data.shift();
    }
    data.forEach(function(item){
      Object.keys(item).forEach(function(key){
        var value = data[key];
        if (Array.isArray(value)){
          aggregate[key] = aggregate[key].concat(value);
        }
        else if (typeof value === 'number'){
          aggregate[key] += value;
        }
        else if ($.isPlainObject(value)){
          aggregate[key] = aggregateStatsData(value, aggregate[key]);
        }
      });
    });
    return aggregate;
  }
function aggregateStatsData ( data , aggregate ) { if ( arguments . length === 1 ) { aggregate = data . shift ( ) ; } data . forEach ( function ( item ) { Object . keys ( item ) . forEach ( function ( key ) { var value = data [ key ] ; if ( Array . isArray ( value ) ) { aggregate [ key ] = aggregate [ key ] . concat ( value ) ; } else if ( typeof value === 'number' ) { aggregate [ key ] += value ; } else if ( $ . isPlainObject ( value ) ) { aggregate [ key ] = aggregateStatsData ( value , aggregate [ key ] ) ; } } ) ; } ) ; return aggregate ; }
Aggregates several results in one.
Aggregates several results in one .
// first init? copy the structure of the object to aggregate