Class: Gruff::Spider

Inherits:
Base
  • Object
show all
Defined in:
lib/gruff/spider.rb

Overview

Experimental!!! See also the Net graph.

Submitted by Kevin Clark glu.ttono.us/

Constant Summary

Constants inherited from Base

Base::DATA_COLOR_INDEX, Base::DATA_LABEL_INDEX, Base::DATA_VALUES_INDEX, Base::DATA_VALUES_X_INDEX, Base::DEBUG, Base::DEFAULT_MARGIN, Base::DEFAULT_TARGET_WIDTH, Base::LABEL_MARGIN, Base::LEGEND_MARGIN, Base::THOUSAND_SEPARATOR

Instance Attribute Summary collapse

Attributes inherited from Base

#additional_line_values, #bold_title, #bottom_margin, #center_labels_over_point, #colors, #font, #font_color, #has_left_labels, #hide_legend, #hide_line_markers, #hide_line_numbers, #hide_title, #label_formatting, #label_max_size, #label_stagger_height, #label_truncation_style, #labels, #left_margin, #legend_at_bottom, #legend_box_size, #legend_font_size, #legend_margin, #marker_color, #marker_count, #marker_font_size, #marker_shadow_color, #maximum_value, #minimum_value, #no_data_message, #right_margin, #show_labels_for_bar_values, #sort, #sorted_drawing, #stacked, #title, #title_font, #title_font_size, #title_margin, #top_margin, #use_data_label, #x_axis_increment, #x_axis_label, #y_axis_increment, #y_axis_label

Instance Method Summary collapse

Methods inherited from Base

#add_color, #data, #initialize_ivars, #margins=, #replace_colors, #theme=, #theme_37signals, #theme_greyscale, #theme_keynote, #theme_odeo, #theme_pastel, #theme_rails_keynote, #to_blob, #write

Methods included from Deprecated

#graph_height, #graph_left, #graph_top, #graph_width, #scale_measurements, #total_height

Constructor Details

#initialize(max_value, target_width = 800) ⇒ Spider

Returns a new instance of Spider.



24
25
26
27
28
29
# File 'lib/gruff/spider.rb', line 24

def initialize(max_value, target_width = 800)
  super(target_width)
  @max_value = max_value
  @hide_legend = true
  @rotation = 0
end

Instance Attribute Details

#hide_axesObject

Returns the value of attribute hide_axes.



11
12
13
# File 'lib/gruff/spider.rb', line 11

def hide_axes
  @hide_axes
end

#hide_textObject

Hide all text



10
11
12
# File 'lib/gruff/spider.rb', line 10

def hide_text
  @hide_text
end

#rotationObject

Returns the value of attribute rotation.



13
14
15
# File 'lib/gruff/spider.rb', line 13

def rotation
  @rotation
end

#transparent_backgroundObject

Returns the value of attribute transparent_background.



12
13
14
# File 'lib/gruff/spider.rb', line 12

def transparent_background
  @transparent_background
end

Instance Method Details

#drawObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gruff/spider.rb', line 31

def draw
  @hide_line_markers = true
  
  super

  return unless @has_data

  # Setup basic positioning
  radius = @graph_height / 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
      
  additive_angle = (2 * Math::PI)/ @data.size
  
  # 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