Class: GraphDataProcessor
- Inherits:
-
Object
- Object
- GraphDataProcessor
- Defined in:
- lib/technical_graph/graph_data_processor.rb
Overview
Calculate every aspect of graph, but not directly image oriented variables
Instance Attribute Summary collapse
-
#technical_graph ⇒ Object
readonly
Returns the value of attribute technical_graph.
-
#zoom_x ⇒ Object
readonly
Returns the value of attribute zoom_x.
-
#zoom_y ⇒ Object
readonly
Returns the value of attribute zoom_y.
Instance Method Summary collapse
-
#calc_x_zoomed(old_xes) ⇒ Object
Calculate zoomed X position for Array of X’es.
-
#calc_y_zoomed(old_yes) ⇒ Object
Calculate zoomed Y position for Array of Y’es.
- #enforce_x_axis_range ⇒ Object
- #enforce_y_axis_range ⇒ Object
-
#fixed? ⇒ Boolean
Ranges are fixed.
-
#initialize(technical_graph) ⇒ GraphDataProcessor
constructor
A new instance of GraphDataProcessor.
-
#layers ⇒ Object
Accessor for DataLayer Array.
- #logger ⇒ Object
-
#options ⇒ Object
Accessor for options Hash.
-
#process_data_layer(data_layer) ⇒ Object
Consider changing ranges if needed.
- #raw_x_max ⇒ Object
-
#raw_x_min ⇒ Object
Ranges without zoom.
- #raw_y_max ⇒ Object
- #raw_y_min ⇒ Object
- #x_max ⇒ Object
-
#x_min ⇒ Object
Ranges with zoom.
-
#x_zoom=(z = 1.0) ⇒ Object
Change X axis zoom.
- #y_max ⇒ Object
- #y_min ⇒ Object
-
#y_zoom=(z = 1.0) ⇒ Object
Change X axis zoom.
-
#zoom=(z = 1.0) ⇒ Object
Change overall image zoom.
Constructor Details
#initialize(technical_graph) ⇒ GraphDataProcessor
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/technical_graph/graph_data_processor.rb', line 24 def initialize(technical_graph) @technical_graph = technical_graph # axis label [:x_axis_label] ||= '' [:y_axis_label] ||= '' [:x_min] ||= 0.0 #(Time.now - 24 * 3600).to_f [:x_max] ||= 1.0 #Time.now.to_f [:y_min] ||= 0.0 [:y_max] ||= 1.0 # :default - coords are default # :fixed or whatever else - min/max coords are fixed [:xy_behaviour] ||= :default # number of axis [:y_axis_count] ||= 10 [:x_axis_count] ||= 10 # interval [:y_axis_interval] ||= 1.0 [:x_axis_interval] ||= 1.0 # when false then axis are generated to meet 'count' # when true then axis are generated every X from lowest [:x_axis_fixed_interval] = true if [:x_axis_fixed_interval].nil? [:y_axis_fixed_interval] = true if [:y_axis_fixed_interval].nil? # when set enlarge image so axis are located in sensible distance between themselves [:axis_density_enlarge_image] = false if [:axis_density_enlarge_image].nil? # distance in pixels [:x_axis_min_distance] ||= 30 # distance in pixels [:y_axis_min_distance] ||= 50 # default truncate string used for rendering numbers [:truncate_string] ||= "%.2f" @zoom_x = 1.0 @zoom_y = 1.0 end |
Instance Attribute Details
#technical_graph ⇒ Object (readonly)
Returns the value of attribute technical_graph.
8 9 10 |
# File 'lib/technical_graph/graph_data_processor.rb', line 8 def technical_graph @technical_graph end |
#zoom_x ⇒ Object (readonly)
Returns the value of attribute zoom_x.
170 171 172 |
# File 'lib/technical_graph/graph_data_processor.rb', line 170 def zoom_x @zoom_x end |
#zoom_y ⇒ Object (readonly)
Returns the value of attribute zoom_y.
170 171 172 |
# File 'lib/technical_graph/graph_data_processor.rb', line 170 def zoom_y @zoom_y end |
Instance Method Details
#calc_x_zoomed(old_xes) ⇒ Object
Calculate zoomed X position for Array of X’es
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/technical_graph/graph_data_processor.rb', line 173 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) ⇒ Object
Calculate zoomed Y position for Array of Y’es
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/technical_graph/graph_data_processor.rb', line 195 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 ⇒ Object
90 91 92 93 94 95 |
# File 'lib/technical_graph/graph_data_processor.rb', line 90 def enforce_x_axis_range if [:x_min] == [:x_max] [:x_min] -= 0.01 [:x_max] += 0.01 end end |
#enforce_y_axis_range ⇒ Object
97 98 99 100 101 102 |
# File 'lib/technical_graph/graph_data_processor.rb', line 97 def enforce_y_axis_range if [:y_min] == [:y_max] [:y_min] -= 0.01 [:y_max] += 0.01 end end |
#fixed? ⇒ Boolean
Ranges are fixed
65 66 67 |
# File 'lib/technical_graph/graph_data_processor.rb', line 65 def fixed? [:xy_behaviour] == :fixed end |
#layers ⇒ Object
Accessor for DataLayer Array
16 17 18 |
# File 'lib/technical_graph/graph_data_processor.rb', line 16 def layers @technical_graph.layers end |
#logger ⇒ Object
20 21 22 |
# File 'lib/technical_graph/graph_data_processor.rb', line 20 def logger @technical_graph.logger end |
#options ⇒ Object
Accessor for options Hash
11 12 13 |
# File 'lib/technical_graph/graph_data_processor.rb', line 11 def @technical_graph. end |
#process_data_layer(data_layer) ⇒ Object
Consider changing ranges if needed
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/technical_graph/graph_data_processor.rb', line 142 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 ⇒ Object
75 76 77 78 |
# File 'lib/technical_graph/graph_data_processor.rb', line 75 def raw_x_max enforce_x_axis_range [:x_max] end |
#raw_x_min ⇒ Object
Ranges without zoom
70 71 72 73 |
# File 'lib/technical_graph/graph_data_processor.rb', line 70 def raw_x_min enforce_x_axis_range [:x_min] end |
#raw_y_max ⇒ Object
85 86 87 88 |
# File 'lib/technical_graph/graph_data_processor.rb', line 85 def raw_y_max enforce_y_axis_range [:y_max] end |
#raw_y_min ⇒ Object
80 81 82 83 |
# File 'lib/technical_graph/graph_data_processor.rb', line 80 def raw_y_min enforce_y_axis_range [:y_min] end |
#x_max ⇒ Object
109 110 111 |
# File 'lib/technical_graph/graph_data_processor.rb', line 109 def x_max calc_x_zoomed([self.raw_x_max]).first end |
#x_min ⇒ Object
Ranges with zoom
105 106 107 |
# File 'lib/technical_graph/graph_data_processor.rb', line 105 def x_min calc_x_zoomed([self.raw_x_min]).first end |
#x_zoom=(z = 1.0) ⇒ Object
Change X axis zoom
161 162 163 |
# File 'lib/technical_graph/graph_data_processor.rb', line 161 def x_zoom=(z = 1.0) @zoom_x = z end |
#y_max ⇒ Object
117 118 119 |
# File 'lib/technical_graph/graph_data_processor.rb', line 117 def y_max calc_y_zoomed([self.raw_y_max]).first end |
#y_min ⇒ Object
113 114 115 |
# File 'lib/technical_graph/graph_data_processor.rb', line 113 def y_min calc_y_zoomed([self.raw_y_min]).first end |
#y_zoom=(z = 1.0) ⇒ Object
Change X axis zoom
166 167 168 |
# File 'lib/technical_graph/graph_data_processor.rb', line 166 def y_zoom=(z = 1.0) @zoom_y = z end |
#zoom=(z = 1.0) ⇒ Object
Change overall image zoom
155 156 157 158 |
# File 'lib/technical_graph/graph_data_processor.rb', line 155 def zoom=(z = 1.0) self.x_zoom = z self.y_zoom = z end |