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

Constructor Details

#initialize(max_value, target_width = 800) ⇒ Spider

Returns a new instance of Spider.



30
31
32
33
# File 'lib/gruff/spider.rb', line 30

def initialize(max_value, target_width = 800)
  super(target_width)
  @max_value = max_value
end

Instance Attribute Details

#hide_axes=(value) ⇒ Object (writeonly)

Hide all text.



19
20
21
# File 'lib/gruff/spider.rb', line 19

def hide_axes=(value)
  @hide_axes = value
end

#rotation=(value) ⇒ Object (writeonly)

Sets the attribute rotation

Parameters:

  • value

    the value to set the attribute rotation to.



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

def rotation=(value)
  @rotation = value
end

Instance Method Details

#drawObject



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

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)
end

#hide_text=(value) ⇒ Object



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

def hide_text=(value)
  @hide_title = @hide_text = value
end

#transparent_background=(value) ⇒ Object



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

def transparent_background=(value)
  Gruff::Renderer.setup_transparent_background(@columns, @rows) if value
end