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.21.6 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.21.5 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.21.4 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.21.3 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.21.2 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.21.1 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.21.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.20.1 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.20.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.19.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.18.3 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.18.2 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.18.1 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.18.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.17.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.16.2 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.16.1 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.16.0 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.15.3 lib/tasks/gruff/gruff_plot.rb
ruby-mext-0.15.2 lib/tasks/gruff/gruff_plot.rb