src/lib/metrics.js
// this is efficient if the points comes in increasing order
this is efficient if the points comes in increasing order
this is efficient if the points comes in increasing order
function insertOrReplacePoint(data, time, value) {
  const lastIndex = data.length - 1;
  if (lastIndex === -1 || data[lastIndex][0] < time) {
    data.push([time, value]);
  } else {
    for (var i = lastIndex; i >= 0; i--) {
      if (data[i][0] < time) {
        data.splice(i + 1, 0, [time, value]);
        return;
      } else if (data[i][0] === time) {
        if (data[i][1] > value) {
          console.log(
            'Warning: Overwriting metric at',
            time,
            'with a lower value.'
          );
        }
        data[i][1] = value;
        return;
      }
    }
    data.unshift([time, value]);
  }
}
function insertOrReplacePoint ( data , time , value ) { const lastIndex = data . length - 1 ; if ( lastIndex === - 1 || data [ lastIndex ] [ 0 ] < time ) { data . push ( [ time , value ] ) ; } else { for ( var i = lastIndex ; i >= 0 ; i -- ) { if ( data [ i ] [ 0 ] < time ) { data . splice ( i + 1 , 0 , [ time , value ] ) ; return ; } else if ( data [ i ] [ 0 ] === time ) { if ( data [ i ] [ 1 ] > value ) { console . log ( 'Warning: Overwriting metric at' , time , 'with a lower value.' ) ; } data [ i ] [ 1 ] = value ; return ; } } data . unshift ( [ time , value ] ) ; } }
this is efficient if the points comes in increasing order
this is efficient if the points comes in increasing order