Sha256: 549b0d1b96aad885e1acb7572b2152664d9556cb7063a90434c05e683593fa8f

Contents?: true

Size: 848 Bytes

Versions: 3

Compression:

Stored size: 848 Bytes

Contents

module Daru
  module Plotting
    module Category
      module NyaplotLibrary
        def plot opts
          case type = opts[:type]
          when :bar
            plot = Nyaplot::Plot.new
            opts[:method] ||= :count
            values = frequencies opts[:method]
            diagram = plot.add :bar, values.index.to_a, values.to_a
            # Set yrange for good view
            set_yrange plot, opts[:method]
            yield plot, diagram if block_given?
            plot.show
          else
            raise ArgumentError, "#{type} type is not supported."
          end
        end

        private

        def set_yrange plot, method
          case method
          when :percentage
            plot.yrange [0, 100]
          when :fraction
            plot.yrange [0, 1]
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
daru-0.1.5 lib/daru/plotting/nyaplot/category.rb
daru-0.1.4.1 lib/daru/plotting/nyaplot/category.rb
daru-0.1.4 lib/daru/plotting/nyaplot/category.rb