lib/write_xlsx/chart/pie.rb in write_xlsx-1.09.4 vs lib/write_xlsx/chart/pie.rb in write_xlsx-1.09.5
- old
+ new
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
+
###############################################################################
#
# Pie - A class for writing Excel Pie charts.
#
# Used in conjunction with Chart.
@@ -45,10 +46,11 @@
#
# 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
@@ -69,11 +71,11 @@
def write_pie_chart
@writer.tag_elements('c:pieChart') do
# Write the c:varyColors element.
write_vary_colors
# Write the series elements.
- @series.each {|s| write_series(s)}
+ @series.each { |s| write_series(s) }
# Write the c:firstSliceAng element.
write_first_slice_ang
end
end
@@ -92,15 +94,15 @@
# Write the subclass chart type element.
write_chart_type
# Configure a combined chart if present.
if second_chart
# Secondary axis has unique id otherwise use same as primary.
- if second_chart.is_secondary?
- second_chart.id = 1000 + @id
- else
- second_chart.id = @id
- end
+ second_chart.id = if second_chart.is_secondary?
+ 1000 + @id
+ else
+ @id
+ end
# Share the same filehandle for writing
second_chart.writer = @writer
# Share series index with primary chart.
@@ -119,11 +121,11 @@
#
# Write the <c:legend> element.
#
def write_legend
position = @legend.position
- allowed = %w(right left top bottom)
+ allowed = %w[right left top bottom]
delete_series = @legend.delete_series || []
if @legend.position =~ /^overlay_/
position = @legend.position.sub(/^overlay_/, '')
overlay = true
@@ -155,13 +157,11 @@
#
# Write the <c:txPr> element for legends.
#
def write_tx_pr_legend(horiz, font)
rotation = nil
- if ptrue?(font) && font[:_rotation]
- rotation = font[:_rotation]
- end
+ rotation = font[:_rotation] if ptrue?(font) && font[:_rotation]
@writer.tag_elements('c:txPr') do
# Write the a:bodyPr element.
write_a_body_pr(rotation, horiz)
# Write the a:lstStyle element.
@@ -185,27 +185,27 @@
#
# Write the <a:pPr> element for legends.
#
def write_a_p_pr_legend(font)
- @writer.tag_elements('a:pPr', [ ['rtl', 0] ]) do
+ @writer.tag_elements('a:pPr', [['rtl', 0]]) do
# Write the a:defRPr element.
write_a_def_rpr(font)
end
end
#
# Write the <c:varyColors> element.
#
def write_vary_colors
- @writer.empty_tag('c:varyColors', [ ['val', 1] ])
+ @writer.empty_tag('c:varyColors', [['val', 1]])
end
#
# Write the <c:firstSliceAng> element.
#
def write_first_slice_ang
- @writer.empty_tag('c:firstSliceAng', [ ['val', @rotation] ])
+ @writer.empty_tag('c:firstSliceAng', [['val', @rotation]])
end
end
end
end