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", "x2label", "ylabel", "y2label", "clabel", "cblabel", "zlabel" ]
Instance Attribute Summary collapse
-
#arbitrary_lines ⇒ Object
Returns the value of attribute arbitrary_lines.
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#data ⇒ Object
Returns the value of attribute data.
-
#settings ⇒ Object
Returns the value of attribute settings.
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.
- #store_datasets(io = "") ⇒ Object
- #to_gplot(io = "") ⇒ Object
-
#unset(var) ⇒ Object
Unset a variable.
Constructor Details
#initialize(io = nil, cmd = "plot") {|_self| ... } ⇒ Plot
Returns a new instance of Plot.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/gnuplot.rb', line 95 def initialize (io = nil, cmd = "plot") @cmd = cmd @settings = [] @arbitrary_lines = [] @data = [] yield self if block_given? puts "writing this to gnuplot:\n" + to_gplot + "\n" if $VERBOSE if io io << to_gplot io << store_datasets end 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.
114 115 116 |
# File 'lib/gnuplot.rb', line 114 def method_missing( methId, *args ) set methId.id2name, *args end |
Instance Attribute Details
#arbitrary_lines ⇒ Object
Returns the value of attribute arbitrary_lines.
108 109 110 |
# File 'lib/gnuplot.rb', line 108 def arbitrary_lines @arbitrary_lines end |
#cmd ⇒ Object
Returns the value of attribute cmd.
91 92 93 |
# File 'lib/gnuplot.rb', line 91 def cmd @cmd end |
#data ⇒ Object
Returns the value of attribute data.
91 92 93 |
# File 'lib/gnuplot.rb', line 91 def data @data end |
#settings ⇒ Object
Returns the value of attribute settings.
91 92 93 |
# File 'lib/gnuplot.rb', line 91 def settings @settings 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.
141 142 143 144 145 146 147 148 |
# File 'lib/gnuplot.rb', line 141 def [] ( var ) v = @settings.rassoc( var ) if v.nil? or v.first == :unset nil else v[2] end end |
#add_data(ds) ⇒ Object
151 152 153 |
# File 'lib/gnuplot.rb', line 151 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.
126 127 128 129 |
# File 'lib/gnuplot.rb', line 126 def set ( var, value = "" ) value = "\"#{value}\"" if QUOTED.include? var unless value =~ /^'.*'$/ @settings << [ :set, var, value ] end |
#store_datasets(io = "") ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/gnuplot.rb', line 165 def store_datasets (io = "") if @data.size > 0 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 |
#to_gplot(io = "") ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'lib/gnuplot.rb', line 156 def to_gplot (io = "") @settings.each do |setting| io << setting.map(&:to_s).join(" ") << "\n" end @arbitrary_lines.each{|line| io << line << "\n" } io end |
#unset(var) ⇒ Object
Unset a variable. Var
must be a gnuplot variable.
132 133 134 |
# File 'lib/gnuplot.rb', line 132 def unset ( var ) @settings << [ :unset, var ] end |