Class: SimpleOutput::SimpleOutputPlugin

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

Direct Known Subclasses

SimpleCSV, SimpleChartkick, SimpleLog, SimplePlot

Instance Method Summary collapse

Constructor Details

#initializeSimpleOutputPlugin

Returns a new instance of SimpleOutputPlugin.



21
22
23
24
25
26
27
28
29
30
# File 'lib/simpleoutput.rb', line 21

def initialize()
   @x = {}
   @y = {}
   @series_names = {}
   @data_id = 0
   @annotations = {}
   @current_name = "NameError"
   @series_id = 0
   @metadata = {}
end

Instance Method Details

#advance_series(name = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/simpleoutput.rb', line 55

def advance_series(name=nil)
   @series_id  += 1
   @current_name = name == nil ? "series-#{@series_id}" : name
   self.new_data_callback(name)
   if !@series_names.has_key?(@current_name)
      @series_names[@current_name] = []
   end
   @annotations[@current_name] = []
   @current_name
end

#annotate(annotation, name = nil, options = {}) ⇒ Object



152
153
154
155
156
# File 'lib/simpleoutput.rb', line 152

def annotate(annotation, name=nil, options = {})
   name = translate_name(name)
   @annotations[name] << annotation
   self.options_callback(options)
end

#append_callback(x, y, name, options) ⇒ Object



41
42
# File 'lib/simpleoutput.rb', line 41

def append_callback(x,y,name,options)
end

#append_hash(hash = {}, name = nil, options = {}) ⇒ Object



141
142
143
144
145
# File 'lib/simpleoutput.rb', line 141

def append_hash(hash = {}, name=nil, options={})
   name = translate_name(name)
   x, y = self.hash_to_xy(hash)
   self.append_xy(x,y,name,options)
end

#append_points(points = [], name = nil, options = {}) ⇒ Object



121
122
123
124
125
126
127
128
129
# File 'lib/simpleoutput.rb', line 121

def append_points(points =[], name=nil, options={})
   x = []
   y = []
   points.each do |point|
      x << point[0]
      y << point[1]
   end
   self.append_xy(x,y,name,options)
end

#append_series_name(name = nil, options = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/simpleoutput.rb', line 66

def append_series_name(name=nil, options={})
   name = translate_name(name)
   if !@series_names.has_key?(name)
      @series_names[name] = []
   end
   if options.has_key?('series')
      @series_names[name] << options['series']
   else
      @series_names[name] << "data-#{@data_id}"
      @data_id += 1
   end
end

#append_xy(x = [], y = [], name = nil, options = {}) ⇒ Object

Interface Functions ===================================



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/simpleoutput.rb', line 104

def append_xy( x=[], y=[],name=nil, options={})
   name = translate_name(name)
   if !self.new_data_check(name)
      @x[name] << x
      @y[name] << y
      self.append_series_name(name, options)
      self.options_callback(options)
      self.append_callback(x,y,name,options)
   else
      self.new_data(x,y,name,options)
   end
end

#get_data_as_pointsObject

Internal Helpers



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/simpleoutput.rb', line 163

def get_data_as_points
   series_data = {}
   @x.each_pair do |(key, x_series)|
      #For each series of data
      y_series = @y[key]
      series_data[key] = []

      x_series.each_with_index do |x_line, index|
         #For each line
         series_data[key] << [] #Create an empty set
         y_line = y_series[index]
         x_line.each_with_index do |x_point, index|
            y_point = y_line[index]
            series_data[key].last << [x_point, y_point]
         end
      end
   end
   return series_data    
end

#get_data_as_xyObject



183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/simpleoutput.rb', line 183

def get_data_as_xy
   series_data = {}
   @x.each_pair do |(key, x_series)|
      y_series = @y[key]
      series_data[key] = []
      x_series.each_with_index do |x_line, index|
         y_line = y_series[index]
         series_data[key] << [x_line, y_line]
      end
   end
   return series_data
end

#get_series_hashesObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/simpleoutput.rb', line 196

def get_series_hashes
   data_hash = {}
  
   @x.each_pair do |(key, x_series)|
      
      data_hash[key] = {}
      y_series = @y[key]
      x_series.each_with_index do |x_data, index|
         
         y_data = y_series[index]
         series_key = @series_names[key][index]
         data_hash[key][series_key] = {}
         x_data.each_with_index do |x_point, index|
            y_point = y_data[index]
            data_hash[key][series_key][x_point] = y_point
         end
      end
   end
   return data_hash
end

#new_data(x = [], y = [], name = nil, options = {}) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/simpleoutput.rb', line 95

def new_data( x=[], y=[],name=nil, options={})
   name = self.advance_series(name)
   self.set_x_data(x, name, options)
   self.set_y_data(y, name, options)
   self.append_series_name(name,options)
   self.options_callback(options)
end

#new_data_callback(name) ⇒ Object



44
45
# File 'lib/simpleoutput.rb', line 44

def new_data_callback(name)
end

#new_data_check(name = nil) ⇒ Object



79
80
81
# File 'lib/simpleoutput.rb', line 79

def new_data_check(name=nil)
   (!@x.has_key?(name)) || (!@y.has_key?(name)) 
end

#options_callback(options) ⇒ Object

Virtual Functions



32
33
# File 'lib/simpleoutput.rb', line 32

def options_callback(options)
end

#saveObject

Output



218
219
220
# File 'lib/simpleoutput.rb', line 218

def save()
  
end

#set_hash(hash = {}, name = nil, options = {}) ⇒ Object



147
148
149
150
# File 'lib/simpleoutput.rb', line 147

def set_hash(hash ={}, name=nil, options={})
   x, y = self.hash_to_xy(hash)
   self.set_xy(x,y,name,options)
end

#set_options(name = nil, options = {}) ⇒ Object



158
159
160
# File 'lib/simpleoutput.rb', line 158

def set_options(name=nil, options = {})
   self.options_callback(options)
end

#set_points(points = [], name = nil, options = {}) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/simpleoutput.rb', line 131

def set_points(points = [], name=nil, options={})
   x = []
   y = []
   points.each do |point|
      x << point[0]
      y << point[1]
   end
   self.set_xy(x,y,name, options)
end

#set_x_callback(data, name, options) ⇒ Object



35
36
# File 'lib/simpleoutput.rb', line 35

def set_x_callback(data, name, options)
end

#set_x_data(data, name, options = {}) ⇒ Object



83
84
85
86
87
# File 'lib/simpleoutput.rb', line 83

def set_x_data(data, name, options={})
  @x[name] = []
  @x[name] << data
  self.set_x_callback(data, name, options)
end

#set_xy(x = [], y = [], name = nil, options = {}) ⇒ Object



117
118
119
# File 'lib/simpleoutput.rb', line 117

def set_xy(x=[], y=[], name=nil, options={})
   self.new_data(x,y,name,options)
end

#set_y_callback(data, name, options) ⇒ Object



38
39
# File 'lib/simpleoutput.rb', line 38

def set_y_callback(data, name, options)
end

#set_y_data(data, name, options = {}) ⇒ Object



89
90
91
92
93
# File 'lib/simpleoutput.rb', line 89

def set_y_data(data, name, options={})
   @y[name] = []
   @y[name] << data
   self.set_y_callback(data, name, options)
end

#translate_name(name) ⇒ Object

CORE functions



48
49
50
51
52
53
# File 'lib/simpleoutput.rb', line 48

def translate_name(name)
   if name == nil
      name = @current_name
   end
   return name
end