lib/write_xlsx/chart/pie.rb in write_xlsx-0.77.2 vs lib/write_xlsx/chart/pie.rb in write_xlsx-0.78.0
- old
+ new
@@ -26,13 +26,27 @@
class Pie < self
include Writexlsx::Utility
def initialize(subtype)
super(subtype)
+ @vary_data_color = 1
+ @rotation = 0
end
#
+ # Set the Pie/Doughnut chart rotation: the angle of the first slice.
+ #
+ def set_rotation(rotation)
+ return unless rotation
+ if rotation >= 0 && rotation <= 360
+ @rotation = rotation
+ else
+ raise "Chart rotation $rotation outside range: 0 <= rotation <= 360"
+ end
+ end
+
+ #
# Override the virtual superclass method with a chart specific method.
#
def write_chart_type
# Write the c:areaChart element.
write_pie_chart
@@ -53,11 +67,11 @@
end
end
#
# Over-ridden method to remove the cat_axis() and val_axis() code since
- # Pie charts don't require those axes.
+ # Pie/Doughnut charts don't require those axes.
#
# Write the <c:plotArea> element.
#
def write_plot_area
@writer.tag_elements('c:plotArea') do
@@ -154,10 +168,10 @@
#
# Write the <c:firstSliceAng> element.
#
def write_first_slice_ang
- @writer.empty_tag('c:firstSliceAng', [ ['val', 0] ])
+ @writer.empty_tag('c:firstSliceAng', [ ['val', @rotation] ])
end
end
end
end