caxlsx 3.3.0 → 4.0.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 (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +25 -7
  4. data/Rakefile +7 -6
  5. data/lib/axlsx/content_type/abstract_content_type.rb +11 -9
  6. data/lib/axlsx/content_type/content_type.rb +7 -9
  7. data/lib/axlsx/content_type/default.rb +4 -6
  8. data/lib/axlsx/content_type/override.rb +3 -5
  9. data/lib/axlsx/doc_props/app.rb +27 -30
  10. data/lib/axlsx/doc_props/core.rb +9 -12
  11. data/lib/axlsx/drawing/area_chart.rb +13 -14
  12. data/lib/axlsx/drawing/area_series.rb +13 -14
  13. data/lib/axlsx/drawing/ax_data_source.rb +3 -6
  14. data/lib/axlsx/drawing/axes.rb +10 -9
  15. data/lib/axlsx/drawing/axis.rb +27 -30
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +17 -18
  17. data/lib/axlsx/drawing/bar_chart.rb +16 -17
  18. data/lib/axlsx/drawing/bar_series.rb +9 -13
  19. data/lib/axlsx/drawing/bubble_chart.rb +8 -9
  20. data/lib/axlsx/drawing/bubble_series.rb +9 -10
  21. data/lib/axlsx/drawing/cat_axis.rb +14 -17
  22. data/lib/axlsx/drawing/chart.rb +25 -28
  23. data/lib/axlsx/drawing/d_lbls.rb +29 -26
  24. data/lib/axlsx/drawing/drawing.rb +60 -62
  25. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  26. data/lib/axlsx/drawing/hyperlink.rb +12 -13
  27. data/lib/axlsx/drawing/line_3D_chart.rb +13 -15
  28. data/lib/axlsx/drawing/line_chart.rb +13 -14
  29. data/lib/axlsx/drawing/line_series.rb +13 -14
  30. data/lib/axlsx/drawing/marker.rb +14 -16
  31. data/lib/axlsx/drawing/num_data.rb +13 -16
  32. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  33. data/lib/axlsx/drawing/num_val.rb +9 -10
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +10 -10
  35. data/lib/axlsx/drawing/pic.rb +57 -22
  36. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +6 -9
  38. data/lib/axlsx/drawing/pie_series.rb +9 -12
  39. data/lib/axlsx/drawing/scaling.rb +9 -10
  40. data/lib/axlsx/drawing/scatter_chart.rb +9 -10
  41. data/lib/axlsx/drawing/scatter_series.rb +15 -16
  42. data/lib/axlsx/drawing/ser_axis.rb +9 -11
  43. data/lib/axlsx/drawing/series.rb +8 -8
  44. data/lib/axlsx/drawing/series_title.rb +6 -6
  45. data/lib/axlsx/drawing/str_data.rb +10 -13
  46. data/lib/axlsx/drawing/str_val.rb +8 -9
  47. data/lib/axlsx/drawing/title.rb +23 -27
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +8 -8
  49. data/lib/axlsx/drawing/val_axis.rb +5 -6
  50. data/lib/axlsx/drawing/view_3D.rb +32 -30
  51. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  52. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  53. data/lib/axlsx/package.rb +81 -79
  54. data/lib/axlsx/rels/relationship.rb +30 -28
  55. data/lib/axlsx/rels/relationships.rb +7 -8
  56. data/lib/axlsx/stylesheet/border.rb +7 -8
  57. data/lib/axlsx/stylesheet/border_pr.rb +8 -8
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +14 -20
  59. data/lib/axlsx/stylesheet/cell_protection.rb +6 -7
  60. data/lib/axlsx/stylesheet/cell_style.rb +12 -14
  61. data/lib/axlsx/stylesheet/color.rb +15 -12
  62. data/lib/axlsx/stylesheet/dxf.rb +7 -9
  63. data/lib/axlsx/stylesheet/fill.rb +3 -5
  64. data/lib/axlsx/stylesheet/font.rb +24 -21
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +9 -9
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +7 -6
  67. data/lib/axlsx/stylesheet/num_fmt.rb +9 -14
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +8 -8
  69. data/lib/axlsx/stylesheet/styles.rb +104 -98
  70. data/lib/axlsx/stylesheet/table_style.rb +8 -9
  71. data/lib/axlsx/stylesheet/table_style_element.rb +7 -8
  72. data/lib/axlsx/stylesheet/table_styles.rb +8 -10
  73. data/lib/axlsx/stylesheet/xf.rb +21 -22
  74. data/lib/axlsx/util/accessors.rb +6 -6
  75. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  76. data/lib/axlsx/util/constants.rb +119 -108
  77. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  78. data/lib/axlsx/util/options_parser.rb +4 -3
  79. data/lib/axlsx/util/serialized_attributes.rb +45 -21
  80. data/lib/axlsx/util/simple_typed_list.rb +58 -57
  81. data/lib/axlsx/util/storage.rb +38 -41
  82. data/lib/axlsx/util/validators.rb +107 -44
  83. data/lib/axlsx/util/zip_command.rb +10 -12
  84. data/lib/axlsx/version.rb +3 -2
  85. data/lib/axlsx/workbook/defined_name.rb +11 -8
  86. data/lib/axlsx/workbook/defined_names.rb +4 -3
  87. data/lib/axlsx/workbook/shared_strings_table.rb +10 -11
  88. data/lib/axlsx/workbook/workbook.rb +121 -114
  89. data/lib/axlsx/workbook/workbook_view.rb +8 -11
  90. data/lib/axlsx/workbook/workbook_views.rb +4 -4
  91. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +72 -14
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -7
  93. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +24 -21
  94. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  95. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
  96. data/lib/axlsx/workbook/worksheet/border_creator.rb +30 -25
  97. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  98. data/lib/axlsx/workbook/worksheet/cell.rb +92 -65
  99. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +32 -28
  100. data/lib/axlsx/workbook/worksheet/cfvo.rb +7 -5
  101. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  102. data/lib/axlsx/workbook/worksheet/col.rb +9 -10
  103. data/lib/axlsx/workbook/worksheet/col_breaks.rb +8 -7
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  105. data/lib/axlsx/workbook/worksheet/cols.rb +9 -7
  106. data/lib/axlsx/workbook/worksheet/comment.rb +12 -11
  107. data/lib/axlsx/workbook/worksheet/comments.rb +10 -12
  108. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +12 -8
  109. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +19 -21
  110. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +5 -5
  111. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  112. data/lib/axlsx/workbook/worksheet/data_validation.rb +34 -33
  113. data/lib/axlsx/workbook/worksheet/data_validations.rb +5 -6
  114. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/dimension.rb +9 -6
  116. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -3
  117. data/lib/axlsx/workbook/worksheet/icon_set.rb +24 -8
  118. data/lib/axlsx/workbook/worksheet/merged_cells.rb +10 -10
  119. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -3
  120. data/lib/axlsx/workbook/worksheet/page_margins.rb +17 -12
  121. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -4
  122. data/lib/axlsx/workbook/worksheet/page_setup.rb +128 -129
  123. data/lib/axlsx/workbook/worksheet/pane.rb +27 -26
  124. data/lib/axlsx/workbook/worksheet/pivot_table.rb +23 -25
  125. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  126. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +5 -4
  127. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -2
  128. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  129. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +12 -10
  130. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  131. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +35 -17
  132. data/lib/axlsx/workbook/worksheet/row.rb +30 -22
  133. data/lib/axlsx/workbook/worksheet/row_breaks.rb +8 -7
  134. data/lib/axlsx/workbook/worksheet/selection.rb +16 -16
  135. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +10 -7
  136. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  137. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  138. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +11 -7
  139. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +21 -20
  140. data/lib/axlsx/workbook/worksheet/sheet_view.rb +48 -53
  141. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  142. data/lib/axlsx/workbook/worksheet/table_style_info.rb +6 -5
  143. data/lib/axlsx/workbook/worksheet/tables.rb +7 -5
  144. data/lib/axlsx/workbook/worksheet/worksheet.rb +92 -63
  145. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +10 -8
  146. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  147. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +9 -8
  148. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +7 -5
  149. data/lib/axlsx.rb +75 -47
  150. data/lib/caxlsx.rb +3 -2
  151. metadata +50 -44
@@ -1,14 +1,15 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # a Pic object represents an image in your worksheet
4
5
  # Worksheet#add_image is the recommended way to manage images in your sheets
5
6
  # @see Worksheet#add_image
6
7
  class Pic
7
-
8
8
  include Axlsx::OptionsParser
9
9
 
10
10
  # Creates a new Pic(ture) object
11
11
  # @param [Anchor] anchor the anchor that holds this image
12
+ # @option options [Boolean] :remote indicates if image_src is a remote URI
12
13
  # @option options [String] :name
13
14
  # @option options [String] :descr
14
15
  # @option options [String] :image_src
@@ -16,10 +17,11 @@ module Axlsx
16
17
  # @option options [Integer] :width
17
18
  # @option options [Integer] :height
18
19
  # @option options [Float] :opacity - set the picture opacity, accepts a value between 0.0 and 1.0
19
- def initialize(anchor, options={})
20
+ def initialize(anchor, options = {})
20
21
  @anchor = anchor
21
22
  @hyperlink = nil
22
23
  @anchor.drawing.worksheet.workbook.images << self
24
+ @remote = options[:remote]
23
25
  parse_options options
24
26
  start_at(*options[:start_at]) if options[:start_at]
25
27
  yield self if block_given?
@@ -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]
@@ -56,10 +58,14 @@ module Axlsx
56
58
  # @return [Integer]
57
59
  attr_reader :opacity
58
60
 
61
+ # Flag for remote picture (from URI)
62
+ # @return [Boolean]
63
+ attr_reader :remote
64
+
59
65
  # sets or updates a hyperlink for this image.
60
66
  # @param [String] v The href value for the hyper link
61
67
  # @option options @see Hyperlink#initialize All options available to the Hyperlink class apply - however href will be overridden with the v parameter value.
62
- def hyperlink=(v, options={})
68
+ def hyperlink=(v, options = {})
63
69
  options[:href] = v
64
70
  if hyperlink.is_a?(Hyperlink)
65
71
  options.each do |o|
@@ -72,22 +78,35 @@ module Axlsx
72
78
  end
73
79
 
74
80
  def image_src=(v)
75
- Axlsx::validate_string(v)
76
- RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeTypeUtils.get_mime_type(v)
77
- raise ArgumentError, "File does not exist" unless File.exist?(v)
81
+ Axlsx.validate_string(v)
82
+ if remote?
83
+ RegexValidator.validate('Pic.image_src', /\A#{URI::DEFAULT_PARSER.make_regexp}\z/, v)
84
+ RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeTypeUtils.get_mime_type_from_uri(v)
85
+ else
86
+ RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeTypeUtils.get_mime_type(v)
87
+ raise ArgumentError, "File does not exist" unless File.exist?(v)
88
+ end
89
+
78
90
  @image_src = v
79
91
  end
80
92
 
81
93
  # @see name
82
- def name=(v) Axlsx::validate_string(v); @name = v; end
94
+ def name=(v) Axlsx.validate_string(v); @name = v; end
83
95
 
84
96
  # @see descr
85
- def descr=(v) Axlsx::validate_string(v); @descr = v; end
97
+ def descr=(v) Axlsx.validate_string(v); @descr = v; end
98
+
99
+ # @see remote
100
+ def remote=(v) Axlsx.validate_boolean(v); @remote = v; end
101
+
102
+ def remote?
103
+ remote == 1 || remote.to_s == 'true'
104
+ end
86
105
 
87
106
  # The file name of image_src without any path information
88
107
  # @return [String]
89
108
  def file_name
90
- File.basename(image_src) unless image_src.nil?
109
+ File.basename(image_src) unless remote? || image_src.nil?
91
110
  end
92
111
 
93
112
  # returns the extension of image_src without the preceeding '.'
@@ -105,19 +124,24 @@ module Axlsx
105
124
  # The part name for this image used in serialization and relationship building
106
125
  # @return [String]
107
126
  def pn
108
- "#{IMAGE_PN % [(index+1), extname]}"
127
+ format(IMAGE_PN, index + 1, extname)
109
128
  end
110
129
 
111
130
  # The relationship object for this pic.
112
131
  # @return [Relationship]
113
132
  def relationship
114
- Relationship.new(self, IMAGE_R, "../#{pn}")
133
+ if remote?
134
+ Relationship.new(self, IMAGE_R, image_src.to_s, target_mode: :External)
135
+ else
136
+ Relationship.new(self, IMAGE_R, "../#{pn}")
137
+ end
115
138
  end
116
139
 
117
140
  # providing access to the anchor's width attribute
118
141
  # @see OneCellAnchor.width
119
142
  def width
120
143
  return unless @anchor.is_a?(OneCellAnchor)
144
+
121
145
  @anchor.width
122
146
  end
123
147
 
@@ -147,7 +171,7 @@ module Axlsx
147
171
  # @param [Integer] x The column
148
172
  # @param [Integer] y The row
149
173
  # @return [Marker]
150
- def start_at(x, y=nil)
174
+ def start_at(x, y = nil)
151
175
  @anchor.start_at x, y
152
176
  @anchor.from
153
177
  end
@@ -156,7 +180,7 @@ module Axlsx
156
180
  # @param [Integer] x The column
157
181
  # @param [Integer] y The row
158
182
  # @return [Marker]
159
- def end_at(x, y=nil)
183
+ def end_at(x, y = nil)
160
184
  use_two_cell_anchor unless @anchor.is_a?(TwoCellAnchor)
161
185
  @anchor.end_at x, y
162
186
  @anchor.to
@@ -165,16 +189,16 @@ module Axlsx
165
189
  # Serializes the object
166
190
  # @param [String] str
167
191
  # @return [String]
168
- def to_xml_string(str = '')
192
+ def to_xml_string(str = +'')
169
193
  str << '<xdr:pic>'
170
194
  str << '<xdr:nvPicPr>'
171
- str << ('<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">')
195
+ str << '<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">'
172
196
  hyperlink.to_xml_string(str) if hyperlink.is_a?(Hyperlink)
173
197
  str << '</xdr:cNvPr><xdr:cNvPicPr>'
174
198
  picture_locking.to_xml_string(str)
175
199
  str << '</xdr:cNvPicPr></xdr:nvPicPr>'
176
200
  str << '<xdr:blipFill>'
177
- str << ('<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '">')
201
+ str << relationship_xml_portion
178
202
  if opacity
179
203
  str << "<a:alphaModFix amt=\"#{opacity}\"/>"
180
204
  end
@@ -186,17 +210,28 @@ module Axlsx
186
210
 
187
211
  private
188
212
 
213
+ # Return correct xml relationship string portion
214
+ def relationship_xml_portion
215
+ if remote?
216
+ (+'<a:blip xmlns:r ="' << XML_NS_R << '" r:link="' << relationship.Id << '">')
217
+ else
218
+ (+'<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '">')
219
+ end
220
+ end
221
+
189
222
  # Changes the anchor to a one cell anchor.
190
223
  def use_one_cell_anchor
191
224
  return if @anchor.is_a?(OneCellAnchor)
192
- new_anchor = OneCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row])
225
+
226
+ new_anchor = OneCellAnchor.new(@anchor.drawing, start_at: [@anchor.from.col, @anchor.from.row])
193
227
  swap_anchor(new_anchor)
194
228
  end
195
229
 
196
- #changes the anchor type to a two cell anchor
230
+ # changes the anchor type to a two cell anchor
197
231
  def use_two_cell_anchor
198
232
  return if @anchor.is_a?(TwoCellAnchor)
199
- new_anchor = TwoCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row])
233
+
234
+ new_anchor = TwoCellAnchor.new(@anchor.drawing, start_at: [@anchor.from.col, @anchor.from.row])
200
235
  swap_anchor(new_anchor)
201
236
  end
202
237
 
@@ -204,7 +239,7 @@ module Axlsx
204
239
  def swap_anchor(new_anchor)
205
240
  new_anchor.drawing.anchors.delete(new_anchor)
206
241
  @anchor.drawing.anchors[@anchor.drawing.anchors.index(@anchor)] = new_anchor
207
- new_anchor.instance_variable_set "@object", @anchor.object
242
+ new_anchor.instance_variable_set :@object, @anchor.object
208
243
  @anchor = new_anchor
209
244
  end
210
245
  end
@@ -1,15 +1,15 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # The picture locking class defines the locking properties for pictures in your workbook.
4
5
  class PictureLocking
5
-
6
6
  include Axlsx::OptionsParser
7
7
  include Axlsx::SerializedAttributes
8
8
  include Axlsx::Accessors
9
9
 
10
10
  boolean_attr_accessor :noGrp, :noSelect, :noRot, :noChangeAspect,
11
- :noMove, :noResize, :noEditPoints, :noAdjustHandles,
12
- :noChangeArrowheads, :noChangeShapeType
11
+ :noMove, :noResize, :noEditPoints, :noAdjustHandles,
12
+ :noChangeArrowheads, :noChangeShapeType
13
13
 
14
14
  serializable_attributes :noGrp, :noSelect, :noRot, :noChangeAspect,
15
15
  :noMove, :noResize, :noEditPoints, :noAdjustHandles,
@@ -26,7 +26,7 @@ module Axlsx
26
26
  # @option options [Boolean] noAdjustHandles
27
27
  # @option options [Boolean] noChangeArrowheads
28
28
  # @option options [Boolean] noChangeShapeType
29
- def initialize(options={})
29
+ def initialize(options = {})
30
30
  @noChangeAspect = true
31
31
  parse_options options
32
32
  end
@@ -34,9 +34,8 @@ module Axlsx
34
34
  # Serializes the object
35
35
  # @param [String] str
36
36
  # @return [String]
37
- def to_xml_string(str = '')
37
+ def to_xml_string(str = +'')
38
38
  serialized_tag('a:picLocks', str)
39
39
  end
40
-
41
40
  end
42
41
  end
@@ -1,13 +1,11 @@
1
- # encoding: UTF-8
2
- module Axlsx
3
-
1
+ # frozen_string_literal: true
4
2
 
3
+ module Axlsx
5
4
  # The Pie3DChart is a three dimentional piechart (who would have guessed?) that you can add to your worksheet.
6
5
  # @see Worksheet#add_chart
7
6
  # @see Chart#add_series
8
7
  # @see README for an example
9
8
  class Pie3DChart < Chart
10
-
11
9
  # Creates a new pie chart object
12
10
  # @param [GraphicFrame] frame The workbook that owns this chart.
13
11
  # @option options [Cell, String] title
@@ -22,26 +20,25 @@ module Axlsx
22
20
  # @option options [Integer] perspective
23
21
  # @see Chart
24
22
  # @see View3D
25
- def initialize(frame, options={})
23
+ def initialize(frame, options = {})
26
24
  @vary_colors = true
27
25
  super(frame, options)
28
26
  @series_type = PieSeries
29
- @view_3D = View3D.new({:rot_x =>30, :perspective=>30}.merge(options))
27
+ @view_3D = View3D.new({ rot_x: 30, perspective: 30 }.merge(options))
30
28
  @d_lbls = nil
31
29
  end
32
30
 
33
31
  # Serializes the object
34
32
  # @param [String] str
35
33
  # @return [String]
36
- def to_xml_string(str = '')
34
+ def to_xml_string(str = +'')
37
35
  super(str) do
38
36
  str << '<c:pie3DChart>'
39
- str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
37
+ str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
40
38
  @series.each { |ser| ser.to_xml_string(str) }
41
39
  d_lbls.to_xml_string(str) if @d_lbls
42
40
  str << '</c:pie3DChart>'
43
41
  end
44
42
  end
45
-
46
43
  end
47
44
  end
@@ -1,12 +1,11 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # A PieSeries defines the data and labels and explosion for pie charts series.
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
  class PieSeries < Series
9
-
10
9
  # The data for this series.
11
10
  # @return [SimpleTypedList]
12
11
  attr_reader :data
@@ -28,11 +27,11 @@ module Axlsx
28
27
  # @option options [String] title
29
28
  # @option options [Integer] explosion
30
29
  # @param [Chart] chart
31
- def initialize(chart, options={})
30
+ def initialize(chart, options = {})
32
31
  @explosion = nil
33
32
  @colors = []
34
33
  super(chart, options)
35
- self.labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
34
+ self.labels = AxDataSource.new(data: options[:labels]) unless options[:labels].nil?
36
35
  self.data = NumDataSource.new(options) unless options[:data].nil?
37
36
  end
38
37
 
@@ -40,19 +39,19 @@ module Axlsx
40
39
  def colors=(v) DataTypeValidator.validate "BarSeries.colors", [Array], v; @colors = v end
41
40
 
42
41
  # @see explosion
43
- def explosion=(v) Axlsx::validate_unsigned_int(v); @explosion = v; end
42
+ def explosion=(v) Axlsx.validate_unsigned_int(v); @explosion = v; end
44
43
 
45
44
  # Serializes the object
46
45
  # @param [String] str
47
46
  # @return [String]
48
- def to_xml_string(str = '')
47
+ def to_xml_string(str = +'')
49
48
  super(str) do
50
- str << '<c:explosion val="' + @explosion.to_s + '"/>' unless @explosion.nil?
49
+ str << '<c:explosion val="' << @explosion.to_s << '"/>' unless @explosion.nil?
51
50
  colors.each_with_index do |c, index|
52
51
  str << '<c:dPt>'
53
- str << ('<c:idx val="' << index.to_s << '"/>')
52
+ str << '<c:idx val="' << index.to_s << '"/>'
54
53
  str << '<c:spPr><a:solidFill>'
55
- str << ('<a:srgbClr val="' << c << '"/>')
54
+ str << '<a:srgbClr val="' << c << '"/>'
56
55
  str << '</a:solidFill></c:spPr></c:dPt>'
57
56
  end
58
57
  @labels.to_xml_string str unless @labels.nil?
@@ -68,7 +67,5 @@ module Axlsx
68
67
 
69
68
  # assigns the labels for this series
70
69
  def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
71
-
72
70
  end
73
-
74
71
  end
@@ -1,8 +1,8 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # The Scaling class defines axis scaling
4
5
  class Scaling
5
-
6
6
  include Axlsx::OptionsParser
7
7
 
8
8
  # creates a new Scaling object
@@ -10,7 +10,7 @@ module Axlsx
10
10
  # @option options [Symbol] orientation
11
11
  # @option options [Float] max
12
12
  # @option options [Float] min
13
- def initialize(options={})
13
+ def initialize(options = {})
14
14
  @orientation = :minMax
15
15
  @logBase, @min, @max = nil, nil, nil
16
16
  parse_options options
@@ -35,7 +35,7 @@ module Axlsx
35
35
  attr_reader :min
36
36
 
37
37
  # @see logBase
38
- def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer], v, lambda { |arg| arg >= 2 && arg <= 1000}; @logBase = v; end
38
+ def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer], v, ->(arg) { arg >= 2 && arg <= 1000 }; @logBase = v; end
39
39
  # @see orientation
40
40
  def orientation=(v) RestrictionValidator.validate "Scaling.orientation", [:minMax, :maxMin], v; @orientation = v; end
41
41
  # @see max
@@ -47,14 +47,13 @@ module Axlsx
47
47
  # Serializes the object
48
48
  # @param [String] str
49
49
  # @return [String]
50
- def to_xml_string(str = '')
50
+ def to_xml_string(str = +'')
51
51
  str << '<c:scaling>'
52
- str << ('<c:logBase val="' << @logBase.to_s << '"/>') unless @logBase.nil?
53
- str << ('<c:orientation val="' << @orientation.to_s << '"/>') unless @orientation.nil?
54
- str << ('<c:min val="' << @min.to_s << '"/>') unless @min.nil?
55
- str << ('<c:max val="' << @max.to_s << '"/>') unless @max.nil?
52
+ str << '<c:logBase val="' << @logBase.to_s << '"/>' unless @logBase.nil?
53
+ str << '<c:orientation val="' << @orientation.to_s << '"/>' unless @orientation.nil?
54
+ str << '<c:min val="' << @min.to_s << '"/>' unless @min.nil?
55
+ str << '<c:max val="' << @max.to_s << '"/>' unless @max.nil?
56
56
  str << '</c:scaling>'
57
57
  end
58
-
59
58
  end
60
59
  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 ScatterChart allows you to insert a scatter 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 ScatterChart < Chart
9
-
10
9
  include Axlsx::OptionsParser
11
10
 
12
11
  # The Style for the scatter chart
@@ -30,11 +29,11 @@ module Axlsx
30
29
  alias :yValAxis :y_val_axis
31
30
 
32
31
  # Creates a new scatter chart
33
- def initialize(frame, options={})
32
+ def initialize(frame, options = {})
34
33
  @vary_colors = 0
35
34
  @scatter_style = :lineMarker
36
35
 
37
- super(frame, options)
36
+ super(frame, options)
38
37
  @series_type = ScatterSeries
39
38
  @d_lbls = nil
40
39
  parse_options options
@@ -50,14 +49,14 @@ module Axlsx
50
49
  # Serializes the object
51
50
  # @param [String] str
52
51
  # @return [String]
53
- def to_xml_string(str = '')
52
+ def to_xml_string(str = +'')
54
53
  super(str) do
55
54
  str << '<c:scatterChart>'
56
- str << ('<c:scatterStyle val="' << scatter_style.to_s << '"/>')
57
- 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 << '"/>'
58
57
  @series.each { |ser| ser.to_xml_string(str) }
59
58
  d_lbls.to_xml_string(str) if @d_lbls
60
- axes.to_xml_string(str, :ids => true)
59
+ axes.to_xml_string(str, ids: true)
61
60
  str << '</c:scatterChart>'
62
61
  axes.to_xml_string(str)
63
62
  end
@@ -68,7 +67,7 @@ module Axlsx
68
67
  # a y_val_axis
69
68
  # @return [Axes]
70
69
  def axes
71
- @axes ||= Axes.new(:x_val_axis => ValAxis, :y_val_axis => ValAxis)
70
+ @axes ||= Axes.new(x_val_axis: ValAxis, y_val_axis: ValAxis)
72
71
  end
73
72
  end
74
73
  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 ScatterSeries defines the x and y position 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 ScatterSeries < Series
10
-
11
10
  # The x data for this series.
12
11
  # @return [NamedAxisData]
13
12
  attr_reader :xData
@@ -37,14 +36,14 @@ module Axlsx
37
36
  attr_reader :marker_symbol
38
37
 
39
38
  # Creates a new ScatterSeries
40
- def initialize(chart, options={})
39
+ def initialize(chart, options = {})
41
40
  @xData, @yData = nil
42
41
  if options[:smooth].nil?
43
42
  # If caller hasn't specified smoothing or not, turn smoothing on or off based on scatter style
44
43
  @smooth = [:smooth, :smoothMarker].include?(chart.scatter_style)
45
44
  else
46
45
  # Set smoothing according to the option provided
47
- Axlsx::validate_boolean(options[:smooth])
46
+ Axlsx.validate_boolean(options[:smooth])
48
47
  @smooth = options[:smooth]
49
48
  end
50
49
  @ln_width = options[:ln_width] unless options[:ln_width].nil?
@@ -52,8 +51,8 @@ module Axlsx
52
51
  @marker_symbol = :default
53
52
 
54
53
  super(chart, options)
55
- @xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil?
56
- @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?
57
56
  end
58
57
 
59
58
  # @see color
@@ -63,7 +62,7 @@ module Axlsx
63
62
 
64
63
  # @see smooth
65
64
  def smooth=(v)
66
- Axlsx::validate_boolean(v)
65
+ Axlsx.validate_boolean(v)
67
66
  @smooth = v
68
67
  end
69
68
 
@@ -74,29 +73,29 @@ module Axlsx
74
73
 
75
74
  # @see marker_symbol
76
75
  def marker_symbol=(v)
77
- Axlsx::validate_marker_symbol(v)
76
+ Axlsx.validate_marker_symbol(v)
78
77
  @marker_symbol = v
79
78
  end
80
79
 
81
80
  # Serializes the object
82
81
  # @param [String] str
83
82
  # @return [String]
84
- def to_xml_string(str = '')
83
+ def to_xml_string(str = +'')
85
84
  super(str) do
86
85
  # needs to override the super color here to push in ln/and something else!
87
86
  if color
88
87
  str << '<c:spPr><a:solidFill>'
89
- str << ('<a:srgbClr val="' << color << '"/>')
88
+ str << '<a:srgbClr val="' << color << '"/>'
90
89
  str << '</a:solidFill>'
91
90
  str << '<a:ln><a:solidFill>'
92
- str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
91
+ str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
93
92
  str << '</c:spPr>'
94
93
  str << '<c:marker>'
95
94
  str << '<c:spPr><a:solidFill>'
96
- str << ('<a:srgbClr val="' << color << '"/>')
95
+ str << '<a:srgbClr val="' << color << '"/>'
97
96
  str << '</a:solidFill>'
98
97
  str << '<a:ln><a:solidFill>'
99
- str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
98
+ str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
100
99
  str << '</c:spPr>'
101
100
  str << marker_symbol_xml
102
101
  str << '</c:marker>'
@@ -111,7 +110,7 @@ module Axlsx
111
110
  end
112
111
  @xData.to_xml_string(str) unless @xData.nil?
113
112
  @yData.to_xml_string(str) unless @yData.nil?
114
- str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
113
+ str << '<c:smooth val="' << (smooth ? '1' : '0') << '"/>'
115
114
  end
116
115
  str
117
116
  end
@@ -122,7 +121,7 @@ module Axlsx
122
121
  if !@show_marker
123
122
  '<c:symbol val="none"/>'
124
123
  elsif @marker_symbol != :default
125
- '<c:symbol val="' + @marker_symbol.to_s + '"/>'
124
+ +'<c:symbol val="' << @marker_symbol.to_s << '"/>'
126
125
  end.to_s
127
126
  end
128
127
  end
@@ -1,8 +1,8 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
- #A SerAxis object defines a series axis
4
+ # A SerAxis object defines a series axis
4
5
  class SerAxis < Axis
5
-
6
6
  # The number of tick lables to skip between labels
7
7
  # @return [Integer]
8
8
  attr_reader :tick_lbl_skip
@@ -16,30 +16,28 @@ module Axlsx
16
16
  # Creates a new SerAxis object
17
17
  # @option options [Integer] tick_lbl_skip
18
18
  # @option options [Integer] tick_mark_skip
19
- def initialize(options={})
19
+ def initialize(options = {})
20
20
  @tick_lbl_skip, @tick_mark_skip = 1, 1
21
21
  super(options)
22
22
  end
23
23
 
24
24
  # @see tickLblSkip
25
- def tick_lbl_skip=(v) Axlsx::validate_unsigned_int(v); @tick_lbl_skip = v; end
25
+ def tick_lbl_skip=(v) Axlsx.validate_unsigned_int(v); @tick_lbl_skip = v; end
26
26
  alias :tickLblSkip= :tick_lbl_skip=
27
27
 
28
28
  # @see tickMarkSkip
29
- def tick_mark_skip=(v) Axlsx::validate_unsigned_int(v); @tick_mark_skip = v; end
29
+ def tick_mark_skip=(v) Axlsx.validate_unsigned_int(v); @tick_mark_skip = v; end
30
30
  alias :tickMarkSkip= :tick_mark_skip=
31
31
 
32
32
  # Serializes the object
33
33
  # @param [String] str
34
34
  # @return [String]
35
- def to_xml_string(str = '')
35
+ def to_xml_string(str = +'')
36
36
  str << '<c:serAx>'
37
37
  super(str)
38
- str << ('<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>') unless @tick_lbl_skip.nil?
39
- str << ('<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>') unless @tick_mark_skip.nil?
38
+ str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>' unless @tick_lbl_skip.nil?
39
+ str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>' unless @tick_mark_skip.nil?
40
40
  str << '</c:serAx>'
41
41
  end
42
42
  end
43
-
44
-
45
43
  end
@@ -1,11 +1,11 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # A Series defines the common series attributes and is the super class for all concrete series types.
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 Series
8
-
9
9
  include Axlsx::OptionsParser
10
10
 
11
11
  # The chart that owns this series
@@ -20,7 +20,7 @@ module Axlsx
20
20
  # @param [Chart] chart
21
21
  # @option options [Integer] order
22
22
  # @option options [String] title
23
- def initialize(chart, options={})
23
+ def initialize(chart, options = {})
24
24
  @order = nil
25
25
  self.chart = chart
26
26
  @chart.series << self
@@ -40,7 +40,7 @@ module Axlsx
40
40
  end
41
41
 
42
42
  # @see order
43
- def order=(v) Axlsx::validate_unsigned_int(v); @order = v; end
43
+ def order=(v) Axlsx.validate_unsigned_int(v); @order = v; end
44
44
 
45
45
  # @see title
46
46
  def title=(v)
@@ -52,15 +52,15 @@ module Axlsx
52
52
  private
53
53
 
54
54
  # assigns the chart for this series
55
- def chart=(v) DataTypeValidator.validate "Series.chart", Chart, v; @chart = v; end
55
+ def chart=(v) DataTypeValidator.validate "Series.chart", Chart, v; @chart = v; end
56
56
 
57
57
  # Serializes the object
58
58
  # @param [String] str
59
59
  # @return [String]
60
- def to_xml_string(str = '')
60
+ def to_xml_string(str = +'')
61
61
  str << '<c:ser>'
62
- str << ('<c:idx val="' << index.to_s << '"/>')
63
- str << ('<c:order val="' << (order || index).to_s << '"/>')
62
+ str << '<c:idx val="' << index.to_s << '"/>'
63
+ str << '<c:order val="' << (order || index).to_s << '"/>'
64
64
  title.to_xml_string(str) unless title.nil?
65
65
  yield if block_given?
66
66
  str << '</c:ser>'