Class: Gruff::Net
Overview
See also the Spider graph.
Here’s how to make a Gruff::Net.
g = Gruff::Net.new
g.title = "Net Graph"
g.labels = {
0 => '5/6',
1 => '5/15',
2 => '5/24',
3 => '5/30',
4 => '6/4',
5 => '6/12',
6 => '6/21',
7 => '6/28'
}
g.line_width = 3
g.dot_radius = 4
g.data :Jimmy, [25, 36, 86, 39, 25, 31, 79, 88]
g.data :Julie, [22, 29, 35, 38, 36, 40, 46, 57]
g.write("net.png")
Constant Summary
Constants inherited from Base
Base::DEFAULT_MARGIN, Base::DEFAULT_TARGET_WIDTH, Base::LABEL_MARGIN, Base::LEGEND_MARGIN
Instance Attribute Summary collapse
-
#dot_radius ⇒ Object
writeonly
Sets the attribute dot_radius.
-
#hide_dots ⇒ Object
writeonly
Hide parts of the graph to fit more data points, or for a different appearance.
-
#line_width ⇒ Object
writeonly
Dimensions of lines and dots; calculated based on dataset size if left unspecified.
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=, #initialize, #margins=, #replace_colors, #theme=, #theme_37signals, #theme_greyscale, #theme_keynote, #theme_odeo, #theme_pastel, #theme_rails_keynote, #to_blob, #to_image, #write
Constructor Details
This class inherits a constructor from Gruff::Base
Instance Attribute Details
#dot_radius=(value) ⇒ Object (writeonly)
Sets the attribute dot_radius
31 32 33 |
# File 'lib/gruff/net.rb', line 31 def dot_radius=(value) @dot_radius = value end |
#hide_dots=(value) ⇒ Object (writeonly)
Hide parts of the graph to fit more data points, or for a different appearance.
27 28 29 |
# File 'lib/gruff/net.rb', line 27 def hide_dots=(value) @hide_dots = value end |
#line_width=(value) ⇒ Object (writeonly)
Dimensions of lines and dots; calculated based on dataset size if left unspecified.
30 31 32 |
# File 'lib/gruff/net.rb', line 30 def line_width=(value) @line_width = value end |
Instance Method Details
#draw ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gruff/net.rb', line 44 def draw super return unless data_given? store.norm_data.each do |data_row| data_row.points.each_with_index do |data_point, index| next if data_point.nil? rad_pos = index * Math::PI * 2 / column_count point_distance = data_point * @radius start_x = @center_x + Math.sin(rad_pos) * point_distance start_y = @center_y - Math.cos(rad_pos) * point_distance next_index = index + 1 < data_row.points.length ? index + 1 : 0 next_rad_pos = next_index * Math::PI * 2 / column_count next_point_distance = data_row.points[next_index] * @radius end_x = @center_x + Math.sin(next_rad_pos) * next_point_distance end_y = @center_y - Math.cos(next_rad_pos) * next_point_distance Gruff::Renderer::Line.new(color: data_row.color, width: @stroke_width).render(start_x, start_y, end_x, end_y) unless @hide_dots circle_renderer = Gruff::Renderer::Circle.new(color: data_row.color, width: @stroke_width) circle_renderer.render(start_x, start_y, start_x - @circle_radius, start_y) end end end end |