caxlsx 3.3.0 → 4.5.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 (155) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -11
  3. data/README.md +43 -16
  4. data/Rakefile +5 -11
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +15 -10
  7. data/lib/axlsx/content_type/content_type.rb +8 -10
  8. data/lib/axlsx/content_type/default.rb +7 -6
  9. data/lib/axlsx/content_type/override.rb +6 -5
  10. data/lib/axlsx/doc_props/app.rb +96 -32
  11. data/lib/axlsx/doc_props/core.rb +9 -12
  12. data/lib/axlsx/drawing/area_chart.rb +16 -17
  13. data/lib/axlsx/drawing/area_series.rb +23 -18
  14. data/lib/axlsx/drawing/ax_data_source.rb +4 -7
  15. data/lib/axlsx/drawing/axes.rb +11 -10
  16. data/lib/axlsx/drawing/axis.rb +83 -36
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +30 -21
  18. data/lib/axlsx/drawing/bar_chart.rb +29 -20
  19. data/lib/axlsx/drawing/bar_series.rb +23 -18
  20. data/lib/axlsx/drawing/bubble_chart.rb +9 -10
  21. data/lib/axlsx/drawing/bubble_series.rb +11 -12
  22. data/lib/axlsx/drawing/cat_axis.rb +38 -28
  23. data/lib/axlsx/drawing/chart.rb +52 -30
  24. data/lib/axlsx/drawing/d_lbls.rb +36 -32
  25. data/lib/axlsx/drawing/drawing.rb +61 -62
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  27. data/lib/axlsx/drawing/hyperlink.rb +22 -14
  28. data/lib/axlsx/drawing/line_3D_chart.rb +15 -17
  29. data/lib/axlsx/drawing/line_chart.rb +16 -17
  30. data/lib/axlsx/drawing/line_series.rb +23 -18
  31. data/lib/axlsx/drawing/marker.rb +29 -16
  32. data/lib/axlsx/drawing/num_data.rb +13 -16
  33. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  34. data/lib/axlsx/drawing/num_val.rb +10 -11
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +16 -10
  36. data/lib/axlsx/drawing/pic.rb +68 -24
  37. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +9 -12
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +26 -17
  41. data/lib/axlsx/drawing/scaling.rb +26 -13
  42. data/lib/axlsx/drawing/scatter_chart.rb +10 -11
  43. data/lib/axlsx/drawing/scatter_series.rb +17 -18
  44. data/lib/axlsx/drawing/ser_axis.rb +22 -19
  45. data/lib/axlsx/drawing/series.rb +14 -8
  46. data/lib/axlsx/drawing/series_title.rb +6 -6
  47. data/lib/axlsx/drawing/str_data.rb +10 -13
  48. data/lib/axlsx/drawing/str_val.rb +8 -9
  49. data/lib/axlsx/drawing/title.rb +23 -27
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +9 -9
  51. data/lib/axlsx/drawing/val_axis.rb +7 -8
  52. data/lib/axlsx/drawing/view_3D.rb +38 -30
  53. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  54. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  55. data/lib/axlsx/package.rb +134 -99
  56. data/lib/axlsx/rels/relationship.rb +42 -30
  57. data/lib/axlsx/rels/relationships.rb +9 -10
  58. data/lib/axlsx/stylesheet/border.rb +16 -8
  59. data/lib/axlsx/stylesheet/border_pr.rb +24 -12
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +44 -21
  61. data/lib/axlsx/stylesheet/cell_protection.rb +13 -7
  62. data/lib/axlsx/stylesheet/cell_style.rb +36 -15
  63. data/lib/axlsx/stylesheet/color.rb +23 -14
  64. data/lib/axlsx/stylesheet/dxf.rb +36 -15
  65. data/lib/axlsx/stylesheet/fill.rb +7 -6
  66. data/lib/axlsx/stylesheet/font.rb +71 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +16 -10
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -6
  69. data/lib/axlsx/stylesheet/num_fmt.rb +15 -14
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +20 -8
  71. data/lib/axlsx/stylesheet/styles.rb +167 -118
  72. data/lib/axlsx/stylesheet/table_style.rb +20 -10
  73. data/lib/axlsx/stylesheet/table_style_element.rb +16 -8
  74. data/lib/axlsx/stylesheet/table_styles.rb +16 -11
  75. data/lib/axlsx/stylesheet/theme.rb +163 -0
  76. data/lib/axlsx/stylesheet/xf.rb +78 -25
  77. data/lib/axlsx/util/accessors.rb +13 -11
  78. data/lib/axlsx/util/buffered_zip_output_stream.rb +64 -0
  79. data/lib/axlsx/util/constants.rb +133 -110
  80. data/lib/axlsx/util/mime_type_utils.rb +75 -5
  81. data/lib/axlsx/util/options_parser.rb +4 -3
  82. data/lib/axlsx/util/serialized_attributes.rb +47 -23
  83. data/lib/axlsx/util/simple_typed_list.rb +77 -64
  84. data/lib/axlsx/util/storage.rb +38 -41
  85. data/lib/axlsx/util/uri_utils.rb +70 -0
  86. data/lib/axlsx/util/validators.rb +111 -48
  87. data/lib/axlsx/util/zip_command.rb +10 -12
  88. data/lib/axlsx/version.rb +3 -2
  89. data/lib/axlsx/workbook/defined_name.rb +13 -9
  90. data/lib/axlsx/workbook/defined_names.rb +5 -4
  91. data/lib/axlsx/workbook/shared_strings_table.rb +13 -14
  92. data/lib/axlsx/workbook/workbook.rb +152 -120
  93. data/lib/axlsx/workbook/workbook_view.rb +9 -12
  94. data/lib/axlsx/workbook/workbook_views.rb +5 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +87 -15
  96. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +16 -10
  97. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +28 -25
  98. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  99. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +54 -0
  100. data/lib/axlsx/workbook/worksheet/border_creator.rb +34 -29
  101. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  102. data/lib/axlsx/workbook/worksheet/cell.rb +125 -78
  103. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +33 -29
  104. data/lib/axlsx/workbook/worksheet/cfvo.rb +13 -5
  105. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  106. data/lib/axlsx/workbook/worksheet/col.rb +32 -19
  107. data/lib/axlsx/workbook/worksheet/col_breaks.rb +9 -8
  108. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  109. data/lib/axlsx/workbook/worksheet/cols.rb +10 -8
  110. data/lib/axlsx/workbook/worksheet/comment.rb +14 -13
  111. data/lib/axlsx/workbook/worksheet/comments.rb +11 -13
  112. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +19 -9
  113. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +75 -22
  114. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  116. data/lib/axlsx/workbook/worksheet/data_validation.rb +73 -33
  117. data/lib/axlsx/workbook/worksheet/data_validations.rb +8 -9
  118. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  119. data/lib/axlsx/workbook/worksheet/dimension.rb +10 -7
  120. data/lib/axlsx/workbook/worksheet/header_footer.rb +5 -4
  121. data/lib/axlsx/workbook/worksheet/icon_set.rb +40 -12
  122. data/lib/axlsx/workbook/worksheet/merged_cells.rb +11 -11
  123. data/lib/axlsx/workbook/worksheet/outline_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_margins.rb +41 -13
  125. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -6
  126. data/lib/axlsx/workbook/worksheet/page_setup.rb +153 -131
  127. data/lib/axlsx/workbook/worksheet/pane.rb +34 -26
  128. data/lib/axlsx/workbook/worksheet/pivot_table.rb +78 -29
  129. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  130. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +6 -5
  131. data/lib/axlsx/workbook/worksheet/print_options.rb +4 -2
  132. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  133. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +13 -11
  134. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  135. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +66 -28
  136. data/lib/axlsx/workbook/worksheet/row.rb +34 -23
  137. data/lib/axlsx/workbook/worksheet/row_breaks.rb +9 -8
  138. data/lib/axlsx/workbook/worksheet/selection.rb +22 -16
  139. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +11 -7
  140. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  141. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  142. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +12 -8
  143. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +22 -21
  144. data/lib/axlsx/workbook/worksheet/sheet_view.rb +71 -55
  145. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  146. data/lib/axlsx/workbook/worksheet/table_style_info.rb +8 -6
  147. data/lib/axlsx/workbook/worksheet/tables.rb +8 -6
  148. data/lib/axlsx/workbook/worksheet/worksheet.rb +120 -79
  149. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +13 -11
  150. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  151. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +12 -10
  152. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +9 -7
  153. data/lib/axlsx.rb +120 -60
  154. data/lib/caxlsx.rb +3 -2
  155. metadata +42 -75
@@ -1,9 +1,8 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # the access class defines common properties and values for a chart axis.
5
5
  class Axis
6
-
7
6
  include Axlsx::OptionsParser
8
7
 
9
8
  # Creates an Axis object
@@ -12,14 +11,16 @@ module Axlsx
12
11
  # @option options [Symbol] crosses
13
12
  # @option options [Symbol] tick_lbl_pos
14
13
  # @raise [ArgumentError] If axi_id or cross_ax are not unsigned integers
15
- def initialize(options={})
16
- @id = rand(8 ** 8)
14
+ def initialize(options = {})
15
+ @id = rand(8**8)
17
16
  @format_code = "General"
18
17
  @delete = @label_rotation = 0
19
- @scaling = Scaling.new(:orientation=>:minMax)
18
+ @scaling = Scaling.new(orientation: :minMax)
20
19
  @title = @color = nil
21
20
  self.ax_pos = :b
22
21
  self.tick_lbl_pos = :nextTo
22
+ self.major_tick_mark = :cross
23
+ self.minor_tick_mark = :none
23
24
  self.format_code = "General"
24
25
  self.crosses = :autoZero
25
26
  self.gridlines = true
@@ -58,6 +59,18 @@ module Axlsx
58
59
  attr_reader :tick_lbl_pos
59
60
  alias :tickLblPos :tick_lbl_pos
60
61
 
62
+ # the type of major tick mark
63
+ # must be one of [:cross, :in, :none, :out]
64
+ # @return [Symbol]
65
+ attr_reader :major_tick_mark
66
+ alias :majorTickMark :major_tick_mark
67
+
68
+ # the type of minor tick mark
69
+ # must be one of [:cross, :in, :none, :out]
70
+ # @return [Symbol]
71
+ attr_reader :minor_tick_mark
72
+ alias :minorTickMark :minor_tick_mark
73
+
61
74
  # The number format format code for this axis
62
75
  # default :General
63
76
  # @return [String]
@@ -83,53 +96,89 @@ module Axlsx
83
96
  # the title for the axis. This can be a cell or a fixed string.
84
97
  attr_reader :title
85
98
 
86
- # The color for this axis. This value is used when rendering the axis line in the chart.
99
+ # The color for this axis. This value is used when rendering the axis line in the chart.
87
100
  # colors should be in 6 character rbg format
88
- # @return [String] the rbg color assinged.
101
+ # @return [String] the rbg color assigned.
89
102
  # @see color
90
103
  def color=(color_rgb)
91
104
  @color = color_rgb
92
105
  end
93
-
106
+
94
107
  # The crossing axis for this axis
95
108
  # @param [Axis] axis
96
109
  def cross_axis=(axis)
97
- DataTypeValidator.validate "#{self.class}.cross_axis", [Axis], axis
98
- @cross_axis = axis
110
+ DataTypeValidator.validate "#{self.class}.cross_axis", [Axis], axis
111
+ @cross_axis = axis
99
112
  end
100
113
 
101
114
  # The position of the axis
102
115
  # must be one of [:l, :r, :t, :b]
103
- def ax_pos=(v) RestrictionValidator.validate "#{self.class}.ax_pos", [:l, :r, :b, :t], v; @ax_pos = v; end
116
+ def ax_pos=(v)
117
+ RestrictionValidator.validate "#{self.class}.ax_pos", [:l, :r, :b, :t], v
118
+ @ax_pos = v
119
+ end
104
120
  alias :axPos= :ax_pos=
105
121
 
106
122
  # the position of the tick labels
107
123
  # must be one of [:nextTo, :high, :low1]
108
- def tick_lbl_pos=(v) RestrictionValidator.validate "#{self.class}.tick_lbl_pos", [:nextTo, :high, :low, :none], v; @tick_lbl_pos = v; end
124
+ def tick_lbl_pos=(v)
125
+ RestrictionValidator.validate "#{self.class}.tick_lbl_pos", [:nextTo, :high, :low, :none], v
126
+ @tick_lbl_pos = v
127
+ end
109
128
  alias :tickLblPos= :tick_lbl_pos=
110
129
 
130
+ VALID_TICK_MARK_VALUES = [:cross, :in, :none, :out].freeze
131
+
132
+ # the type of major tick mark
133
+ # must be one of [:cross, :in, :none, :out]
134
+ def major_tick_mark=(v)
135
+ RestrictionValidator.validate "#{self.class}.major_tick_mark", VALID_TICK_MARK_VALUES, v
136
+ @major_tick_mark = v
137
+ end
138
+ alias :majorTickMark= :major_tick_mark=
139
+
140
+ # the type of minor tick mark
141
+ # must be one of [:cross, :in, :none, :out]
142
+ def minor_tick_mark=(v)
143
+ RestrictionValidator.validate "#{self.class}.minor_tick_mark", VALID_TICK_MARK_VALUES, v
144
+ @minor_tick_mark = v
145
+ end
146
+ alias :minorTickMark= :minor_tick_mark=
147
+
111
148
  # The number format format code for this axis
112
149
  # default :General
113
- def format_code=(v) Axlsx::validate_string(v); @format_code = v; end
150
+ def format_code=(v)
151
+ Axlsx.validate_string(v)
152
+ @format_code = v
153
+ end
114
154
 
115
155
  # Specify if gridlines should be shown for this axis
116
156
  # default true
117
- def gridlines=(v) Axlsx::validate_boolean(v); @gridlines = v; end
157
+ def gridlines=(v)
158
+ Axlsx.validate_boolean(v)
159
+ @gridlines = v
160
+ end
118
161
 
119
162
  # Specify if axis should be removed from the chart
120
163
  # default false
121
- def delete=(v) Axlsx::validate_boolean(v); @delete = v; end
164
+ def delete=(v)
165
+ Axlsx.validate_boolean(v)
166
+ @delete = v
167
+ end
122
168
 
123
169
  # specifies how the perpendicular axis is crossed
124
170
  # must be one of [:autoZero, :min, :max]
125
- def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end
171
+ def crosses=(v)
172
+ RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v
173
+ @crosses = v
174
+ end
126
175
 
127
176
  # Specify the degree of label rotation to apply to labels
128
177
  # default true
129
178
  def label_rotation=(v)
130
- Axlsx::validate_int(v)
179
+ Axlsx.validate_int(v)
131
180
  adjusted = v.to_i * 60000
132
- Axlsx::validate_angle(adjusted)
181
+ Axlsx.validate_angle(adjusted)
133
182
  @label_rotation = adjusted
134
183
  end
135
184
 
@@ -149,13 +198,13 @@ module Axlsx
149
198
  # Serializes the object
150
199
  # @param [String] str
151
200
  # @return [String]
152
- def to_xml_string(str = '')
153
- str << ('<c:axId val="' << @id.to_s << '"/>')
201
+ def to_xml_string(str = +'')
202
+ str << '<c:axId val="' << @id.to_s << '"/>'
154
203
  @scaling.to_xml_string str
155
- str << ('<c:delete val="' << @delete.to_s << '"/>')
156
- str << ('<c:axPos val="' << @ax_pos.to_s << '"/>')
204
+ str << '<c:delete val="' << @delete.to_s << '"/>'
205
+ str << '<c:axPos val="' << @ax_pos.to_s << '"/>'
157
206
  str << '<c:majorGridlines>'
158
- # TODO shape properties need to be extracted into a class
207
+ # TODO: shape properties need to be extracted into a class
159
208
  if gridlines == false
160
209
  str << '<c:spPr>'
161
210
  str << '<a:ln>'
@@ -164,27 +213,25 @@ module Axlsx
164
213
  str << '</c:spPr>'
165
214
  end
166
215
  str << '</c:majorGridlines>'
167
- @title.to_xml_string(str) unless @title == nil
216
+ @title.to_xml_string(str) unless @title.nil?
168
217
  # Need to set sourceLinked to 0 if we're setting a format code on this row
169
218
  # otherwise it will never take, as it will always prefer the 'General' formatting
170
219
  # of the cells themselves
171
- str << ('<c:numFmt formatCode="' << @format_code << '" sourceLinked="' << (@format_code.eql?('General') ? '1' : '0') << '"/>')
172
- str << '<c:majorTickMark val="none"/>'
173
- str << '<c:minorTickMark val="none"/>'
174
- str << ('<c:tickLblPos val="' << @tick_lbl_pos.to_s << '"/>')
175
- # TODO - this is also being used for series colors
220
+ str << '<c:numFmt formatCode="' << @format_code << '" sourceLinked="' << (@format_code.eql?('General') ? '1' : '0') << '"/>'
221
+ str << '<c:majorTickMark val="' << @major_tick_mark.to_s << '"/>'
222
+ str << '<c:minorTickMark val="' << @minor_tick_mark.to_s << '"/>'
223
+ str << '<c:tickLblPos val="' << @tick_lbl_pos.to_s << '"/>'
224
+ # TODO: this is also being used for series colors
176
225
  # time to extract this into a class spPr - Shape Properties
177
226
  if @color
178
227
  str << '<c:spPr><a:ln><a:solidFill>'
179
- str << ('<a:srgbClr val="' << @color << '"/>')
228
+ str << '<a:srgbClr val="' << @color << '"/>'
180
229
  str << '</a:solidFill></a:ln></c:spPr>'
181
230
  end
182
231
  # some potential value in implementing this in full. Very detailed!
183
- 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>')
184
- str << ('<c:crossAx val="' << @cross_axis.id.to_s << '"/>')
185
- str << ('<c:crosses val="' << @crosses.to_s << '"/>')
232
+ 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>'
233
+ str << '<c:crossAx val="' << @cross_axis.id.to_s << '"/>'
234
+ str << '<c:crosses val="' << @crosses.to_s << '"/>'
186
235
  end
187
-
188
236
  end
189
-
190
237
  end
@@ -1,13 +1,12 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
4
- # The Bar3DChart is a three dimentional barchart (who would have guessed?) that you can add to your worksheet.
3
+ module Axlsx
4
+ # The Bar3DChart is a three dimensional barchart (who would have guessed?) that you can add to your worksheet.
5
5
  # @see Worksheet#add_chart
6
6
  # @see Chart#add_series
7
7
  # @see Package#serialize
8
8
  # @see README for an example
9
9
  class Bar3DChart < Chart
10
-
11
10
  # the category axis
12
11
  # @return [CatAxis]
13
12
  def cat_axis
@@ -42,7 +41,7 @@ module Axlsx
42
41
  end
43
42
  alias :gapWidth :gap_width
44
43
 
45
- #grouping for a column, line, or area chart.
44
+ # grouping for a column, line, or area chart.
46
45
  # must be one of [:percentStacked, :clustered, :standard, :stacked]
47
46
  # @return [Symbol]
48
47
  def grouping
@@ -73,12 +72,12 @@ module Axlsx
73
72
  # @option options [Integer] perspective
74
73
  # @see Chart
75
74
  # @see View3D
76
- def initialize(frame, options={})
75
+ def initialize(frame, options = {})
77
76
  @vary_colors = true
78
77
  @gap_width, @gap_depth, @shape = nil, nil, nil
79
- super(frame, options)
78
+ super
80
79
  @series_type = BarSeries
81
- @view_3D = View3D.new({:r_ang_ax=>1}.merge(options))
80
+ @view_3D = View3D.new({ r_ang_ax: 1 }.merge(options))
82
81
  @d_lbls = nil
83
82
  end
84
83
 
@@ -90,7 +89,7 @@ module Axlsx
90
89
  end
91
90
  alias :barDir= :bar_dir=
92
91
 
93
- #grouping for a column, line, or area chart.
92
+ # grouping for a column, line, or area chart.
94
93
  # must be one of [:percentStacked, :clustered, :standard, :stacked]
95
94
  def grouping=(v)
96
95
  RestrictionValidator.validate "Bar3DChart.grouping", [:percentStacked, :clustered, :standard, :stacked], v
@@ -100,14 +99,14 @@ module Axlsx
100
99
  # space between bar or column clusters, as a percentage of the bar or column width.
101
100
  def gap_width=(v)
102
101
  RangeValidator.validate "Bar3DChart.gap_width", 0, 500, v
103
- @gap_width=(v)
102
+ @gap_width = v
104
103
  end
105
104
  alias :gapWidth= :gap_width=
106
105
 
107
106
  # space between bar or column clusters, as a percentage of the bar or column width.
108
107
  def gap_depth=(v)
109
108
  RangeValidator.validate "Bar3DChart.gap_depth", 0, 500, v
110
- @gap_depth=(v)
109
+ @gap_depth = v
111
110
  end
112
111
  alias :gapDepth= :gap_depth=
113
112
 
@@ -121,18 +120,18 @@ module Axlsx
121
120
  # Serializes the object
122
121
  # @param [String] str
123
122
  # @return [String]
124
- def to_xml_string(str = '')
125
- super(str) do
123
+ def to_xml_string(str = +'')
124
+ super do
126
125
  str << '<c:bar3DChart>'
127
- str << ('<c:barDir val="' << bar_dir.to_s << '"/>')
128
- str << ('<c:grouping val="' << grouping.to_s << '"/>')
129
- str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
126
+ str << '<c:barDir val="' << bar_dir.to_s << '"/>'
127
+ str << '<c:grouping val="' << grouping.to_s << '"/>'
128
+ str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
130
129
  @series.each { |ser| ser.to_xml_string(str) }
131
130
  @d_lbls.to_xml_string(str) if @d_lbls
132
- str << ('<c:gapWidth val="' << @gap_width.to_s << '"/>') unless @gap_width.nil?
133
- str << ('<c:gapDepth val="' << @gap_depth.to_s << '"/>') unless @gap_depth.nil?
134
- str << ('<c:shape val="' << @shape.to_s << '"/>') unless @shape.nil?
135
- axes.to_xml_string(str, :ids => true)
131
+ str << '<c:gapWidth val="' << @gap_width.to_s << '"/>' unless @gap_width.nil?
132
+ str << '<c:gapDepth val="' << @gap_depth.to_s << '"/>' unless @gap_depth.nil?
133
+ str << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
134
+ axes.to_xml_string(str, ids: true)
136
135
  str << '</c:bar3DChart>'
137
136
  axes.to_xml_string(str)
138
137
  end
@@ -142,7 +141,17 @@ module Axlsx
142
141
  # category axes specified via axes[:val_axes] and axes[:cat_axis]
143
142
  # @return [Axes]
144
143
  def axes
145
- @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
144
+ @axes ||= begin
145
+ a = Axes.new(cat_axis: CatAxis, val_axis: ValAxis)
146
+
147
+ if bar_dir == :col
148
+ a[:val_axis].ax_pos = :l
149
+ else
150
+ a[:cat_axis].ax_pos = :l
151
+ end
152
+
153
+ a
154
+ end
146
155
  end
147
156
  end
148
157
  end
@@ -1,13 +1,12 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
4
- # The BarChart is a two dimentional barchart that you can add to your worksheet.
3
+ module Axlsx
4
+ # The BarChart is a two dimensional barchart that you can add to your worksheet.
5
5
  # @see Worksheet#add_chart
6
6
  # @see Chart#add_series
7
7
  # @see Package#serialize
8
8
  # @see README for an example
9
9
  class BarChart < Chart
10
-
11
10
  # the category axis
12
11
  # @return [CatAxis]
13
12
  def cat_axis
@@ -37,7 +36,7 @@ module Axlsx
37
36
  end
38
37
  alias :gapWidth :gap_width
39
38
 
40
- #grouping for a column, line, or area chart.
39
+ # grouping for a column, line, or area chart.
41
40
  # must be one of [:percentStacked, :clustered, :standard, :stacked]
42
41
  # @return [Symbol]
43
42
  def grouping
@@ -66,10 +65,10 @@ module Axlsx
66
65
  # @option options [String] gap_width
67
66
  # @option options [Symbol] shape
68
67
  # @see Chart
69
- def initialize(frame, options={})
68
+ def initialize(frame, options = {})
70
69
  @vary_colors = true
71
70
  @gap_width, @overlap, @shape = nil, nil, nil
72
- super(frame, options)
71
+ super
73
72
  @series_type = BarSeries
74
73
  @d_lbls = nil
75
74
  end
@@ -82,7 +81,7 @@ module Axlsx
82
81
  end
83
82
  alias :barDir= :bar_dir=
84
83
 
85
- #grouping for a column, line, or area chart.
84
+ # grouping for a column, line, or area chart.
86
85
  # must be one of [:percentStacked, :clustered, :standard, :stacked]
87
86
  def grouping=(v)
88
87
  RestrictionValidator.validate "BarChart.grouping", [:percentStacked, :clustered, :standard, :stacked], v
@@ -92,13 +91,13 @@ module Axlsx
92
91
  # space between bar or column clusters, as a percentage of the bar or column width.
93
92
  def gap_width=(v)
94
93
  RangeValidator.validate "BarChart.gap_width", 0, 500, v
95
- @gap_width=(v)
94
+ @gap_width = v
96
95
  end
97
96
  alias :gapWidth= :gap_width=
98
97
 
99
98
  def overlap=(v)
100
99
  RangeValidator.validate "BarChart.overlap", -100, 100, v
101
- @overlap=(v)
100
+ @overlap = v
102
101
  end
103
102
 
104
103
  # The shape of the bars or columns
@@ -111,18 +110,18 @@ module Axlsx
111
110
  # Serializes the object
112
111
  # @param [String] str
113
112
  # @return [String]
114
- def to_xml_string(str = '')
115
- super(str) do
113
+ def to_xml_string(str = +'')
114
+ super do
116
115
  str << '<c:barChart>'
117
- str << ('<c:barDir val="' << bar_dir.to_s << '"/>')
118
- str << ('<c:grouping val="' << grouping.to_s << '"/>')
119
- str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
116
+ str << '<c:barDir val="' << bar_dir.to_s << '"/>'
117
+ str << '<c:grouping val="' << grouping.to_s << '"/>'
118
+ str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
120
119
  @series.each { |ser| ser.to_xml_string(str) }
121
120
  @d_lbls.to_xml_string(str) if @d_lbls
122
- str << ('<c:overlap val="' << @overlap.to_s << '"/>') unless @overlap.nil?
123
- str << ('<c:gapWidth val="' << @gap_width.to_s << '"/>') unless @gap_width.nil?
124
- str << ('<c:shape val="' << @shape.to_s << '"/>') unless @shape.nil?
125
- axes.to_xml_string(str, :ids => true)
121
+ str << '<c:overlap val="' << @overlap.to_s << '"/>' unless @overlap.nil?
122
+ str << '<c:gapWidth val="' << @gap_width.to_s << '"/>' unless @gap_width.nil?
123
+ str << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
124
+ axes.to_xml_string(str, ids: true)
126
125
  str << '</c:barChart>'
127
126
  axes.to_xml_string(str)
128
127
  end
@@ -132,7 +131,17 @@ module Axlsx
132
131
  # category axes specified via axes[:val_axes] and axes[:cat_axis]
133
132
  # @return [Axes]
134
133
  def axes
135
- @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
134
+ @axes ||= begin
135
+ a = Axes.new(cat_axis: CatAxis, val_axis: ValAxis)
136
+
137
+ if bar_dir == :col
138
+ a[:val_axis].ax_pos = :l
139
+ else
140
+ a[:cat_axis].ax_pos = :l
141
+ end
142
+
143
+ a
144
+ end
136
145
  end
137
146
  end
138
147
  end
@@ -1,12 +1,11 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # A BarSeries defines the title, data and labels for bar charts
4
5
  # @note The recommended way to manage series is to use Chart#add_series
5
6
  # @see Worksheet#add_chart
6
7
  # @see Chart#add_series
7
8
  class BarSeries < Series
8
-
9
-
10
9
  # The data for this series.
11
10
  # @return [NumDataSource]
12
11
  attr_reader :data
@@ -35,16 +34,19 @@ module Axlsx
35
34
  # @option options [String] colors an array of colors to use when rendering each data point
36
35
  # @option options [String] series_color a color to use when rendering series
37
36
  # @param [Chart] chart
38
- def initialize(chart, options={})
37
+ def initialize(chart, options = {})
39
38
  @shape = :box
40
39
  @colors = []
41
- super(chart, options)
42
- self.labels = AxDataSource.new({:data => options[:labels]}) unless options[:labels].nil?
40
+ super
41
+ self.labels = AxDataSource.new({ data: options[:labels] }) unless options[:labels].nil?
43
42
  self.data = NumDataSource.new(options) unless options[:data].nil?
44
43
  end
45
44
 
46
45
  # @see colors
47
- def colors=(v) DataTypeValidator.validate "BarSeries.colors", [Array], v; @colors = v end
46
+ def colors=(v)
47
+ DataTypeValidator.validate "BarSeries.colors", [Array], v
48
+ @colors = v
49
+ end
48
50
 
49
51
  def series_color=(v)
50
52
  @series_color = v
@@ -59,20 +61,19 @@ module Axlsx
59
61
  # Serializes the object
60
62
  # @param [String] str
61
63
  # @return [String]
62
- def to_xml_string(str = '')
63
- super(str) do
64
-
64
+ def to_xml_string(str = +'')
65
+ super do
65
66
  colors.each_with_index do |c, index|
66
67
  str << '<c:dPt>'
67
- str << ('<c:idx val="' << index.to_s << '"/>')
68
+ str << '<c:idx val="' << index.to_s << '"/>'
68
69
  str << '<c:spPr><a:solidFill>'
69
- str << ('<a:srgbClr val="' << c << '"/>')
70
+ str << '<a:srgbClr val="' << c << '"/>'
70
71
  str << '</a:solidFill></c:spPr></c:dPt>'
71
72
  end
72
73
 
73
74
  if series_color
74
75
  str << '<c:spPr><a:solidFill>'
75
- str << ('<a:srgbClr val="' << series_color << '"/>')
76
+ str << '<a:srgbClr val="' << series_color << '"/>'
76
77
  str << '</a:solidFill>'
77
78
  str << '</c:spPr>'
78
79
  end
@@ -80,18 +81,22 @@ module Axlsx
80
81
  @labels.to_xml_string(str) unless @labels.nil?
81
82
  @data.to_xml_string(str) unless @data.nil?
82
83
  # this is actually only required for shapes other than box
83
- str << ('<c:shape val="' << shape.to_s << '"></c:shape>')
84
+ str << '<c:shape val="' << shape.to_s << '"></c:shape>'
84
85
  end
85
86
  end
86
87
 
87
88
  private
88
89
 
89
90
  # assigns the data for this series
90
- def data=(v) DataTypeValidator.validate "Series.data", [NumDataSource], v; @data = v; end
91
+ def data=(v)
92
+ DataTypeValidator.validate "Series.data", [NumDataSource], v
93
+ @data = v
94
+ end
91
95
 
92
96
  # assigns the labels for this series
93
- def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
94
-
97
+ def labels=(v)
98
+ DataTypeValidator.validate "Series.labels", [AxDataSource], v
99
+ @labels = v
100
+ end
95
101
  end
96
-
97
102
  end
@@ -1,12 +1,11 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # The BubbleChart allows you to insert a bubble chart into your worksheet
5
5
  # @see Worksheet#add_chart
6
6
  # @see Chart#add_series
7
7
  # @see README for an example
8
8
  class BubbleChart < Chart
9
-
10
9
  include Axlsx::OptionsParser
11
10
 
12
11
  # the x value axis
@@ -24,10 +23,10 @@ module Axlsx
24
23
  alias :yValAxis :y_val_axis
25
24
 
26
25
  # Creates a new bubble chart
27
- def initialize(frame, options={})
26
+ def initialize(frame, options = {})
28
27
  @vary_colors = 0
29
28
 
30
- super(frame, options)
29
+ super
31
30
  @series_type = BubbleSeries
32
31
  @d_lbls = nil
33
32
  parse_options options
@@ -36,13 +35,13 @@ module Axlsx
36
35
  # Serializes the object
37
36
  # @param [String] str
38
37
  # @return [String]
39
- def to_xml_string(str = '')
40
- super(str) do
38
+ def to_xml_string(str = +'')
39
+ super do
41
40
  str << '<c:bubbleChart>'
42
- str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
41
+ str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
43
42
  @series.each { |ser| ser.to_xml_string(str) }
44
43
  d_lbls.to_xml_string(str) if @d_lbls
45
- axes.to_xml_string(str, :ids => true)
44
+ axes.to_xml_string(str, ids: true)
46
45
  str << '</c:bubbleChart>'
47
46
  axes.to_xml_string(str)
48
47
  end
@@ -53,7 +52,7 @@ module Axlsx
53
52
  # a y_val_axis
54
53
  # @return [Axes]
55
54
  def axes
56
- @axes ||= Axes.new(:x_val_axis => ValAxis, :y_val_axis => ValAxis)
55
+ @axes ||= Axes.new(x_val_axis: ValAxis, y_val_axis: ValAxis)
57
56
  end
58
57
  end
59
58
  end
@@ -1,13 +1,12 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # A BubbleSeries defines the x/y position and bubble size of data in the chart
5
5
  # @note The recommended way to manage series is to use Chart#add_series
6
6
  # @see Worksheet#add_chart
7
7
  # @see Chart#add_series
8
8
  # @see examples/example.rb
9
9
  class BubbleSeries < Series
10
-
11
10
  # The x data for this series.
12
11
  # @return [AxDataSource]
13
12
  attr_reader :xData
@@ -26,12 +25,12 @@ module Axlsx
26
25
  attr_reader :color
27
26
 
28
27
  # Creates a new BubbleSeries
29
- def initialize(chart, options={})
28
+ def initialize(chart, options = {})
30
29
  @xData, @yData, @bubbleSize = nil
31
- super(chart, options)
32
- @xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil?
33
- @yData = NumDataSource.new({:tag_name => :yVal, :data => options[:yData]}) unless options[:yData].nil?
34
- @bubbleSize = NumDataSource.new({:tag_name => :bubbleSize, :data => options[:bubbleSize]}) unless options[:bubbleSize].nil?
30
+ super
31
+ @xData = AxDataSource.new(tag_name: :xVal, data: options[:xData]) unless options[:xData].nil?
32
+ @yData = NumDataSource.new({ tag_name: :yVal, data: options[:yData] }) unless options[:yData].nil?
33
+ @bubbleSize = NumDataSource.new({ tag_name: :bubbleSize, data: options[:bubbleSize] }) unless options[:bubbleSize].nil?
35
34
  end
36
35
 
37
36
  # @see color
@@ -42,15 +41,15 @@ module Axlsx
42
41
  # Serializes the object
43
42
  # @param [String] str
44
43
  # @return [String]
45
- def to_xml_string(str = '')
46
- super(str) do
44
+ def to_xml_string(str = +'')
45
+ super do
47
46
  # needs to override the super color here to push in ln/and something else!
48
47
  if color
49
48
  str << '<c:spPr><a:solidFill>'
50
- str << ('<a:srgbClr val="' << color << '"/>')
49
+ str << '<a:srgbClr val="' << color << '"/>'
51
50
  str << '</a:solidFill>'
52
51
  str << '<a:ln><a:solidFill>'
53
- str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
52
+ str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
54
53
  str << '</c:spPr>'
55
54
  end
56
55
  @xData.to_xml_string(str) unless @xData.nil?