blob: 3647f22e0e4704e93ba2227f155525001432fc13 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
module Axlsx
# A Series defines the common series attributes and is the super class for all concrete series types.
# @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 title of the series
# @return [SeriesTitle]
attr_reader :title
# Creates a new series
# @param [Chart] chart
# @option options [Integer] order
# @option options [String] title
def initialize(chart, options={})
@order = nil
self.chart = chart
@chart.series << self
options.each do |o|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
end
end
# The index of this series in the chart's series.
# @return [Integer]
def index
@chart.series.index(self)
end
# The order of this series in the chart's series. By default the order is the index of the series.
# @return [Integer]
def order
@order || index
end
# @see order
def order=(v) Axlsx::validate_unsigned_int(v); @order = v; end
# @see title
def title=(v)
v = SeriesTitle.new(v) if v.is_a?(String) || v.is_a?(Cell)
DataTypeValidator.validate "#{self.class}.title", SeriesTitle, 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)
title.to_xml(xml) unless title.nil?
yield xml if block_given?
}
end
end
end
|