Class: FnordMetric::BarsWidget

Inherits:
Widget
  • Object
show all
Defined in:
lib/fnordmetric/widgets/bars_widget.rb

Instance Attribute Summary

Attributes inherited from Widget

#gauges, #tick

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Widget

#add_gauges, #default_range, #ensure_has_tick!, #error!, #include_current?, #initialize, #range, #render, #ticks, #title, #token

Constructor Details

This class inherits a constructor from FnordMetric::Widget

Class Method Details

.execute(namespace, event) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fnordmetric/widgets/bars_widget.rb', line 3

def self.execute(namespace, event)
  resp = if event["cmd"] == "values_for"
    {
      :cmd => :values_for,
      :values => execute_values_for(namespace.gauges[event["gauge"].to_sym], event["until"])
    }
  end

  return false unless resp

  resp.merge(
    :type => "widget_response",
    :widget_key => event["widget_key"]
  )
end

.execute_values_for(gauge, time) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/fnordmetric/widgets/bars_widget.rb', line 19

def self.execute_values_for(gauge, time)
  gauge.field_values_at(time).sort do |a,b|
    a.first.to_i <=> b.first.to_i
  end.map do |a|
    [a.first, a.second.to_i]
  end
end

Instance Method Details

#dataObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fnordmetric/widgets/bars_widget.rb', line 27

def data
  super.merge(
    :gauge => gauges.first.name,
    :title => gauges.first.title,
    :autoupdate => (@opts[:autoupdate] || 60),
    :order_by => (@opts[:order_by] || 'value'),
    :plot_style => (@opts[:plot_style] || 'vertical'),
    :async_chart => true,
    :color => FnordMetric::COLORS.last,
    :tick => tick
  )
end

#has_tick?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/fnordmetric/widgets/bars_widget.rb', line 40

def has_tick?
  false
end