class Spout::Models::Graphables::ChoicesVsNumeric

Public Instance Methods

categories() click to toggle source
# 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
series() click to toggle source
# 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
stacking() click to toggle source
# File lib/spout/models/graphables/choices_vs_numeric.rb, line 38
def stacking
  "percent"
end
units() click to toggle source
# File lib/spout/models/graphables/choices_vs_numeric.rb, line 21
def units
  "percent"
end

Private Instance Methods

filter_and_sort_subjects() click to toggle source
# File lib/spout/models/graphables/choices_vs_numeric.rb, line 44
def filter_and_sort_subjects
  @filter_and_sort_subjects ||= begin
    @subjects.select do |s|
      s.send(@variable.id) != nil and s.send(@chart_variable.id) != nil
    end.sort_by(&@chart_variable.id.to_sym)
  rescue
    []
  end
end