Commit cf1ca923 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

toplist widget

parent 9e9a6342
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ require "fnordmetric/worker"
require "fnordmetric/widget"
require "fnordmetric/timeline_widget"
require "fnordmetric/numbers_widget"
require "fnordmetric/toplist_widget"
require "fnordmetric/namespace"
require "fnordmetric/gauge_modifiers"
require "fnordmetric/gauge_calculations"
+25 −0
Original line number Diff line number Diff line
class FnordMetric::ToplistWidget < FnordMetric::Widget

  def data
    super.merge(
      :gauges => data_gauges,
      :autoupdate => (@opts[:autoupdate] || 0)
    )
  end

  def data_gauges
    Hash.new.tap do |hash|
      gauges.each do |g|
        hash[g.name] = {
          :tick => g.tick,
          :title => g.title
        }
      end
    end
  end

  def has_tick?
    false
  end

end
 No newline at end of file
+9 −2
Original line number Diff line number Diff line
@@ -26,6 +26,13 @@ body{ background:#3b3e45; color:#333; margin:0; padding:0; overflow-y:scroll; fo
.widget .inner{ margin:20px; }
/*.widget .headbar{ margin-bottom:30px; }*/

.toplist_inner{ min-height:300px; }
.toplist_inner.loading{ opacity:0.5; background:url('/loader.gif') no-repeat center center;  }

.toplist_item{ border-bottom:1px solid #dedede; height:42px; }
.toplist_item .title{ float:left; line-height:42px; margin-left:20px; font-size:13px; color:#333; }
.toplist_item .value{ float:right; line-height:42px; margin-right:20px; font-size:13px; font-weight:bold; color:#333; width:70px; color:#666; }
.toplist_item .percent{ float:right; line-height:42px; margin-right:20px; font-size:18px; font-weight:bold; color:#333; width:70px; }

.headbar {

@@ -58,12 +65,12 @@ text-shadow: 1px 0px 2px rgba(255, 255, 255, 1);
.headbar .button{
  margin:8px 0px; height:16px; float:right; display:block;
  margin-right:-1px;
  background:url('/fnordmetric/sprite.png') no-repeat 0 -49px #eee; 
  background:url('/sprite.png') no-repeat 0 -49px #eee; 
  border:1px solid #999;
  border-bottom-color:#888;
  -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, .1); 
  cursor:pointer;
  
  border-radius:3px;
  font-size: 11px;
  font-weight:bold;
  line-height:16px;
+78 −0
Original line number Diff line number Diff line
@@ -70,6 +70,83 @@ var FnordMetric = (function(){
    return (currentWidgetUID += 1);
  }

 var toplistWidget = function(){

    function render(opts){

      var current_gauge = false;

      var headbar = $('<div class="headbar"></div>').append(
        $('<h2></h2>').html(opts.title)
      );

      opts.elem.append(headbar).css({
        'marginBottom': 20,
        'overflow': 'hidden'
      }).append(
        $('<div class="toplist_inner"></div>')
      );

      var first = true;
      for(k in opts.gauges){
        headbar.append(
          $('<div></div>')
            .attr('class', 'button mr')
            .attr('rel', k)
            .append(
              $('<span></span>').html(opts.gauges[k].title)
            ).click(function(){ 
              loadGauge($(this).attr('rel')); 
            }
          )
        );
        if(first){
          first = false;
          loadGauge(k);
        }
      }

      if(opts.autoupdate){
        var secs = parseInt(opts.autoupdate);
        if(secs > 0){
          window.setInterval(function(){
            loadGauge();
          }, secs*1000);
        }
      };
      
      function loadGauge(gkey){
        if(!gkey){ gkey = current_gauge; }
        current_gauge = gkey;
        $('.toplist_inner', opts.elem).addClass('loading');
        var _url = '/' + currentNamespace + '/gauge/' + gkey;
        $.get(_url, function(_resp){
          var resp = JSON.parse(_resp);
          renderGauge(gkey, resp);
        })
      }

      function renderGauge(gkey, gdata){
        var _elem = $('.toplist_inner', opts.elem).removeClass('loading').html('');
        $(gdata.values).each(function(n, _gd){
          var _perc  = (parseInt(gdata.values[n][1]) / parseFloat(gdata.count))*100;
          var _item = $('<div class="toplist_item"><div class="title"></div><div class="value"></div><div class="percent"></div></div>');
          $('.title', _item).html(gdata.values[n][0]);
          $('.value', _item).html(formatValue(parseInt(gdata.values[n][1])));
          $('.percent', _item).html(_perc.toFixed(1) + '%');
          _elem.append(_item);
        });
      }

    }


    return {
      render: render  
    };

  };

  var numbersWidget = function(){

    
@@ -633,6 +710,7 @@ var FnordMetric = (function(){
      /* argh... */
      if(widget.klass=='TimelineWidget'){ timelineWidget().render(widget); }
      if(widget.klass=='NumbersWidget'){ numbersWidget().render(widget); }
      if(widget.klass=='ToplistWidget'){ toplistWidget().render(widget); }
    };

    function resizeWidget(wkey){

pub/loader.gif

0 → 100644
+1.81 KiB
Loading image diff...
Loading