Class: ChartSet
- Inherits:
-
Object
- Object
- ChartSet
- Defined in:
- app/models/chart_set.rb
Instance Attribute Summary collapse
-
#charts ⇒ Object
readonly
class which is a set of charts to be shown on a page where the chars draw their data from the same dataset and are shown with the same recordset.
-
#options ⇒ Object
readonly
class which is a set of charts to be shown on a page where the chars draw their data from the same dataset and are shown with the same recordset.
-
#samples ⇒ Object
readonly
class which is a set of charts to be shown on a page where the chars draw their data from the same dataset and are shown with the same recordset.
-
#xaxis ⇒ Object
readonly
class which is a set of charts to be shown on a page where the chars draw their data from the same dataset and are shown with the same recordset.
Instance Method Summary collapse
-
#as_hash(options = {:with_charts => true}) ⇒ Object
returns the values that are to be passed to the client browser, as a hash if with_charts is passed false then only samples and xaxis are included.
-
#initialize(charts, samples, xaxis) ⇒ ChartSet
constructor
constructor taking an array of Charts, an array of samples (which may be nil) and a hash specifying the xaxis options xaxis should specify at least :method the samples may be nil if ajax will be used to fetch the data.
Constructor Details
#initialize(charts, samples, xaxis) ⇒ ChartSet
constructor taking an array of Charts, an array of samples (which may be nil) and a hash specifying the xaxis options xaxis should specify at least :method the samples may be nil if ajax will be used to fetch the data
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/chart_set.rb', line 10 def initialize( charts, samples, xaxis ) @charts = charts @samples = samples @xaxis = xaxis begin method = @xaxis[:method] rescue raise "Flot-rails-plus error: xaxis is not a hash" end if method == nil raise "Flot-rails-plus error: xaxis[:method] is nil" end end |
Instance Attribute Details
#charts ⇒ Object (readonly)
class which is a set of charts to be shown on a page where the chars draw their data from the same dataset and are shown with the same recordset
4 5 6 |
# File 'app/models/chart_set.rb', line 4 def charts @charts end |
#options ⇒ Object (readonly)
class which is a set of charts to be shown on a page where the chars draw their data from the same dataset and are shown with the same recordset
4 5 6 |
# File 'app/models/chart_set.rb', line 4 def @options end |
#samples ⇒ Object (readonly)
class which is a set of charts to be shown on a page where the chars draw their data from the same dataset and are shown with the same recordset
4 5 6 |
# File 'app/models/chart_set.rb', line 4 def samples @samples end |
#xaxis ⇒ Object (readonly)
class which is a set of charts to be shown on a page where the chars draw their data from the same dataset and are shown with the same recordset
4 5 6 |
# File 'app/models/chart_set.rb', line 4 def xaxis @xaxis end |
Instance Method Details
#as_hash(options = {:with_charts => true}) ⇒ Object
returns the values that are to be passed to the client browser, as a hash if with_charts is passed false then only samples and xaxis are included
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 53 54 |
# File 'app/models/chart_set.rb', line 26 def as_hash( = {:with_charts => true} ) samples_mapped = nil if @samples samples_mapped = @samples.map do |r| Hash[(Chart.value_methods(@charts) << @xaxis[:method]).map { |v| [v, r.send(v)] }] end end # fill in xaxis range if not supplied xaxis = @xaxis xaxis_method = xaxis[:method] if @samples && @samples.length > 0 if xaxis[:mode] == "time" # may be nil if none provided # if min and max have been provided by chart they must be scaled accordingly xaxis[:min] ||= @samples.first.send(xaxis_method) xaxis[:min] = xaxis[:min].to_i*1000 xaxis[:max] ||= @samples.last.send(xaxis_method) xaxis[:max] = xaxis[:max].to_i*1000 else xaxis[:min] ||= @samples.first.send(xaxis_method) xaxis[:max] ||= @samples.last.send(xaxis_method) end end hash = {:samples => samples_mapped, :xaxis => xaxis } if [:with_charts] != false # add the chart definitions if required hash[:charts] = @charts.map {|c| c.as_hash } end hash end |