Class: Plot

Inherits:
Object
  • Object
show all
Defined in:
lib/grada/gnuplot.rb

Constant Summary collapse

QUOTED_METHODS =
[ "title", "output", "xlabel", "x2label", "ylabel", "y2label", "clabel", "cblabel", "zlabel" ]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlot

Returns a new instance of Plot.



65
66
67
68
69
70
# File 'lib/grada/gnuplot.rb', line 65

def initialize
  @settings = []
  @arbitrary_lines = []
  @data = []
  @styles = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



80
81
82
# File 'lib/grada/gnuplot.rb', line 80

def method_missing(meth, *args)
  set meth.id2name, *args
end

Instance Attribute Details

#arbitrary_linesObject

Returns the value of attribute arbitrary_lines.



61
62
63
# File 'lib/grada/gnuplot.rb', line 61

def arbitrary_lines
  @arbitrary_lines
end

#cmdObject

Returns the value of attribute cmd.



61
62
63
# File 'lib/grada/gnuplot.rb', line 61

def cmd
  @cmd
end

#dataObject

Returns the value of attribute data.



61
62
63
# File 'lib/grada/gnuplot.rb', line 61

def data
  @data
end

#settingsObject

Returns the value of attribute settings.



61
62
63
# File 'lib/grada/gnuplot.rb', line 61

def settings
  @settings
end

#stylesObject

Returns the value of attribute styles.



61
62
63
# File 'lib/grada/gnuplot.rb', line 61

def styles
  @styles
end

Class Method Details

.construct(&block) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/grada/gnuplot.rb', line 72

def self.construct(&block)
  plot = new
  
  block.call plot if block_given?
  
  { plot_settings: plot.to_gplot, plot_data:  plot.store_datasets }
end

Instance Method Details

#set(var, value = "") ⇒ Object



84
85
86
87
# File 'lib/grada/gnuplot.rb', line 84

def set ( var, value = "" )
  value = "\"#{value}\"" if QUOTED_METHODS.include? var unless value =~ /^'.*'$/
  @settings << [ :set, var, value ]
end

#store_datasets(io = '') ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/grada/gnuplot.rb', line 101

def store_datasets(io = '')
  if @data.size > 0
    io +=  'plot' + " #{ @data.map { |element| element.plot_args }.join(', ') } \n" 
    io += @data.map { |ds| ds.to_gplot }.compact.join("\n") + "\n"
  end
  
  io
end

#to_gplot(io = '') ⇒ Object



93
94
95
96
97
98
99
# File 'lib/grada/gnuplot.rb', line 93

def to_gplot(io = '')
  @settings.each { |setting| io += setting.map(&:to_s).join(' ') + "\n" }
  @styles.each{ |style| io += style.to_s + "\n" }
  @arbitrary_lines.each{ |line| io += line + "\n" }

  io
end

#unset(var) ⇒ Object



89
90
91
# File 'lib/grada/gnuplot.rb', line 89

def unset (var)
  @settings << [ :unset, var ]
end