Sha256: 70e6d8eb7959cd617307fde63bdd6ff5f664c4ae968d76e8144e9b619427e654

Contents?: true

Size: 1.55 KB

Versions: 7

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require 'spout/models/graphables/default'
require 'spout/helpers/array_statistics'

module Spout
  module Models
    module Graphables
      class ChoicesVsNumeric < Spout::Models::Graphables::Default

        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

        def units
          'percent'
        end

        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

        def stacking
          'percent'
        end

        private

        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

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spout-0.12.1 lib/spout/models/graphables/choices_vs_numeric.rb
spout-0.12.0 lib/spout/models/graphables/choices_vs_numeric.rb
spout-0.12.0.rc2 lib/spout/models/graphables/choices_vs_numeric.rb
spout-0.12.0.rc lib/spout/models/graphables/choices_vs_numeric.rb
spout-0.12.0.beta2 lib/spout/models/graphables/choices_vs_numeric.rb
spout-0.12.0.beta1 lib/spout/models/graphables/choices_vs_numeric.rb
spout-0.11.1 lib/spout/models/graphables/choices_vs_numeric.rb