Class: Gnuplot::Plot
- Inherits:
-
Object
- Object
- Gnuplot::Plot
- Defined in:
- lib/gnuplot.rb
Overview
Holds command information and performs the formatting of that command information to a Gnuplot process. When constructing a new plot for gnuplot, this is the first object that must be instantiated. On this object set the various properties and add data sets.
Direct Known Subclasses
Constant Summary collapse
- QUOTED =
[ "title", "output", "xlabel", "ylabel" ]
Instance Attribute Summary collapse
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#data ⇒ Object
Returns the value of attribute data.
-
#sets ⇒ Object
Returns the value of attribute sets.
Instance Method Summary collapse
-
#[](var) ⇒ Object
Return the current value of the variable.
- #add_data(ds) ⇒ Object
-
#initialize(io = nil, cmd = "plot") {|_self| ... } ⇒ Plot
constructor
A new instance of Plot.
-
#method_missing(methId, *args) ⇒ Object
Invoke the set method on the plot using the name of the invoked method as the set variable and any arguments that have been passed as the value.
-
#set(var, value = "") ⇒ Object
Set a variable to the given value.
- #to_gplot(io = "") ⇒ Object
Constructor Details
#initialize(io = nil, cmd = "plot") {|_self| ... } ⇒ Plot
Returns a new instance of Plot.
37 38 39 40 41 42 43 44 |
# File 'lib/gnuplot.rb', line 37 def initialize (io = nil, cmd = "plot") @cmd = cmd @sets = [] @data = [] yield self if block_given? io << to_gplot if io end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methId, *args) ⇒ Object
Invoke the set method on the plot using the name of the invoked method as the set variable and any arguments that have been passed as the value. See the set method for more details.
50 51 52 |
# File 'lib/gnuplot.rb', line 50 def method_missing( methId, *args ) set methId.id2name, *args end |
Instance Attribute Details
#cmd ⇒ Object
Returns the value of attribute cmd.
33 34 35 |
# File 'lib/gnuplot.rb', line 33 def cmd @cmd end |
#data ⇒ Object
Returns the value of attribute data.
33 34 35 |
# File 'lib/gnuplot.rb', line 33 def data @data end |
#sets ⇒ Object
Returns the value of attribute sets.
33 34 35 |
# File 'lib/gnuplot.rb', line 33 def sets @sets end |
Instance Method Details
#[](var) ⇒ Object
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.
72 73 74 75 |
# File 'lib/gnuplot.rb', line 72 def [] ( var ) v = @sets.assoc( var ) v[1] || nil end |
#add_data(ds) ⇒ Object
78 79 80 |
# File 'lib/gnuplot.rb', line 78 def add_data ( ds ) @data << ds end |
#set(var, value = "") ⇒ Object
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.
62 63 64 65 |
# File 'lib/gnuplot.rb', line 62 def set ( var, value = "" ) value = "'#{value}'" if QUOTED.include? var unless value =~ /^'.*'$/ @sets << [ var, value ] end |
#to_gplot(io = "") ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gnuplot.rb', line 83 def to_gplot (io = "") @sets.each { |var, val| io << "set #{var} #{val}\n" } if @data.size > 0 then io << @cmd << " " << @data.collect { |e| e.plot_args }.join(", ") io << "\n" v = @data.collect { |ds| ds.to_gplot } io << v.compact.join("e\n") end io end |