Class: GraphAxis
- Inherits:
-
Object
- Object
- GraphAxis
- Defined in:
- lib/technical_graph/graph_axis.rb
Overview
Calculate axis (only) and draw them
Instance Attribute Summary collapse
-
#technical_graph ⇒ Object
readonly
Returns the value of attribute technical_graph.
Instance Method Summary collapse
- #antialias ⇒ Object
-
#axis_distance_image_enlarge ⇒ Object
Enlarge image to maintain proper axis density.
-
#calc_axis(from, to, interval, count, fixed_interval) ⇒ Object
Calculate axis using 2 methods.
-
#data_processor ⇒ Object
Calculate everything.
- #drawer ⇒ Object
- #image ⇒ Object
-
#initialize(technical_graph) ⇒ GraphAxis
constructor
A new instance of GraphAxis.
-
#layers ⇒ Object
Accessor for DataLayer Array.
- #logger ⇒ Object
-
#options ⇒ Object
Accessor for options Hash.
-
#parameter_axis ⇒ Object
Where to put axis values.
-
#render_axis ⇒ Object
Render normal axis.
- #render_axis_labels ⇒ Object
-
#render_on_image(image) ⇒ Object
Render axis on image.
-
#render_zero_axis ⇒ Object
Render axis for zeros.
- #truncate_string ⇒ Object
-
#value_axis ⇒ Object
Where to put axis values.
-
#x_axis_distance_image_enlarge ⇒ Object
Enlarge image to maintain proper axis density.
- #x_axis_fixed? ⇒ Boolean
- #x_axis_interval ⇒ Object
-
#y_axis_distance_image_enlarge ⇒ Object
Enlarge image to maintain proper axis density.
-
#y_axis_fixed? ⇒ Boolean
Value axis has fixed count.
- #y_axis_interval ⇒ Object
Constructor Details
#initialize(technical_graph) ⇒ GraphAxis
Returns a new instance of GraphAxis.
40 41 42 |
# File 'lib/technical_graph/graph_axis.rb', line 40 def initialize(technical_graph) @technical_graph = technical_graph end |
Instance Attribute Details
#technical_graph ⇒ Object (readonly)
Returns the value of attribute technical_graph.
7 8 9 |
# File 'lib/technical_graph/graph_axis.rb', line 7 def technical_graph @technical_graph end |
Instance Method Details
#antialias ⇒ Object
160 161 162 |
# File 'lib/technical_graph/graph_axis.rb', line 160 def antialias [:antialias] == true end |
#axis_distance_image_enlarge ⇒ Object
Enlarge image to maintain proper axis density
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/technical_graph/graph_axis.rb', line 100 def axis_distance_image_enlarge if [:axis_density_enlarge_image] t = Time.now x_axis_distance_image_enlarge y_axis_distance_image_enlarge logger.debug "axis enlarged" logger.debug " TIME COST #{Time.now - t}" end end |
#calc_axis(from, to, interval, count, fixed_interval) ⇒ Object
Calculate axis using 2 methods
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/technical_graph/graph_axis.rb', line 72 def calc_axis(from, to, interval, count, fixed_interval) t = Time.now axis = Array.new l = to - from current = from if fixed_interval while current < to axis << current current += interval end logger.debug "fixed interval axis calculation from #{from} to #{to} using int. #{interval}" logger.debug " TIME COST #{Time.now - t}" return axis else (0...count).each do |i| axis << from + (l.to_f * i.to_f) / count.to_f end logger.debug "fixed count axis calculation from #{from} to #{to} using count #{count}" logger.debug " TIME COST #{Time.now - t}" return axis end end |
#data_processor ⇒ Object
Calculate everything
20 21 22 |
# File 'lib/technical_graph/graph_axis.rb', line 20 def data_processor @technical_graph.data_processor end |
#drawer ⇒ Object
28 29 30 |
# File 'lib/technical_graph/graph_axis.rb', line 28 def drawer image.drawer end |
#image ⇒ Object
24 25 26 |
# File 'lib/technical_graph/graph_axis.rb', line 24 def image @technical_graph.image_drawer end |
#layers ⇒ Object
Accessor for DataLayer Array
15 16 17 |
# File 'lib/technical_graph/graph_axis.rb', line 15 def layers @technical_graph.layers end |
#logger ⇒ Object
32 33 34 |
# File 'lib/technical_graph/graph_axis.rb', line 32 def logger @technical_graph.logger end |
#options ⇒ Object
Accessor for options Hash
10 11 12 |
# File 'lib/technical_graph/graph_axis.rb', line 10 def @technical_graph. end |
#parameter_axis ⇒ Object
Where to put axis values
67 68 69 |
# File 'lib/technical_graph/graph_axis.rb', line 67 def parameter_axis return calc_axis(data_processor.x_min, data_processor.x_max, [:x_axis_interval], [:x_axis_count], x_axis_fixed?) end |
#render_axis ⇒ Object
Render normal axis
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/technical_graph/graph_axis.rb', line 165 def render_axis drawer.axis( # X parameter_axis.collect { |x| image.calc_bitmap_x(x).to_i }, # Y value_axis.collect { |y| image.calc_bitmap_y(y).to_i }, # options { :color => [:axis_color], :width => 1 }, # draw labels [:axis_value_and_param_labels], # X axis labels parameter_axis, # Y axis labels value_axis ) end |
#render_axis_labels ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/technical_graph/graph_axis.rb', line 201 def render_axis_labels drawer.axis_labels( [:x_axis_label].to_s, [:y_axis_label].to_s, { :color => [:axis_color], :width => 1, :size => [:axis_label_font_size], } ) end |
#render_on_image(image) ⇒ Object
Render axis on image
152 153 154 155 156 157 158 |
# File 'lib/technical_graph/graph_axis.rb', line 152 def render_on_image(image) @image = image render_axis render_zero_axis render_axis_labels end |
#render_zero_axis ⇒ Object
Render axis for zeros
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/technical_graph/graph_axis.rb', line 183 def render_zero_axis drawer.axis( # X - 0 image.calc_bitmap_x(0.0).to_i, # Y - 0 image.calc_bitmap_y(0.0).to_i, # options, slightly wider { :color => [:axis_color], :width => 2 }, # draw label [:axis_zero_labels], # X label, [0.0], # Y label [0.0] ) end |
#truncate_string ⇒ Object
36 37 38 |
# File 'lib/technical_graph/graph_axis.rb', line 36 def truncate_string [:truncate_string] end |
#value_axis ⇒ Object
Where to put axis values
62 63 64 |
# File 'lib/technical_graph/graph_axis.rb', line 62 def value_axis return calc_axis(data_processor.y_min, data_processor.y_max, [:y_axis_interval], [:y_axis_count], y_axis_fixed?) end |
#x_axis_distance_image_enlarge ⇒ Object
Enlarge image to maintain proper axis density
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/technical_graph/graph_axis.rb', line 112 def x_axis_distance_image_enlarge a = parameter_axis # must be at least 2 axis return if a.size < 2 ax = a[0] ax = image.calc_bitmap_y(ax).round bx = a[1] bx = image.calc_bitmap_y(bx).round axis_distance = (bx - ax).abs if axis_distance < [:x_axis_min_distance] # enlarging image [:old_width] = [:width] [:width] *= ([:x_axis_min_distance] / axis_distance).ceil end end |
#x_axis_fixed? ⇒ Boolean
44 45 46 |
# File 'lib/technical_graph/graph_axis.rb', line 44 def x_axis_fixed? [:x_axis_fixed_interval] == true end |
#x_axis_interval ⇒ Object
57 58 59 |
# File 'lib/technical_graph/graph_axis.rb', line 57 def x_axis_interval [:x_axis_interval] end |
#y_axis_distance_image_enlarge ⇒ Object
Enlarge image to maintain proper axis density
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/technical_graph/graph_axis.rb', line 132 def y_axis_distance_image_enlarge a = value_axis # must be at least 2 axis return if a.size < 2 ay = a[0] ay = image.calc_bitmap_y(ay).round by = a[1] by = image.calc_bitmap_y(by).round axis_distance = (by - ay).abs if axis_distance < [:y_axis_min_distance] # enlarging image [:old_height] = [:height] [:height] *= ([:y_axis_min_distance] / axis_distance).ceil end end |
#y_axis_fixed? ⇒ Boolean
Value axis has fixed count
49 50 51 |
# File 'lib/technical_graph/graph_axis.rb', line 49 def y_axis_fixed? [:y_axis_fixed_interval] == true end |
#y_axis_interval ⇒ Object
53 54 55 |
# File 'lib/technical_graph/graph_axis.rb', line 53 def y_axis_interval [:y_axis_interval] end |