Class: Gruff::Pie
Overview
Here’s how to make a Gruff::Pie.
g = Gruff::Pie.new
g.title = "Visual Pie Graph Test"
g.data 'Fries', 20
g.data 'Hamburgers', 50
g.write("pie_keynote.png")
To control where the pie chart starts creating slices, use #zero_degree=.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_TEXT_OFFSET_PERCENTAGE =
0.15
Constants inherited from Base
Base::DEFAULT_MARGIN, Base::DEFAULT_TARGET_WIDTH, Base::LABEL_MARGIN, Base::LEGEND_MARGIN
Instance Attribute Summary collapse
- #hide_labels_less_than ⇒ Object
-
#show_values_as_labels ⇒ Object
Use values instead of percentages.
- #text_offset_percentage ⇒ Object
- #zero_degree ⇒ Object
Attributes inherited from Base
#bold_title, #bottom_margin, #center_labels_over_point, #colors, #font, #font_color, #has_left_labels, #hide_legend, #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, #initialize, #margins=, #replace_colors, #theme=, #theme_37signals, #theme_greyscale, #theme_keynote, #theme_odeo, #theme_pastel, #theme_rails_keynote, #to_blob, #write
Constructor Details
This class inherits a constructor from Gruff::Base
Instance Attribute Details
#hide_labels_less_than ⇒ Object
47 48 49 |
# File 'lib/gruff/pie.rb', line 47 def hide_labels_less_than @hide_labels_less_than ||= 0.0 end |
#show_values_as_labels ⇒ Object
Use values instead of percentages.
32 33 34 |
# File 'lib/gruff/pie.rb', line 32 def show_values_as_labels @show_values_as_labels end |
#text_offset_percentage ⇒ Object
51 52 53 |
# File 'lib/gruff/pie.rb', line 51 def text_offset_percentage @text_offset_percentage ||= DEFAULT_TEXT_OFFSET_PERCENTAGE end |
#zero_degree ⇒ Object
43 44 45 |
# File 'lib/gruff/pie.rb', line 43 def zero_degree @zero_degree ||= 0.0 end |
Instance Method Details
#draw ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gruff/pie.rb', line 64 def draw hide_line_markers super return unless data_given? slices.each do |slice| if slice.value > 0 Gruff::Renderer::Ellipse.new(color: slice.color, width: radius) .render(center_x, center_y, radius / 2.0, radius / 2.0, chart_degrees, chart_degrees + slice.degrees + 0.5) process_label_for slice update_chart_degrees_with slice.degrees end end Gruff::Renderer.finish end |
#options ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/gruff/pie.rb', line 55 def { zero_degree: zero_degree, hide_labels_less_than: hide_labels_less_than, text_offset_percentage: text_offset_percentage, show_values_as_labels: show_values_as_labels } end |