Sha256: ad79c2ce8b0c2d4adac0b3c75a588067f8b5fdd2578e8b75fe85751966b70a71

Contents?: true

Size: 1.19 KB

Versions: 41

Compression:

Stored size: 1.19 KB

Contents

require 'gruff'
require 'byebug'

module Mext
  module Gruff

    class Plotter
      attr_reader :title, :size, :datasets, :ranges
      attr_accessor :step, :dot_radius

      OUTPUT_PATH = File.expand_path(File.join(['..'] * 4, 'tmp', 'output'), __FILE__)
      DEFAULT_STEP = 0.1
      DEFAULT_DOT_RADIUS = 2.0

      def initialize(t, s, ds, r = nil, stp = DEFAULT_STEP)
        @title = t
        @size = s
        @datasets = ds
        @ranges = r
        self.step = stp
        self.dot_radius = DEFAULT_DOT_RADIUS
      end

      def plot
        @ranges = [Range.new(0, self.datasets-1)] unless self.ranges
        idx = 0
        self.ranges.each do
          |range|
          g = ::Gruff::Line.new(self.size)
          g.title = self.title + " (#{idx})"
          g.theme = ::Gruff::Themes::PASTEL
          g.dot_radius = self.dot_radius
          self.datasets[range].each do
            |args|
            f = yield(args)
            (xdata, ydata) = f.xy(self.step)
            g.dataxy(f.label, xdata, ydata)
          end
          g.write(File.join(Mext::Gruff::Plotter::OUTPUT_PATH, self.title.gsub(/\s+/, '_') + "_#{idx}.png"))
          idx += 1
        end
      end

    end

  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
ruby-mext-0.15.1 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.15.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.14.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.13.1 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.13.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.12.1 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.12.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.11.1 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.11.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.10.1 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.10.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.9.1 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.9.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.8.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.7.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.6.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.5.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.4.1 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.4.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.3.2 lib/tasks/gruff/gruff_plot.rb