Class: PulseMeter::DygraphsVisualize::Layout

Inherits:
Base
  • Object
show all
Includes:
Mixins::Utils
Defined in:
lib/pulse_meter/dygraphs_visualize/layout.rb

Constant Summary collapse

DEFAULT_TIMESPAN_IN_INTERVALS =
50

Instance Method Summary collapse

Methods inherited from Base

#method_missing

Constructor Details

#initialize(opts) ⇒ Layout

Returns a new instance of Layout.



6
7
8
9
10
# File 'lib/pulse_meter/dygraphs_visualize/layout.rb', line 6

def initialize(opts)
  super
  @opts[:pages] ||= []
  @opts[:dygraphs_options] ||= {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PulseMeter::DygraphsVisualize::Base

Instance Method Details

#dynamic_widget(args) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/pulse_meter/dygraphs_visualize/layout.rb', line 59

def dynamic_widget(args)
  sensor_names = args.delete(:sensors)
  sensors = sensor_names.map{|n| PulseMeter::Sensor::Base.restore(n)}
  timespan = if args[:timespan] && args[:timespan] > 0
    args[:timespan].to_i
  else
    sensors.first.interval * DEFAULT_TIMESPAN_IN_INTERVALS
  end

  type = args.delete(:type)
  widget_dsl_class = constantize("PulseMeter::DygraphsVisualize::DSL::Widgets::#{type.capitalize}")
  widget = widget_dsl_class.new('Dynamic Widget')
  widget.timespan(timespan)
  sensor_names.each{|n| widget.sensor(n)}

  widget.to_data.data(args.merge(id: 1, timespan: timespan))
end

#optionsObject



28
29
30
31
32
33
# File 'lib/pulse_meter/dygraphs_visualize/layout.rb', line 28

def options
				{
					use_utc: use_utc,
    dygraphs_options: dygraphs_options
  }
end

#page_infosObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pulse_meter/dygraphs_visualize/layout.rb', line 16

def page_infos
	res = []
	pages.each_with_index do |p, i|
		res << {
			id: i + 1,
			title: p.title,
         dygraphs_options: p.dygraphs_options
		}
	end
	res
end

#sensor_listObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pulse_meter/dygraphs_visualize/layout.rb', line 43

def sensor_list
  PulseMeter::Sensor::Base
    .list_objects
    .select{|s| s.is_a?(PulseMeter::Sensor::Timeline)}
    .map do |s|
    {
      id: s.name,
      annotation: s.annotation || '',
      type: s.class.to_s.split('::').last,
      interval: s.interval
    }
  end
end

#to_appObject



12
13
14
# File 'lib/pulse_meter/dygraphs_visualize/layout.rb', line 12

def to_app
  PulseMeter::DygraphsVisualize::App.new(self)
end

#widget(page_id, widget_id, opts = {}) ⇒ Object



35
36
37
# File 'lib/pulse_meter/dygraphs_visualize/layout.rb', line 35

def widget(page_id, widget_id, opts = {})
  pages[page_id].widget_data(widget_id, opts)
end

#widgets(page_id) ⇒ Object



39
40
41
# File 'lib/pulse_meter/dygraphs_visualize/layout.rb', line 39

def widgets(page_id)
  pages[page_id].widget_datas
end