Class: Gnuplot::Plot

### Home Classes Methods

### In Files

- lib/gnuplot.rb

### Parent

Object

### Methods

- ::new
- #[]
- #add_data
- #method_missing
- #set
- #store_datasets
- #to_gplot
- #unset

### Files

- ChangeLog
- LICENSE.txt

### Class/Module Index

Quicksearch

- Gnuplot
- Gnuplot::DataSet
- Gnuplot::Plot
- Gnuplot::SPlot
- Array
- Matrix

No matching classes.

# Gnuplot::Plot

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.

### Constants

QUOTED

### Attributes

arbitrary_lines[RW]
cmd[RW]
data[RW]
settings[RW]

### Public Class Methods

new(io = nil, cmd = "plot") click to toggle source

    # 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

### Public Instance Methods

[]( var ) click to toggle source

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 141
    def [] ( var )
      v = @settings.rassoc( var )
      if v.nil? or v.first == :unset
          nil
      else
          v[2]
      end
    end

add_data( ds ) click to toggle source

    # File lib/gnuplot.rb, line 151
    def add_data ( ds )
      @data << ds
    end

method_missing( methId, *args ) click to toggle source

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.

    # File lib/gnuplot.rb, line 114
    def method_missing( methId, *args )
      set methId.id2name, *args
    end

set( var, value = "" ) click to toggle source

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 126
    def set ( var, value = "" )
      value = "\"#{value}\"" if QUOTED.include? var unless value =~ /^'.*'$/
      @settings << [ :set, var, value ]
    end

store_datasets(io = "") click to toggle source

    # 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 = "") click to toggle source

    # 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 ) click to toggle source

Unset a variable. `Var` must be a gnuplot variable.

    # File lib/gnuplot.rb, line 132
    def unset ( var )
        @settings << [ :unset, var ]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.