Class: Spout::Models::Graphables::ChoicesVsNumeric

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

Instance Attribute Summary

Attributes inherited from Default

#chart_variable, #stratification_variable, #subjects, #variable

Instance Method Summary collapse

Methods inherited from Default

#initialize, #subtitle, #title, #to_hash, #valid?, #x_axis_title

Constructor Details

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

Instance Method Details

#categoriesObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/spout/models/graphables/choices_vs_numeric.rb', line 10

def categories
  filtered_subjects = filter_and_sort_subjects

  return [] if filtered_subjects.size == 0

  [:quartile_one, :quartile_two, :quartile_three, :quartile_four].collect do |quartile|
    quartile = filtered_subjects.send(quartile).collect(&@chart_variable.id.to_sym)
    "#{quartile.min} to #{quartile.max}"
  end
end

#seriesObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/spout/models/graphables/choices_vs_numeric.rb', line 25

def series
  filtered_subjects = filter_and_sort_subjects

  return [] if filtered_subjects.size == 0

  filtered_domain_options(@variable).collect do |option|
    data = [:quartile_one, :quartile_two, :quartile_three, :quartile_four].collect do |quartile|
      filtered_subjects.send(quartile).select{ |s| s.send(@variable.id) == option.value }.count
    end
    { name: option.display_name, data: data }
  end
end

#stackingObject



38
39
40
# File 'lib/spout/models/graphables/choices_vs_numeric.rb', line 38

def stacking
  "percent"
end

#unitsObject



21
22
23
# File 'lib/spout/models/graphables/choices_vs_numeric.rb', line 21

def units
  "percent"
end