Sha256: 538b08251622f7959197312af1af0733ec17d9d572c48a9b93f383bf112d059c

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

module D3
  class Histogram
    include D3::Native

    def call(data)
      @native.call(data)
    end

    attributes_d3 %i[value domain]

    def thresholds(count=nil, &block)
      if block_given?
        @native.JS.thresholds(block)
      elsif count.is_a?(Numeric)
        @native.JS.thresholds(count)
      elsif count == :scott
        @native.JS.thresholds{|*args| D3.threshold_scott(*args)}
      elsif count == :sturges
        @native.JS.thresholds{|*args| D3.threshold_sturges(*args)}
      elsif count == :freedman_diaconis
        @native.JS.thresholds{|*args| D3.threshold_freedman_diaconis(*args)}
      else
        raise ArgumentError, "Wrong use of D3::Histogram.thresholds API - pass block, number, or symbol"
      end
      self
    end
  end

  class << self
    def histogram
      D3::Histogram.new @d3.JS.histogram
    end

    def threshold_freedman_diaconis(*args)
      @d3.JS.thresholdFreedmanDiaconis(*args)
    end

    def threshold_scott(*args)
      @d3.JS.thresholdScott(*args)
    end

    def threshold_sturges(*args)
      @d3.JS.thresholdSturges(*args)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hyper-d3-1.0.0.lap28 lib/d3/histograms.rb
hyper-d3-1.0.0.lap27 lib/d3/histograms.rb
hyper-d3-1.0.0.lap26 lib/d3/histograms.rb
hyper-d3-1.0.0.lap25 lib/d3/histograms.rb
hyper-d3-1.0.0.lap24 lib/d3/histograms.rb
hyper-d3-1.0.0.lap23 lib/d3/histograms.rb