class ImageParadise::Gruff::Spider
Attributes
hide_axes[RW]
hide_text[R]
Hide all text
rotation[RW]
transparent_background[R]
Public Class Methods
new(max_value, target_width = 800)
click to toggle source
Public Instance Methods
draw()
click to toggle source
#¶ ↑
draw¶ ↑
#¶ ↑
Calls superclass method
ImageParadise::Gruff::Base#draw
# File lib/image_paradise/graphs/spider.rb, line 43 def draw @hide_line_markers = true super return unless @has_data # Setup basic positioning # diameter = @graph_height # Variable not in use. radius = @graph_height / 2.0 # top_x = @graph_left + (@graph_width - diameter) / 2.0 center_x = @graph_left + (@graph_width / 2.0) center_y = @graph_top + (@graph_height / 2.0) - 25 # Move graph up a bit @unit_length = radius / @max_value # total_sum = sums_for_spider # Not in use. # prev_degrees = 0.0 # Not in use. additive_angle = (2 * Math::PI)/ @data.size # current_angle = rotation * Math::PI / 180.0 # Not in use. # Draw axes draw_axes(center_x, center_y, radius, additive_angle) unless hide_axes # Draw polygon draw_polygon(center_x, center_y, additive_angle) @d.draw(@base_image) end
hide_text=(value)
click to toggle source
Private Instance Methods
draw_axes(center_x, center_y, radius, additive_angle, line_color = nil)
click to toggle source
#¶ ↑
draw_axes
¶ ↑
#¶ ↑
# File lib/image_paradise/graphs/spider.rb, line 112 def draw_axes(center_x, center_y, radius, additive_angle, line_color = nil) return if hide_axes current_angle = rotation * Math::PI / 180.0 @data.each do |data_row| @d.stroke(line_color || data_row[DATA_COLOR_INDEX]) @d.stroke_width 5.0 x_offset = radius * Math.cos(current_angle) y_offset = radius * Math.sin(current_angle) @d.line(center_x, center_y, center_x + x_offset, center_y + y_offset) draw_label(center_x, center_y, current_angle, radius, data_row[DATA_LABEL_INDEX].to_s) unless hide_text current_angle += additive_angle end end
draw_label(center_x, center_y, angle, radius, amount)
click to toggle source
#¶ ↑
draw_label
¶ ↑
#¶ ↑
# File lib/image_paradise/graphs/spider.rb, line 89 def draw_label(center_x, center_y, angle, radius, amount) r_offset = 50 # The distance out from the center of the pie to get point x_offset = center_x # The label points need to be tweaked slightly y_offset = center_y + 0 # This one doesn't though x = x_offset + ((radius + r_offset) * Math.cos(angle)) y = y_offset + ((radius + r_offset) * Math.sin(angle)) # Draw label @d.fill = @marker_color @d.font = @font if @font @d.pointsize = scale_fontsize(legend_font_size) @d.stroke = 'transparent' @d.font_weight = BoldWeight @d.gravity = CenterGravity @d.annotate_scaled( @base_image, 0, 0, x, y, amount, @scale) end
draw_polygon(center_x, center_y, additive_angle, color = nil)
click to toggle source
#¶ ↑
draw_polygon
¶ ↑
#¶ ↑
# File lib/image_paradise/graphs/spider.rb, line 137 def draw_polygon(center_x, center_y, additive_angle, color = nil) points = [] current_angle = rotation * Math::PI / 180.0 @data.each { |data_row| points << center_x + normalize_points(data_row[DATA_VALUES_INDEX].first) * Math.cos(current_angle) points << center_y + normalize_points(data_row[DATA_VALUES_INDEX].first) * Math.sin(current_angle) current_angle += additive_angle } @d.stroke_width 1.0 @d.stroke(color || @marker_color) @d.fill(color || @marker_color) @d.fill_opacity 0.4 @d.polygon(*points) end
normalize_points(value)
click to toggle source