caxlsx 3.4.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -1
  3. data/README.md +9 -11
  4. data/Rakefile +7 -5
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +12 -4
  7. data/lib/axlsx/content_type/content_type.rb +8 -6
  8. data/lib/axlsx/content_type/default.rb +7 -2
  9. data/lib/axlsx/content_type/override.rb +7 -2
  10. data/lib/axlsx/doc_props/app.rb +95 -26
  11. data/lib/axlsx/doc_props/core.rb +8 -6
  12. data/lib/axlsx/drawing/area_chart.rb +10 -8
  13. data/lib/axlsx/drawing/area_series.rb +20 -12
  14. data/lib/axlsx/drawing/ax_data_source.rb +2 -0
  15. data/lib/axlsx/drawing/axes.rb +6 -4
  16. data/lib/axlsx/drawing/axis.rb +42 -22
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -12
  18. data/lib/axlsx/drawing/bar_chart.rb +13 -11
  19. data/lib/axlsx/drawing/bar_series.rb +20 -9
  20. data/lib/axlsx/drawing/bubble_chart.rb +6 -4
  21. data/lib/axlsx/drawing/bubble_series.rb +8 -6
  22. data/lib/axlsx/drawing/cat_axis.rb +29 -12
  23. data/lib/axlsx/drawing/chart.rb +46 -20
  24. data/lib/axlsx/drawing/d_lbls.rb +10 -8
  25. data/lib/axlsx/drawing/drawing.rb +59 -56
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -4
  27. data/lib/axlsx/drawing/hyperlink.rb +19 -8
  28. data/lib/axlsx/drawing/line_3D_chart.rb +7 -5
  29. data/lib/axlsx/drawing/line_chart.rb +10 -8
  30. data/lib/axlsx/drawing/line_series.rb +20 -12
  31. data/lib/axlsx/drawing/marker.rb +24 -7
  32. data/lib/axlsx/drawing/num_data.rb +9 -7
  33. data/lib/axlsx/drawing/num_data_source.rb +9 -7
  34. data/lib/axlsx/drawing/num_val.rb +7 -5
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +13 -5
  36. data/lib/axlsx/drawing/pic.rb +26 -15
  37. data/lib/axlsx/drawing/picture_locking.rb +3 -1
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +6 -4
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +23 -9
  41. data/lib/axlsx/drawing/scaling.rb +25 -9
  42. data/lib/axlsx/drawing/scatter_chart.rb +7 -5
  43. data/lib/axlsx/drawing/scatter_series.rb +14 -12
  44. data/lib/axlsx/drawing/ser_axis.rb +13 -5
  45. data/lib/axlsx/drawing/series.rb +13 -5
  46. data/lib/axlsx/drawing/series_title.rb +6 -4
  47. data/lib/axlsx/drawing/str_data.rb +7 -5
  48. data/lib/axlsx/drawing/str_val.rb +6 -4
  49. data/lib/axlsx/drawing/title.rb +13 -14
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +4 -2
  51. data/lib/axlsx/drawing/val_axis.rb +4 -2
  52. data/lib/axlsx/drawing/view_3D.rb +16 -8
  53. data/lib/axlsx/drawing/vml_drawing.rb +18 -16
  54. data/lib/axlsx/drawing/vml_shape.rb +24 -22
  55. data/lib/axlsx/package.rb +73 -67
  56. data/lib/axlsx/rels/relationship.rb +21 -6
  57. data/lib/axlsx/rels/relationships.rb +6 -4
  58. data/lib/axlsx/stylesheet/border.rb +15 -4
  59. data/lib/axlsx/stylesheet/border_pr.rb +19 -6
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +41 -10
  61. data/lib/axlsx/stylesheet/cell_protection.rb +12 -3
  62. data/lib/axlsx/stylesheet/cell_style.rb +33 -8
  63. data/lib/axlsx/stylesheet/color.rb +15 -7
  64. data/lib/axlsx/stylesheet/dxf.rb +34 -9
  65. data/lib/axlsx/stylesheet/fill.rb +7 -2
  66. data/lib/axlsx/stylesheet/font.rb +65 -17
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +12 -4
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -5
  69. data/lib/axlsx/stylesheet/num_fmt.rb +14 -10
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +18 -5
  71. data/lib/axlsx/stylesheet/styles.rb +124 -82
  72. data/lib/axlsx/stylesheet/table_style.rb +19 -6
  73. data/lib/axlsx/stylesheet/table_style_element.rb +15 -4
  74. data/lib/axlsx/stylesheet/table_styles.rb +14 -5
  75. data/lib/axlsx/stylesheet/xf.rb +73 -18
  76. data/lib/axlsx/util/accessors.rb +10 -6
  77. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  78. data/lib/axlsx/util/constants.rb +117 -104
  79. data/lib/axlsx/util/mime_type_utils.rb +3 -5
  80. data/lib/axlsx/util/options_parser.rb +3 -1
  81. data/lib/axlsx/util/serialized_attributes.rb +42 -17
  82. data/lib/axlsx/util/simple_typed_list.rb +47 -47
  83. data/lib/axlsx/util/storage.rb +11 -10
  84. data/lib/axlsx/util/validators.rb +101 -41
  85. data/lib/axlsx/util/zip_command.rb +10 -10
  86. data/lib/axlsx/version.rb +3 -1
  87. data/lib/axlsx/workbook/defined_name.rb +6 -4
  88. data/lib/axlsx/workbook/defined_names.rb +4 -2
  89. data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
  90. data/lib/axlsx/workbook/workbook.rb +94 -79
  91. data/lib/axlsx/workbook/workbook_view.rb +3 -1
  92. data/lib/axlsx/workbook/workbook_views.rb +4 -2
  93. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
  94. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +11 -7
  96. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  97. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
  98. data/lib/axlsx/workbook/worksheet/border_creator.rb +5 -3
  99. data/lib/axlsx/workbook/worksheet/break.rb +3 -1
  100. data/lib/axlsx/workbook/worksheet/cell.rb +83 -64
  101. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
  102. data/lib/axlsx/workbook/worksheet/cfvo.rb +11 -3
  103. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -1
  104. data/lib/axlsx/workbook/worksheet/col.rb +5 -3
  105. data/lib/axlsx/workbook/worksheet/col_breaks.rb +6 -4
  106. data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
  107. data/lib/axlsx/workbook/worksheet/cols.rb +4 -2
  108. data/lib/axlsx/workbook/worksheet/comment.rb +8 -6
  109. data/lib/axlsx/workbook/worksheet/comments.rb +6 -4
  110. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +16 -5
  111. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +73 -16
  112. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +4 -2
  113. data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
  114. data/lib/axlsx/workbook/worksheet/data_validation.rb +69 -28
  115. data/lib/axlsx/workbook/worksheet/data_validations.rb +4 -2
  116. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +7 -5
  117. data/lib/axlsx/workbook/worksheet/dimension.rb +4 -2
  118. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -2
  119. data/lib/axlsx/workbook/worksheet/icon_set.rb +38 -9
  120. data/lib/axlsx/workbook/worksheet/merged_cells.rb +6 -6
  121. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
  122. data/lib/axlsx/workbook/worksheet/page_margins.rb +39 -11
  123. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_setup.rb +34 -9
  125. data/lib/axlsx/workbook/worksheet/pane.rb +17 -9
  126. data/lib/axlsx/workbook/worksheet/pivot_table.rb +20 -19
  127. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -6
  128. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -1
  129. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -1
  130. data/lib/axlsx/workbook/worksheet/protected_range.rb +3 -1
  131. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +6 -4
  132. data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
  133. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +46 -24
  134. data/lib/axlsx/workbook/worksheet/row.rb +11 -9
  135. data/lib/axlsx/workbook/worksheet/row_breaks.rb +7 -5
  136. data/lib/axlsx/workbook/worksheet/selection.rb +15 -7
  137. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -2
  138. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  139. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +6 -2
  140. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +8 -4
  141. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +11 -9
  142. data/lib/axlsx/workbook/worksheet/sheet_view.rb +38 -15
  143. data/lib/axlsx/workbook/worksheet/table.rb +9 -7
  144. data/lib/axlsx/workbook/worksheet/table_style_info.rb +4 -2
  145. data/lib/axlsx/workbook/worksheet/tables.rb +4 -2
  146. data/lib/axlsx/workbook/worksheet/worksheet.rb +56 -39
  147. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -2
  148. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +8 -2
  149. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +7 -5
  150. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +5 -3
  151. data/lib/axlsx.rb +56 -42
  152. data/lib/caxlsx.rb +3 -1
  153. metadata +39 -71
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # This class specifies data for a particular data point.
3
5
  class NumVal < StrVal
@@ -16,15 +18,15 @@ module Axlsx
16
18
 
17
19
  # @see format_code
18
20
  def format_code=(v)
19
- Axlsx::validate_string(v)
21
+ Axlsx.validate_string(v)
20
22
  @format_code = v
21
23
  end
22
24
 
23
25
  # serialize the object
24
- def to_xml_string(idx, str = "")
25
- Axlsx::validate_unsigned_int(idx)
26
- if !v.to_s.empty?
27
- str << ('<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>')
26
+ def to_xml_string(idx, str = +'')
27
+ Axlsx.validate_unsigned_int(idx)
28
+ unless v.to_s.empty?
29
+ str << '<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>'
28
30
  end
29
31
  end
30
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # This class details a single cell anchor for drawings.
3
5
  # @note The recommended way to manage drawings, images and charts is Worksheet#add_chart or Worksheet#add_image.
@@ -58,10 +60,16 @@ module Axlsx
58
60
 
59
61
  #
60
62
  # @see height
61
- def height=(v) Axlsx::validate_unsigned_int(v); @height = v; end
63
+ def height=(v)
64
+ Axlsx.validate_unsigned_int(v)
65
+ @height = v
66
+ end
62
67
 
63
68
  # @see width
64
- def width=(v) Axlsx::validate_unsigned_int(v); @width = v; end
69
+ def width=(v)
70
+ Axlsx.validate_unsigned_int(v)
71
+ @width = v
72
+ end
65
73
 
66
74
  # The index of this anchor in the drawing
67
75
  # @return [Integer]
@@ -72,12 +80,12 @@ module Axlsx
72
80
  # Serializes the object
73
81
  # @param [String] str
74
82
  # @return [String]
75
- def to_xml_string(str = '')
83
+ def to_xml_string(str = +'')
76
84
  str << '<xdr:oneCellAnchor>'
77
85
  str << '<xdr:from>'
78
86
  from.to_xml_string(str)
79
87
  str << '</xdr:from>'
80
- str << ('<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>')
88
+ str << '<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>'
81
89
  @object.to_xml_string(str)
82
90
  str << '<xdr:clientData/>'
83
91
  str << '</xdr:oneCellAnchor>'
@@ -91,7 +99,7 @@ module Axlsx
91
99
  def ext
92
100
  cy = @height * 914400 / 96
93
101
  cx = @width * 914400 / 96
94
- { :cy => cy, :cx => cx }
102
+ { cy: cy, cx: cx }
95
103
  end
96
104
  end
97
105
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # a Pic object represents an image in your worksheet
3
5
  # Worksheet#add_image is the recommended way to manage images in your sheets
@@ -28,7 +30,7 @@ module Axlsx
28
30
  end
29
31
 
30
32
  # allowed mime types
31
- ALLOWED_MIME_TYPES = %w(image/jpeg image/png image/gif)
33
+ ALLOWED_MIME_TYPES = %w(image/jpeg image/png image/gif).freeze
32
34
 
33
35
  # The name to use for this picture
34
36
  # @return [String]
@@ -67,7 +69,7 @@ module Axlsx
67
69
  options[:href] = v
68
70
  if hyperlink.is_a?(Hyperlink)
69
71
  options.each do |o|
70
- hyperlink.send("#{o[0]}=", o[1]) if hyperlink.respond_to? "#{o[0]}="
72
+ hyperlink.send(:"#{o[0]}=", o[1]) if hyperlink.respond_to? :"#{o[0]}="
71
73
  end
72
74
  else
73
75
  @hyperlink = Hyperlink.new(self, options)
@@ -76,7 +78,7 @@ module Axlsx
76
78
  end
77
79
 
78
80
  def image_src=(v)
79
- Axlsx::validate_string(v)
81
+ Axlsx.validate_string(v)
80
82
  if remote?
81
83
  RegexValidator.validate('Pic.image_src', /\A#{URI::DEFAULT_PARSER.make_regexp}\z/, v)
82
84
  RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeTypeUtils.get_mime_type_from_uri(v)
@@ -89,13 +91,22 @@ module Axlsx
89
91
  end
90
92
 
91
93
  # @see name
92
- def name=(v) Axlsx::validate_string(v); @name = v; end
94
+ def name=(v)
95
+ Axlsx.validate_string(v)
96
+ @name = v
97
+ end
93
98
 
94
99
  # @see descr
95
- def descr=(v) Axlsx::validate_string(v); @descr = v; end
100
+ def descr=(v)
101
+ Axlsx.validate_string(v)
102
+ @descr = v
103
+ end
96
104
 
97
105
  # @see remote
98
- def remote=(v) Axlsx::validate_boolean(v); @remote = v; end
106
+ def remote=(v)
107
+ Axlsx.validate_boolean(v)
108
+ @remote = v
109
+ end
99
110
 
100
111
  def remote?
101
112
  remote == 1 || remote.to_s == 'true'
@@ -122,14 +133,14 @@ module Axlsx
122
133
  # The part name for this image used in serialization and relationship building
123
134
  # @return [String]
124
135
  def pn
125
- "#{IMAGE_PN % [(index + 1), extname]}"
136
+ format(IMAGE_PN, index + 1, extname)
126
137
  end
127
138
 
128
139
  # The relationship object for this pic.
129
140
  # @return [Relationship]
130
141
  def relationship
131
142
  if remote?
132
- Relationship.new(self, IMAGE_R, "#{image_src}", target_mode: :External)
143
+ Relationship.new(self, IMAGE_R, image_src.to_s, target_mode: :External)
133
144
  else
134
145
  Relationship.new(self, IMAGE_R, "../#{pn}")
135
146
  end
@@ -187,10 +198,10 @@ module Axlsx
187
198
  # Serializes the object
188
199
  # @param [String] str
189
200
  # @return [String]
190
- def to_xml_string(str = '')
201
+ def to_xml_string(str = +'')
191
202
  str << '<xdr:pic>'
192
203
  str << '<xdr:nvPicPr>'
193
- str << ('<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">')
204
+ str << '<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">'
194
205
  hyperlink.to_xml_string(str) if hyperlink.is_a?(Hyperlink)
195
206
  str << '</xdr:cNvPr><xdr:cNvPicPr>'
196
207
  picture_locking.to_xml_string(str)
@@ -211,9 +222,9 @@ module Axlsx
211
222
  # Return correct xml relationship string portion
212
223
  def relationship_xml_portion
213
224
  if remote?
214
- ('<a:blip xmlns:r ="' << XML_NS_R << '" r:link="' << relationship.Id << '">')
225
+ (+'<a:blip xmlns:r ="' << XML_NS_R << '" r:link="' << relationship.Id << '">')
215
226
  else
216
- ('<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '">')
227
+ (+'<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '">')
217
228
  end
218
229
  end
219
230
 
@@ -221,7 +232,7 @@ module Axlsx
221
232
  def use_one_cell_anchor
222
233
  return if @anchor.is_a?(OneCellAnchor)
223
234
 
224
- new_anchor = OneCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row])
235
+ new_anchor = OneCellAnchor.new(@anchor.drawing, start_at: [@anchor.from.col, @anchor.from.row])
225
236
  swap_anchor(new_anchor)
226
237
  end
227
238
 
@@ -229,7 +240,7 @@ module Axlsx
229
240
  def use_two_cell_anchor
230
241
  return if @anchor.is_a?(TwoCellAnchor)
231
242
 
232
- new_anchor = TwoCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row])
243
+ new_anchor = TwoCellAnchor.new(@anchor.drawing, start_at: [@anchor.from.col, @anchor.from.row])
233
244
  swap_anchor(new_anchor)
234
245
  end
235
246
 
@@ -237,7 +248,7 @@ module Axlsx
237
248
  def swap_anchor(new_anchor)
238
249
  new_anchor.drawing.anchors.delete(new_anchor)
239
250
  @anchor.drawing.anchors[@anchor.drawing.anchors.index(@anchor)] = new_anchor
240
- new_anchor.instance_variable_set "@object", @anchor.object
251
+ new_anchor.instance_variable_set :@object, @anchor.object
241
252
  @anchor = new_anchor
242
253
  end
243
254
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The picture locking class defines the locking properties for pictures in your workbook.
3
5
  class PictureLocking
@@ -32,7 +34,7 @@ module Axlsx
32
34
  # Serializes the object
33
35
  # @param [String] str
34
36
  # @return [String]
35
- def to_xml_string(str = '')
37
+ def to_xml_string(str = +'')
36
38
  serialized_tag('a:picLocks', str)
37
39
  end
38
40
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
- # The Pie3DChart is a three dimentional piechart (who would have guessed?) that you can add to your worksheet.
4
+ # The Pie3DChart is a three dimensional pie chart (who would have guessed?) that you can add to your worksheet.
3
5
  # @see Worksheet#add_chart
4
6
  # @see Chart#add_series
5
7
  # @see README for an example
@@ -22,17 +24,17 @@ module Axlsx
22
24
  @vary_colors = true
23
25
  super(frame, options)
24
26
  @series_type = PieSeries
25
- @view_3D = View3D.new({ :rot_x => 30, :perspective => 30 }.merge(options))
27
+ @view_3D = View3D.new({ rot_x: 30, perspective: 30 }.merge(options))
26
28
  @d_lbls = nil
27
29
  end
28
30
 
29
31
  # Serializes the object
30
32
  # @param [String] str
31
33
  # @return [String]
32
- def to_xml_string(str = '')
34
+ def to_xml_string(str = +'')
33
35
  super(str) do
34
36
  str << '<c:pie3DChart>'
35
- str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
37
+ str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
36
38
  @series.each { |ser| ser.to_xml_string(str) }
37
39
  d_lbls.to_xml_string(str) if @d_lbls
38
40
  str << '</c:pie3DChart>'
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Axlsx
4
+ # The PieChart is a pie chart that you can add to your worksheet.
5
+ # @see Worksheet#add_chart
6
+ # @see Chart#add_series
7
+ # @see README for an example
8
+ class PieChart < Chart
9
+ # Creates a new pie chart object
10
+ # @param [GraphicFrame] frame The workbook that owns this chart.
11
+ # @option options [Cell, String] title
12
+ # @option options [Boolean] show_legend
13
+ # @option options [Symbol] grouping
14
+ # @option options [String] gap_depth
15
+ # @see Chart
16
+ def initialize(frame, options = {})
17
+ @vary_colors = true
18
+ super(frame, options)
19
+ @series_type = PieSeries
20
+ @d_lbls = nil
21
+ end
22
+
23
+ # Serializes the object
24
+ # @param [String] str
25
+ # @return [String]
26
+ def to_xml_string(str = +'')
27
+ super(str) do
28
+ str << '<c:pieChart>'
29
+ str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
30
+ @series.each { |ser| ser.to_xml_string(str) }
31
+ d_lbls.to_xml_string(str) if @d_lbls
32
+ str << '</c:pieChart>'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A PieSeries defines the data and labels and explosion for pie charts series.
3
5
  # @note The recommended way to manage series is to use Chart#add_series
@@ -29,27 +31,33 @@ module Axlsx
29
31
  @explosion = nil
30
32
  @colors = []
31
33
  super(chart, options)
32
- self.labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
34
+ self.labels = AxDataSource.new(data: options[:labels]) unless options[:labels].nil?
33
35
  self.data = NumDataSource.new(options) unless options[:data].nil?
34
36
  end
35
37
 
36
38
  # @see colors
37
- def colors=(v) DataTypeValidator.validate "BarSeries.colors", [Array], v; @colors = v end
39
+ def colors=(v)
40
+ DataTypeValidator.validate "BarSeries.colors", [Array], v
41
+ @colors = v
42
+ end
38
43
 
39
44
  # @see explosion
40
- def explosion=(v) Axlsx::validate_unsigned_int(v); @explosion = v; end
45
+ def explosion=(v)
46
+ Axlsx.validate_unsigned_int(v)
47
+ @explosion = v
48
+ end
41
49
 
42
50
  # Serializes the object
43
51
  # @param [String] str
44
52
  # @return [String]
45
- def to_xml_string(str = '')
53
+ def to_xml_string(str = +'')
46
54
  super(str) do
47
- str << '<c:explosion val="' + @explosion.to_s + '"/>' unless @explosion.nil?
55
+ str << '<c:explosion val="' << @explosion.to_s << '"/>' unless @explosion.nil?
48
56
  colors.each_with_index do |c, index|
49
57
  str << '<c:dPt>'
50
- str << ('<c:idx val="' << index.to_s << '"/>')
58
+ str << '<c:idx val="' << index.to_s << '"/>'
51
59
  str << '<c:spPr><a:solidFill>'
52
- str << ('<a:srgbClr val="' << c << '"/>')
60
+ str << '<a:srgbClr val="' << c << '"/>'
53
61
  str << '</a:solidFill></c:spPr></c:dPt>'
54
62
  end
55
63
  @labels.to_xml_string str unless @labels.nil?
@@ -61,9 +69,15 @@ module Axlsx
61
69
  private
62
70
 
63
71
  # assigns the data for this series
64
- def data=(v) DataTypeValidator.validate "Series.data", [NumDataSource], v; @data = v; end
72
+ def data=(v)
73
+ DataTypeValidator.validate "Series.data", [NumDataSource], v
74
+ @data = v
75
+ end
65
76
 
66
77
  # assigns the labels for this series
67
- def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
78
+ def labels=(v)
79
+ DataTypeValidator.validate "Series.labels", [AxDataSource], v
80
+ @labels = v
81
+ end
68
82
  end
69
83
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The Scaling class defines axis scaling
3
5
  class Scaling
@@ -33,24 +35,38 @@ module Axlsx
33
35
  attr_reader :min
34
36
 
35
37
  # @see logBase
36
- def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer], v, lambda { |arg| arg >= 2 && arg <= 1000 }; @logBase = v; end
38
+ def logBase=(v)
39
+ DataTypeValidator.validate "Scaling.logBase", [Integer], v, ->(arg) { arg >= 2 && arg <= 1000 }
40
+ @logBase = v
41
+ end
42
+
37
43
  # @see orientation
38
- def orientation=(v) RestrictionValidator.validate "Scaling.orientation", [:minMax, :maxMin], v; @orientation = v; end
44
+ def orientation=(v)
45
+ RestrictionValidator.validate "Scaling.orientation", [:minMax, :maxMin], v
46
+ @orientation = v
47
+ end
48
+
39
49
  # @see max
40
- def max=(v) DataTypeValidator.validate "Scaling.max", Float, v; @max = v; end
50
+ def max=(v)
51
+ DataTypeValidator.validate "Scaling.max", Float, v
52
+ @max = v
53
+ end
41
54
 
42
55
  # @see min
43
- def min=(v) DataTypeValidator.validate "Scaling.min", Float, v; @min = v; end
56
+ def min=(v)
57
+ DataTypeValidator.validate "Scaling.min", Float, v
58
+ @min = v
59
+ end
44
60
 
45
61
  # Serializes the object
46
62
  # @param [String] str
47
63
  # @return [String]
48
- def to_xml_string(str = '')
64
+ def to_xml_string(str = +'')
49
65
  str << '<c:scaling>'
50
- str << ('<c:logBase val="' << @logBase.to_s << '"/>') unless @logBase.nil?
51
- str << ('<c:orientation val="' << @orientation.to_s << '"/>') unless @orientation.nil?
52
- str << ('<c:min val="' << @min.to_s << '"/>') unless @min.nil?
53
- str << ('<c:max val="' << @max.to_s << '"/>') unless @max.nil?
66
+ str << '<c:logBase val="' << @logBase.to_s << '"/>' unless @logBase.nil?
67
+ str << '<c:orientation val="' << @orientation.to_s << '"/>' unless @orientation.nil?
68
+ str << '<c:min val="' << @min.to_s << '"/>' unless @min.nil?
69
+ str << '<c:max val="' << @max.to_s << '"/>' unless @max.nil?
54
70
  str << '</c:scaling>'
55
71
  end
56
72
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The ScatterChart allows you to insert a scatter chart into your worksheet
3
5
  # @see Worksheet#add_chart
@@ -47,14 +49,14 @@ module Axlsx
47
49
  # Serializes the object
48
50
  # @param [String] str
49
51
  # @return [String]
50
- def to_xml_string(str = '')
52
+ def to_xml_string(str = +'')
51
53
  super(str) do
52
54
  str << '<c:scatterChart>'
53
- str << ('<c:scatterStyle val="' << scatter_style.to_s << '"/>')
54
- str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
55
+ str << '<c:scatterStyle val="' << scatter_style.to_s << '"/>'
56
+ str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
55
57
  @series.each { |ser| ser.to_xml_string(str) }
56
58
  d_lbls.to_xml_string(str) if @d_lbls
57
- axes.to_xml_string(str, :ids => true)
59
+ axes.to_xml_string(str, ids: true)
58
60
  str << '</c:scatterChart>'
59
61
  axes.to_xml_string(str)
60
62
  end
@@ -65,7 +67,7 @@ module Axlsx
65
67
  # a y_val_axis
66
68
  # @return [Axes]
67
69
  def axes
68
- @axes ||= Axes.new(:x_val_axis => ValAxis, :y_val_axis => ValAxis)
70
+ @axes ||= Axes.new(x_val_axis: ValAxis, y_val_axis: ValAxis)
69
71
  end
70
72
  end
71
73
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A ScatterSeries defines the x and y position of data in the chart
3
5
  # @note The recommended way to manage series is to use Chart#add_series
@@ -41,7 +43,7 @@ module Axlsx
41
43
  @smooth = [:smooth, :smoothMarker].include?(chart.scatter_style)
42
44
  else
43
45
  # Set smoothing according to the option provided
44
- Axlsx::validate_boolean(options[:smooth])
46
+ Axlsx.validate_boolean(options[:smooth])
45
47
  @smooth = options[:smooth]
46
48
  end
47
49
  @ln_width = options[:ln_width] unless options[:ln_width].nil?
@@ -49,8 +51,8 @@ module Axlsx
49
51
  @marker_symbol = :default
50
52
 
51
53
  super(chart, options)
52
- @xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil?
53
- @yData = NumDataSource.new({ :tag_name => :yVal, :data => options[:yData] }) unless options[:yData].nil?
54
+ @xData = AxDataSource.new(tag_name: :xVal, data: options[:xData]) unless options[:xData].nil?
55
+ @yData = NumDataSource.new({ tag_name: :yVal, data: options[:yData] }) unless options[:yData].nil?
54
56
  end
55
57
 
56
58
  # @see color
@@ -60,7 +62,7 @@ module Axlsx
60
62
 
61
63
  # @see smooth
62
64
  def smooth=(v)
63
- Axlsx::validate_boolean(v)
65
+ Axlsx.validate_boolean(v)
64
66
  @smooth = v
65
67
  end
66
68
 
@@ -71,29 +73,29 @@ module Axlsx
71
73
 
72
74
  # @see marker_symbol
73
75
  def marker_symbol=(v)
74
- Axlsx::validate_marker_symbol(v)
76
+ Axlsx.validate_marker_symbol(v)
75
77
  @marker_symbol = v
76
78
  end
77
79
 
78
80
  # Serializes the object
79
81
  # @param [String] str
80
82
  # @return [String]
81
- def to_xml_string(str = '')
83
+ def to_xml_string(str = +'')
82
84
  super(str) do
83
85
  # needs to override the super color here to push in ln/and something else!
84
86
  if color
85
87
  str << '<c:spPr><a:solidFill>'
86
- str << ('<a:srgbClr val="' << color << '"/>')
88
+ str << '<a:srgbClr val="' << color << '"/>'
87
89
  str << '</a:solidFill>'
88
90
  str << '<a:ln><a:solidFill>'
89
- str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
91
+ str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
90
92
  str << '</c:spPr>'
91
93
  str << '<c:marker>'
92
94
  str << '<c:spPr><a:solidFill>'
93
- str << ('<a:srgbClr val="' << color << '"/>')
95
+ str << '<a:srgbClr val="' << color << '"/>'
94
96
  str << '</a:solidFill>'
95
97
  str << '<a:ln><a:solidFill>'
96
- str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
98
+ str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
97
99
  str << '</c:spPr>'
98
100
  str << marker_symbol_xml
99
101
  str << '</c:marker>'
@@ -108,7 +110,7 @@ module Axlsx
108
110
  end
109
111
  @xData.to_xml_string(str) unless @xData.nil?
110
112
  @yData.to_xml_string(str) unless @yData.nil?
111
- str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
113
+ str << '<c:smooth val="' << (smooth ? '1' : '0') << '"/>'
112
114
  end
113
115
  str
114
116
  end
@@ -119,7 +121,7 @@ module Axlsx
119
121
  if !@show_marker
120
122
  '<c:symbol val="none"/>'
121
123
  elsif @marker_symbol != :default
122
- '<c:symbol val="' + @marker_symbol.to_s + '"/>'
124
+ +'<c:symbol val="' << @marker_symbol.to_s << '"/>'
123
125
  end.to_s
124
126
  end
125
127
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A SerAxis object defines a series axis
3
5
  class SerAxis < Axis
@@ -20,21 +22,27 @@ module Axlsx
20
22
  end
21
23
 
22
24
  # @see tickLblSkip
23
- def tick_lbl_skip=(v) Axlsx::validate_unsigned_int(v); @tick_lbl_skip = v; end
25
+ def tick_lbl_skip=(v)
26
+ Axlsx.validate_unsigned_int(v)
27
+ @tick_lbl_skip = v
28
+ end
24
29
  alias :tickLblSkip= :tick_lbl_skip=
25
30
 
26
31
  # @see tickMarkSkip
27
- def tick_mark_skip=(v) Axlsx::validate_unsigned_int(v); @tick_mark_skip = v; end
32
+ def tick_mark_skip=(v)
33
+ Axlsx.validate_unsigned_int(v)
34
+ @tick_mark_skip = v
35
+ end
28
36
  alias :tickMarkSkip= :tick_mark_skip=
29
37
 
30
38
  # Serializes the object
31
39
  # @param [String] str
32
40
  # @return [String]
33
- def to_xml_string(str = '')
41
+ def to_xml_string(str = +'')
34
42
  str << '<c:serAx>'
35
43
  super(str)
36
- str << ('<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>') unless @tick_lbl_skip.nil?
37
- str << ('<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>') unless @tick_mark_skip.nil?
44
+ str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>' unless @tick_lbl_skip.nil?
45
+ str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>' unless @tick_mark_skip.nil?
38
46
  str << '</c:serAx>'
39
47
  end
40
48
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A Series defines the common series attributes and is the super class for all concrete series types.
3
5
  # @note The recommended way to manage series is to use Chart#add_series
@@ -38,7 +40,10 @@ module Axlsx
38
40
  end
39
41
 
40
42
  # @see order
41
- def order=(v) Axlsx::validate_unsigned_int(v); @order = v; end
43
+ def order=(v)
44
+ Axlsx.validate_unsigned_int(v)
45
+ @order = v
46
+ end
42
47
 
43
48
  # @see title
44
49
  def title=(v)
@@ -50,15 +55,18 @@ module Axlsx
50
55
  private
51
56
 
52
57
  # assigns the chart for this series
53
- def chart=(v) DataTypeValidator.validate "Series.chart", Chart, v; @chart = v; end
58
+ def chart=(v)
59
+ DataTypeValidator.validate "Series.chart", Chart, v
60
+ @chart = v
61
+ end
54
62
 
55
63
  # Serializes the object
56
64
  # @param [String] str
57
65
  # @return [String]
58
- def to_xml_string(str = '')
66
+ def to_xml_string(str = +'')
59
67
  str << '<c:ser>'
60
- str << ('<c:idx val="' << index.to_s << '"/>')
61
- str << ('<c:order val="' << (order || index).to_s << '"/>')
68
+ str << '<c:idx val="' << index.to_s << '"/>'
69
+ str << '<c:order val="' << (order || index).to_s << '"/>'
62
70
  title.to_xml_string(str) unless title.nil?
63
71
  yield if block_given?
64
72
  str << '</c:ser>'
@@ -1,19 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A series title is a Title with a slightly different serialization than chart titles.
3
5
  class SeriesTitle < Title
4
6
  # Serializes the object
5
7
  # @param [String] str
6
8
  # @return [String]
7
- def to_xml_string(str = '')
8
- clean_value = Axlsx::trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@text.to_s))
9
+ def to_xml_string(str = +'')
10
+ clean_value = Axlsx.trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@text.to_s))
9
11
 
10
12
  str << '<c:tx>'
11
13
  str << '<c:strRef>'
12
- str << ('<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>')
14
+ str << '<c:f>' << Axlsx.cell_range([@cell]) << '</c:f>'
13
15
  str << '<c:strCache>'
14
16
  str << '<c:ptCount val="1"/>'
15
17
  str << '<c:pt idx="0">'
16
- str << ('<c:v>' << clean_value << '</c:v>')
18
+ str << '<c:v>' << clean_value << '</c:v>'
17
19
  str << '</c:pt>'
18
20
  str << '</c:strCache>'
19
21
  str << '</c:strRef>'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # This specifies the last string data used for a chart. (e.g. strLit and strCache)
3
5
  # This class is extended for NumData to include the formatCode attribute required for numLit and numCache
@@ -20,18 +22,18 @@ module Axlsx
20
22
  @tag_name = values.first.is_a?(Cell) ? :strCache : :strLit
21
23
  values.each do |value|
22
24
  v = value.is_a?(Cell) ? value.value : value
23
- @pt << @type.new(:v => v)
25
+ @pt << @type.new(v: v)
24
26
  end
25
27
  end
26
28
 
27
29
  # serialize the object
28
- def to_xml_string(str = "")
29
- str << ('<c:' << @tag_name.to_s << '>')
30
- str << ('<c:ptCount val="' << @pt.size.to_s << '"/>')
30
+ def to_xml_string(str = +'')
31
+ str << '<c:' << @tag_name.to_s << '>'
32
+ str << '<c:ptCount val="' << @pt.size.to_s << '"/>'
31
33
  @pt.each_with_index do |value, index|
32
34
  value.to_xml_string index, str
33
35
  end
34
- str << ('</c:' << @tag_name.to_s << '>')
36
+ str << '</c:' << @tag_name.to_s << '>'
35
37
  end
36
38
  end
37
39
  end