Sha256: 88058afb038f3d6275193d5a68d7004598be2265315bfd8e16902c7f76fc3d51

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

require 'spout/models/graphables/default'

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

        def title
          @variable.display_name
        end

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

        def units
          'Subjects'
        end

        def series
          @chart_variable.domain.options.collect do |option|
            visit_subjects = @subjects.select{ |s| s.send(@chart_variable.id) == option.value and s.send(@variable.id) != nil } 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 |option|
                visit_subject_values.select{ |v| v == option.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

        def x_axis_title
          @variable.units
        end

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spout-0.10.2 lib/spout/models/graphables/histogram.rb
spout-0.10.1 lib/spout/models/graphables/histogram.rb
spout-0.10.0 lib/spout/models/graphables/histogram.rb
spout-0.10.0.rc3 lib/spout/models/graphables/histogram.rb
spout-0.10.0.rc2 lib/spout/models/graphables/histogram.rb
spout-0.10.0.rc lib/spout/models/graphables/histogram.rb
spout-0.10.0.beta10 lib/spout/models/graphables/histogram.rb