Class: Plotty::Graph
- Inherits:
-
Object
- Object
- Plotty::Graph
- Defined in:
- lib/plotty/graph.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(x, y) ⇒ Graph
constructor
A new instance of Graph.
- #plot!(script = nil) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Graph
Returns a new instance of Graph.
92 93 94 95 |
# File 'lib/plotty/graph.rb', line 92 def initialize(x, y) @x = x @y = y end |
Class Method Details
.parse(x, y, commands) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/plotty/graph.rb', line 97 def self.parse(x, y, commands) self.new( Sequence.parse(x), commands.collect{|command| Function.new(y, command)}, ) end |
Instance Method Details
#plot!(script = nil) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/plotty/graph.rb', line 108 def plot!(script = nil) File.open("data.txt", "w") do |file| @x.each do |x| values = @y.collect do |function| function.call(x) end puts "#{x}: #{values.inspect}" file.puts "#{x} #{values.join(' ')}" end end plots = @y.collect.with_index{|function, index| "'data.txt' using 1:#{index+2} with lines title #{function.title.dump}"} system("gnuplot", "-e", "#{script}; plot #{plots.join(', ')}") end |
#size ⇒ Object
104 105 106 |
# File 'lib/plotty/graph.rb', line 104 def size TTY::Screen.size.reverse end |