lib/gruff/pie.rb in gruff-0.2.6 vs lib/gruff/pie.rb in gruff-0.2.7

- old
+ new

@@ -3,10 +3,19 @@ class Gruff::Pie < Gruff::Base TEXT_OFFSET_PERCENTAGE = 0.15 + # Can be used to make the pie start cutting slices at the top (-90.0) + # or at another angle. Default is 0.0, which starts at 3 o'clock. + attr_accessor :zero_degree + + def initialize_ivars + super + @zero_degree = 0.0 + end + def draw @hide_line_markers = true super @@ -16,11 +25,11 @@ radius = ([@graph_width, @graph_height].min / 2.0) * 0.8 top_x = @graph_left + (@graph_width - diameter) / 2.0 center_x = @graph_left + (@graph_width / 2.0) center_y = @graph_top + (@graph_height / 2.0) - 10 # Move graph up a bit total_sum = sums_for_pie() - prev_degrees = 0.0 + prev_degrees = @zero_degree # Use full data since we can easily calculate percentages @data.sort{ |a, b| a[DATA_VALUES_INDEX][0] <=> b[DATA_VALUES_INDEX][0] }.each do |data_row| if data_row[DATA_VALUES_INDEX][0] > 0 @d = @d.stroke data_row[DATA_COLOR_INDEX] @@ -59,14 +68,14 @@ ## # Labels are drawn around a slightly wider ellipse to give room for # labels on the left and right. def draw_label(center_x, center_y, angle, radius, amount) # TODO Don't use so many hard-coded numbers - r_offset = 5.0 # The distance out from the center of the pie to get point + r_offset = 20.0 # The distance out from the center of the pie to get point x_offset = center_x # + 15.0 # The label points need to be tweaked slightly y_offset = center_y # This one doesn't though radius_offset = (radius + r_offset) - ellipse_factor = radius_offset * 0.10 + ellipse_factor = radius_offset * 0.15 x = x_offset + ((radius_offset + ellipse_factor) * Math.cos(angle.deg2rad)) y = y_offset + (radius_offset * Math.sin(angle.deg2rad)) # Draw label @d.fill = @font_color