Class: OMF::Web::Widget::DataWidget

Inherits:
AbstractWidget show all
Defined in:
lib/omf-web/widget/data_widget.rb

Overview

Supports widgets which visualize the content of a Table which may also dynamically change.

Instance Attribute Summary collapse

Attributes inherited from AbstractWidget

#widget_id, #widget_type

Instance Method Summary collapse

Methods inherited from AbstractWidget

#layout?, #mime_type, #title, #tools_menu, #widget_info

Constructor Details

#initialize(opts = {}) ⇒ DataWidget

opts

:data_sources .. Either a single table, or a hash of 'name' => table.
:js_class .. Javascript class used for visualizing data
:wopts .. options sent to the javascript instance
:js_url .. URL where +jsVizClass+ can be loaded from
:dynamic .. update the widget when the data_table is changing
  :updateInterval .. if web sockets aren't used, check every :updateInterval sec [3]


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/omf-web/widget/data_widget.rb', line 22

def initialize(opts = {})
  opts = opts.dup # not sure why we may need to this. Is this hash used anywhere wlse?
  unless vizType = opts[:type].split('/')[-1]
    raise "Missing widget option ':viz_type' for widget '#{name}' (#{opts.inspect})"
  end
  name = opts[:name] ||= 'Unknown'
  opts[:js_module] = "graph/#{vizType}"
  opts[:js_url] = "graph/js/#{vizType}.js"
  opts[:js_class] = "OML.#{vizType}"
  opts[:base_el] = "\##{dom_id}"
  super opts

  if (ds = opts.delete(:data_source))
    # single source
    data_sources = {:default => ds}
  end
  unless data_sources ||= opts.delete(:data_sources)
    raise "Missing option ':data_sources' for widget '#{name}'"
  end
  unless data_sources.kind_of? Hash
    data_sources = {:default => data_sources}
  end
  opts[:data_sources] = data_sources.collect do |name, ds_descr|
    unless ds_descr.is_a? Hash
      ds_descr = {:name => ds_descr}
    end
    ds_descr[:alias] = "#{name}_#{self.object_id}"
    {:stream => ds_descr, :name => name}
  end
  #puts "DTA_WIDGTE>>> #{opts[:data_sources].inspect}"
end

Instance Attribute Details

#nameObject (readonly)

depends_on :css, “/resource/css/graph.css”



11
12
13
# File 'lib/omf-web/widget/data_widget.rb', line 11

def name
  @name
end

#optsObject (readonly)

depends_on :css, “/resource/css/graph.css”



11
12
13
# File 'lib/omf-web/widget/data_widget.rb', line 11

def opts
  @opts
end

Instance Method Details

#collect_data_sources(ds_set) ⇒ Object

end



99
100
101
102
103
104
105
# File 'lib/omf-web/widget/data_widget.rb', line 99

def collect_data_sources(ds_set)
  #puts "DATA_SOURCES>>>> #{@data_sources.values.inspect}"
  @opts[:data_sources].each do |ds|
    ds_set.add(ds[:stream])
  end
  ds_set
end

#contentObject



62
63
64
65
# File 'lib/omf-web/widget/data_widget.rb', line 62

def content()
  OMF::Web::Theme.require 'data_renderer'
  OMF::Web::Theme::DataRenderer.new(self, @opts)
end

#dom_idObject

This is the DOM id which should be used by the renderer for this widget. We need to keep this here as various renderes at various levels may need to get a reference to it to allow for such functionalities as hiding, stacking, …



58
59
60
# File 'lib/omf-web/widget/data_widget.rb', line 58

def dom_id
  "w#{object_id.abs}"
end