Class Gnuplot::Plot
In: lib/gnuplot.rb
Parent: Object
Plot SPlot DataSet lib/gnuplot.rb Gnuplot dot/m_0_0.png

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.

Methods

[]   add_data   method_missing   new   set   to_gplot  

Constants

QUOTED = [ "title", "output", "xlabel", "ylabel" ]

Attributes

cmd  [RW] 
data  [RW] 
sets  [RW] 

Public Class methods

[Source]

    # 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

Public Instance methods

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.

[Source]

     # File lib/gnuplot.rb, line 108
108:     def [] ( var )
109:       v = @sets.assoc( var )
110:       v[1] || nil
111:     end

[Source]

     # File lib/gnuplot.rb, line 114
114:     def add_data ( ds )
115:       @data << ds
116:     end

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.

[Source]

    # File lib/gnuplot.rb, line 86
86:     def method_missing( methId, *args )
87:       set methId.id2name, *args
88:     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.

[Source]

     # 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

[Source]

     # 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

[Validate]