Class: SimpleOutput::SimpleOutputPlugin
- Inherits:
-
Object
- Object
- SimpleOutput::SimpleOutputPlugin
show all
- Defined in:
- lib/simpleoutput.rb
Instance Method Summary
collapse
-
#advance_series(name = nil) ⇒ Object
-
#annotate(annotation, name = nil, options = {}) ⇒ Object
-
#append_callback(x, y, name, options) ⇒ Object
-
#append_series_name(name = nil, options = {}) ⇒ Object
-
#appendHash(hash = {}, name = nil, options = {}) ⇒ Object
-
#appendPoints(points = [], name = nil, options = {}) ⇒ Object
-
#appendXY(x = [], y = [], name = nil, options = {}) ⇒ Object
Interface Functions ===================================.
-
#getDataAsPoints ⇒ Object
-
#getDataAsXY ⇒ Object
-
#getSeriesHashes ⇒ Object
-
#initialize ⇒ SimpleOutputPlugin
constructor
A new instance of SimpleOutputPlugin.
-
#new_data_callback(name) ⇒ Object
-
#newData(x = [], y = [], name = nil, options = {}) ⇒ Object
-
#options_callback(options) ⇒ Object
-
#save ⇒ Object
-
#set_x_callback(data, name, options) ⇒ Object
-
#set_y_callback(data, name, options) ⇒ Object
-
#setHash(hash = {}, name = nil, options = {}) ⇒ Object
-
#setOptions(name = nil, options = {}) ⇒ Object
-
#setPoints(points = [], name = nil, options = {}) ⇒ Object
-
#setXData(data, name, options = {}) ⇒ Object
-
#setXY(x = [], y = [], name = nil, options = {}) ⇒ Object
-
#setYData(data, name, options = {}) ⇒ Object
-
#translate_name(name) ⇒ Object
Constructor Details
Returns a new instance of SimpleOutputPlugin.
25
26
27
28
29
30
31
32
33
|
# File 'lib/simpleoutput.rb', line 25
def initialize()
@x = {}
@y = {}
@series_names = {}
@data_id = 0
@annotations = {}
@current_name = ""
@series_id = 0
end
|
Instance Method Details
#advance_series(name = nil) ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/simpleoutput.rb', line 64
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
179
180
181
182
183
|
# File 'lib/simpleoutput.rb', line 179
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
44
45
|
# File 'lib/simpleoutput.rb', line 44
def append_callback(x,y,name,options)
end
|
#append_series_name(name = nil, options = {}) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/simpleoutput.rb', line 75
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
|
#appendHash(hash = {}, name = nil, options = {}) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/simpleoutput.rb', line 142
def appendHash(hash = {}, name=nil, options={})
name = translate_name(name)
x = []
y = []
hash.each_with_index do |(key, value), index|
if key.is_a? Numeric
x << key
else
x << index
end
if value.is_a? Numeric
y << value
else
y << 0
end
end
self.appendXY(x,y,name,options)
end
|
#appendPoints(points = [], name = nil, options = {}) ⇒ Object
122
123
124
125
126
127
128
129
130
|
# File 'lib/simpleoutput.rb', line 122
def appendPoints(points =[], name=nil, options={})
x = []
y = []
points.each do |point|
x << point[0]
y << point[1]
end
self.appendXY(x,y,name,options)
end
|
#appendXY(x = [], y = [], name = nil, options = {}) ⇒ Object
Interface Functions ===================================
109
110
111
112
113
114
115
116
|
# File 'lib/simpleoutput.rb', line 109
def appendXY( x=[], y=[],name=nil, options={})
name = translate_name(name)
@x[name] << x
@y[name] << y
self.append_series_name(name, options)
self.options_callback(options)
self.append_callback(x,y,name,options)
end
|
#getDataAsPoints ⇒ Object
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/simpleoutput.rb', line 190
def getDataAsPoints
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|
series_data[key] << [] 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
|
#getDataAsXY ⇒ Object
210
211
212
213
214
215
216
217
218
219
220
221
|
# File 'lib/simpleoutput.rb', line 210
def getDataAsXY
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
|
#getSeriesHashes ⇒ Object
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/simpleoutput.rb', line 223
def getSeriesHashes
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_callback(name) ⇒ Object
47
48
|
# File 'lib/simpleoutput.rb', line 47
def new_data_callback(name)
end
|
#newData(x = [], y = [], name = nil, options = {}) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/simpleoutput.rb', line 100
def newData( x=[], y=[],name=nil, options={})
name = self.advance_series(name)
self.setXData(x, name, options)
self.setYData(y, name, options)
self.append_series_name(name,options)
self.options_callback(options)
end
|
#options_callback(options) ⇒ Object
35
36
|
# File 'lib/simpleoutput.rb', line 35
def options_callback(options)
end
|
#save ⇒ Object
245
246
247
|
# File 'lib/simpleoutput.rb', line 245
def save()
end
|
#set_x_callback(data, name, options) ⇒ Object
38
39
|
# File 'lib/simpleoutput.rb', line 38
def set_x_callback(data, name, options)
end
|
#set_y_callback(data, name, options) ⇒ Object
41
42
|
# File 'lib/simpleoutput.rb', line 41
def set_y_callback(data, name, options)
end
|
#setHash(hash = {}, name = nil, options = {}) ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/simpleoutput.rb', line 161
def setHash(hash ={}, name=nil, options={})
x = []
y = []
hash.each_with_index do |(key, value), index|
if key.is_a? Numeric
x << key
else
x << index
end
if value.is_a? Numeric
y << value
else
y << 0
end
end
self.setXY(x,y,name,options)
end
|
#setOptions(name = nil, options = {}) ⇒ Object
185
186
187
|
# File 'lib/simpleoutput.rb', line 185
def setOptions(name=nil, options = {})
self.options_callback(options)
end
|
#setPoints(points = [], name = nil, options = {}) ⇒ Object
132
133
134
135
136
137
138
139
140
|
# File 'lib/simpleoutput.rb', line 132
def setPoints(points = [], name=nil, options={})
x = []
y = []
points.each do |point|
x << point[0]
y << point[1]
end
self.setXY(x,y,name, options)
end
|
#setXData(data, name, options = {}) ⇒ Object
88
89
90
91
92
|
# File 'lib/simpleoutput.rb', line 88
def setXData(data, name, options={})
@x[name] = []
@x[name] << data
self.set_x_callback(data, name, options)
end
|
#setXY(x = [], y = [], name = nil, options = {}) ⇒ Object
118
119
120
|
# File 'lib/simpleoutput.rb', line 118
def setXY(x=[], y=[], name=nil, options={})
self.newData(x,y,name,options)
end
|
#setYData(data, name, options = {}) ⇒ Object
94
95
96
97
98
|
# File 'lib/simpleoutput.rb', line 94
def setYData(data, name, options={})
@y[name] = []
@y[name] << data
self.set_y_callback(data, name, options)
end
|
#translate_name(name) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/simpleoutput.rb', line 51
def translate_name(name)
if name == nil
name = @current_name
end
if !@x.has_key?(name)
@x[name] = []
end
if !@y.has_key?(name)
@y[name] = []
end
return name
end
|