axlsx 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +32 -0
- data/README.md +34 -35
- data/Rakefile +19 -8
- data/doc/Axlsx.html +4 -4
- data/doc/Axlsx/App.html +1 -1
- data/doc/Axlsx/Axis.html +45 -19
- data/doc/Axlsx/Bar3DChart.html +134 -107
- data/doc/Axlsx/BarSeries.html +6 -64
- data/doc/Axlsx/Border.html +1 -1
- data/doc/Axlsx/BorderPr.html +1 -1
- data/doc/Axlsx/CatAxis.html +34 -31
- data/doc/Axlsx/CatAxisData.html +400 -0
- data/doc/Axlsx/Cell.html +1 -1
- data/doc/Axlsx/CellAlignment.html +1 -1
- data/doc/Axlsx/CellProtection.html +1 -1
- data/doc/Axlsx/CellStyle.html +1 -1
- data/doc/Axlsx/Chart.html +449 -212
- data/doc/Axlsx/Color.html +1 -1
- data/doc/Axlsx/ContentType.html +2 -2
- data/doc/Axlsx/Core.html +1 -1
- data/doc/Axlsx/DataTypeValidator.html +1 -1
- data/doc/Axlsx/Default.html +1 -1
- data/doc/Axlsx/Drawing.html +65 -91
- data/doc/Axlsx/Fill.html +1 -1
- data/doc/Axlsx/Font.html +1 -1
- data/doc/Axlsx/GradientFill.html +1 -1
- data/doc/Axlsx/GradientStop.html +1 -1
- data/doc/Axlsx/GraphicFrame.html +7 -5
- data/doc/Axlsx/Line3DChart.html +109 -28
- data/doc/Axlsx/LineSeries.html +17 -73
- data/doc/Axlsx/Marker.html +1 -1
- data/doc/Axlsx/NumFmt.html +1 -1
- data/doc/Axlsx/Override.html +1 -1
- data/doc/Axlsx/Package.html +1 -1
- data/doc/Axlsx/PatternFill.html +1 -1
- data/doc/Axlsx/Pie3DChart.html +118 -66
- data/doc/Axlsx/PieSeries.html +30 -89
- data/doc/Axlsx/RegexValidator.html +1 -1
- data/doc/Axlsx/Relationship.html +1 -1
- data/doc/Axlsx/Relationships.html +2 -2
- data/doc/Axlsx/RestrictionValidator.html +1 -1
- data/doc/Axlsx/Row.html +1 -1
- data/doc/Axlsx/Scaling.html +1 -1
- data/doc/Axlsx/SerAxis.html +52 -37
- data/doc/Axlsx/Series.html +25 -10
- data/doc/Axlsx/SeriesTitle.html +3 -2
- data/doc/Axlsx/SimpleTypedList.html +86 -17
- data/doc/Axlsx/Styles.html +1 -1
- data/doc/Axlsx/TableStyle.html +2 -2
- data/doc/Axlsx/TableStyleElement.html +1 -1
- data/doc/Axlsx/TableStyles.html +2 -2
- data/doc/Axlsx/Title.html +1 -1
- data/doc/Axlsx/TwoCellAnchor.html +40 -280
- data/doc/Axlsx/ValAxis.html +7 -8
- data/doc/Axlsx/ValAxisData.html +326 -0
- data/doc/Axlsx/View3D.html +39 -39
- data/doc/Axlsx/Workbook.html +1 -1
- data/doc/Axlsx/Worksheet.html +84 -39
- data/doc/Axlsx/Xf.html +1 -1
- data/doc/_index.html +15 -1
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +30 -49
- data/doc/index.html +30 -49
- data/doc/method_list.html +448 -416
- data/doc/top-level-namespace.html +1 -1
- data/examples/#example.rb# +87 -0
- data/examples/example.rb +4 -1
- data/examples/multi_chart.xlsx +0 -0
- data/lib/axlsx/drawing/#bar_series.rb# +62 -0
- data/lib/axlsx/drawing/axis.rb +7 -6
- data/lib/axlsx/drawing/bar_3D_chart.rb +12 -30
- data/lib/axlsx/drawing/bar_series.rb +6 -35
- data/lib/axlsx/drawing/cat_axis.rb +8 -10
- data/lib/axlsx/drawing/cat_axis_data.rb +34 -0
- data/lib/axlsx/drawing/cat_axis_data.rb~ +28 -0
- data/lib/axlsx/drawing/chart.rb +48 -21
- data/lib/axlsx/drawing/drawing.rb +14 -12
- data/lib/axlsx/drawing/graphic_frame.rb +1 -0
- data/lib/axlsx/drawing/line_3D_chart.rb +11 -1
- data/lib/axlsx/drawing/line_series.rb +10 -40
- data/lib/axlsx/drawing/pie_3D_chart.rb +17 -34
- data/lib/axlsx/drawing/pie_series.rb +11 -45
- data/lib/axlsx/drawing/ser_axis.rb +13 -14
- data/lib/axlsx/drawing/series.rb +2 -3
- data/lib/axlsx/drawing/series_title.rb +1 -1
- data/lib/axlsx/drawing/two_cell_anchor.rb +10 -34
- data/lib/axlsx/drawing/val_axis.rb +4 -4
- data/lib/axlsx/drawing/val_axis_data.rb +28 -0
- data/lib/axlsx/drawing/val_axis_data.rb~ +29 -0
- data/lib/axlsx/drawing/view_3D.rb +12 -6
- data/lib/axlsx/util/constants.rb +0 -3
- data/lib/axlsx/util/simple_typed_list.rb +7 -2
- data/lib/axlsx/version.rb +4 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +9 -1
- data/test/drawing/tc_axis.rb +1 -0
- data/test/drawing/tc_cat_axis_data.rb +18 -0
- data/test/drawing/tc_cat_axis_data.rb~ +32 -0
- data/test/drawing/tc_chart.rb +12 -0
- data/test/drawing/tc_line_series.rb +27 -0
- data/test/drawing/{tc_line_series.tc → tc_line_series.rb~} +0 -0
- data/test/drawing/tc_ser_axis.rb +13 -5
- data/test/drawing/tc_two_cell_anchor.rb +18 -17
- data/test/drawing/tc_val_axis.rb +5 -0
- data/test/drawing/tc_val_axis_data.rb +18 -0
- data/test/drawing/tc_val_axis_data.rb~ +18 -0
- data/test/drawing/tc_view_3D.rb +10 -1
- data/test/tc_package.rb +13 -13
- metadata +21 -6
data/lib/axlsx/drawing/chart.rb
CHANGED
|
@@ -2,19 +2,12 @@
|
|
|
2
2
|
module Axlsx
|
|
3
3
|
# A Chart is the superclass for specific charts
|
|
4
4
|
# @note Worksheet#add_chart is the recommended way to create charts for your worksheets.
|
|
5
|
+
# @see README for examples
|
|
5
6
|
class Chart
|
|
6
7
|
|
|
7
|
-
# The title object for the chart.
|
|
8
|
-
# @return [Title]
|
|
9
|
-
attr_accessor :title
|
|
10
|
-
|
|
11
|
-
# The style for the chart.
|
|
12
|
-
# see ECMA Part 1 §21.2.2.196
|
|
13
|
-
# @return [Integer]
|
|
14
|
-
attr_accessor :style
|
|
15
8
|
|
|
16
9
|
# The 3D view properties for the chart
|
|
17
|
-
|
|
10
|
+
attr_reader :view3D
|
|
18
11
|
|
|
19
12
|
# A reference to the graphic frame that owns this chart
|
|
20
13
|
# @return [GraphicFrame]
|
|
@@ -24,7 +17,7 @@ module Axlsx
|
|
|
24
17
|
# @return [SimpleTypedList]
|
|
25
18
|
attr_reader :series
|
|
26
19
|
|
|
27
|
-
# The type of series to use for this chart
|
|
20
|
+
# The type of series to use for this chart.
|
|
28
21
|
# @return [Series]
|
|
29
22
|
attr_reader :series_type
|
|
30
23
|
|
|
@@ -39,13 +32,14 @@ module Axlsx
|
|
|
39
32
|
#TODO data labels!
|
|
40
33
|
#attr_accessor :dLabls
|
|
41
34
|
|
|
42
|
-
# The
|
|
43
|
-
# @return [
|
|
44
|
-
|
|
35
|
+
# The title object for the chart.
|
|
36
|
+
# @return [Title]
|
|
37
|
+
attr_accessor :title
|
|
45
38
|
|
|
46
|
-
# The
|
|
47
|
-
#
|
|
48
|
-
|
|
39
|
+
# The style for the chart.
|
|
40
|
+
# see ECMA Part 1 §21.2.2.196
|
|
41
|
+
# @return [Integer]
|
|
42
|
+
attr_accessor :style
|
|
49
43
|
|
|
50
44
|
# Show the legend in the chart
|
|
51
45
|
# @return [Boolean]
|
|
@@ -65,6 +59,8 @@ module Axlsx
|
|
|
65
59
|
options.each do |o|
|
|
66
60
|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
67
61
|
end
|
|
62
|
+
start_at *options[:start_at] if options[:start_at]
|
|
63
|
+
end_at *options[:end_at] if options[:start_at]
|
|
68
64
|
yield self if block_given?
|
|
69
65
|
end
|
|
70
66
|
|
|
@@ -76,8 +72,6 @@ module Axlsx
|
|
|
76
72
|
"#{CHART_PN % (index+1)}"
|
|
77
73
|
end
|
|
78
74
|
|
|
79
|
-
def view3D=(v) DataTypeValidator.validate "#{self.class}.view3D", View3D, v; @view3D = v; end
|
|
80
|
-
|
|
81
75
|
def title=(v)
|
|
82
76
|
v = Title.new(v) if v.is_a?(String) || v.is_a?(Cell)
|
|
83
77
|
DataTypeValidator.validate "#{self.class}.title", Title, v
|
|
@@ -88,6 +82,19 @@ module Axlsx
|
|
|
88
82
|
|
|
89
83
|
def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, lambda { |v| v >= 1 && v <= 48 }; @style = v; end
|
|
90
84
|
|
|
85
|
+
# backwards compatibility to allow chart.to and chart.from access to anchor markers
|
|
86
|
+
# @note This will be disconinued in version 2.0.0. Please use the end_at method
|
|
87
|
+
def to
|
|
88
|
+
@graphic_frame.anchor.to
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# backwards compatibility to allow chart.to and chart.from access to anchor markers
|
|
92
|
+
# @note This will be disconinued in version 2.0.0. please use the start_at method
|
|
93
|
+
#
|
|
94
|
+
def from
|
|
95
|
+
@graphic_frame.anchor.from
|
|
96
|
+
end
|
|
97
|
+
|
|
91
98
|
# Adds a new series to the chart's series collection.
|
|
92
99
|
# @return [Series]
|
|
93
100
|
# @see Series
|
|
@@ -122,10 +129,30 @@ module Axlsx
|
|
|
122
129
|
builder.to_xml
|
|
123
130
|
end
|
|
124
131
|
|
|
132
|
+
# This is a short cut method to set the start anchor position
|
|
133
|
+
# If you need finer granularity in positioning use
|
|
134
|
+
# graphic_frame.anchor.from.colOff / rowOff
|
|
135
|
+
# @param [Integer] x The column
|
|
136
|
+
# @param [Integer] y The row
|
|
137
|
+
# @return [Marker]
|
|
138
|
+
def start_at(x, y)
|
|
139
|
+
@graphic_frame.anchor.from.col = x
|
|
140
|
+
@graphic_frame.anchor.from.row = y
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# This is a short cut method to set the end anchor position
|
|
144
|
+
# If you need finer granularity in positioning use
|
|
145
|
+
# graphic_frame.anchor.to.colOff / rowOff
|
|
146
|
+
# @param [Integer] x The column
|
|
147
|
+
# @param [Integer] y The row
|
|
148
|
+
# @return [Marker]
|
|
149
|
+
def end_at(x, y)
|
|
150
|
+
@graphic_frame.anchor.to.col = x
|
|
151
|
+
@graphic_frame.anchor.to.row = y
|
|
152
|
+
end
|
|
153
|
+
|
|
125
154
|
private
|
|
126
|
-
|
|
127
|
-
def start_at=(v) DataTypeValidator.validate "#{self.class}.start_at", Marker, v; @start_at = v; end
|
|
128
|
-
def end_at=(v) DataTypeValidator.validate "#{self.class}.end_at", Marker, v; @end_at = v; end
|
|
155
|
+
def view3D=(v) DataTypeValidator.validate "#{self.class}.view3D", View3D, v; @view3D = v; end
|
|
129
156
|
|
|
130
157
|
end
|
|
131
158
|
end
|
|
@@ -6,35 +6,39 @@ module Axlsx
|
|
|
6
6
|
require 'axlsx/drawing/bar_series.rb'
|
|
7
7
|
require 'axlsx/drawing/line_series.rb'
|
|
8
8
|
|
|
9
|
+
require 'axlsx/drawing/scaling.rb'
|
|
9
10
|
require 'axlsx/drawing/axis.rb'
|
|
10
11
|
require 'axlsx/drawing/ser_axis.rb'
|
|
11
12
|
require 'axlsx/drawing/cat_axis.rb'
|
|
12
13
|
require 'axlsx/drawing/val_axis.rb'
|
|
13
|
-
require 'axlsx/drawing/view_3D.rb'
|
|
14
|
-
require 'axlsx/drawing/scaling.rb'
|
|
15
14
|
|
|
16
|
-
require 'axlsx/drawing/
|
|
15
|
+
require 'axlsx/drawing/cat_axis_data.rb'
|
|
16
|
+
require 'axlsx/drawing/val_axis_data.rb'
|
|
17
|
+
|
|
17
18
|
require 'axlsx/drawing/marker.rb'
|
|
18
19
|
require 'axlsx/drawing/two_cell_anchor.rb'
|
|
20
|
+
require 'axlsx/drawing/graphic_frame.rb'
|
|
19
21
|
|
|
22
|
+
require 'axlsx/drawing/view_3D.rb'
|
|
20
23
|
require 'axlsx/drawing/chart.rb'
|
|
21
24
|
require 'axlsx/drawing/pie_3D_chart.rb'
|
|
22
25
|
require 'axlsx/drawing/bar_3D_chart.rb'
|
|
23
26
|
require 'axlsx/drawing/line_3D_chart.rb'
|
|
24
27
|
|
|
25
|
-
# A Drawing is a canvas for charts. Each worksheet has a single drawing that
|
|
26
|
-
#
|
|
28
|
+
# A Drawing is a canvas for charts. Each worksheet has a single drawing that manages anchors.
|
|
29
|
+
# The anchors reference the charts via graphical frames. This is not a trivial relationship so please do follow the advice in the note.
|
|
30
|
+
# @note The recommended way to manage drawings is to use the Worksheet.add_chart method.
|
|
27
31
|
# @see Worksheet#add_chart
|
|
28
|
-
# @see TwoCellAnchor
|
|
29
32
|
# @see Chart
|
|
33
|
+
# see README for an example of how to create a chart.
|
|
30
34
|
class Drawing
|
|
31
35
|
|
|
32
36
|
# The worksheet that owns the drawing
|
|
33
37
|
# @return [Worksheet]
|
|
34
38
|
attr_reader :worksheet
|
|
35
|
-
|
|
36
39
|
|
|
37
40
|
# A collection of anchors for this drawing
|
|
41
|
+
# only TwoCellAnchors are supported in this version
|
|
38
42
|
# @return [SimpleTypedList]
|
|
39
43
|
attr_reader :anchors
|
|
40
44
|
|
|
@@ -72,12 +76,10 @@ module Axlsx
|
|
|
72
76
|
end
|
|
73
77
|
|
|
74
78
|
|
|
75
|
-
# Adds a chart to the drawing.
|
|
76
|
-
# @note The recommended way to manage charts is to use Worksheet.add_chart.
|
|
77
|
-
# @
|
|
78
|
-
# @param [Hash] options
|
|
79
|
+
# Adds a chart to the drawing.
|
|
80
|
+
# @note The recommended way to manage charts is to use Worksheet.add_chart. Please refer to that method for documentation.
|
|
81
|
+
# @see Worksheet#add_chart
|
|
79
82
|
def add_chart(chart_type, options={})
|
|
80
|
-
DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type
|
|
81
83
|
TwoCellAnchor.new(self, chart_type, options)
|
|
82
84
|
@anchors.last.graphic_frame.chart
|
|
83
85
|
end
|
|
@@ -22,6 +22,7 @@ module Axlsx
|
|
|
22
22
|
# @param [TwoCellAnchor] anchor
|
|
23
23
|
# @param [Class] chart_type
|
|
24
24
|
def initialize(anchor, chart_type, options)
|
|
25
|
+
DataTypeValidator.validate "Drawing.chart_type", Chart, chart_type
|
|
25
26
|
@anchor = anchor
|
|
26
27
|
@chart = chart_type.new(self, options)
|
|
27
28
|
end
|
|
@@ -46,8 +46,18 @@ module Axlsx
|
|
|
46
46
|
|
|
47
47
|
# Creates a new line chart object
|
|
48
48
|
# @param [GraphicFrame] frame The workbook that owns this chart.
|
|
49
|
+
# @option options [Cell, String] title
|
|
50
|
+
# @option options [Boolean] show_legend
|
|
49
51
|
# @option options [Symbol] grouping
|
|
50
52
|
# @option options [String] gapDepth
|
|
53
|
+
# @option options [Integer] rotX
|
|
54
|
+
# @option options [String] hPercent
|
|
55
|
+
# @option options [Integer] rotY
|
|
56
|
+
# @option options [String] depthPercent
|
|
57
|
+
# @option options [Boolean] rAngAx
|
|
58
|
+
# @option options [Integer] perspective
|
|
59
|
+
# @see Chart
|
|
60
|
+
# @see View3D
|
|
51
61
|
def initialize(frame, options={})
|
|
52
62
|
@grouping = :standard
|
|
53
63
|
@catAxId = rand(8 ** 8)
|
|
@@ -56,9 +66,9 @@ module Axlsx
|
|
|
56
66
|
@catAxis = CatAxis.new(@catAxId, @valAxId)
|
|
57
67
|
@valAxis = ValAxis.new(@valAxId, @catAxId)
|
|
58
68
|
@serAxis = SerAxis.new(@serAxId, @valAxId)
|
|
59
|
-
@view3D = View3D.new(:perspective=>30)
|
|
60
69
|
super(frame, options)
|
|
61
70
|
@series_type = LineSeries
|
|
71
|
+
@view3D = View3D.new({:perspective=>30}.merge(options))
|
|
62
72
|
end
|
|
63
73
|
|
|
64
74
|
def grouping=(v)
|
|
@@ -6,11 +6,11 @@ module Axlsx
|
|
|
6
6
|
class LineSeries < Series
|
|
7
7
|
|
|
8
8
|
# The data for this series.
|
|
9
|
-
# @return [
|
|
9
|
+
# @return [ValAxisData]
|
|
10
10
|
attr_reader :data
|
|
11
11
|
|
|
12
12
|
# The labels for this series.
|
|
13
|
-
# @return [
|
|
13
|
+
# @return [CatAxisData]
|
|
14
14
|
attr_reader :labels
|
|
15
15
|
|
|
16
16
|
# Creates a new series
|
|
@@ -19,58 +19,28 @@ module Axlsx
|
|
|
19
19
|
# @param [Chart] chart
|
|
20
20
|
def initialize(chart, options={})
|
|
21
21
|
super(chart, options)
|
|
22
|
-
self.
|
|
23
|
-
self.
|
|
22
|
+
self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
|
|
23
|
+
self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
# Serializes the series
|
|
27
27
|
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
|
28
28
|
# @return [String]
|
|
29
|
+
# TODO create series_cat and series_val classes as this serialization is duplicated
|
|
29
30
|
def to_xml(xml)
|
|
30
31
|
super(xml) do |xml|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
xml.send('c:strRef') {
|
|
34
|
-
xml.send('c:f', Axlsx::cell_range(labels))
|
|
35
|
-
xml.send('c:strCache') {
|
|
36
|
-
xml.send('c:ptCount', :val=>labels.size)
|
|
37
|
-
labels.each_with_index do |cell, index|
|
|
38
|
-
v = cell.is_a?(Cell) ? cell.value : cell
|
|
39
|
-
xml.send('c:pt', :idx=>index) {
|
|
40
|
-
xml.send('c:v', v)
|
|
41
|
-
}
|
|
42
|
-
end
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
end
|
|
47
|
-
xml.send('c:val') {
|
|
48
|
-
xml.send('c:numRef') {
|
|
49
|
-
xml.send('c:f', Axlsx::cell_range(data))
|
|
50
|
-
xml.send('c:numCache') {
|
|
51
|
-
xml.send('c:formatCode', 'General')
|
|
52
|
-
xml.send('c:ptCount', :val=>data.size)
|
|
53
|
-
data.each_with_index do |cell, index|
|
|
54
|
-
v = cell.is_a?(Cell) ? cell.value : cell
|
|
55
|
-
xml.send('c:pt', :idx=>index) {
|
|
56
|
-
xml.send('c:v', v)
|
|
57
|
-
}
|
|
58
|
-
end
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
32
|
+
@labels.to_xml(xml) unless @labels.nil?
|
|
33
|
+
@data.to_xml(xml) unless @data.nil?
|
|
62
34
|
end
|
|
63
35
|
end
|
|
64
|
-
|
|
65
|
-
private
|
|
66
36
|
|
|
37
|
+
private
|
|
67
38
|
|
|
68
39
|
# assigns the data for this series
|
|
69
|
-
def data=(v) DataTypeValidator.validate "Series.data", [
|
|
40
|
+
def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
|
|
70
41
|
|
|
71
42
|
# assigns the labels for this series
|
|
72
|
-
def labels=(v) DataTypeValidator.validate "Series.labels", [
|
|
43
|
+
def labels=(v) DataTypeValidator.validate "Series.labels", [SimpleTypedList], v; @labels = v; end
|
|
73
44
|
|
|
74
45
|
end
|
|
75
|
-
|
|
76
46
|
end
|
|
@@ -2,47 +2,30 @@ module Axlsx
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
# The Pie3DChart is a three dimentional piechart (who would have guessed?) that you can add to your worksheet.
|
|
5
|
-
# @example Creating a chart
|
|
6
|
-
# # This example creates two charts in a single sheet.
|
|
7
|
-
# # The first uses data directly fed to the sheet, while the second references cells withing the worksheet for data.
|
|
8
|
-
#
|
|
9
|
-
# require "rubygems" # if that is your preferred way to manage gems!
|
|
10
|
-
# require "axlsx"
|
|
11
|
-
#
|
|
12
|
-
# p = Axlsx::Package.new
|
|
13
|
-
# ws = p.workbook.add_worksheet
|
|
14
|
-
# ws.add_row :values => ["This is a chart with no data in the sheet"]
|
|
15
|
-
#
|
|
16
|
-
# chart = ws.add_chart(Axlsx::Pie3DChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
|
|
17
|
-
# chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]
|
|
18
|
-
#
|
|
19
|
-
# ws.add_row :values => ["This chart uses the data below"]
|
|
20
|
-
# title_row = ws.add_row :values => ["Least Popular Pets"]
|
|
21
|
-
# label_row = ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"]
|
|
22
|
-
# data_row = ws.add_row :values => ["Votes", 6, 4, 1]
|
|
23
|
-
#
|
|
24
|
-
# chart = ws.add_chart(Axlsx::Pie3DChart, :start_at => [0,11], :end_at =>[0,16], :title => title_row.cells.last)
|
|
25
|
-
# chart.add_series :data => data_row.cells[(1..-1)], :labels => label_row.cells
|
|
26
|
-
#
|
|
27
|
-
# f = File.open('example_pie_3d_chart.xlsx', 'w')
|
|
28
|
-
# p.serialize(f)
|
|
29
|
-
#
|
|
30
5
|
# @see Worksheet#add_chart
|
|
31
|
-
# @see Worksheet#add_row
|
|
32
6
|
# @see Chart#add_series
|
|
33
|
-
# @see
|
|
34
|
-
# @see Package#serialize
|
|
7
|
+
# @see README for an example
|
|
35
8
|
class Pie3DChart < Chart
|
|
36
9
|
|
|
37
|
-
|
|
38
10
|
# Creates a new pie chart object
|
|
39
|
-
# @param [
|
|
11
|
+
# @param [GraphicFrame] frame The workbook that owns this chart.
|
|
40
12
|
# @option options [Cell, String] title
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
13
|
+
# @option options [Boolean] show_legend
|
|
14
|
+
# @option options [Symbol] grouping
|
|
15
|
+
# @option options [String] gapDepth
|
|
16
|
+
# @option options [Integer] rotX
|
|
17
|
+
# @option options [String] hPercent
|
|
18
|
+
# @option options [Integer] rotY
|
|
19
|
+
# @option options [String] depthPercent
|
|
20
|
+
# @option options [Boolean] rAngAx
|
|
21
|
+
# @option options [Integer] perspective
|
|
22
|
+
# @see Chart
|
|
23
|
+
# @see View3D
|
|
24
|
+
def initialize(frame, options={})
|
|
25
|
+
super(frame, options)
|
|
44
26
|
@series_type = PieSeries
|
|
45
|
-
@view3D = View3D.new(:rotX
|
|
27
|
+
@view3D = View3D.new({:rotX=>30, :perspective=>30}.merge(options))
|
|
28
|
+
|
|
46
29
|
end
|
|
47
30
|
|
|
48
31
|
# Serializes the pie chart
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
module Axlsx
|
|
2
|
-
# A PieSeries defines the
|
|
2
|
+
# A PieSeries defines the data and labels and explosion for pie charts series.
|
|
3
3
|
# @note The recommended way to manage series is to use Chart#add_series
|
|
4
4
|
# @see Worksheet#add_chart
|
|
5
5
|
# @see Chart#add_series
|
|
6
6
|
class PieSeries < Series
|
|
7
7
|
|
|
8
8
|
# The data for this series.
|
|
9
|
-
# @return [
|
|
9
|
+
# @return [SimpleTypedList]
|
|
10
10
|
attr_reader :data
|
|
11
11
|
|
|
12
|
-
|
|
13
12
|
# The labels for this series.
|
|
14
|
-
# @return [
|
|
13
|
+
# @return [SimpleTypedList]
|
|
15
14
|
attr_reader :labels
|
|
16
15
|
|
|
17
|
-
|
|
18
16
|
# The explosion for this series
|
|
19
|
-
# @return [
|
|
17
|
+
# @return [Integert]
|
|
20
18
|
attr_accessor :explosion
|
|
21
19
|
|
|
22
20
|
# Creates a new series
|
|
@@ -27,61 +25,29 @@ module Axlsx
|
|
|
27
25
|
# @param [Chart] chart
|
|
28
26
|
def initialize(chart, options={})
|
|
29
27
|
super(chart, options)
|
|
30
|
-
self.
|
|
31
|
-
self.
|
|
28
|
+
self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
|
|
29
|
+
self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
def explosion=(v) Axlsx::validate_unsigned_int(v); @explosion = v; end
|
|
33
|
+
|
|
35
34
|
# Serializes the series
|
|
36
35
|
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
|
37
36
|
# @return [String]
|
|
38
37
|
def to_xml(xml)
|
|
39
38
|
super(xml) do |xml|
|
|
40
39
|
xml.send('c:explosion', :val=>@explosion) unless @explosion.nil?
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
xml.send('c:strRef') {
|
|
44
|
-
xml.send('c:f', Axlsx::cell_range(labels))
|
|
45
|
-
xml.send('c:strCache') {
|
|
46
|
-
xml.send('c:ptCount', :val=>labels.size)
|
|
47
|
-
labels.each_with_index do |cell, index|
|
|
48
|
-
v = cell.is_a?(Cell) ? cell.value : cell
|
|
49
|
-
xml.send('c:pt', :idx=>index) {
|
|
50
|
-
xml.send('c:v', v)
|
|
51
|
-
}
|
|
52
|
-
end
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
end
|
|
57
|
-
xml.send('c:val') {
|
|
58
|
-
xml.send('c:numRef') {
|
|
59
|
-
xml.send('c:f', Axlsx::cell_range(data))
|
|
60
|
-
xml.send('c:numCache') {
|
|
61
|
-
xml.send('c:formatCode', 'General')
|
|
62
|
-
xml.send('c:ptCount', :val=>data.size)
|
|
63
|
-
data.each_with_index do |cell, index|
|
|
64
|
-
v = cell.is_a?(Cell) ? cell.value : cell
|
|
65
|
-
xml.send('c:pt', :idx=>index) {
|
|
66
|
-
xml.send('c:v', v)
|
|
67
|
-
}
|
|
68
|
-
end
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
40
|
+
@labels.to_xml(xml) unless @labels.nil?
|
|
41
|
+
@data.to_xml(xml) unless @data.nil?
|
|
73
42
|
end
|
|
74
43
|
end
|
|
75
|
-
|
|
76
|
-
|
|
77
44
|
private
|
|
78
45
|
|
|
79
|
-
|
|
80
46
|
# assigns the data for this series
|
|
81
|
-
def data=(v) DataTypeValidator.validate "Series.data", [
|
|
47
|
+
def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
|
|
82
48
|
|
|
83
49
|
# assigns the labels for this series
|
|
84
|
-
def labels=(v) DataTypeValidator.validate "Series.labels", [
|
|
50
|
+
def labels=(v) DataTypeValidator.validate "Series.labels", [SimpleTypedList], v; @labels = v; end
|
|
85
51
|
|
|
86
52
|
end
|
|
87
53
|
|