axlsx 1.0.7 → 1.0.8

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.
Files changed (207) hide show
  1. data/README.md +21 -3
  2. data/doc/Axlsx.html +150 -6
  3. data/doc/Axlsx/App.html +1 -1
  4. data/doc/Axlsx/Axis.html +1 -1
  5. data/doc/Axlsx/Bar3DChart.html +1 -1
  6. data/doc/Axlsx/BarSeries.html +1 -1
  7. data/doc/Axlsx/Border.html +1 -1
  8. data/doc/Axlsx/BorderPr.html +1 -1
  9. data/doc/Axlsx/CatAxis.html +1 -1
  10. data/doc/Axlsx/CatAxisData.html +7 -5
  11. data/doc/Axlsx/Cell.html +1 -1
  12. data/doc/Axlsx/CellAlignment.html +1 -1
  13. data/doc/Axlsx/CellProtection.html +1 -1
  14. data/doc/Axlsx/CellStyle.html +1 -1
  15. data/doc/Axlsx/Chart.html +16 -16
  16. data/doc/Axlsx/Color.html +1 -1
  17. data/doc/Axlsx/ContentType.html +1 -1
  18. data/doc/Axlsx/Core.html +1 -1
  19. data/doc/Axlsx/DataTypeValidator.html +1 -1
  20. data/doc/Axlsx/Default.html +1 -1
  21. data/doc/Axlsx/Drawing.html +243 -65
  22. data/doc/Axlsx/Fill.html +1 -1
  23. data/doc/Axlsx/Font.html +1 -1
  24. data/doc/Axlsx/GradientFill.html +1 -1
  25. data/doc/Axlsx/GradientStop.html +1 -1
  26. data/doc/Axlsx/GraphicFrame.html +21 -21
  27. data/doc/Axlsx/Line3DChart.html +1 -1
  28. data/doc/Axlsx/LineSeries.html +6 -8
  29. data/doc/Axlsx/Marker.html +1 -1
  30. data/doc/Axlsx/NumFmt.html +1 -1
  31. data/doc/Axlsx/OneCellAnchor.html +988 -0
  32. data/doc/Axlsx/Override.html +1 -1
  33. data/doc/Axlsx/Package.html +127 -75
  34. data/doc/Axlsx/PatternFill.html +1 -1
  35. data/doc/Axlsx/Pic.html +1532 -0
  36. data/doc/Axlsx/Pie3DChart.html +5 -7
  37. data/doc/Axlsx/PieSeries.html +1 -1
  38. data/doc/Axlsx/RegexValidator.html +1 -1
  39. data/doc/Axlsx/Relationship.html +6 -6
  40. data/doc/Axlsx/Relationships.html +1 -1
  41. data/doc/Axlsx/RestrictionValidator.html +1 -1
  42. data/doc/Axlsx/Row.html +1 -1
  43. data/doc/Axlsx/Scaling.html +1 -1
  44. data/doc/Axlsx/SerAxis.html +1 -1
  45. data/doc/Axlsx/Series.html +1 -1
  46. data/doc/Axlsx/SeriesTitle.html +1 -1
  47. data/doc/Axlsx/SimpleTypedList.html +1 -1
  48. data/doc/Axlsx/Styles.html +1 -1
  49. data/doc/Axlsx/TableStyle.html +1 -1
  50. data/doc/Axlsx/TableStyleElement.html +1 -1
  51. data/doc/Axlsx/TableStyles.html +1 -1
  52. data/doc/Axlsx/Title.html +1 -1
  53. data/doc/Axlsx/TwoCellAnchor.html +165 -61
  54. data/doc/Axlsx/ValAxis.html +1 -1
  55. data/doc/Axlsx/ValAxisData.html +1 -1
  56. data/doc/Axlsx/View3D.html +1 -1
  57. data/doc/Axlsx/Workbook.html +151 -47
  58. data/doc/Axlsx/Worksheet.html +172 -35
  59. data/doc/Axlsx/Xf.html +1 -1
  60. data/doc/_index.html +15 -1
  61. data/doc/class_list.html +1 -1
  62. data/doc/file.README.html +29 -4
  63. data/doc/index.html +29 -4
  64. data/doc/method_list.html +571 -363
  65. data/doc/top-level-namespace.html +1 -1
  66. data/examples/example.rb +13 -0
  67. data/examples/image1.gif +0 -0
  68. data/examples/image1.jpeg +0 -0
  69. data/examples/image1.jpg +0 -0
  70. data/examples/image1.png +0 -0
  71. data/lib/axlsx/drawing/bar_series.rb +0 -1
  72. data/lib/axlsx/drawing/cat_axis_data.rb +1 -0
  73. data/lib/axlsx/drawing/chart.rb +0 -1
  74. data/lib/axlsx/drawing/drawing.rb +31 -7
  75. data/lib/axlsx/drawing/graphic_frame.rb +0 -2
  76. data/lib/axlsx/drawing/line_series.rb +0 -1
  77. data/lib/axlsx/drawing/one_cell_anchor.rb +89 -0
  78. data/lib/axlsx/drawing/pic.rb +158 -0
  79. data/lib/axlsx/drawing/pie_3D_chart.rb +0 -1
  80. data/lib/axlsx/drawing/two_cell_anchor.rb +17 -4
  81. data/lib/axlsx/package.rb +31 -5
  82. data/lib/axlsx/rels/relationship.rb +1 -2
  83. data/lib/axlsx/util/constants.rb +24 -0
  84. data/lib/axlsx/util/validators.rb +2 -2
  85. data/lib/axlsx/version.rb +1 -1
  86. data/lib/axlsx/workbook/workbook.rb +8 -0
  87. data/lib/axlsx/workbook/worksheet/worksheet.rb +10 -1
  88. data/test/drawing/tc_drawing.rb +10 -1
  89. data/test/drawing/tc_one_cell_anchor.rb +67 -0
  90. data/test/drawing/tc_pic.rb +71 -0
  91. data/test/tc_package.rb +0 -2
  92. metadata +13 -118
  93. data/examples/#example.rb# +0 -87
  94. data/examples/example.rb~ +0 -79
  95. data/examples/multi_chart.xlsx +0 -0
  96. data/lib/axlsx.rb~ +0 -67
  97. data/lib/axlsx/content_type/content_type.rb~ +0 -20
  98. data/lib/axlsx/content_type/default.rb~ +0 -32
  99. data/lib/axlsx/content_type/override.rb~ +0 -30
  100. data/lib/axlsx/doc_props/app.rb~ +0 -127
  101. data/lib/axlsx/doc_props/core.rb~ +0 -25
  102. data/lib/axlsx/drawing/#bar_series.rb# +0 -62
  103. data/lib/axlsx/drawing/axis.rb~ +0 -0
  104. data/lib/axlsx/drawing/bar_3D_chart.rb~ +0 -64
  105. data/lib/axlsx/drawing/bar_series.rb~ +0 -92
  106. data/lib/axlsx/drawing/cat_axis.rb~ +0 -32
  107. data/lib/axlsx/drawing/cat_axis_data.rb~ +0 -28
  108. data/lib/axlsx/drawing/chart.rb~ +0 -0
  109. data/lib/axlsx/drawing/drawing.rb~ +0 -102
  110. data/lib/axlsx/drawing/graphic_frame.rb~ +0 -40
  111. data/lib/axlsx/drawing/line_3D_chart.rb~ +0 -138
  112. data/lib/axlsx/drawing/line_series.rb~ +0 -91
  113. data/lib/axlsx/drawing/marker.rb~ +0 -50
  114. data/lib/axlsx/drawing/pie_3D_chart.rb~ +0 -132
  115. data/lib/axlsx/drawing/pie_series.rb~ +0 -0
  116. data/lib/axlsx/drawing/scaling.rb~ +0 -0
  117. data/lib/axlsx/drawing/ser_axis.rb~ +0 -48
  118. data/lib/axlsx/drawing/series.rb~ +0 -114
  119. data/lib/axlsx/drawing/series_title.rb~ +0 -18
  120. data/lib/axlsx/drawing/title.rb~ +0 -69
  121. data/lib/axlsx/drawing/two_cell_anchor.rb~ +0 -70
  122. data/lib/axlsx/drawing/val_axis.rb~ +0 -34
  123. data/lib/axlsx/drawing/val_axis_data.rb~ +0 -29
  124. data/lib/axlsx/drawing/view_3D.rb~ +0 -21
  125. data/lib/axlsx/package.rb~ +0 -181
  126. data/lib/axlsx/rels/relationship.rb~ +0 -18
  127. data/lib/axlsx/rels/relationships.rb~ +0 -23
  128. data/lib/axlsx/stylesheet/border.rb~ +0 -24
  129. data/lib/axlsx/stylesheet/border_pr.rb~ +0 -64
  130. data/lib/axlsx/stylesheet/cell_alignment.rb~ +0 -93
  131. data/lib/axlsx/stylesheet/cell_protection.rb~ +0 -16
  132. data/lib/axlsx/stylesheet/cell_style.rb~ +0 -61
  133. data/lib/axlsx/stylesheet/color.rb~ +0 -56
  134. data/lib/axlsx/stylesheet/fill.rb~ +0 -31
  135. data/lib/axlsx/stylesheet/font.rb~ +0 -33
  136. data/lib/axlsx/stylesheet/gradient_fill.rb~ +0 -70
  137. data/lib/axlsx/stylesheet/gradient_stop.rb~ +0 -15
  138. data/lib/axlsx/stylesheet/num_fmt.rb~ +0 -60
  139. data/lib/axlsx/stylesheet/pattern_fill.rb~ +0 -63
  140. data/lib/axlsx/stylesheet/styles.rb~ +0 -279
  141. data/lib/axlsx/stylesheet/table_style.rb~ +0 -43
  142. data/lib/axlsx/stylesheet/table_style_element.rb~ +0 -66
  143. data/lib/axlsx/stylesheet/table_styles.rb~ +0 -36
  144. data/lib/axlsx/stylesheet/xf.rb~ +0 -37
  145. data/lib/axlsx/util/constants.rb~ +0 -187
  146. data/lib/axlsx/util/monkey_patches_for_true_zip_stream.rb~ +0 -61
  147. data/lib/axlsx/util/simple_typed_list.rb~ +0 -79
  148. data/lib/axlsx/util/validators.rb~ +0 -132
  149. data/lib/axlsx/util/xml_escape.rb~ +0 -6
  150. data/lib/axlsx/workbook/workbook.rb~ +0 -130
  151. data/lib/axlsx/workbook/worksheet/cell.rb~ +0 -185
  152. data/lib/axlsx/workbook/worksheet/row.rb~ +0 -92
  153. data/lib/axlsx/workbook/worksheet/worksheet.rb~ +0 -194
  154. data/test/content_type/tc_content_type.rb~ +0 -81
  155. data/test/content_type/tc_default.rb~ +0 -40
  156. data/test/content_type/tc_override.rb~ +0 -40
  157. data/test/doc_props/tc_app.rb~ +0 -19
  158. data/test/drawing/tc_axis.rb~ +0 -0
  159. data/test/drawing/tc_bar_3D_chart.rb~ +0 -66
  160. data/test/drawing/tc_bar_series.rb~ +0 -31
  161. data/test/drawing/tc_cat_axis.rb~ +0 -39
  162. data/test/drawing/tc_cat_axis_data.rb~ +0 -32
  163. data/test/drawing/tc_chart.rb~ +0 -59
  164. data/test/drawing/tc_graphic_frame.rb~ +0 -21
  165. data/test/drawing/tc_line_3d_chart.rb~ +0 -48
  166. data/test/drawing/tc_line_series.rb~ +0 -34
  167. data/test/drawing/tc_marker.rb~ +0 -26
  168. data/test/drawing/tc_pie_3D_chart.rb~ +0 -33
  169. data/test/drawing/tc_pie_series.rb~ +0 -26
  170. data/test/drawing/tc_scaling.rb~ +0 -45
  171. data/test/drawing/tc_ser_axis.rb~ +0 -20
  172. data/test/drawing/tc_series.rb~ +0 -31
  173. data/test/drawing/tc_series_title.rb~ +0 -34
  174. data/test/drawing/tc_title.rb~ +0 -34
  175. data/test/drawing/tc_two_cell_anchor.rb~ +0 -37
  176. data/test/drawing/tc_val_axis.rb~ +0 -32
  177. data/test/drawing/tc_val_axis_data.rb~ +0 -18
  178. data/test/drawing/tc_view_3D.rb~ +0 -37
  179. data/test/rels/tc_relationship.rb~ +0 -39
  180. data/test/rels/tc_relationships.rb~ +0 -37
  181. data/test/stylesheet/tc_border.rb~ +0 -31
  182. data/test/stylesheet/tc_border_pr.rb~ +0 -31
  183. data/test/stylesheet/tc_cell_alignment.rb~ +0 -38
  184. data/test/stylesheet/tc_cell_protection.rb~ +0 -77
  185. data/test/stylesheet/tc_cell_style.rb~ +0 -30
  186. data/test/stylesheet/tc_color.rb~ +0 -38
  187. data/test/stylesheet/tc_fill.rb~ +0 -19
  188. data/test/stylesheet/tc_font.rb~ +0 -19
  189. data/test/stylesheet/tc_gradient_fill.rb~ +0 -114
  190. data/test/stylesheet/tc_gradient_stop.rb~ +0 -65
  191. data/test/stylesheet/tc_num_fmt.rb~ +0 -32
  192. data/test/stylesheet/tc_pattern_fill.rb~ +0 -31
  193. data/test/stylesheet/tc_table_style.rb~ +0 -38
  194. data/test/stylesheet/tc_table_style_element.rb~ +0 -37
  195. data/test/stylesheet/tc_table_styles.rb~ +0 -37
  196. data/test/stylesheet/tc_xf.rb~ +0 -30
  197. data/test/tc_app.rb~ +0 -19
  198. data/test/tc_border_pr.rb~ +0 -21
  199. data/test/tc_package.rb~ +0 -64
  200. data/test/tc_pie_3D_chart.rb~ +0 -66
  201. data/test/tc_relationships.rb~ +0 -37
  202. data/test/tc_series.rb~ +0 -31
  203. data/test/tc_styles.rb~ +0 -64
  204. data/test/tc_validators.rb~ +0 -77
  205. data/test/tc_worksheet.rb~ +0 -85
  206. data/test/workbook/worksheet/tc_row.rb~ +0 -30
  207. data/test/workbook/worksheet/tc_worksheet.rb~ +0 -85
@@ -1,138 +0,0 @@
1
- module Axlsx
2
-
3
- # The Line3DChart is a three dimentional barchart (who would have guessed?) that you can add to your worksheet.
4
- # @example Creating a chart
5
- # # This example creates two charts in a single sheet.
6
- # # The first uses data directly fed to the sheet, while the second references cells withing the worksheet for data.
7
- #
8
- # require "rubygems" # if that is your preferred way to manage gems!
9
- # require "axlsx"
10
- #
11
- # p = Axlsx::Package.new
12
- # ws = p.workbook.add_worksheet
13
- # ws.add_row :values => ["This is a chart with no data in the sheet"]
14
- #
15
- # chart = ws.add_chart(Axlsx::Line3DChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
16
- # chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]
17
- #
18
- # ws.add_row :values => ["This chart uses the data below"]
19
- # title_row = ws.add_row :values => ["Least Popular Pets"]
20
- # label_row = ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"]
21
- # data_row = ws.add_row :values => ["Votes", 6, 4, 1]
22
- #
23
- # chart = ws.add_chart(Axlsx::Pie3DChart, :start_at => [0,11], :end_at =>[0,16], :title => title_row.cells.last)
24
- # chart.add_series :data => data_row.cells[(1..-1)], :labels => label_row.cells
25
- #
26
- # f = File.open('example_pie_3d_chart.xlsx', 'w')
27
- # p.serialize(f)
28
- #
29
- # @see Worksheet#add_chart
30
- # @see Worksheet#add_row
31
- # @see Chart#add_series
32
- # @see Series
33
- # @see Package#serialize
34
- class Bar3DChart < Chart
35
-
36
- # the category axis
37
- # @return [CatAxis]
38
- attr_reader :catAxis
39
-
40
- # the category axis
41
- # @return [ValAxis]
42
- attr_reader :valAxis
43
-
44
- # The direction of the bars in the chart
45
- # must be one of [:bar, :col]
46
- # @return [Symbol]
47
- attr_accessor :barDir
48
-
49
- # space between bar or column clusters, as a percentage of the bar or column width.
50
- # @return [String]
51
- attr_accessor :gapDepth
52
-
53
- # space between bar or column clusters, as a percentage of the bar or column width.
54
- # @return [String]
55
- attr_accessor :gapWidth
56
-
57
- #grouping for a column, line, or area chart.
58
- # must be one of [:percentStacked, :clustered, :standard, :stacked]
59
- # @return [Symbol]
60
- attr_accessor :grouping
61
-
62
- # The shabe of the bars or columns
63
- # must be one of [:percentStacked, :clustered, :standard, :stacked]
64
- # @return [Symbol]
65
- attr_accessor :shape
66
-
67
- # validation regex for gap amount percent
68
- GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
69
-
70
- # Creates a new bar chart object
71
- # @param [GraphicFrame] frame The workbook that owns this chart.
72
- # @option options [Cell, String] title
73
- # @option options [Boolean] show_legend
74
- # @option options [Symbol] barDir
75
- # @option options [Symbol] grouping
76
- # @option options [String] gapWidth
77
- # @option options [String] gapDepth
78
- # @option options [Symbol] shape
79
- def initialize(frame, options={})
80
- super(frame, options)
81
- @series_type = BarSeries
82
- @barDir = :bar
83
- @grouping = :clustered
84
- @catAxId = rand(8 ** 8)
85
- @valAxId = rand(8 ** 8)
86
- @catAxis = CatAxis.new(@catAxId, @valAxId)
87
- @valAxis = ValAxis.new(@valAxId, @catAxId)
88
- @view3D = View3D.new(:rAngAx=>1)
89
- end
90
-
91
- def barDir=(v)
92
- RestrictionValidator.validate "Bar3DChart.barDir", [:bar, :col], v
93
- @barDir = v
94
- end
95
-
96
-
97
- def grouping=(v)
98
- RestrictionValidator.validate "Bar3DChart.grouping", [:percentStacked, :clustered, :standard, :stacked], v
99
- @grouping = v
100
- end
101
-
102
- def gapWidth=(v)
103
- RegexValidator.validate "Bar3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
104
- @gapWidth=(v)
105
- end
106
-
107
- def gapDepth=(v)
108
- RegexValidator.validate "Bar3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
109
- @gapDepth=(v)
110
- end
111
-
112
- def shape=(v)
113
- RestrictionValidator.validate "Bar3DChart.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
114
- @shape = v
115
- end
116
-
117
- # Serializes the bar chart
118
- # @return [String]
119
- def to_xml
120
- super() do |xml|
121
- xml.send('c:bar3DChart') {
122
- xml.send('c:barDir', :val => barDir)
123
- xml.send('c:grouping', :val=>grouping)
124
- xml.send('c:varyColors', :val=>1)
125
- @series.each { |ser| ser.to_xml(xml) }
126
- xml.send('c:gapWidth', :val=>@gapWidth) unless @gapWidth.nil?
127
- xml.send('c:gapDepth', :val=>@gapDepth) unless @gapDepth.nil?
128
- xml.send('c:shape', :val=>@shape) unless @shape.nil?
129
- xml.send('c:axId', :val=>@catAxId)
130
- xml.send('c:axId', :val=>@valAxId)
131
- xml.send('c:axId', :val=>0)
132
- }
133
- @catAxis.to_xml(xml)
134
- @valAxis.to_xml(xml)
135
- end
136
- end
137
- end
138
- end
@@ -1,91 +0,0 @@
1
- module Axlsx
2
- # A BarSeries defines the title, data and labels for bar charts
3
- # @note The recommended way to manage series is to use Chart#add_series
4
- # @see Worksheet#add_chart
5
- # @see Chart#add_series
6
- class BarSeries < Series
7
-
8
-
9
- # The data for this series.
10
- # @return [Array, SimpleTypedList]
11
- attr_reader :data
12
-
13
- # The labels for this series.
14
- # @return [Array, SimpleTypedList]
15
- attr_reader :labels
16
-
17
- # The shabe of the bars or columns
18
- # must be one of [:percentStacked, :clustered, :standard, :stacked]
19
- # @return [Symbol]
20
- attr_accessor :shape
21
-
22
- # Creates a new series
23
- # @option options [Array, SimpleTypedList] data
24
- # @option options [Array, SimpleTypedList] labels
25
- # @option options [String] title
26
- # @option options [String] shape
27
- # @param [Chart] chart
28
- def initialize(chart, options={})
29
- @shape = :box
30
- super(chart, options)
31
- self.data = options[:data] || []
32
- self.labels = options[:labels] || []
33
- end
34
-
35
- def shape=(v)
36
- RestrictionValidator.validate "BarSeries.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
37
- @shape = v
38
- end
39
-
40
- # Serializes the series
41
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
42
- # @return [String]
43
- def to_xml(xml)
44
- super(xml) do |xml|
45
- if !labels.empty?
46
- xml.send('c:cat') {
47
- xml.send('c:strRef') {
48
- xml.send('c:f', Axlsx::cell_range(labels))
49
- xml.send('c:strCache') {
50
- xml.send('c:ptCount', :val=>labels.size)
51
- labels.each_with_index do |cell, index|
52
- v = cell.is_a?(Cell) ? cell.value : cell
53
- xml.send('c:pt', :idx=>index) {
54
- xml.send('c:v', v)
55
- }
56
- end
57
- }
58
- }
59
- }
60
- end
61
- xml.send('c:val') {
62
- xml.send('c:numRef') {
63
- xml.send('c:f', Axlsx::cell_range(data))
64
- xml.send('c:numCache') {
65
- xml.send('c:formatCode', 'General')
66
- xml.send('c:ptCount', :val=>data.size)
67
- data.each_with_index do |cell, index|
68
- v = cell.is_a?(Cell) ? cell.value : cell
69
- xml.send('c:pt', :idx=>index) {
70
- xml.send('c:v', v)
71
- }
72
- end
73
- }
74
- }
75
- }
76
- end
77
- end
78
-
79
-
80
- private
81
-
82
-
83
- # assigns the data for this series
84
- def data=(v) DataTypeValidator.validate "Series.data", [Array, SimpleTypedList], v; @data = v; end
85
-
86
- # assigns the labels for this series
87
- def labels=(v) DataTypeValidator.validate "Series.labels", [Array, SimpleTypedList], v; @labels = v; end
88
-
89
- end
90
-
91
- end
@@ -1,50 +0,0 @@
1
- module Axlsx
2
- # The Marker class defines a point in the worksheet that drawing anchors attach to.
3
- # @note The recommended way to manage markers is Worksheet#add_chart Markers are created for a two cell anchor based on the :start and :end options.
4
- # @see Worksheet#add_chart
5
- class Marker
6
-
7
- # The column this marker anchors to
8
- # @return [Integer]
9
- attr_accessor :col
10
-
11
- # The offset distance from this marker's column
12
- # @return [Integer]
13
- attr_accessor :colOff
14
-
15
- # The row this marker anchors to
16
- # @return [Integer]
17
- attr_accessor :row
18
-
19
- # The offset distance from this marker's row
20
- # @return [Integer]
21
- attr_accessor :rowOff
22
-
23
- # Creates a new Marker object
24
- # @option options [Integer] col
25
- # @option options [Integer] colOff
26
- # @option options [Integer] row
27
- # @option options [Integer] rowOff
28
- def initialize(options={})
29
- @col, @colOff, @row, @rowOff = 0, 0, 0, 0
30
- options.each do |o|
31
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
32
- end
33
- end
34
-
35
- def col=(v) Axlsx::validate_unsigned_int v; @col = v end
36
- def colOff=(v) Axlsx::validate_int v; @colOff = v end
37
- def row=(v) Axlsx::validate_unsigned_int v; @row = v end
38
- def rowOff=(v) Axlsx::validate_int v; @rowOff = v end
39
-
40
- # Serializes the gradientStop
41
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
42
- # @return [String]
43
- def to_xml(xml)
44
- [:col, :colOff, :row, :rowOff].each do |k|
45
- xml.send("xdr:#{k.to_s}", self.send(k))
46
- end
47
- end
48
- end
49
-
50
- end
@@ -1,132 +0,0 @@
1
- module Axlsx
2
-
3
- # A Chart is the class that real classes (e.g. Pie3DChart) inherit from. When you actually create a chart, you will not be creating a new instance of this class, but an instance of a subclass that defines the behavour and serialization for the chart.
4
- # @note Worksheet#add_chart is the recommended way to create charts for your worksheets.
5
- class Chart
6
-
7
- # The title object for the chart.
8
- # @return [Title]
9
- attr_reader :title
10
-
11
- # A reference to the workbook that owns this chart
12
- # @return [Workbook]
13
- attr_reader :workbook
14
-
15
- # A collection of series objects that are applied to the chart
16
- # @return [SimpleTypedList]
17
- attr_reader :series
18
-
19
- # The relation referece id for this object.
20
- # @return [String]
21
- attr_reader :rId
22
-
23
- # The index of this chart in the workbooks charts collection
24
- # @return [Integer]
25
- attr_reader :index
26
-
27
- # The part name for this chart
28
- # @return [String]
29
- attr_reader :pn
30
-
31
-
32
- # Creates a new chart object
33
- # @param [Workbook] workbook The workbook that owns this chart.
34
- # @option options [Cell, String] title
35
- def initialize(workbook, options={})
36
- @workbook=workbook
37
- @workbook.charts << self
38
- @title = Title.new options[:title]
39
- @series = SimpleTypedList.new Series
40
- end
41
-
42
-
43
- def rId
44
- "rId#{index+1}"
45
- end
46
-
47
- def index
48
- @workbook.charts.index(self)
49
- end
50
-
51
- def pn
52
- "#{CHART_PN % (index+1)}"
53
- end
54
-
55
- # Adds a new series to the chart's series collection.
56
- #
57
- # @return [Series]
58
- # @see Series
59
- def add_series(options={})
60
- Series.new(self, options)
61
- @series.last
62
- end
63
-
64
- # @raise [StandardError] This method must be overridden in subclasses.
65
- def to_xml
66
- raise "This method must be overriden in subclasses."
67
- end
68
- end
69
-
70
- # The Pie3DChart is a three dimentional piechart (who would have guessed?) that you can add to your worksheet.
71
- # @example Creating a chart
72
- # # This example creates two charts in a single sheet.
73
- # # The first uses data directly fed to the sheet, while the second references cells withing the worksheet for data.
74
- #
75
- # require "rubygems" # if that is your preferred way to manage gems!
76
- # require "axlsx"
77
- #
78
- # p = Axlsx::Package.new
79
- # ws = p.workbook.add_worksheet
80
- # ws.add_row :values => ["This is a chart with no data in the sheet"]
81
- #
82
- # chart = ws.add_chart(Axlsx::Pie3DChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
83
- # chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]
84
- #
85
- # ws.add_row :values => ["This chart uses the data below"]
86
- # title_row = ws.add_row :values => ["Least Popular Pets"]
87
- # label_row = ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"]
88
- # data_row = ws.add_row :values => ["Votes", 6, 4, 1]
89
- #
90
- # chart = ws.add_chart(Axlsx::Pie3DChart, :start_at => [0,11], :end_at =>[0,16], :title => title_row.cells.last)
91
- # chart.add_series :data => data_row.cells[(1..-1)], :labels => label_row.cells
92
- #
93
- # f = File.open('example_pie_3d_chart.xlsx', 'w')
94
- # p.serialize(f)
95
- #
96
- # @see Worksheet#add_chart
97
- # @see Worksheet#add_row
98
- # @see Chart#add_series
99
- # @see Series
100
- # @see Package#serialize
101
- class Pie3DChart < Chart
102
-
103
- # Serializes the pie chart
104
- # @return [String]
105
- def to_xml
106
- builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
107
- xml.send('c:chartSpace',:'xmlns:c' => XML_NS_C,
108
- :'xmlns:a' => XML_NS_A) {
109
- xml.send('c:chart') {
110
- @title.to_xml(xml)
111
- xml.send('c:view3D') {
112
- xml.send('c:rotX', :val=>30)
113
- xml.send('c:perspective', :val=>30)
114
- }
115
- xml.send('c:plotArea') {
116
- xml.send('c:layout')
117
- xml.send('c:pie3DChart') {
118
- xml.send('c:varyColors', :val=>1)
119
- @series.each { |ser| ser.to_xml(xml) }
120
- }
121
- }
122
- xml.send('c:legend') {
123
- xml.send('c:legendPos', :val => "r")
124
- xml.send('c:layout')
125
- }
126
- }
127
- }
128
- end
129
- builder.to_xml
130
- end
131
- end
132
- end
File without changes
File without changes
@@ -1,48 +0,0 @@
1
- module Axlsx
2
- #A CatAxis object defines a chart category axis
3
- class SerAxis < Axis
4
-
5
- # @return [Boolean]
6
- attr_accessor :tickLblSkip
7
-
8
- # @return [Boolean]
9
- attr_accessor :tickMarkSkip
10
-
11
- # Creates a new SerAxis object
12
- # @param [Integer] axId the id of this axis
13
- # @param [Integer] crossAx the id of the perpendicular axis
14
- # @option options [Symbol] axPos
15
- # @option options [Symbol] tickLblPos
16
- # @option options [Symbol] crosses
17
- # @option options [Boolean] auto
18
- # @option options [Symbol] lblAlgn
19
- # @option options [Integer] lblOffset
20
- def initialize(axId, crossAx, options={})
21
- super(axId, crossAx, options)
22
- self.auto = true
23
- self.lblAlgn = :ctr
24
- self.lblOffset = "100%"
25
- options.each do |o|
26
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
27
- end
28
- end
29
-
30
- def auto=(v) Axlsx::validate_boolean(v); @auto = v; end
31
- def lblAlgn=(v) RestrictionValidator.validate "#{self.class}.lblAlgn", [:ctr, :l, :r], v; @lblAlgn = v; end
32
- def lblOffset=(v) RegexValidator.validate "#{self.class}.lblOffset", LBL_OFFSET_REGEX, v; @lblOffset = v; end
33
-
34
- # Serializes the category axis
35
- # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
36
- # @return [String]
37
- def to_xml(xml)
38
- xml.send('c:catAx') {
39
- super(xml)
40
- xml.send('c:auto', :val=>@auto)
41
- xml.send('c:lblAlgn', :val=>@lblAlgn)
42
- xml.send('c:lblOffset', :val=>@lblOffset)
43
- }
44
- end
45
- end
46
-
47
-
48
- end