diff options
| author | Randy Morgan <[email protected]> | 2011-11-20 23:22:04 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-11-20 23:22:04 +0900 |
| commit | e53f04284618713b0a90b7a691425c380e829476 (patch) | |
| tree | 801fea138160f9af426d62bf94ad5bf97123ece9 /lib/axlsx/drawing/series.rb | |
| download | caxlsx-e53f04284618713b0a90b7a691425c380e829476.tar.gz caxlsx-e53f04284618713b0a90b7a691425c380e829476.zip | |
first commit
Diffstat (limited to 'lib/axlsx/drawing/series.rb')
| -rw-r--r-- | lib/axlsx/drawing/series.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/axlsx/drawing/series.rb b/lib/axlsx/drawing/series.rb new file mode 100644 index 00000000..ef446921 --- /dev/null +++ b/lib/axlsx/drawing/series.rb @@ -0,0 +1,70 @@ +module Axlsx + # A Series defines the title, data and labels for chart data. + # @note The recommended way to manage series is to use Chart#add_series + # @see Worksheet#add_chart + # @see Chart#add_series + class Series + + # The chart that owns this series + # @return [Chart] + attr_reader :chart + + # The index of this series in the chart's series. + # @return [Integer] + attr_reader :index + + # The order of this series in the chart's series. + # @return [Integer] + attr_accessor :order + + # The title of the series + # @return [String] + attr_accessor :title + + # Creates a new series + # @param [Chart] chart + # @option options [Integer] order + # @option options [String] title + def initialize(chart, options={}) + self.chart = chart + @chart.series << self + options.each do |o| + self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" + end + end + + # retrieves the series index in the chart's series collection + def index + @chart.series.index(self) + end + + def order=(v) Axlsx::validate_unsigned_int(v); @order = v; end + + def order + @order || index + end + + def title=(v) Axlsx::validate_string(v); @title = v; end + + private + + # assigns the chart for this series + def chart=(v) DataTypeValidator.validate "Series.chart", Chart, v; @chart = 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) + xml.send('c:ser') { + xml.send('c:idx', :val=>index) + xml.send('c:order', :val=>order || index) + xml.send('c:tx') { + xml.send('c:v', self.title) + } + yield xml if block_given? + } + end + + end + +end |
