Class: Mext::Gruff::Plotter
- Inherits:
-
Object
- Object
- Mext::Gruff::Plotter
- Defined in:
- lib/tasks/gruff/gruff_plot.rb
Constant Summary collapse
- OUTPUT_PATH =
File.(File.join(['..'] * 4, 'tmp', 'output'), __FILE__)
- DEFAULT_STEP =
0.1
- DEFAULT_DOT_RADIUS =
2.0
Instance Attribute Summary collapse
-
#datasets ⇒ Object
readonly
Returns the value of attribute datasets.
-
#dot_radius ⇒ Object
Returns the value of attribute dot_radius.
-
#ranges ⇒ Object
readonly
Returns the value of attribute ranges.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#step ⇒ Object
Returns the value of attribute step.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(t, s, ds, r = nil, stp = DEFAULT_STEP) ⇒ Plotter
constructor
A new instance of Plotter.
- #plot ⇒ Object
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
#datasets ⇒ Object (readonly)
Returns the value of attribute datasets.
8 9 10 |
# File 'lib/tasks/gruff/gruff_plot.rb', line 8 def datasets @datasets end |
#dot_radius ⇒ Object
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 |
#ranges ⇒ Object (readonly)
Returns the value of attribute ranges.
8 9 10 |
# File 'lib/tasks/gruff/gruff_plot.rb', line 8 def ranges @ranges end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
8 9 10 |
# File 'lib/tasks/gruff/gruff_plot.rb', line 8 def size @size end |
#step ⇒ Object
Returns the value of attribute step.
9 10 11 |
# File 'lib/tasks/gruff/gruff_plot.rb', line 9 def step @step end |
#title ⇒ Object (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
#plot ⇒ Object
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 |