Module: AlgoPlot
- Defined in:
- lib/algoplot.rb,
lib/algoplot/options.rb
Defined Under Namespace
Classes: Options
Class Method Summary collapse
-
.create_dataset(func) ⇒ Object
ds.with = “lines”.
- .get_extension(filename) ⇒ Object
- .is_extension_allowed?(ext) ⇒ Boolean
- .plot(n, functions, filename) ⇒ Object
Class Method Details
.create_dataset(func) ⇒ Object
ds.with = “lines”
14 15 16 |
# File 'lib/algoplot.rb', line 14 def self.create_dataset(func) Gnuplot::DataSet.new(func) end |
.get_extension(filename) ⇒ Object
5 6 7 |
# File 'lib/algoplot.rb', line 5 def self.get_extension(filename) File.extname(filename.downcase).delete('.') end |
.is_extension_allowed?(ext) ⇒ Boolean
9 10 11 |
# File 'lib/algoplot.rb', line 9 def self.is_extension_allowed?(ext) %w(pdf png jpg).include? ext end |
.plot(n, functions, filename) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/algoplot.rb', line 18 def self.plot(n, functions, filename) ext = get_extension(filename) fail "Extension #{ext} not allowed" unless is_extension_allowed?(ext) Gnuplot.open do |gp| Gnuplot::Plot.new(gp) do |plot| plot.terminal ext plot.output filename plot.xrange "[0:#{n}]" plot.title "Growth of #{functions.join(', ')}" plot.ylabel "steps" plot.xlabel "N" plot.data = functions.map { |f| create_dataset(f) } end end end |