Class: RailsDataExplorer::DataType

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_data_explorer/data_type.rb,
lib/rails_data_explorer/data_type/categorical.rb,
lib/rails_data_explorer/data_type/quantitative.rb,
lib/rails_data_explorer/data_type/quantitative/decimal.rb,
lib/rails_data_explorer/data_type/quantitative/integer.rb,
lib/rails_data_explorer/data_type/quantitative/temporal.rb

Overview

Responsibilities:

* Represent a type of data
* Determine available chart types
* Compute descriptive statistics
* Compute modified values

Collaborators:

* DataSeries
* Chart

Direct Known Subclasses

Categorical, Quantitative

Defined Under Namespace

Classes: Categorical, Quantitative

Instance Method Summary collapse

Instance Method Details

#available_chart_types(constraints = {}) ⇒ Object

@param[Hash, optional] constraints

* :dimensions_count - how many data_series are there?


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rails_data_explorer/data_type.rb', line 19

def available_chart_types(constraints={})
  r = all_available_chart_types
  if(c = constraints.delete(:dimensions_count))
    r = r.find_all { |chart_type|
      (
        chart_type[:dimensions_count_min].nil? ||
        (chart_type[:dimensions_count_min] <= c)
      ) && (
        chart_type[:dimensions_count_max].nil? ||
        (chart_type[:dimensions_count_max] >= c)
      )
    }
  end
  if(c = constraints.delete(:chart_roles))
    # c = { ChartClass => [:x, :y], ... }
    r = r.find_all { |chart_type|
      c[chart_type[:chart_class]].nil? ||
      (c[chart_type[:chart_class]] & chart_type[:chart_roles]).any?
    }
  end
  # check for any unhandled options
  if constraints.any?
    raise "Unhandled constraints: #{ constraints.inspect }"
  end
  r
end