Class: Grada::Gnuplot::Plot

Inherits:
Object
  • Object
show all
Defined in:
lib/grada/types/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.



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

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



86
87
88
# File 'lib/grada/types/gnuplot.rb', line 86

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

Instance Attribute Details

#arbitrary_linesObject

Returns the value of attribute arbitrary_lines.



67
68
69
# File 'lib/grada/types/gnuplot.rb', line 67

def arbitrary_lines
  @arbitrary_lines
end

#cmdObject

Returns the value of attribute cmd.



67
68
69
# File 'lib/grada/types/gnuplot.rb', line 67

def cmd
  @cmd
end

#dataObject

Returns the value of attribute data.



67
68
69
# File 'lib/grada/types/gnuplot.rb', line 67

def data
  @data
end

#settingsObject

Returns the value of attribute settings.



67
68
69
# File 'lib/grada/types/gnuplot.rb', line 67

def settings
  @settings
end

#stylesObject

Returns the value of attribute styles.



67
68
69
# File 'lib/grada/types/gnuplot.rb', line 67

def styles
  @styles
end

Class Method Details

.construct(&block) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/grada/types/gnuplot.rb', line 78

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



90
91
92
93
# File 'lib/grada/types/gnuplot.rb', line 90

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

#store_datasets(io = '') ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/grada/types/gnuplot.rb', line 107

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



99
100
101
102
103
104
105
# File 'lib/grada/types/gnuplot.rb', line 99

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



95
96
97
# File 'lib/grada/types/gnuplot.rb', line 95

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