Commit 8404f5df authored by Paul Asmuth's avatar Paul Asmuth
Browse files

realtime gauge...

parent 98cfdd4b
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -11,7 +11,9 @@ class FnordMetric::RealtimeGauge < FnordMetric::MultiGauge
  end

  def react(event)
    #puts event.inspect
    if event["_class"] == "observe"
      respond(:_class => "widget_push", :cmd => "value", :value => rand(23))
    end
  end

  def running_since
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ FnordMetric.views.gaugeView = (function(gauge_name, conf){
  };

  function announce(evt){
    if(evt._class == "widget_response"){
    if((evt._class == "widget_response") || (evt._class == "widget_push")){
      for(_wkey in widgets){
        widget_objs[_wkey].announce(evt);
      }  
+43 −19
Original line number Diff line number Diff line
@@ -7,9 +7,13 @@ FnordMetric.widgets.realtimeValueWidget = function(){
    var ypadding = 20;
    var bmargin = 6;
    var bwidth  = 5;
    var bcolor  = '#06C';

    var bars = [];
    var max = 0;
    var max = 1;

    var next_values = [];
    var next_value_interval = false;

    function render(_opts){
      opts = _opts;
@@ -27,19 +31,37 @@ FnordMetric.widgets.realtimeValueWidget = function(){

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

      window.setInterval(function(){
        nextValue(Math.random() * 50);  
      }, 60);      

      //canvas.drawGrid(0, 0, width+(2*xpadding), height, 1, 6, "#ececec");
      for(var n=parseInt(width / bmargin); n > 0; n--){
        drawValue(false, n-1);
      }
    }

    function nextValue(value){
      if (value > max){
        max = value * 1.2;
      }

      drawValue(value);

      canvas.selectAll('.valuebar').each(function(){
        $(this).attr("x",  parseInt($(this).attr('x'))-bmargin);
      });

      pruneValues();
      next_value_interval = false;
      nextValueAsync();
    }

    function nextValueAsync(value){
      if(value){ next_values.unshift(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); }
          }, 60);  
        }
      }   
    }

    function pruneValues(){
@@ -49,31 +71,33 @@ FnordMetric.widgets.realtimeValueWidget = function(){
    }

    function drawValue(value, offset){

      if(!value){ theight = 0; }
      if(!offset){ offset = 0; }
      if(!value){ value = 0; }

      if(value > 0){ 
        var theight = (height-(ypadding*4)) * (value/max);

      canvas.selectAll('.valuebar')
        .transition()
        .attr("x", function(){ return parseInt($(this).attr('x'))-bmargin; })
        .duration(20);
        var fillc = bcolor;
      } else {
        var theight = 5;
        var fillc = '#ddd';
      }  
      
      bars.unshift(canvas
        .append("svg:rect")
        .attr("class", "valuebar")
        .attr("x", width+xpadding-(offset*bmargin))
        .attr("y", height-(ypadding*2)-theight)
        .attr("fill", fillc)
        .attr("width", bwidth)
        .attr("height", theight));
    }

    function announce(evt){
      if(evt.widget_key == opts.widget_key){
      if((evt._class == "widget_push") && (evt.cmd == "value")){
          console.log('YEAH');
        nextValueAsync(parseInt(evt.value));
      }
      if(evt.widget_key == opts.widget_key){

      }
    }