class DataLayer
Stores only data used for one layer Instances of this class are used elsewhere Stores also drawing parameters for one layer
Attributes
data_params[R]
Additional parameters
processor[R]
can be used to approximation and other data processing
Public Class Methods
new(d = [], options = { }, technical_graph = nil)
click to toggle source
# File lib/technical_graph/data_layer.rb, line 26 def initialize(d = [], options = { }, technical_graph = nil) # used for accessing logger @technical_graph = technical_graph @data_params = options @data_params[:color] ||= GraphColorLibrary.instance.get_color @data_params[:label] ||= ' ' # default true, write values near dots @data_params[:value_labels] = false if options[:value_labels] == false # smoothing parameters # by default it is false @data_params[:simple_smoother] = true if options[:simple_smoother] == true @data_params[:simple_smoother_x] = true if options[:simple_smoother_x] == true @data_params[:simple_smoother_level] ||= 3 @data_params[:simple_smoother_strategy] ||= DataLayerProcessor::DEFAULT_SIMPLE_SMOOTHER_STRATEGY # was already done @data_params[:processor_finished] = false @processor = DataLayerProcessor.new(self) # set data and append initial data clear_data append_data(d) end
Public Instance Methods
append_data(data_array)
click to toggle source
Accessor for setting chart data for layer to draw
# File lib/technical_graph/data_layer.rb, line 57 def append_data(data_array) if data_array.kind_of? Array # append as DataPoint # convert to DataPoints, which has more specialized methods t = Time.now data_array.each do |d| @data << DataPoint.new(d) end logger.debug "appending data, size #{data_array.size}" logger.debug " TIME COST #{Time.now - t}" # sort, clean bad records process_data_internal # @raw_data is dirty, deleting @processed_data @processed_data = nil else raise 'Data not an Array' end end
clear_data()
click to toggle source
Clear data
# File lib/technical_graph/data_layer.rb, line 143 def clear_data @data = Array.new end
color()
click to toggle source
Color of
# File lib/technical_graph/data_layer.rb, line 106 def color return @data_params[:color] end
label()
click to toggle source
# File lib/technical_graph/data_layer.rb, line 110 def label return @data_params[:label] end
logger()
click to toggle source
Use global logger for technical_graph or create new
# File lib/technical_graph/data_layer.rb, line 14 def logger return @logger if not @logger.nil? if not @technical_graph.nil? @logger = @technical_graph.logger else @logger = Logger.new(STDOUT) end @logger end
perform_parameter_uniq()
click to toggle source
# File lib/technical_graph/data_layer.rb, line 138 def perform_parameter_uniq return @data_params[:perform_parameter_uniq] == true end
process!()
click to toggle source
Run external processor (smoothing, …)
# File lib/technical_graph/data_layer.rb, line 94 def process! t = Time.now @processed_data = @data.clone @processed_data = @processor.process logger.debug "processed data using external processor" logger.debug " TIME COST #{Time.now - t}" end
process_data_internal()
click to toggle source
Clean and process data used for drawing current data layer
# File lib/technical_graph/data_layer.rb, line 148 def process_data_internal t = Time.now # delete duplicates if perform_parameter_uniq @data = @data.inject([]) { |result, d| result << d unless result.select { |r| r.x == d.x }.size > 0; result } end logger.debug "internal processor - deleting duplicates" logger.debug " TIME COST #{Time.now - t}" t = Time.now @data.delete_if { |d| d.x.nil? or d.y.nil? } @data.sort! { |d, e| d.x <=> e.x } logger.debug "internal processor - deleting nils and sorting" logger.debug " TIME COST #{Time.now - t}" t = Time.now # default X values, if data is not empty if @data.size > 0 @data_params[:x_min] = @data.first.x || @options[:default_x_min] @data_params[:x_max] = @data.last.x || @options[:default_x_max] # default Y values y_sort = @data.sort { |a, b| a.y <=> b.y } @data_params[:y_min] = y_sort.first.y || @options[:default_y_min] @data_params[:y_max] = y_sort.last.y || @options[:@default_y_max] end logger.debug "internal processor - setting min and max" logger.debug " TIME COST #{Time.now - t}" end
processed_data()
click to toggle source
Array
of DataPoints, after external processing
# File lib/technical_graph/data_layer.rb, line 85 def processed_data if @processed_data.nil? process! end @processed_data end
raw_data()
click to toggle source
Array
of DataPoints, not processed
# File lib/technical_graph/data_layer.rb, line 80 def raw_data @data end
simple_smoother()
click to toggle source
Turn on smoothing processor
# File lib/technical_graph/data_layer.rb, line 120 def simple_smoother return @data_params[:simple_smoother] end
simple_smoother_level()
click to toggle source
Smoother level
# File lib/technical_graph/data_layer.rb, line 125 def simple_smoother_level return @data_params[:simple_smoother_level] end
simple_smoother_strategy()
click to toggle source
Smoother strategy
# File lib/technical_graph/data_layer.rb, line 130 def simple_smoother_strategy return @data_params[:simple_smoother_strategy] end
simple_smoother_x()
click to toggle source
# File lib/technical_graph/data_layer.rb, line 134 def simple_smoother_x return @data_params[:simple_smoother_x] end
value_labels()
click to toggle source
Write values near dots
# File lib/technical_graph/data_layer.rb, line 115 def value_labels return @data_params[:value_labels] end
x_max()
click to toggle source
# File lib/technical_graph/data_layer.rb, line 186 def x_max @data_params[:x_max] end
x_min()
click to toggle source
# File lib/technical_graph/data_layer.rb, line 182 def x_min @data_params[:x_min] end
y_max()
click to toggle source
# File lib/technical_graph/data_layer.rb, line 194 def y_max @data_params[:y_max] end
y_min()
click to toggle source
# File lib/technical_graph/data_layer.rb, line 190 def y_min @data_params[:y_min] end