Class: Gruff::Pie

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

Overview

Here’s how to make a Pie graph:

g = Gruff::Pie.new
g.title = "Visual Pie Graph Test"
g.data 'Fries', 20
g.data 'Hamburgers', 50
g.write("test/output/pie_keynote.png")

To control where the pie chart starts creating slices, use #zero_degree.

Direct Known Subclasses

Mini::Pie

Defined Under Namespace

Classes: PieSlice

Constant Summary collapse

DEFAULT_TEXT_OFFSET_PERCENTAGE =
0.15

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_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, #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_left, #graph_top, #scale_measurements, #total_height

Constructor Details

This class inherits a constructor from Gruff::Base

Instance Attribute Details

#hide_labels_less_thanObject



43
44
45
# File 'lib/gruff/pie.rb', line 43

def hide_labels_less_than
  @hide_labels_less_than ||= 0.0
end

#show_values_as_labelsObject

Use values instead of percentages



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

def show_values_as_labels
  @show_values_as_labels
end

#text_offset_percentageObject



47
48
49
# File 'lib/gruff/pie.rb', line 47

def text_offset_percentage
  @text_offset_percentage ||= DEFAULT_TEXT_OFFSET_PERCENTAGE
end

#zero_degreeObject



39
40
41
# File 'lib/gruff/pie.rb', line 39

def zero_degree
  @zero_degree ||= 0.0
end

Instance Method Details

#drawObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/gruff/pie.rb', line 60

def draw
  hide_line_markers

  super

  return unless data_given?

  slices.each do |slice|
    if slice.value > 0
      set_stroke_color slice
      set_fill_color
      set_stroke_width
      set_drawing_points_for slice
      process_label_for slice
      update_chart_degrees_with slice.degrees
    end
  end

  trigger_final_draw
end

#initialize_ivarsObject



33
34
35
36
37
# File 'lib/gruff/pie.rb', line 33

def initialize_ivars
  super

  @show_values_as_labels = false
end

#optionsObject



51
52
53
54
55
56
57
58
# File 'lib/gruff/pie.rb', line 51

def options
  {
    :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