summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/pie_series.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2011-11-23 12:28:10 +0900
committerRandy Morgan <[email protected]>2011-11-23 12:28:10 +0900
commit6739c249e7bf3cf7d2132b2aa49b6faf6bebec29 (patch)
treec68e1527212c3665464debeebd2d97c127b0887e /lib/axlsx/drawing/pie_series.rb
parent099a1d5a7824b7a6392bfe2f124ebeaf9d8122db (diff)
downloadcaxlsx-6739c249e7bf3cf7d2132b2aa49b6faf6bebec29.tar.gz
caxlsx-6739c249e7bf3cf7d2132b2aa49b6faf6bebec29.zip
-refactoring chart position and axis data/category for chart.
-additional specs and documentation improvements.
Diffstat (limited to 'lib/axlsx/drawing/pie_series.rb')
-rw-r--r--lib/axlsx/drawing/pie_series.rb56
1 files changed, 11 insertions, 45 deletions
diff --git a/lib/axlsx/drawing/pie_series.rb b/lib/axlsx/drawing/pie_series.rb
index 98b61728..1f20058d 100644
--- a/lib/axlsx/drawing/pie_series.rb
+++ b/lib/axlsx/drawing/pie_series.rb
@@ -1,22 +1,20 @@
module Axlsx
- # A PieSeries defines the title, data and labels for pie charts
+ # A PieSeries defines the data and labels and explosion for pie charts series.
# @note The recommended way to manage series is to use Chart#add_series
# @see Worksheet#add_chart
# @see Chart#add_series
class PieSeries < Series
# The data for this series.
- # @return [Array, SimpleTypedList]
+ # @return [SimpleTypedList]
attr_reader :data
-
# The labels for this series.
- # @return [Array, SimpleTypedList]
+ # @return [SimpleTypedList]
attr_reader :labels
-
# The explosion for this series
- # @return [Array, SimpleTypedList]
+ # @return [Integert]
attr_accessor :explosion
# Creates a new series
@@ -27,61 +25,29 @@ module Axlsx
# @param [Chart] chart
def initialize(chart, options={})
super(chart, options)
- self.data = options[:data] || []
- self.labels = options[:labels] || []
+ self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
+ self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
end
def explosion=(v) Axlsx::validate_unsigned_int(v); @explosion = v; end
+
# Serializes the series
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
# @return [String]
def to_xml(xml)
super(xml) do |xml|
xml.send('c:explosion', :val=>@explosion) unless @explosion.nil?
- if !labels.empty?
- xml.send('c:cat') {
- xml.send('c:strRef') {
- xml.send('c:f', Axlsx::cell_range(labels))
- xml.send('c:strCache') {
- xml.send('c:ptCount', :val=>labels.size)
- labels.each_with_index do |cell, index|
- v = cell.is_a?(Cell) ? cell.value : cell
- xml.send('c:pt', :idx=>index) {
- xml.send('c:v', v)
- }
- end
- }
- }
- }
- end
- xml.send('c:val') {
- xml.send('c:numRef') {
- xml.send('c:f', Axlsx::cell_range(data))
- xml.send('c:numCache') {
- xml.send('c:formatCode', 'General')
- xml.send('c:ptCount', :val=>data.size)
- data.each_with_index do |cell, index|
- v = cell.is_a?(Cell) ? cell.value : cell
- xml.send('c:pt', :idx=>index) {
- xml.send('c:v', v)
- }
- end
- }
- }
- }
-
+ @labels.to_xml(xml) unless @labels.nil?
+ @data.to_xml(xml) unless @data.nil?
end
end
-
-
private
-
# assigns the data for this series
- def data=(v) DataTypeValidator.validate "Series.data", [Array, SimpleTypedList], v; @data = v; end
+ def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
# assigns the labels for this series
- def labels=(v) DataTypeValidator.validate "Series.labels", [Array, SimpleTypedList], v; @labels = v; end
+ def labels=(v) DataTypeValidator.validate "Series.labels", [SimpleTypedList], v; @labels = v; end
end