Sha256: 88bdefa0160cc934e43ef2e5f5c73889353f67c6e486db3be6912aa6b3199f96

Contents?: true

Size: 790 Bytes

Versions: 1

Compression:

Stored size: 790 Bytes

Contents

var format = (function() {

  var formatFloat = function(number, precision, commas) {
    precision = precision || 2;
    var base = Math.pow(10, precision);
    var val =  Math.round(number * base) / base;

    if(!commas) {
      return val;
    }

    var parts = (val + '').split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(".");
  }

  var metricTemplate = _.template('<div class="bar {{state}}" style="width: {{percent}}%">{{metric}}</div>'); 
  var metric = function(e, max) {
    var max = (max || 1);
    var data = {
      'state': e.state,
      'percent': (e.metric / max * 100),
      'metric': formatFloat(e.metric)
    }
    return metricTemplate(data);
  };

  return {
    'float': formatFloat,
    'metric': metric
  }
})();

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riemann-dash-0.2.6 lib/riemann/dash/public/format.js