Sha256: 5e06012d3c07fc94937a1bfb034904c8d736e2e389412df39215af93698aa4bf

Contents?: true

Size: 918 Bytes

Versions: 14

Compression:

Stored size: 918 Bytes

Contents

module Rubyvis
  def self.histogram(data,f=nil)
    Rubyvis::Histogram.new(data,f)
  end
  class Histogram
    module Bin
      attr_accessor :x, :dx, :y
    end
    attr_accessor :frequency
    attr_reader :data
    attr_reader :f
    def initialize(data,f=nil)
      @data=data
      @f=f
      @frequency=true
    end
    def bins(ticks=nil)
      x=Rubyvis.map(data,f)
      bins=[]
      ticks||=Rubyvis::Scale.linear(x).ticks()
      # Initialize the bins
      (ticks.size-1).times {|i|
        bin=bins[i]=[]
        bin.extend Bin
        bin.x=ticks[i]
        bin.dx=ticks[i+1]-ticks[i]
        bin.y=0
      }
      x.size.times {|i|
        j=Rubyvis.search_index(ticks, x[i])-1
        bin=bins[ [0,[bins.size-1,j].min].max]
        bin.y+=1
        bin.push(data[i])
      }
      if !@frequency
        bins.each {|b|
          b.y=b.y/x.size.to_f
        }
      end
      bins
    end
    
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rubyvis-0.7.0 lib/rubyvis/histogram.rb
rubyvis-0.6.1 lib/rubyvis/histogram.rb
rubyvis-0.6.0 lib/rubyvis/histogram.rb
rubyvis-0.5.2 lib/rubyvis/histogram.rb
rubyvis-0.5.1 lib/rubyvis/histogram.rb
rubyvis-0.5.0 lib/rubyvis/histogram.rb
rubyvis-0.4.1 lib/rubyvis/histogram.rb
rubyvis-0.4.0 lib/rubyvis/histogram.rb
rubyvis-0.3.6 lib/rubyvis/histogram.rb
rubyvis-0.3.5 lib/rubyvis/histogram.rb
rubyvis-0.3.4 lib/rubyvis/histogram.rb
rubyvis-0.3.3 lib/rubyvis/histogram.rb
rubyvis-0.3.2 lib/rubyvis/histogram.rb
rubyvis-0.3.1 lib/rubyvis/histogram.rb