class GraphDataProcessor
Calculate every aspect of graph, but not directly image oriented variables
Attributes
technical_graph[R]
zoom_x[R]
zoom_y[R]
Public Class Methods
new(technical_graph)
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 24 def initialize(technical_graph) @technical_graph = technical_graph # axis label options[:x_axis_label] ||= '' options[:y_axis_label] ||= '' options[:x_min] ||= 0.0 #(Time.now - 24 * 3600).to_f options[:x_max] ||= 1.0 #Time.now.to_f options[:y_min] ||= 0.0 options[:y_max] ||= 1.0 # :default - coords are default # :fixed or whatever else - min/max coords are fixed options[:xy_behaviour] ||= :default # number of axis options[:y_axis_count] ||= 10 options[:x_axis_count] ||= 10 # interval options[:y_axis_interval] ||= 1.0 options[:x_axis_interval] ||= 1.0 # when false then axis are generated to meet 'count' # when true then axis are generated every X from lowest options[:x_axis_fixed_interval] = true if options[:x_axis_fixed_interval].nil? options[:y_axis_fixed_interval] = true if options[:y_axis_fixed_interval].nil? # when set enlarge image so axis are located in sensible distance between themselves options[:axis_density_enlarge_image] = false if options[:axis_density_enlarge_image].nil? options[:x_axis_density_enlarge_image] = false if options[:x_axis_density_enlarge_image].nil? options[:y_axis_density_enlarge_image] = false if options[:y_axis_density_enlarge_image].nil? # distance in pixels options[:x_axis_min_distance] ||= 30 # distance in pixels options[:y_axis_min_distance] ||= 30 # default truncate string used for rendering numbers options[:truncate_string] ||= "%.2f" @zoom_x = 1.0 @zoom_y = 1.0 end
Public Instance Methods
calc_x_zoomed(old_xes)
click to toggle source
Calculate zoomed X position for Array
of X'es
# File lib/technical_graph/graph_data_processor.rb, line 175 def calc_x_zoomed(old_xes) t = Time.now # default zoom if self.zoom_x == 1.0 return old_xes end a = (raw_x_max.to_f + raw_x_min.to_f) / 2.0 new_xes = Array.new old_xes.each do |x| d = x - a new_xes << (a + d * self.zoom_x) end logger.debug "calc_x_zoomed for #{old_xes.size}" logger.debug " TIME COST #{Time.now - t}" return new_xes end
calc_y_zoomed(old_yes)
click to toggle source
Calculate zoomed Y position for Array
of Y'es
# File lib/technical_graph/graph_data_processor.rb, line 197 def calc_y_zoomed(old_yes) t = Time.now # default zoom if self.zoom_y == 1.0 return old_yes end a = (raw_y_max.to_f + raw_y_min.to_f) / 2.0 new_yes = Array.new old_yes.each do |y| d = y - a new_yes << (a + d * self.zoom_y) end logger.debug "calc_y_zoomed for #{old_yes.size}" logger.debug " TIME COST #{Time.now - t}" return new_yes end
enforce_x_axis_range()
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 92 def enforce_x_axis_range if options[:x_min] == options[:x_max] options[:x_min] -= 0.01 options[:x_max] += 0.01 end end
enforce_y_axis_range()
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 99 def enforce_y_axis_range if options[:y_min] == options[:y_max] options[:y_min] -= 0.01 options[:y_max] += 0.01 end end
fixed?()
click to toggle source
Ranges are fixed
# File lib/technical_graph/graph_data_processor.rb, line 67 def fixed? options[:xy_behaviour] == :fixed end
layers()
click to toggle source
logger()
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 20 def logger @technical_graph.logger end
options()
click to toggle source
Accessor for options Hash
# File lib/technical_graph/graph_data_processor.rb, line 11 def options @technical_graph.options end
process_data_layer(data_layer)
click to toggle source
Consider changing ranges if needed
# File lib/technical_graph/graph_data_processor.rb, line 144 def process_data_layer(data_layer) # ranges are set, can't change return if fixed? # updating ranges, enlarging self.raw_y_max = data_layer.y_max if not data_layer.y_max.nil? and data_layer.y_max > self.raw_y_max self.raw_x_max = data_layer.x_max if not data_layer.x_max.nil? and data_layer.x_max > self.raw_x_max self.raw_y_min = data_layer.y_min if not data_layer.y_min.nil? and data_layer.y_min < self.raw_y_min self.raw_x_min = data_layer.x_min if not data_layer.x_min.nil? and data_layer.x_min < self.raw_x_min end
raw_x_max()
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 77 def raw_x_max enforce_x_axis_range options[:x_max] end
raw_x_min()
click to toggle source
Ranges without zoom
# File lib/technical_graph/graph_data_processor.rb, line 72 def raw_x_min enforce_x_axis_range options[:x_min] end
raw_y_max()
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 87 def raw_y_max enforce_y_axis_range options[:y_max] end
raw_y_min()
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 82 def raw_y_min enforce_y_axis_range options[:y_min] end
x_max()
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 111 def x_max calc_x_zoomed([self.raw_x_max]).first end
x_min()
click to toggle source
Ranges with zoom
# File lib/technical_graph/graph_data_processor.rb, line 107 def x_min calc_x_zoomed([self.raw_x_min]).first end
x_zoom=(z = 1.0)
click to toggle source
Change X axis zoom
# File lib/technical_graph/graph_data_processor.rb, line 163 def x_zoom=(z = 1.0) @zoom_x = z end
y_max()
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 119 def y_max calc_y_zoomed([self.raw_y_max]).first end
y_min()
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 115 def y_min calc_y_zoomed([self.raw_y_min]).first end
y_zoom=(z = 1.0)
click to toggle source
Change X axis zoom
# File lib/technical_graph/graph_data_processor.rb, line 168 def y_zoom=(z = 1.0) @zoom_y = z end
zoom=(z = 1.0)
click to toggle source
Change overall image zoom
# File lib/technical_graph/graph_data_processor.rb, line 157 def zoom=(z = 1.0) self.x_zoom = z self.y_zoom = z end
Private Instance Methods
raw_x_max=(x)
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 129 def raw_x_max=(x) options[:x_max] = x end
raw_x_min=(x)
click to toggle source
Accessors
# File lib/technical_graph/graph_data_processor.rb, line 125 def raw_x_min=(x) options[:x_min] = x end
raw_y_max=(y)
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 137 def raw_y_max=(y) options[:y_max] = y end
raw_y_min=(y)
click to toggle source
# File lib/technical_graph/graph_data_processor.rb, line 133 def raw_y_min=(y) options[:y_min] = y end