Class: Mext::Gruff::Plotter

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/gruff/gruff_plot.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(t, s, ds, r = nil, stp = DEFAULT_STEP) ⇒ Plotter

Returns a new instance of Plotter.



15
16
17
18
19
20
21
22
# File 'lib/tasks/gruff/gruff_plot.rb', line 15

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

Instance Attribute Details

#datasetsObject (readonly)

Returns the value of attribute datasets.



8
9
10
# File 'lib/tasks/gruff/gruff_plot.rb', line 8

def datasets
  @datasets
end

#dot_radiusObject

Returns the value of attribute dot_radius.



9
10
11
# File 'lib/tasks/gruff/gruff_plot.rb', line 9

def dot_radius
  @dot_radius
end

#rangesObject (readonly)

Returns the value of attribute ranges.



8
9
10
# File 'lib/tasks/gruff/gruff_plot.rb', line 8

def ranges
  @ranges
end

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'lib/tasks/gruff/gruff_plot.rb', line 8

def size
  @size
end

#stepObject

Returns the value of attribute step.



9
10
11
# File 'lib/tasks/gruff/gruff_plot.rb', line 9

def step
  @step
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/tasks/gruff/gruff_plot.rb', line 8

def title
  @title
end

Instance Method Details

#plotObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tasks/gruff/gruff_plot.rb', line 24

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