Sha256: 25d900f24bddbc16f8c973704f4ca1a53923eae33ed556a56b11bc2091f8c6e0

Contents?: true

Size: 1.19 KB

Versions: 7

Compression:

Stored size: 1.19 KB

Contents

require 'spout/helpers/array_statistics'
require 'spout/helpers/table_formatting'

module Spout
  module Helpers
    class ChartTypes
      def self.get_bucket(buckets, value)
        return nil if buckets.size == 0 or not value.kind_of?(Numeric)
        buckets.each do |b|
          return "#{b[0]} to #{b[1]}" if value >= b[0] and value <= b[1]
        end
        if value <= buckets.first[0]
          "#{buckets.first[0]} to #{buckets.first[1]}"
        else
          "#{buckets.last[0]} to #{buckets.last[1]}"
        end
      end

      def self.continuous_buckets(values)
        values.select!{|v| v.kind_of? Numeric}
        return [] if values.count == 0
        minimum_bucket = values.min
        maximum_bucket = values.max
        max_buckets = 12
        bucket_size = ((maximum_bucket - minimum_bucket) / max_buckets.to_f)
        precision = (bucket_size == 0 ? 0 : [-Math.log10(bucket_size).floor, 0].max)

        buckets = []
        (0..(max_buckets-1)).to_a.each do |index|
          start = (minimum_bucket + index * bucket_size)
          stop = (start + bucket_size)
          buckets << [start.round(precision),stop.round(precision)]
        end
        buckets
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spout-0.10.2 lib/spout/helpers/chart_types.rb
spout-0.10.1 lib/spout/helpers/chart_types.rb
spout-0.10.0 lib/spout/helpers/chart_types.rb
spout-0.10.0.rc3 lib/spout/helpers/chart_types.rb
spout-0.10.0.rc2 lib/spout/helpers/chart_types.rb
spout-0.10.0.rc lib/spout/helpers/chart_types.rb
spout-0.10.0.beta10 lib/spout/helpers/chart_types.rb