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.
Files changed (108) hide show
  1. data/CHANGELOG.md +32 -0
  2. data/README.md +34 -35
  3. data/Rakefile +19 -8
  4. data/doc/Axlsx.html +4 -4
  5. data/doc/Axlsx/App.html +1 -1
  6. data/doc/Axlsx/Axis.html +45 -19
  7. data/doc/Axlsx/Bar3DChart.html +134 -107
  8. data/doc/Axlsx/BarSeries.html +6 -64
  9. data/doc/Axlsx/Border.html +1 -1
  10. data/doc/Axlsx/BorderPr.html +1 -1
  11. data/doc/Axlsx/CatAxis.html +34 -31
  12. data/doc/Axlsx/CatAxisData.html +400 -0
  13. data/doc/Axlsx/Cell.html +1 -1
  14. data/doc/Axlsx/CellAlignment.html +1 -1
  15. data/doc/Axlsx/CellProtection.html +1 -1
  16. data/doc/Axlsx/CellStyle.html +1 -1
  17. data/doc/Axlsx/Chart.html +449 -212
  18. data/doc/Axlsx/Color.html +1 -1
  19. data/doc/Axlsx/ContentType.html +2 -2
  20. data/doc/Axlsx/Core.html +1 -1
  21. data/doc/Axlsx/DataTypeValidator.html +1 -1
  22. data/doc/Axlsx/Default.html +1 -1
  23. data/doc/Axlsx/Drawing.html +65 -91
  24. data/doc/Axlsx/Fill.html +1 -1
  25. data/doc/Axlsx/Font.html +1 -1
  26. data/doc/Axlsx/GradientFill.html +1 -1
  27. data/doc/Axlsx/GradientStop.html +1 -1
  28. data/doc/Axlsx/GraphicFrame.html +7 -5
  29. data/doc/Axlsx/Line3DChart.html +109 -28
  30. data/doc/Axlsx/LineSeries.html +17 -73
  31. data/doc/Axlsx/Marker.html +1 -1
  32. data/doc/Axlsx/NumFmt.html +1 -1
  33. data/doc/Axlsx/Override.html +1 -1
  34. data/doc/Axlsx/Package.html +1 -1
  35. data/doc/Axlsx/PatternFill.html +1 -1
  36. data/doc/Axlsx/Pie3DChart.html +118 -66
  37. data/doc/Axlsx/PieSeries.html +30 -89
  38. data/doc/Axlsx/RegexValidator.html +1 -1
  39. data/doc/Axlsx/Relationship.html +1 -1
  40. data/doc/Axlsx/Relationships.html +2 -2
  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 +52 -37
  45. data/doc/Axlsx/Series.html +25 -10
  46. data/doc/Axlsx/SeriesTitle.html +3 -2
  47. data/doc/Axlsx/SimpleTypedList.html +86 -17
  48. data/doc/Axlsx/Styles.html +1 -1
  49. data/doc/Axlsx/TableStyle.html +2 -2
  50. data/doc/Axlsx/TableStyleElement.html +1 -1
  51. data/doc/Axlsx/TableStyles.html +2 -2
  52. data/doc/Axlsx/Title.html +1 -1
  53. data/doc/Axlsx/TwoCellAnchor.html +40 -280
  54. data/doc/Axlsx/ValAxis.html +7 -8
  55. data/doc/Axlsx/ValAxisData.html +326 -0
  56. data/doc/Axlsx/View3D.html +39 -39
  57. data/doc/Axlsx/Workbook.html +1 -1
  58. data/doc/Axlsx/Worksheet.html +84 -39
  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 +30 -49
  63. data/doc/index.html +30 -49
  64. data/doc/method_list.html +448 -416
  65. data/doc/top-level-namespace.html +1 -1
  66. data/examples/#example.rb# +87 -0
  67. data/examples/example.rb +4 -1
  68. data/examples/multi_chart.xlsx +0 -0
  69. data/lib/axlsx/drawing/#bar_series.rb# +62 -0
  70. data/lib/axlsx/drawing/axis.rb +7 -6
  71. data/lib/axlsx/drawing/bar_3D_chart.rb +12 -30
  72. data/lib/axlsx/drawing/bar_series.rb +6 -35
  73. data/lib/axlsx/drawing/cat_axis.rb +8 -10
  74. data/lib/axlsx/drawing/cat_axis_data.rb +34 -0
  75. data/lib/axlsx/drawing/cat_axis_data.rb~ +28 -0
  76. data/lib/axlsx/drawing/chart.rb +48 -21
  77. data/lib/axlsx/drawing/drawing.rb +14 -12
  78. data/lib/axlsx/drawing/graphic_frame.rb +1 -0
  79. data/lib/axlsx/drawing/line_3D_chart.rb +11 -1
  80. data/lib/axlsx/drawing/line_series.rb +10 -40
  81. data/lib/axlsx/drawing/pie_3D_chart.rb +17 -34
  82. data/lib/axlsx/drawing/pie_series.rb +11 -45
  83. data/lib/axlsx/drawing/ser_axis.rb +13 -14
  84. data/lib/axlsx/drawing/series.rb +2 -3
  85. data/lib/axlsx/drawing/series_title.rb +1 -1
  86. data/lib/axlsx/drawing/two_cell_anchor.rb +10 -34
  87. data/lib/axlsx/drawing/val_axis.rb +4 -4
  88. data/lib/axlsx/drawing/val_axis_data.rb +28 -0
  89. data/lib/axlsx/drawing/val_axis_data.rb~ +29 -0
  90. data/lib/axlsx/drawing/view_3D.rb +12 -6
  91. data/lib/axlsx/util/constants.rb +0 -3
  92. data/lib/axlsx/util/simple_typed_list.rb +7 -2
  93. data/lib/axlsx/version.rb +4 -0
  94. data/lib/axlsx/workbook/worksheet/worksheet.rb +9 -1
  95. data/test/drawing/tc_axis.rb +1 -0
  96. data/test/drawing/tc_cat_axis_data.rb +18 -0
  97. data/test/drawing/tc_cat_axis_data.rb~ +32 -0
  98. data/test/drawing/tc_chart.rb +12 -0
  99. data/test/drawing/tc_line_series.rb +27 -0
  100. data/test/drawing/{tc_line_series.tc → tc_line_series.rb~} +0 -0
  101. data/test/drawing/tc_ser_axis.rb +13 -5
  102. data/test/drawing/tc_two_cell_anchor.rb +18 -17
  103. data/test/drawing/tc_val_axis.rb +5 -0
  104. data/test/drawing/tc_val_axis_data.rb +18 -0
  105. data/test/drawing/tc_val_axis_data.rb~ +18 -0
  106. data/test/drawing/tc_view_3D.rb +10 -1
  107. data/test/tc_package.rb +13 -13
  108. metadata +21 -6
@@ -94,7 +94,7 @@
94
94
  </div>
95
95
 
96
96
  <div id="footer">
97
- Generated on Tue Nov 22 00:27:58 2011 by
97
+ Generated on Wed Nov 23 12:30:35 2011 by
98
98
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
99
99
  0.7.3 (ruby-1.8.7).
100
100
  </div>
@@ -0,0 +1,87 @@
1
+ require 'rubygems'
2
+ require 'axlsx'
3
+
4
+ #A Simple Workbook
5
+ p = Axlsx::Package.new
6
+ p.workbook.add_worksheet do |sheet|
7
+ sheet.add_row ["First", "Second", "Third"]
8
+ sheet.add_row [1, 2, 3]
9
+ end
10
+ p.serialize("example1.xlsx")
11
+
12
+ #Generating A Bar Chart
13
+ p = Axlsx::Package.new
14
+ p.workbook.add_worksheet do |sheet|
15
+ sheet.add_row ["First", "Second", "Third"]
16
+ sheet.add_row [1, 2, 3]
17
+ sheet.add_chart(Axlsx::Bar3DChart, :start_at => [0,2], :end_at => [5, 15], :title=>"example 2: Chart") do |chart|
18
+ chart.add_series :data=>sheet.rows.last.cells, :labels=> sheet.rows.first.cells
19
+ end
20
+ end
21
+ p.serialize("example2.xlsx")
22
+
23
+ #Generating A Pie Chart
24
+ p = Axlsx::Package.new
25
+ p.workbook.add_worksheet do |sheet|
26
+ sheet.add_row ["First", "Second", "Third"]
27
+ sheet.add_row [1, 2, 3]
28
+ sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,2], :end_at => [5, 15], :title=>"example 3: Pie Chart") do |chart|
29
+ chart.add_series :data=>sheet.rows.last.cells, :labels=> sheet.rows.first.cells
30
+ end
31
+ end
32
+ p.serialize("example3.xlsx")
33
+
34
+
35
+ #Using Custom Styles
36
+
37
+ p = Axlsx::Package.new
38
+ wb = p.workbook
39
+ black_cell = wb.styles.add_style :bg_color => "FF000000", :fg_color => "FFFFFFFF", :sz=>14, :alignment => { :horizontal=> :center }
40
+ blue_cell = wb.styles.add_style :bg_color => "FF0000FF", :fg_color => "FFFFFFFF", :sz=>14, :alignment => { :horizontal=> :center }
41
+ wb.add_worksheet do |sheet|
42
+ sheet.add_row ["Text Autowidth", "Second", "Third"], :style => [black_cell, blue_cell, black_cell]
43
+ sheet.add_row [1, 2, 3], :style => Axlsx::STYLE_THIN_BORDER
44
+ end
45
+ p.serialize("example4.xlsx")
46
+
47
+ #Using Custom Formatting and date1904
48
+
49
+ p = Axlsx::Package.new
50
+ wb = p.workbook
51
+ date = wb.styles.add_style :format_code=>"yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER
52
+ padded = wb.styles.add_style :format_code=>"00#", :border => Axlsx::STYLE_THIN_BORDER
53
+ percent = wb.styles.add_style :format_code=>"0%", :border => Axlsx::STYLE_THIN_BORDER
54
+ wb.date1904 = true # required for generation on mac
55
+ wb.add_worksheet do |sheet|
56
+ sheet.add_row ["Custom Formatted Date", "Percent Formatted Float", "Padded Numbers"], :style => Axlsx::STYLE_THIN_BORDER
57
+ sheet.add_row [Time.now, 0.2, 32], :style => [date, percent, padded]
58
+ end
59
+ p.serialize("example5.xlsx")
60
+
61
+ #Validation
62
+
63
+ p = Axlsx::Package.new
64
+ p.workbook.add_worksheet do |sheet|
65
+ sheet.add_row ["First", "Second", "Third"]
66
+ sheet.add_row [1, 2, 3]
67
+ end
68
+
69
+ p.validate.each do |error|
70
+ puts error.inspect
71
+ end
72
+
73
+ #Generating A Line Chart
74
+
75
+ p = Axlsx::Package.new
76
+ p.workbook.add_worksheet do |sheet|
77
+ sheet.add_row ["First", 1, 5, 7, 9]
78
+ sheet.add_row ["Second", 5, 2, 14, 9]
79
+ sheet.add_chart(Axlsx::Line3DChart, :title=>"example 6: Line Chart") do |chart|
80
+ chart.start_at 0, 2
81
+ chart.end_at 10, 15
82
+ chart.add_series :data=>sheet.rows.first.cells[(1..-1)], :title=> sheet.rows.first.cells.first
83
+ chart.add_series :data=>sheet.rows.last.cells[(1..-1)], :title=> sheet.rows.last.cells.first
84
+ end
85
+
86
+ end
87
+ p.serialize("example6.xlsx")
@@ -59,6 +59,7 @@
59
59
  p.serialize("example5.xlsx")
60
60
 
61
61
  #Validation
62
+
62
63
  p = Axlsx::Package.new
63
64
  p.workbook.add_worksheet do |sheet|
64
65
  sheet.add_row ["First", "Second", "Third"]
@@ -75,7 +76,9 @@
75
76
  p.workbook.add_worksheet do |sheet|
76
77
  sheet.add_row ["First", 1, 5, 7, 9]
77
78
  sheet.add_row ["Second", 5, 2, 14, 9]
78
- sheet.add_chart(Axlsx::Line3DChart, :start_at => [0,2], :end_at => [10, 15], :title=>"example 6: Line Chart") do |chart|
79
+ sheet.add_chart(Axlsx::Line3DChart, :title=>"example 6: Line Chart") do |chart|
80
+ chart.start_at 0, 2
81
+ chart.end_at 10, 15
79
82
  chart.add_series :data=>sheet.rows.first.cells[(1..-1)], :title=> sheet.rows.first.cells.first
80
83
  chart.add_series :data=>sheet.rows.last.cells[(1..-1)], :title=> sheet.rows.last.cells.first
81
84
  end
Binary file
@@ -0,0 +1,62 @@
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.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
32
+ self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
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
+ @labels.to_xml(xml) unless @labels.nil?
46
+ @data.to_xml(xml) unless @data.nil?
47
+ xml.send('c:shape', :val=>@shape)
48
+ end
49
+ end
50
+
51
+
52
+ private
53
+
54
+ # assigns the data for this series
55
+ def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
56
+
57
+ # assigns the labels for this series
58
+ def labels=(v) DataTypeValidator.validate "Series.labels", [SimpleTypedList], v; @labels = v; end
59
+
60
+ end
61
+
62
+ end
@@ -1,9 +1,8 @@
1
1
  module Axlsx
2
- # the access class defines common properties and values for chart axis
2
+ # the access class defines common properties and values for a chart axis.
3
3
  class Axis
4
4
 
5
-
6
- # the id of the axis
5
+ # the id of the axis.
7
6
  # @return [Integer]
8
7
  attr_reader :axId
9
8
 
@@ -12,6 +11,7 @@ module Axlsx
12
11
  attr_reader :crossAx
13
12
 
14
13
  # The scaling of the axis
14
+ # @see Scaling
15
15
  # @return [Scaling]
16
16
  attr_reader :scaling
17
17
 
@@ -25,8 +25,8 @@ module Axlsx
25
25
  # @return [Symbol]
26
26
  attr_accessor :tickLblPos
27
27
 
28
-
29
28
  # The number format format code for this axis
29
+ # default :General
30
30
  # @return [String]
31
31
  attr_accessor :format_code
32
32
 
@@ -41,15 +41,16 @@ module Axlsx
41
41
  # @option options [Symbol] axPos
42
42
  # @option options [Symbol] crosses
43
43
  # @option options [Symbol] tickLblPos
44
+ # @raise [ArgumentError] If axId or crossAx are not unsigned integers
44
45
  def initialize(axId, crossAx, options={})
45
46
  Axlsx::validate_unsigned_int(axId)
46
47
  Axlsx::validate_unsigned_int(crossAx)
47
48
  @axId = axId
48
49
  @crossAx = crossAx
50
+ @scaling = Scaling.new(:orientation=>:minMax)
49
51
  self.axPos = :l
50
52
  self.tickLblPos = :nextTo
51
- @scaling = Scaling.new(:orientation=>:minMax)
52
- @formatCode = ""
53
+ self.format_code = "General"
53
54
  self.crosses = :autoZero
54
55
  options.each do |o|
55
56
  self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
@@ -1,43 +1,17 @@
1
1
  module Axlsx
2
2
 
3
3
  # The Bar3DChart 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::Bar3DChart, :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
4
  # @see Worksheet#add_chart
30
- # @see Worksheet#add_row
31
5
  # @see Chart#add_series
32
- # @see Series
33
6
  # @see Package#serialize
7
+ # @see README for an example
34
8
  class Bar3DChart < Chart
35
9
 
36
10
  # the category axis
37
11
  # @return [CatAxis]
38
12
  attr_reader :catAxis
39
13
 
40
- # the category axis
14
+ # the valueaxis
41
15
  # @return [ValAxis]
42
16
  attr_reader :valAxis
43
17
 
@@ -60,7 +34,7 @@ module Axlsx
60
34
  attr_accessor :grouping
61
35
 
62
36
  # The shabe of the bars or columns
63
- # must be one of [:percentStacked, :clustered, :standard, :stacked]
37
+ # must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]
64
38
  # @return [Symbol]
65
39
  attr_accessor :shape
66
40
 
@@ -76,6 +50,14 @@ module Axlsx
76
50
  # @option options [String] gapWidth
77
51
  # @option options [String] gapDepth
78
52
  # @option options [Symbol] shape
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
79
61
  def initialize(frame, options={})
80
62
  @barDir = :bar
81
63
  @grouping = :clustered
@@ -83,9 +65,9 @@ module Axlsx
83
65
  @valAxId = rand(8 ** 8)
84
66
  @catAxis = CatAxis.new(@catAxId, @valAxId)
85
67
  @valAxis = ValAxis.new(@valAxId, @catAxId)
86
- @view3D = View3D.new(:rAngAx=>1)
87
68
  super(frame, options)
88
69
  @series_type = BarSeries
70
+ @view3D = View3D.new({:rAngAx=>1}.merge(options))
89
71
  end
90
72
 
91
73
  def barDir=(v)
@@ -28,8 +28,8 @@ module Axlsx
28
28
  def initialize(chart, options={})
29
29
  @shape = :box
30
30
  super(chart, options)
31
- self.data = options[:data] || []
32
- self.labels = options[:labels] || []
31
+ self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
32
+ self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
33
33
  end
34
34
 
35
35
  def shape=(v)
@@ -42,37 +42,8 @@ module Axlsx
42
42
  # @return [String]
43
43
  def to_xml(xml)
44
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
- }
45
+ @labels.to_xml(xml) unless @labels.nil?
46
+ @data.to_xml(xml) unless @data.nil?
76
47
  xml.send('c:shape', :val=>@shape)
77
48
  end
78
49
  end
@@ -82,10 +53,10 @@ module Axlsx
82
53
 
83
54
 
84
55
  # assigns the data for this series
85
- def data=(v) DataTypeValidator.validate "Series.data", [Array, SimpleTypedList], v; @data = v; end
56
+ def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
86
57
 
87
58
  # assigns the labels for this series
88
- def labels=(v) DataTypeValidator.validate "Series.labels", [Array, SimpleTypedList], v; @labels = v; end
59
+ def labels=(v) DataTypeValidator.validate "Series.labels", [SimpleTypedList], v; @labels = v; end
89
60
 
90
61
  end
91
62
 
@@ -1,6 +1,7 @@
1
1
  module Axlsx
2
2
  #A CatAxis object defines a chart category axis
3
3
  class CatAxis < Axis
4
+
4
5
  # From the docs: This element specifies that this axis is a date or text axis based on the data that is used for the axis labels, not a specific choice.
5
6
  # @return [Boolean]
6
7
  attr_accessor :auto
@@ -18,23 +19,20 @@ module Axlsx
18
19
  # regex for validating label offset
19
20
  LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)%/
20
21
 
21
- # Creates a new CatAxis object
22
- # @param [Integer] axId the id of this axis
23
- # @param [Integer] crossAx the id of the perpendicular axis
24
- # @option options [Symbol] axPos
25
- # @option options [Symbol] tickLblPos
26
- # @option options [Symbol] crosses
22
+ # Creates a new CatAxis object
23
+ # @param [Integer] axId the id of this axis. Inherited
24
+ # @param [Integer] crossAx the id of the perpendicular axis. Inherited
25
+ # @option options [Symbol] axPos. Inherited
26
+ # @option options [Symbol] tickLblPos. Inherited
27
+ # @option options [Symbol] crosses. Inherited
27
28
  # @option options [Boolean] auto
28
29
  # @option options [Symbol] lblAlgn
29
30
  # @option options [Integer] lblOffset
30
31
  def initialize(axId, crossAx, options={})
31
- super(axId, crossAx, options)
32
32
  self.auto = true
33
33
  self.lblAlgn = :ctr
34
34
  self.lblOffset = "100%"
35
- options.each do |o|
36
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
37
- end
35
+ super(axId, crossAx, options)
38
36
  end
39
37
 
40
38
  def auto=(v) Axlsx::validate_boolean(v); @auto = v; end
@@ -0,0 +1,34 @@
1
+ module Axlsx
2
+ # The CatAxisData class serializes the category axis data for a chart
3
+ class CatAxisData < SimpleTypedList
4
+
5
+ # Create a new CatAxisData object
6
+ # @param [Array, SimpleTypedList] data the data for this category axis. This can be a simple array or a simple typed list of cells.
7
+ def initialize(data=[])
8
+ super Object
9
+ @list.concat data if data.is_a?(Array)
10
+ end
11
+
12
+ # Serializes the category axis data
13
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
14
+ # @return [String]
15
+ def to_xml(xml)
16
+ xml.send('c:cat') {
17
+ xml.send('c:strRef') {
18
+ xml.send('c:f', Axlsx::cell_range(@list))
19
+ xml.send('c:strCache') {
20
+ xml.send('c:ptCount', :val=>size)
21
+ each_with_index do |item, index|
22
+ v = item.is_a?(Cell) ? item.value : item
23
+ xml.send('c:pt', :idx=>index) {
24
+ xml.send('c:v', v)
25
+ }
26
+ end
27
+ }
28
+ }
29
+ }
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,28 @@
1
+ module Axlsx
2
+
3
+ class CatAxisData < SimpleTypedList
4
+ def initialize(data=[])
5
+ super Object
6
+ @list.concat data if data.is_a?(Array)
7
+ end
8
+
9
+ def to_xml(xml)
10
+ xml.send('c:cat') {
11
+ xml.send('c:strRef') {
12
+ xml.send('c:f', Axlsx::cell_range(@list))
13
+ xml.send('c:strCache') {
14
+ xml.send('c:ptCount', :val=>size)
15
+ each_with_index do |item, index|
16
+ v = item.is_a?(Cell) ? item.value : item
17
+ xml.send('c:pt', :idx=>index) {
18
+ xml.send('c:v', v)
19
+ }
20
+ end
21
+ }
22
+ }
23
+ }
24
+ end
25
+
26
+ end
27
+
28
+ end