Class: Spout::Models::Graphables::Histogram

Inherits:
Default
  • Object
show all
Defined in:
lib/spout/models/graphables/histogram.rb

Overview

Generates data for variable histograms

Instance Attribute Summary

Attributes inherited from Default

#chart_variable, #stratification_variable, #subjects, #variable

Instance Method Summary collapse

Methods inherited from Default

#initialize, #stacking, #subtitle, #to_hash, #valid?

Constructor Details

This class inherits a constructor from Spout::Models::Graphables::Default

Instance Method Details

#categoriesObject



14
15
16
17
18
19
20
# File 'lib/spout/models/graphables/histogram.rb', line 14

def categories
  if @variable.type == "choices"
    filtered_domain_options(@variable).collect(&:display_name)
  else
    @buckets.collect(&:display_name)
  end
end

#seriesObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/spout/models/graphables/histogram.rb', line 26

def series
  @chart_variable.domain.options.collect do |option|
    visit_subjects = @subjects.select{ |s| s.send(@chart_variable.id) == option.value && !s.send(@variable.id).nil? && !s.send(@variable.id).is_a?(Spout::Models::Empty) } rescue visit_subjects = []
    visit_subject_values = visit_subjects.collect(&@variable.id.to_sym).sort # rescue visit_subject_values = []
    next unless visit_subject_values.size > 0

    data = []

    if @variable.type == "choices"
      data = filtered_domain_options(@variable).collect do |o|
        visit_subject_values.select { |v| v == o.value }.count
      end
    else
      visit_subject_values.group_by { |v| get_bucket(v) }.each do |key, values|
        data[categories.index(key)] = values.count if categories.index(key)
      end
    end

    { name: option.display_name, data: data }
  end.compact
end

#titleObject



10
11
12
# File 'lib/spout/models/graphables/histogram.rb', line 10

def title
  @variable.display_name
end

#unitsObject



22
23
24
# File 'lib/spout/models/graphables/histogram.rb', line 22

def units
  "Subjects"
end

#x_axis_titleObject



48
49
50
# File 'lib/spout/models/graphables/histogram.rb', line 48

def x_axis_title
  @variable.units
end