| Class | Gnuplot::Plot |
| In: |
lib/gnuplot.rb
|
| Parent: | Object |
| QUOTED | = | [ "title", "output", "xlabel", "ylabel" ] |
| cmd | [RW] | |
| data | [RW] | |
| sets | [RW] |
# File lib/gnuplot.rb, line 73
73: def initialize (io = nil, cmd = "plot")
74: @cmd = cmd
75: @sets = []
76: @data = []
77: yield self if block_given?
78:
79: io << to_gplot if io
80: end
Return the current value of the variable. This will return the setting that is currently in the instance, not one that‘s been given to a gnuplot process.
# File lib/gnuplot.rb, line 108
108: def [] ( var )
109: v = @sets.assoc( var )
110: v[1] || nil
111: end
Set a variable to the given value. Var must be a gnuplot variable and value must be the value to set it to. Automatic quoting will be performed if the variable requires it.
This is overloaded by the method_missing method so see that for more readable code.
# File lib/gnuplot.rb, line 98
98: def set ( var, value = "" )
99: value = "'#{value}'" if QUOTED.include? var unless value =~ /^'.*'$/
100: @sets << [ var, value ]
101: end
# File lib/gnuplot.rb, line 119
119: def to_gplot (io = "")
120: @sets.each { |var, val| io << "set #{var} #{val}\n" }
121:
122: if @data.size > 0 then
123: io << @cmd << " " << @data.collect { |e| e.plot_args }.join(", ")
124: io << "\n"
125:
126: v = @data.collect { |ds| ds.to_gplot }
127: io << v.compact.join("e\n")
128: end
129:
130: io
131: end