static/js/util.js
/**
 * Scale a number by key.
 * @function scaleNum
 * @param {number} num - number to scale
 * @param {string|number} scale - scale name or power
 * @throws if scale is invalid
 * @returns {number} scaled number
 * @todo
 */
Scale a number by key.
Scale a number by key .
function scaleNum(num, scale) {
  if (scale == null) {
    return num;
  } else if (typeof(scale) === 'number') {
    return Math.pow(num, scale);
  } else if (typeof(scale) === 'string') {
    switch(scale) {
      case 'none':
        return num;
      case 'square':
        return Math.pow(num, 2);
      case 'sqrt':
        return Math.sqrt(num);
      case 'cube':
        return Math.pow(num, 3);
      case 'cbrt':
        return Math.pow(num, (1 / 3));
      case 'log':
        return Math.log(num);
      case 'log2':
        return Math.log(num) / Math.LN2;
      case 'log10':
        return Math.log(num) / Math.LN10;
      case 'exp':
        return Math.exp(num);
      case 'exp2':
        return Math.pow(2, num);
      case 'exp10':
        return Math.pow(10, num);
      default:
        throw 'Error: invalid scale name "' + scale + '".';
    }
  } else {
    throw 'Error: invalid scale type';
  }
}
function scaleNum ( num , scale ) { if ( scale == null ) { return num ; } else if ( typeof ( scale ) === 'number' ) { return Math . pow ( num , scale ) ; } else if ( typeof ( scale ) === 'string' ) { switch ( scale ) { case 'none' : return num ; case 'square' : return Math . pow ( num , 2 ) ; case 'sqrt' : return Math . sqrt ( num ) ; case 'cube' : return Math . pow ( num , 3 ) ; case 'cbrt' : return Math . pow ( num , ( 1 / 3 ) ) ; case 'log' : return Math . log ( num ) ; case 'log2' : return Math . log ( num ) / Math . LN2 ; case 'log10' : return Math . log ( num ) / Math . LN10 ; case 'exp' : return Math . exp ( num ) ; case 'exp2' : return Math . pow ( 2 , num ) ; case 'exp10' : return Math . pow ( 10 , num ) ; default : throw 'Error: invalid scale name "' + scale + '".' ; } } else { throw 'Error: invalid scale type' ; } }
Scale a number by key.
Scale a number by key .