Class: Gruff::Spider

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

Overview

Experimental!!! See also the Net graph.

Here’s how to set up a Gruff::Spider.

g = Gruff::Spider.new(30)
g.title = "Spider Graph"
g.data :Strength, [10]
g.data :Dexterity, [16]
g.data :Constitution, [12]
g.data :Intelligence, [12]
g.data :Wisdom, [10]
g.data 'Charisma', [16]
g.write("spider.png")

Constant Summary

Constants inherited from Base

Base::DEFAULT_MARGIN, Base::DEFAULT_TARGET_WIDTH, Base::LABEL_MARGIN, Base::LEGEND_MARGIN

Instance Attribute Summary collapse

Attributes inherited from Base

#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_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, #sort, #sorted_drawing, #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, #margins=, #replace_colors, #theme=, #theme_37signals, #theme_greyscale, #theme_keynote, #theme_odeo, #theme_pastel, #theme_rails_keynote, #to_blob, #write

Constructor Details

#initialize(max_value, target_width = 800) ⇒ Spider

Returns a new instance of Spider.



34
35
36
37
38
39
# File 'lib/gruff/spider.rb', line 34

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.



22
23
24
# File 'lib/gruff/spider.rb', line 22

def hide_axes
  @hide_axes
end

#hide_textObject

Hide all text.



21
22
23
# File 'lib/gruff/spider.rb', line 21

def hide_text
  @hide_text
end

#rotationObject

Returns the value of attribute rotation.



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

def rotation
  @rotation
end

#transparent_backgroundObject

Returns the value of attribute transparent_background.



23
24
25
# File 'lib/gruff/spider.rb', line 23

def transparent_background
  @transparent_background
end

Instance Method Details

#drawObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gruff/spider.rb', line 41

def draw
  @hide_line_markers = true

  super

  return unless data_given?

  # 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) / store.length

  # Draw axes
  draw_axes(center_x, center_y, radius, additive_angle) unless hide_axes

  # Draw polygon
  draw_polygon(center_x, center_y, additive_angle)

  Gruff::Renderer.finish
end