class SimpleOutput::SimpleOutputPlugin
Public Class Methods
new()
click to toggle source
# File lib/simpleoutput.rb, line 21 def initialize() @x = {} @y = {} @series_names = {} @data_id = 0 @annotations = {} @current_name = "NameError" @series_id = 0 @metadata = {} end
Public Instance Methods
advance_series(name=nil)
click to toggle source
# 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 = {})
click to toggle source
# 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)
click to toggle source
# File lib/simpleoutput.rb, line 41 def append_callback(x,y,name,options) end
append_hash(hash = {}, name=nil, options={})
click to toggle source
# 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={})
click to toggle source
# 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={})
click to toggle source
# 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={})
click to toggle source
Interface Functions ===================================
# 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_points()
click to toggle source
Internal Helpers
# 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_xy()
click to toggle source
# 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_hashes()
click to toggle source
# 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={})
click to toggle source
# 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)
click to toggle source
# File lib/simpleoutput.rb, line 44 def new_data_callback(name) end
new_data_check(name=nil)
click to toggle source
# File lib/simpleoutput.rb, line 79 def new_data_check(name=nil) (!@x.has_key?(name)) || (!@y.has_key?(name)) end
options_callback(options)
click to toggle source
Virtual Functions
# File lib/simpleoutput.rb, line 32 def options_callback(options) end
save()
click to toggle source
Output
# File lib/simpleoutput.rb, line 218 def save() end
set_hash(hash ={}, name=nil, options={})
click to toggle source
# 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 = {})
click to toggle source
# File lib/simpleoutput.rb, line 158 def set_options(name=nil, options = {}) self.options_callback(options) end
set_points(points = [], name=nil, options={})
click to toggle source
# 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)
click to toggle source
# File lib/simpleoutput.rb, line 35 def set_x_callback(data, name, options) end
set_x_data(data, name, options={})
click to toggle source
# 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={})
click to toggle source
# 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)
click to toggle source
# File lib/simpleoutput.rb, line 38 def set_y_callback(data, name, options) end
set_y_data(data, name, options={})
click to toggle source
# 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)
click to toggle source
CORE functions
# File lib/simpleoutput.rb, line 48 def translate_name(name) if name == nil name = @current_name end return name end
Protected Instance Methods
hash_to_xy(hash)
click to toggle source
# File lib/simpleoutput.rb, line 223 def hash_to_xy(hash) 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 return x, y end