Commit 9ec13dfa authored by Paul Asmuth's avatar Paul Asmuth
Browse files

Merge branch 'v1.0' of github.com:paulasmuth/fnordmetric2 into v1.0

parents b4f0917b 90992943
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ class FnordMetric::RealtimeGauge < FnordMetric::MultiGauge
    realtime_value_widget(
      :tab => "Overview",
      :title => "Realtime #{key_nouns.last}",
      :desc => "#{key_nouns.last} / Second",
      :ticks => @opts[:ticks]
    )

+15 −1
Original line number Diff line number Diff line
@@ -347,3 +347,17 @@ ul.ui_tabs li.active a{
}

.gauge_viewport{ margin-top:30px; }


.widget.RealtimeValueWidget .big_number{
  float:right;
  margin-right:30px;
  width:200px;
  text-align:center;
  margin-top:70px;
}

.widget.RealtimeValueWidget .big_number .value{
  line-height:80px;
  font-size:58px;
}
+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ FnordMetric.views.gaugeView = (function(gauge_name, conf){
  function renderWidgets(_widgets){
    for(wkey in _widgets){
      var widget = _widgets[wkey];
      widget["elem"] = $('<div class="widget"></div>');
      widget["elem"] = $('<div class="widget"></div>').addClass(widget.klass);
      $('.tab[data-tab="' + widget.tab + '"]', '.viewport_inner').append(widget["elem"]);
      widgets[wkey] = widget;
      resizeWidget(wkey);
+34 −19
Original line number Diff line number Diff line
FnordMetric.widgets.realtimeValueWidget = function(){

    var widget_uid = FnordMetric.util.getNextWidgetUID();
    var width, height, canvas,  opts, max;

    var xpadding = 20;
    var ypadding = 20;
    var ypadding = 10;
    var bmargin = 6;
    var bwidth  = 5;
    var bcolor  = '#06C';
    var zero_height = 5;

    var bars = [];

    var widget_uid = FnordMetric.util.getNextWidgetUID();
    var width, height, canvas,  opts, max;
    var bars = [];
    var tick = false;

    var next_values = [];
    var next_value_interval = false;


    function render(_opts){
      opts = _opts;

      drawLayout();

      width = opts.elem.width() - (xpadding * 2) - 15 - 250;
      height = opts.height || 240;
      height = opts.height || 210;
      //xtick = width / (xticks - 1);

      canvas = d3.select('#container-'+widget_uid)
        .append("svg:svg")
        .attr("width", width+(2*xpadding))
        .attr("height", height+30);
        .attr("height", height);

      canvas.selectAll("*").remove();

      for(var n=parseInt(width / bmargin); n > 0; n--){
        drawValue(false, n-1);
      }

      changeTick(opts.ticks[0]);
    }

@@ -44,6 +40,10 @@ FnordMetric.widgets.realtimeValueWidget = function(){
      canvas.selectAll('.valuebar').remove();
      next_values = [];
      max = 1;

      for(var n=parseInt(width / bmargin); n > 0; n--){
        drawValue(0, n-1);
      }
    }

    function nextValue(value){
@@ -52,6 +52,7 @@ FnordMetric.widgets.realtimeValueWidget = function(){
        max = value * 1.2;
        canvas.selectAll('.valuebar').each(function(){
          var theight = parseInt($(this).attr('height'))*(old_max/max);
          if(theight < zero_height){ theight = zero_height; }
          $(this).attr("y", height-(ypadding*2)-theight)
          $(this).attr("height", theight);
        });
@@ -71,12 +72,15 @@ FnordMetric.widgets.realtimeValueWidget = function(){
    }

    function nextValueAsync(value){
      if(value){ next_values.unshift(value); }
      if(value != undefined){ 
        next_values.unshift(value); 
        $('.big_number .value', opts.elem).html(FnordMetric.util.formatValue(value));
      }
      if(next_values.length > 0){
        if(!next_value_interval){
          next_value_interval = window.setInterval(function(){
            var _v = next_values.pop();
            if(!!_v){ nextValue(_v); }
            if(_v != undefined){ nextValue(_v); }
          }, 20);  
        }
      }   
@@ -96,10 +100,14 @@ FnordMetric.widgets.realtimeValueWidget = function(){
        var theight = (height-(ypadding*4)) * (value/max);
        var fillc = bcolor;
      } else {
        var theight = 5;
        var theight = zero_height;
        var fillc = '#ddd';
      }  

      if(theight < zero_height){
        theight = zero_height;
      }
      
      bars.unshift(canvas
        .append("svg:rect")
        .attr("class", "valuebar")
@@ -108,17 +116,17 @@ FnordMetric.widgets.realtimeValueWidget = function(){
        .attr("fill", fillc)
        .attr("width", bwidth)
        .attr("height", theight));

    }

    function announce(evt){
      if((evt._class == "widget_push") && (evt.cmd == "value")){
        if(evt.values[tick]){
          nextValueAsync(parseFloat(evt.values[tick]));  
        } else {
          nextValueAsync(0);
        }        
      }
      if(evt.widget_key == opts.widget_key){

      }
    }

    function drawLayout(){
@@ -129,7 +137,14 @@ FnordMetric.widgets.realtimeValueWidget = function(){
          height: opts.height + 6,
          marginBottom: 20,
          overflow: 'hidden'
        })
        }).append(
          $('<div></div>')
            .addClass('big_number number')
            .attr('data-current', 0)
            .attr('data', 0)
            .append($('<span class="desc">').html(opts.desc))
            .append($('<span class="value">'))
        )
      );

      if(opts.ticks){
+3 −0
Original line number Diff line number Diff line
@@ -92,6 +92,9 @@ FnordMetric.util.formatOffset = function(offset, next_offset){
FnordMetric.util.formatValue = function(value){
  if(value < 10){
    return value.toFixed(2);
  }
  if(value < 100){
    return value.toFixed(1);
  } else if(value > 1000){
    return (value/1000.0).toFixed(1) + "k";
  } else {