axlsx 1.1.7 → 1.2.0

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 (164) hide show
  1. data/.yardopts +5 -2
  2. data/CHANGELOG.md +39 -0
  3. data/README.md +84 -46
  4. data/Rakefile +3 -2
  5. data/examples/basic_charts.rb +8 -0
  6. data/examples/chart_colors.rb +18 -3
  7. data/examples/example.rb +106 -46
  8. data/examples/example.xlsx +0 -0
  9. data/examples/example_streamed.xlsx +0 -0
  10. data/examples/extractive.pdf +0 -0
  11. data/examples/no-use_autowidth.xlsx +0 -0
  12. data/examples/scraping_html.rb +91 -0
  13. data/examples/shared_strings_example.xlsx +0 -0
  14. data/lib/axlsx/content_type/content_type.rb +2 -0
  15. data/lib/axlsx/content_type/default.rb +21 -12
  16. data/lib/axlsx/content_type/override.rb +22 -11
  17. data/lib/axlsx/doc_props/app.rb +36 -32
  18. data/lib/axlsx/doc_props/core.rb +9 -5
  19. data/lib/axlsx/drawing/ax_data_source.rb +7 -6
  20. data/lib/axlsx/drawing/axis.rb +48 -27
  21. data/lib/axlsx/drawing/bar_3D_chart.rb +49 -45
  22. data/lib/axlsx/drawing/bar_series.rb +1 -0
  23. data/lib/axlsx/drawing/cat_axis.rb +42 -38
  24. data/lib/axlsx/drawing/chart.rb +63 -52
  25. data/lib/axlsx/drawing/d_lbls.rb +100 -0
  26. data/lib/axlsx/drawing/drawing.rb +7 -4
  27. data/lib/axlsx/drawing/line_3D_chart.rb +3 -10
  28. data/lib/axlsx/drawing/num_data_source.rb +1 -1
  29. data/lib/axlsx/drawing/pie_3D_chart.rb +10 -7
  30. data/lib/axlsx/drawing/scatter_chart.rb +2 -8
  31. data/lib/axlsx/drawing/two_cell_anchor.rb +41 -9
  32. data/lib/axlsx/drawing/view_3D.rb +41 -31
  33. data/lib/axlsx/drawing/vml_drawing.rb +1 -1
  34. data/lib/axlsx/package.rb +11 -11
  35. data/lib/axlsx/rels/relationship.rb +3 -3
  36. data/lib/axlsx/stylesheet/styles.rb +1 -1
  37. data/lib/axlsx/util/constants.rb +4 -0
  38. data/lib/axlsx/util/simple_typed_list.rb +15 -8
  39. data/lib/axlsx/util/validators.rb +2 -2
  40. data/lib/axlsx/version.rb +2 -7
  41. data/lib/axlsx/workbook/defined_name.rb +174 -0
  42. data/lib/axlsx/workbook/defined_names.rb +21 -0
  43. data/lib/axlsx/workbook/workbook.rb +39 -14
  44. data/lib/axlsx/workbook/worksheet/auto_filter.rb +34 -0
  45. data/lib/axlsx/workbook/worksheet/cell.rb +25 -2
  46. data/lib/axlsx/workbook/worksheet/col.rb +15 -0
  47. data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
  48. data/lib/axlsx/workbook/worksheet/comments.rb +8 -0
  49. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
  50. data/lib/axlsx/workbook/worksheet/data_bar.rb +1 -1
  51. data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
  52. data/lib/axlsx/workbook/worksheet/dimension.rb +65 -0
  53. data/lib/axlsx/workbook/worksheet/merged_cells.rb +35 -0
  54. data/lib/axlsx/workbook/worksheet/page_setup.rb +9 -0
  55. data/lib/axlsx/workbook/worksheet/protected_range.rb +46 -0
  56. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
  57. data/lib/axlsx/workbook/worksheet/row.rb +1 -1
  58. data/lib/axlsx/workbook/worksheet/sheet_data.rb +25 -0
  59. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +24 -0
  60. data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
  61. data/lib/axlsx/workbook/worksheet/worksheet.rb +300 -293
  62. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +57 -0
  63. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +64 -0
  64. data/lib/axlsx.rb +21 -14
  65. data/test/content_type/tc_content_type.rb +1 -6
  66. data/test/doc_props/tc_core.rb +1 -1
  67. data/test/drawing/tc_axis.rb +8 -0
  68. data/test/drawing/tc_bar_3D_chart.rb +12 -12
  69. data/test/drawing/tc_bar_series.rb +1 -2
  70. data/test/drawing/tc_chart.rb +8 -6
  71. data/test/drawing/tc_d_lbls.rb +47 -0
  72. data/test/drawing/tc_drawing.rb +5 -4
  73. data/test/drawing/tc_line_series.rb +1 -1
  74. data/test/drawing/tc_pie_3D_chart.rb +4 -8
  75. data/test/drawing/tc_pie_series.rb +1 -1
  76. data/test/drawing/tc_scatter_series.rb +1 -1
  77. data/test/drawing/tc_series.rb +1 -1
  78. data/test/drawing/tc_view_3D.rb +18 -18
  79. data/test/tc_package.rb +18 -1
  80. data/test/workbook/tc_defined_name.rb +41 -0
  81. data/test/workbook/tc_workbook.rb +5 -3
  82. data/test/workbook/worksheet/table/tc_table.rb +0 -8
  83. data/test/workbook/worksheet/tc_cell.rb +2 -4
  84. data/test/workbook/worksheet/tc_page_setup.rb +20 -3
  85. data/test/workbook/worksheet/tc_protected_range.rb +17 -0
  86. data/test/workbook/worksheet/tc_row.rb +2 -2
  87. data/test/workbook/worksheet/tc_selection.rb +1 -1
  88. data/test/workbook/worksheet/tc_worksheet.rb +53 -34
  89. metadata +93 -101
  90. data/examples/axis-titles.xlsx +0 -0
  91. data/examples/basic_charts.xlsx +0 -0
  92. data/examples/chart_colors.xlsx +0 -0
  93. data/examples/charts.xlsx +0 -0
  94. data/examples/conditional_formatting/getting_barred.xlsx +0 -0
  95. data/examples/doc/_index.html +0 -84
  96. data/examples/doc/class_list.html +0 -47
  97. data/examples/doc/css/common.css +0 -1
  98. data/examples/doc/css/full_list.css +0 -55
  99. data/examples/doc/css/style.css +0 -322
  100. data/examples/doc/file_list.html +0 -46
  101. data/examples/doc/frames.html +0 -13
  102. data/examples/doc/index.html +0 -84
  103. data/examples/doc/js/app.js +0 -205
  104. data/examples/doc/js/full_list.js +0 -173
  105. data/examples/doc/js/jquery.js +0 -16
  106. data/examples/doc/method_list.html +0 -46
  107. data/examples/doc/top-level-namespace.html +0 -95
  108. data/examples/examples_saved.xlsx +0 -0
  109. data/examples/extractive.xlsx +0 -0
  110. data/examples/fish.xlsx +0 -0
  111. data/examples/pareto.rb +0 -28
  112. data/examples/pareto.xlsx +0 -0
  113. data/examples/pie_chart_excel.xlsx +0 -0
  114. data/examples/pie_chart_saved.xlsx +0 -0
  115. data/examples/sheet_protection.xlsx +0 -0
  116. data/examples/sheet_view.xlsx +0 -0
  117. data/examples/two_cell_anchor_image.xlsx +0 -0
  118. data/examples/~$example.xlsx +0 -0
  119. data/lib/axlsx/drawing/ax_data_source.rb~ +0 -55
  120. data/lib/axlsx/drawing/data_source.rb~ +0 -51
  121. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  122. data/lib/axlsx/drawing/hyperlink.rb~ +0 -64
  123. data/lib/axlsx/drawing/num_data.rb~ +0 -51
  124. data/lib/axlsx/drawing/num_data_source.rb~ +0 -54
  125. data/lib/axlsx/drawing/num_val.rb~ +0 -40
  126. data/lib/axlsx/drawing/picture_locking.rb~ +0 -36
  127. data/lib/axlsx/drawing/ref.rb~ +0 -41
  128. data/lib/axlsx/drawing/str_data.rb~ +0 -58
  129. data/lib/axlsx/drawing/str_val.rb~ +0 -35
  130. data/lib/axlsx/drawing/vml_drawing.rb~ +0 -6
  131. data/lib/axlsx/drawing/vml_shape.rb~ +0 -61
  132. data/lib/axlsx/util/cbf.rb +0 -333
  133. data/lib/axlsx/util/cfb.rb~ +0 -201
  134. data/lib/axlsx/util/font_tables.rb~ +0 -0
  135. data/lib/axlsx/util/ms_off_crypto.rb +0 -189
  136. data/lib/axlsx/util/ms_off_crypto.rb~ +0 -3
  137. data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
  138. data/lib/axlsx/util/parser.rb~ +0 -6
  139. data/lib/axlsx/util/storage.rb~ +0 -0
  140. data/lib/axlsx/workbook/shared_strings_table.rb~ +0 -69
  141. data/lib/axlsx/workbook/worksheet/cfvo.rb~ +0 -0
  142. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  143. data/lib/axlsx/workbook/worksheet/color_scale.rb~ +0 -46
  144. data/lib/axlsx/workbook/worksheet/comment.rb~ +0 -91
  145. data/lib/axlsx/workbook/worksheet/comments.rb~ +0 -86
  146. data/lib/axlsx/workbook/worksheet/data_bar.rb~ +0 -0
  147. data/lib/axlsx/workbook/worksheet/icon_set.rb~ +0 -95
  148. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  149. data/lib/axlsx/workbook/worksheet/table.rb~ +0 -97
  150. data/lib/schema/dc.xsd~ +0 -118
  151. data/lib/schema/dcterms.xsd~ +0 -331
  152. data/lib/schema/opc-coreProperties.xsd~ +0 -50
  153. data/test/drawing/tc_data_source.rb~ +0 -30
  154. data/test/drawing/tc_num_data.rb~ +0 -35
  155. data/test/drawing/tc_num_val.rb~ +0 -29
  156. data/test/drawing/tc_str_data.rb~ +0 -30
  157. data/test/drawing/tc_str_val.rb~ +0 -26
  158. data/test/drawing/tc_vml_drawing.rb~ +0 -0
  159. data/test/workbook/worksheet/table/tc_table.rb~ +0 -72
  160. data/test/workbook/worksheet/tc_cfvo.rb~ +0 -20
  161. data/test/workbook/worksheet/tc_col.rb~ +0 -10
  162. data/test/workbook/worksheet/tc_color_scale.rb~ +0 -0
  163. data/test/workbook/worksheet/tc_data_bar.rb~ +0 -0
  164. data/test/workbook/worksheet/tc_icon_set.rb~ +0 -0
@@ -1,8 +1,23 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+
3
4
  # An default content part. These parts are automatically created by for you based on the content of your package.
4
5
  class Default
5
6
 
7
+ #Creates a new Default object
8
+ # @option options [String] extension
9
+ # @option options [String] content_type
10
+ # @raise [ArgumentError] An argument error is raised if both extension and content_type are not specified.
11
+ def initialize(options={})
12
+ raise ArgumentError, INVALID_ARGUMENTS unless validate_options(options)
13
+ options.each do |name, value|
14
+ self.send("#{name}=", value) if self.respond_to? "#{name}="
15
+ end
16
+ end
17
+
18
+ # Error string for option validation
19
+ INVALID_ARGUMENTS = "extension and content_type are required"
20
+
6
21
  # The extension of the content type.
7
22
  # @return [String]
8
23
  attr_reader :extension
@@ -13,18 +28,6 @@ module Axlsx
13
28
  attr_reader :content_type
14
29
  alias :ContentType :content_type
15
30
 
16
- #Creates a new Default object
17
- # @option options [String] extension
18
- # @option options [String] content_type
19
- # @raise [ArgumentError] An argument error is raised if both extension and content_type are not specified.
20
- def initialize(options={})
21
- raise ArgumentError, "extension and content_type are required" unless (options[:Extension] || options[:extension]) && (options[:content_type] || options[:ContentType])
22
- options.each do |o|
23
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
24
- end
25
- end
26
-
27
-
28
31
  # Sets the file extension for this content type.
29
32
  def extension=(v) Axlsx::validate_string v; @extension = v end
30
33
  alias :Extension= :extension=
@@ -43,5 +46,11 @@ module Axlsx
43
46
  str << '/>'
44
47
  end
45
48
 
49
+ private
50
+ def validate_options(options)
51
+ (options[:Extension] || options[:extension]) && (options[:content_type] || options[:ContentType])
52
+ end
53
+
46
54
  end
55
+
47
56
  end
@@ -1,8 +1,23 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+
3
4
  # An override content part. These parts are automatically created by for you based on the content of your package.
4
5
  class Override
5
6
 
7
+ #Creates a new Override object
8
+ # @option options [String] PartName
9
+ # @option options [String] ContentType
10
+ # @raise [ArgumentError] An argument error is raised if both PartName and ContentType are not specified.
11
+ def initialize(options={})
12
+ raise ArgumentError, INVALID_ARGUMENTS unless validate_options(options)
13
+ options.each do |name, value|
14
+ self.send("#{name}=", value) if self.respond_to? "#{name}="
15
+ end
16
+ end
17
+
18
+ # Error message for invalid options
19
+ INVALID_ARGUMENTS = 'part_name and content_type are required'
20
+
6
21
  # The type of content.
7
22
  # @return [String]
8
23
  attr_reader :content_type
@@ -13,17 +28,6 @@ module Axlsx
13
28
  attr_reader :part_name
14
29
  alias :PartName :part_name
15
30
 
16
- #Creates a new Override object
17
- # @option options [String] PartName
18
- # @option options [String] ContentType
19
- # @raise [ArgumentError] An argument error is raised if both PartName and ContentType are not specified.
20
- def initialize(options={})
21
- raise ArgumentError, "PartName and ContentType are required" unless (options[:PartName] || options[:part_name]) && (options[:ContentType] || options[:content_type])
22
- options.each do |o|
23
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
24
- end
25
- end
26
-
27
31
  # The name and location of the part.
28
32
  def part_name=(v) Axlsx::validate_string v; @part_name = v end
29
33
  alias :PartName= :part_name=
@@ -42,5 +46,12 @@ module Axlsx
42
46
  str << '/>'
43
47
  end
44
48
 
49
+ private
50
+
51
+ def validate_options(options)
52
+ (options[:PartName] || options[:part_name]) && (options[:ContentType] || options[:content_type])
53
+ end
54
+
45
55
  end
56
+
46
57
  end
@@ -1,5 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+
3
4
  # App represents the app.xml document. The attributes for this object are primarily managed by the application the end user uses to edit the document. None of the attributes are required to serialize a valid xlsx object.
4
5
  # @see shared-documentPropertiesExtended.xsd
5
6
  # @note Support is not implemented for the following complex types:
@@ -10,6 +11,35 @@ module Axlsx
10
11
  # DigSig (DigSigBlob)
11
12
  class App
12
13
 
14
+ # Creates an App object
15
+ # @option options [String] template
16
+ # @option options [String] manager
17
+ # @option options [Integer] pages
18
+ # @option options [Integer] words
19
+ # @option options [Integer] characters
20
+ # @option options [String] presentation_format
21
+ # @option options [Integer] lines
22
+ # @option options [Integer] paragraphs
23
+ # @option options [Integer] slides
24
+ # @option options [Integer] notes
25
+ # @option options [Integer] total_time
26
+ # @option options [Integer] hidden_slides
27
+ # @option options [Integer] m_m_clips
28
+ # @option options [Boolean] scale_crop
29
+ # @option options [Boolean] links_up_to_date
30
+ # @option options [Integer] characters_with_spaces
31
+ # @option options [Boolean] share_doc
32
+ # @option options [String] hyperlink_base
33
+ # @option options [String] hyperlinks_changed
34
+ # @option options [String] application
35
+ # @option options [String] app_version
36
+ # @option options [Integer] doc_security
37
+ def initialize(options={})
38
+ options.each do |name, value|
39
+ self.send("#{name}=", value) if self.respond_to? "#{name}="
40
+ end
41
+ end
42
+
13
43
  # @return [String] The name of the document template.
14
44
  attr_reader :template
15
45
  alias :Template :template
@@ -89,7 +119,7 @@ module Axlsx
89
119
  # @return [Boolean] Indicates that the hyper links in the document have been changed.
90
120
  attr_reader :hyperlinks_changed
91
121
  alias :HyperlinksChanged :hyperlinks_changed
92
-
122
+
93
123
  # @return [String] The name of the application
94
124
  attr_reader :application
95
125
  alias :Applicatoin :application
@@ -102,44 +132,17 @@ module Axlsx
102
132
  attr_reader :doc_security
103
133
  alias :DocSecurity :doc_security
104
134
 
105
- # Creates an App object
106
- # @option options [String] template
107
- # @option options [String] manager
108
- # @option options [Integer] pages
109
- # @option options [Integer] words
110
- # @option options [Integer] characters
111
- # @option options [String] presentation_format
112
- # @option options [Integer] lines
113
- # @option options [Integer] paragraphs
114
- # @option options [Integer] slides
115
- # @option options [Integer] notes
116
- # @option options [Integer] total_time
117
- # @option options [Integer] hidden_slides
118
- # @option options [Integer] m_m_clips
119
- # @option options [Boolean] scale_crop
120
- # @option options [Boolean] links_up_to_date
121
- # @option options [Integer] characters_with_spaces
122
- # @option options [Boolean] share_doc
123
- # @option options [String] hyperlink_base
124
- # @option options [String] hyperlinks_changed
125
- # @option options [String] application
126
- # @option options [String] app_version
127
- # @option options [Integer] doc_security
128
- def initialize(options={})
129
- options.each do |o|
130
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
131
- end
132
- end
133
-
134
135
  # Sets the template property of your app.xml file
135
136
  def template=(v) Axlsx::validate_string v; @template = v; end
137
+ alias :Template :template
136
138
 
137
139
  # Sets the manager property of your app.xml file
138
140
  def manager=(v) Axlsx::validate_string v; @manager = v; end
141
+ alias :Manager :manager
139
142
 
140
143
  # Sets the company property of your app.xml file
141
144
  def company=(v) Axlsx::validate_string v; @company = v; end
142
-
145
+ alias :Company :company
143
146
  # Sets the pages property of your app.xml file
144
147
  def pages=(v) Axlsx::validate_int v; @pages = v; end
145
148
 
@@ -214,7 +217,7 @@ module Axlsx
214
217
  # Sets the doc_security property of your app.xml file
215
218
  def doc_security=(v) Axlsx::validate_int v; @doc_security = v; end
216
219
  alias :DocSecurity= :doc_security=
217
-
220
+
218
221
  # Serialize the app.xml document
219
222
  # @return [String]
220
223
  def to_xml_string(str = '')
@@ -225,4 +228,5 @@ module Axlsx
225
228
  end
226
229
 
227
230
  end
231
+
228
232
  end
@@ -1,19 +1,21 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+
3
4
  # The core object for the package.
4
5
  # @note Packages manage their own core object.
5
6
  # @see Package#core
6
7
  class Core
7
- # The author of the document. By default this is 'axlsx'
8
- # @return [String]
9
- attr_accessor :creator
10
-
8
+
11
9
  # Creates a new Core object.
12
10
  # @option options [String] creator
13
11
  def initialize(options={})
14
12
  @creator = options[:creator] || 'axlsx'
15
13
  end
16
14
 
15
+ # The author of the document. By default this is 'axlsx'
16
+ # @return [String]
17
+ attr_accessor :creator
18
+
17
19
  # serializes the core.xml document
18
20
  # @return [String]
19
21
  def to_xml_string(str = '')
@@ -22,9 +24,11 @@ module Axlsx
22
24
  str << 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" '
23
25
  str << 'xmlns:xsi="' << CORE_NS_XSI << '">'
24
26
  str << '<dc:creator>' << self.creator << '</dc:creator>'
25
- str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << Time.now.strftime('%Y-%m-%dT%H:%M:%S') << '</dcterms:created>'
27
+ str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << Time.now.strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>'
26
28
  str << '<cp:revision>0</cp:revision>'
27
29
  str << '</cp:coreProperties>'
28
30
  end
31
+
29
32
  end
33
+
30
34
  end
@@ -1,14 +1,9 @@
1
1
  module Axlsx
2
+
2
3
  # An axis data source that can contain referenced or literal strings or numbers
3
4
  # @note only string data types are supported - mainly because we have not implemented a chart type that requires a numerical axis value
4
5
  class AxDataSource < NumDataSource
5
6
 
6
- # allowed element tag names
7
- # @return [Array]
8
- def self.allowed_tag_names
9
- [:xVal, :cat]
10
- end
11
-
12
7
  # creates a new NumDataSource object
13
8
  # @option options [Array] data An array of Cells or Numeric objects
14
9
  # @option options [Symbol] tag_name see tag_name
@@ -19,6 +14,12 @@ module Axlsx
19
14
  super(options)
20
15
  end
21
16
 
17
+ # allowed element tag names for serialization
18
+ # @return [Array]
19
+ def self.allowed_tag_names
20
+ [:xVal, :cat]
21
+ end
22
+
22
23
  end
23
24
 
24
25
  end
@@ -1,8 +1,40 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
- # the access class defines common properties and values for a chart axis.
3
+
4
+ # the access class defines common properties and values for a chart axis.
4
5
  class Axis
5
6
 
7
+ # Creates an Axis object
8
+ # @param [Integer] ax_id the id of this axis
9
+ # @param [Integer] cross_ax the id of the perpendicular axis
10
+ # @option options [Symbol] ax_pos
11
+ # @option options [Symbol] crosses
12
+ # @option options [Symbol] tick_lbl_pos
13
+ # @raise [ArgumentError] If axi_id or cross_ax are not unsigned integers
14
+ def initialize(ax_id, cross_ax, options={})
15
+ Axlsx::validate_unsigned_int(ax_id)
16
+ Axlsx::validate_unsigned_int(cross_ax)
17
+ @ax_id = ax_id
18
+ @cross_ax = cross_ax
19
+ @format_code = "General"
20
+ @delete = @label_rotation = 0
21
+ @scaling = Scaling.new(:orientation=>:minMax)
22
+ @title = @color = nil
23
+ self.ax_pos = :b
24
+ self.tick_lbl_pos = :nextTo
25
+ self.format_code = "General"
26
+ self.crosses = :autoZero
27
+ self.gridlines = true
28
+ options.each do |name, value|
29
+ self.send("#{name}=", value) if self.respond_to? "#{name}="
30
+ end
31
+ end
32
+
33
+ # the fill color to use in the axis shape properties. This should be a 6 character long hex string
34
+ # e.g. FF0000 for red
35
+ # @return [String]
36
+ attr_reader :color
37
+
6
38
  # the id of the axis.
7
39
  # @return [Integer]
8
40
  attr_reader :ax_id
@@ -55,30 +87,12 @@ module Axlsx
55
87
  # the title for the axis. This can be a cell or a fixed string.
56
88
  attr_reader :title
57
89
 
58
- # Creates an Axis object
59
- # @param [Integer] ax_id the id of this axis
60
- # @param [Integer] cross_ax the id of the perpendicular axis
61
- # @option options [Symbol] ax_pos
62
- # @option options [Symbol] crosses
63
- # @option options [Symbol] tick_lbl_pos
64
- # @raise [ArgumentError] If axi_id or cross_ax are not unsigned integers
65
- def initialize(ax_id, cross_ax, options={})
66
- Axlsx::validate_unsigned_int(ax_id)
67
- Axlsx::validate_unsigned_int(cross_ax)
68
- @ax_id = ax_id
69
- @cross_ax = cross_ax
70
- @format_code = "General"
71
- @delete = @label_rotation = 0
72
- @scaling = Scaling.new(:orientation=>:minMax)
73
- @title = nil
74
- self.ax_pos = :b
75
- self.tick_lbl_pos = :nextTo
76
- self.format_code = "General"
77
- self.crosses = :autoZero
78
- self.gridlines = true
79
- options.each do |o|
80
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
81
- end
90
+ # The color for this axis. This value is used when rendering the axis line in the chart.
91
+ # colors should be in 6 character rbg format
92
+ # @return [String] the rbg color assinged.
93
+ # @see color
94
+ def color=(color_rgb)
95
+ @color = color_rgb
82
96
  end
83
97
 
84
98
  # The position of the axis
@@ -99,7 +113,6 @@ module Axlsx
99
113
  # default true
100
114
  def gridlines=(v) Axlsx::validate_boolean(v); @gridlines = v; end
101
115
 
102
-
103
116
  # Specify if axis should be removed from the chart
104
117
  # default false
105
118
  def delete=(v) Axlsx::validate_boolean(v); @delete = v; end
@@ -117,7 +130,6 @@ module Axlsx
117
130
  @label_rotation = adjusted
118
131
  end
119
132
 
120
-
121
133
  # The title object for the chart.
122
134
  # @param [String, Cell] v
123
135
  # @return [Title]
@@ -140,6 +152,7 @@ module Axlsx
140
152
  str << '<c:delete val="'<< @delete.to_s << '"/>'
141
153
  str << '<c:axPos val="' << @ax_pos.to_s << '"/>'
142
154
  str << '<c:majorGridlines>'
155
+ # TODO shape properties need to be extracted into a class
143
156
  if gridlines == false
144
157
  str << '<c:spPr>'
145
158
  str << '<a:ln>'
@@ -153,6 +166,13 @@ module Axlsx
153
166
  str << '<c:majorTickMark val="none"/>'
154
167
  str << '<c:minorTickMark val="none"/>'
155
168
  str << '<c:tickLblPos val="' << @tick_lbl_pos.to_s << '"/>'
169
+ # TODO - this is also being used for series colors
170
+ # time to extract this into a class spPr - Shape Properties
171
+ if @color
172
+ str << '<c:spPr><a:ln><a:solidFill>'
173
+ str << '<a:srgbClr val="' << @color << '"/>'
174
+ str << '</a:solidFill></a:ln></c:spPr>'
175
+ end
156
176
  # some potential value in implementing this in full. Very detailed!
157
177
  str << '<c:txPr><a:bodyPr rot="' << @label_rotation.to_s << '"/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr/></a:p></c:txPr>'
158
178
  str << '<c:crossAx val="' << @cross_ax.to_s << '"/>'
@@ -160,4 +180,5 @@ module Axlsx
160
180
  end
161
181
 
162
182
  end
183
+
163
184
  end
@@ -10,24 +10,29 @@ module Axlsx
10
10
 
11
11
  # the category axis
12
12
  # @return [CatAxis]
13
- attr_reader :catAxis
13
+ attr_reader :cat_axis
14
+ alias :catAxis :cat_axis
14
15
 
15
- # the valueaxis
16
+ # the value axis
16
17
  # @return [ValAxis]
17
- attr_reader :valAxis
18
+ attr_reader :val_axis
19
+ alias :valAxis :val_axis
18
20
 
19
21
  # The direction of the bars in the chart
20
22
  # must be one of [:bar, :col]
21
23
  # @return [Symbol]
22
- attr_reader :barDir
24
+ attr_reader :bar_dir
25
+ alias :barDir :bar_dir
23
26
 
24
27
  # space between bar or column clusters, as a percentage of the bar or column width.
25
28
  # @return [String]
26
- attr_reader :gapDepth
29
+ attr_reader :gap_depth
30
+ alias :gapDepth :gap_depth
27
31
 
28
32
  # space between bar or column clusters, as a percentage of the bar or column width.
29
33
  # @return [String]
30
- attr_reader :gapWidth
34
+ attr_reader :gap_width
35
+ alias :gapWidth :gap_width
31
36
 
32
37
  #grouping for a column, line, or area chart.
33
38
  # must be one of [:percentStacked, :clustered, :standard, :stacked]
@@ -46,38 +51,42 @@ module Axlsx
46
51
  # @param [GraphicFrame] frame The workbook that owns this chart.
47
52
  # @option options [Cell, String] title
48
53
  # @option options [Boolean] show_legend
49
- # @option options [Symbol] barDir
54
+ # @option options [Symbol] bar_dir
50
55
  # @option options [Symbol] grouping
51
- # @option options [String] gapWidth
52
- # @option options [String] gapDepth
56
+ # @option options [String] gap_width
57
+ # @option options [String] gap_depth
53
58
  # @option options [Symbol] shape
54
- # @option options [Integer] rotX
55
- # @option options [String] hPercent
56
- # @option options [Integer] rotY
57
- # @option options [String] depthPercent
58
- # @option options [Boolean] rAngAx
59
+ # @option options [Integer] rot_x
60
+ # @option options [String] h_percent
61
+ # @option options [Integer] rot_y
62
+ # @option options [String] depth_percent
63
+ # @option options [Boolean] r_ang_ax
59
64
  # @option options [Integer] perspective
60
65
  # @see Chart
61
66
  # @see View3D
62
67
  def initialize(frame, options={})
63
- @barDir = :bar
68
+ @bar_dir = :bar
64
69
  @grouping = :clustered
65
- @gapWidth, @gapDepth, @shape = nil, nil, nil
66
- @catAxId = rand(8 ** 8)
67
- @valAxId = rand(8 ** 8)
68
- @catAxis = CatAxis.new(@catAxId, @valAxId)
69
- @valAxis = ValAxis.new(@valAxId, @catAxId, :tickLblPos => :low)
70
+ @shape = :box
71
+ @gap_width = 150
72
+ @gap_width, @gap_depth, @shape = nil, nil, nil
73
+ @cat_ax_id = rand(8 ** 8)
74
+ @val_ax_id = rand(8 ** 8)
75
+ @cat_axis = CatAxis.new(@cat_ax_id, @val_ax_id)
76
+ @val_axis = ValAxis.new(@val_ax_id, @cat_ax_id, :tick_lbl_pos => :low, :ax_pos => :l)
70
77
  super(frame, options)
71
78
  @series_type = BarSeries
72
- @view3D = View3D.new({:rAngAx=>1}.merge(options))
79
+ @view_3D = View3D.new({:r_ang_ax=>1}.merge(options))
80
+ @d_lbls = nil
73
81
  end
74
82
 
75
83
  # The direction of the bars in the chart
76
84
  # must be one of [:bar, :col]
77
- def barDir=(v)
78
- RestrictionValidator.validate "Bar3DChart.barDir", [:bar, :col], v
79
- @barDir = v
85
+ def bar_dir=(v)
86
+ RestrictionValidator.validate "Bar3DChart.bar_dir", [:bar, :col], v
87
+ @bar_dir = v
80
88
  end
89
+ alias :barDir= :bar_dir=
81
90
 
82
91
  #grouping for a column, line, or area chart.
83
92
  # must be one of [:percentStacked, :clustered, :standard, :stacked]
@@ -87,16 +96,18 @@ module Axlsx
87
96
  end
88
97
 
89
98
  # space between bar or column clusters, as a percentage of the bar or column width.
90
- def gapWidth=(v)
91
- RegexValidator.validate "Bar3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
92
- @gapWidth=(v)
99
+ def gap_width=(v)
100
+ RegexValidator.validate "Bar3DChart.gap_width", GAP_AMOUNT_PERCENT, v
101
+ @gap_width=(v)
93
102
  end
103
+ alias :gapWidth= :gap_width=
94
104
 
95
105
  # space between bar or column clusters, as a percentage of the bar or column width.
96
- def gapDepth=(v)
97
- RegexValidator.validate "Bar3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
98
- @gapDepth=(v)
106
+ def gap_depth=(v)
107
+ RegexValidator.validate "Bar3DChart.gap_didth", GAP_AMOUNT_PERCENT, v
108
+ @gap_depth=(v)
99
109
  end
110
+ alias :gapDepth= :gap_depth=
100
111
 
101
112
  # The shabe of the bars or columns
102
113
  # must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]
@@ -111,27 +122,20 @@ module Axlsx
111
122
  def to_xml_string(str = '')
112
123
  super(str) do |str_inner|
113
124
  str_inner << '<c:bar3DChart>'
114
- str_inner << '<c:barDir val="' << barDir.to_s << '"/>'
125
+ str_inner << '<c:barDir val="' << bar_dir.to_s << '"/>'
115
126
  str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
116
127
  str_inner << '<c:varyColors val="1"/>'
117
128
  @series.each { |ser| ser.to_xml_string(str_inner) }
118
- str_inner << '<c:dLbls>'
119
- str_inner << '<c:showLegendKey val="0"/>'
120
- str_inner << '<c:showVal val="0"/>'
121
- str_inner << '<c:showCatName val="0"/>'
122
- str_inner << '<c:showSerName val="0"/>'
123
- str_inner << '<c:showPercent val="0"/>'
124
- str_inner << '<c:showBubbleSize val="0"/>'
125
- str_inner << '</c:dLbls>'
126
- str_inner << '<c:gapWidth val="' << @gapWidth.to_s << '"/>' unless @gapWidth.nil?
127
- str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
129
+ @d_lbls.to_xml_string(str) if @d_lbls
130
+ str_inner << '<c:gapWidth val="' << @gap_width.to_s << '"/>' unless @gap_width.nil?
131
+ str_inner << '<c:gapDepth val="' << @gap_depth.to_s << '"/>' unless @gap_depth.nil?
128
132
  str_inner << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
129
- str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
130
- str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
133
+ str_inner << '<c:axId val="' << @cat_ax_id.to_s << '"/>'
134
+ str_inner << '<c:axId val="' << @val_ax_id.to_s << '"/>'
131
135
  str_inner << '<c:axId val="0"/>'
132
136
  str_inner << '</c:bar3DChart>'
133
- @catAxis.to_xml_string str_inner
134
- @valAxis.to_xml_string str_inner
137
+ @cat_axis.to_xml_string str_inner
138
+ @val_axis.to_xml_string str_inner
135
139
  end
136
140
  end
137
141
  end
@@ -64,6 +64,7 @@ module Axlsx
64
64
 
65
65
  @labels.to_xml_string(str_inner) unless @labels.nil?
66
66
  @data.to_xml_string(str_inner) unless @data.nil?
67
+ # this is actually only required for shapes other than box
67
68
  str_inner << '<c:shape val="' << shape.to_s << '"></c:shape>'
68
69
  end
69
70
  end