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,11 +1,11 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # This class details a single cell anchor for drawings.
4
5
  # @note The recommended way to manage drawings, images and charts is Worksheet#add_chart or Worksheet#add_image.
5
6
  # @see Worksheet#add_chart
6
7
  # @see Worksheet#add_image
7
8
  class OneCellAnchor
8
-
9
9
  include Axlsx::OptionsParser
10
10
 
11
11
  # Creates a new OneCellAnchor object and an Pic associated with it.
@@ -16,7 +16,7 @@ module Axlsx
16
16
  # @option options [String] image_src the file location of the image you will render
17
17
  # @option options [String] name the name attribute for the rendered image
18
18
  # @option options [String] descr the description of the image rendered
19
- def initialize(drawing, options={})
19
+ def initialize(drawing, options = {})
20
20
  @drawing = drawing
21
21
  @width = 0
22
22
  @height = 0
@@ -54,15 +54,22 @@ module Axlsx
54
54
  # We just 'figure it out' for you.
55
55
  # @param [Array, String, Cell, Integer] x Accepts many inputs for defining the starting position of the cell.
56
56
  # @param [Integer] y When x is an integer, this value is used for the row index at which the anchor starts.
57
- def start_at(x, y=0)
57
+ def start_at(x, y = 0)
58
58
  from.coord x, y
59
59
  end
60
+
60
61
  #
61
62
  # @see height
62
- 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
63
67
 
64
68
  # @see width
65
- 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
66
73
 
67
74
  # The index of this anchor in the drawing
68
75
  # @return [Integer]
@@ -73,12 +80,12 @@ module Axlsx
73
80
  # Serializes the object
74
81
  # @param [String] str
75
82
  # @return [String]
76
- def to_xml_string(str = '')
83
+ def to_xml_string(str = +'')
77
84
  str << '<xdr:oneCellAnchor>'
78
85
  str << '<xdr:from>'
79
86
  from.to_xml_string(str)
80
87
  str << '</xdr:from>'
81
- 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 << '"/>'
82
89
  @object.to_xml_string(str)
83
90
  str << '<xdr:clientData/>'
84
91
  str << '</xdr:oneCellAnchor>'
@@ -92,8 +99,7 @@ module Axlsx
92
99
  def ext
93
100
  cy = @height * 914400 / 96
94
101
  cx = @width * 914400 / 96
95
- {:cy=>cy, :cx=>cx}
102
+ { cy: cy, cx: cx }
96
103
  end
97
-
98
104
  end
99
105
  end
@@ -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,14 +58,18 @@ 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|
66
- 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]}="
67
73
  end
68
74
  else
69
75
  @hyperlink = Hyperlink.new(self, options)
@@ -72,25 +78,47 @@ 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#{Axlsx.uri_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)
95
+ Axlsx.validate_string(v)
96
+ @name = v
97
+ end
83
98
 
84
99
  # @see descr
85
- def descr=(v) Axlsx::validate_string(v); @descr = v; end
100
+ def descr=(v)
101
+ Axlsx.validate_string(v)
102
+ @descr = v
103
+ end
104
+
105
+ # @see remote
106
+ def remote=(v)
107
+ Axlsx.validate_boolean(v)
108
+ @remote = v
109
+ end
110
+
111
+ def remote?
112
+ remote == 1 || remote.to_s == 'true'
113
+ end
86
114
 
87
115
  # The file name of image_src without any path information
88
116
  # @return [String]
89
117
  def file_name
90
- File.basename(image_src) unless image_src.nil?
118
+ File.basename(image_src) unless remote? || image_src.nil?
91
119
  end
92
120
 
93
- # returns the extension of image_src without the preceeding '.'
121
+ # returns the extension of image_src without the preceding '.'
94
122
  # @return [String]
95
123
  def extname
96
124
  File.extname(image_src).delete('.') unless image_src.nil?
@@ -105,19 +133,24 @@ module Axlsx
105
133
  # The part name for this image used in serialization and relationship building
106
134
  # @return [String]
107
135
  def pn
108
- "#{IMAGE_PN % [(index+1), extname]}"
136
+ format(IMAGE_PN, index + 1, extname)
109
137
  end
110
138
 
111
139
  # The relationship object for this pic.
112
140
  # @return [Relationship]
113
141
  def relationship
114
- Relationship.new(self, IMAGE_R, "../#{pn}")
142
+ if remote?
143
+ Relationship.new(self, IMAGE_R, image_src.to_s, target_mode: :External)
144
+ else
145
+ Relationship.new(self, IMAGE_R, "../#{pn}")
146
+ end
115
147
  end
116
148
 
117
149
  # providing access to the anchor's width attribute
118
150
  # @see OneCellAnchor.width
119
151
  def width
120
152
  return unless @anchor.is_a?(OneCellAnchor)
153
+
121
154
  @anchor.width
122
155
  end
123
156
 
@@ -147,7 +180,7 @@ module Axlsx
147
180
  # @param [Integer] x The column
148
181
  # @param [Integer] y The row
149
182
  # @return [Marker]
150
- def start_at(x, y=nil)
183
+ def start_at(x, y = nil)
151
184
  @anchor.start_at x, y
152
185
  @anchor.from
153
186
  end
@@ -156,7 +189,7 @@ module Axlsx
156
189
  # @param [Integer] x The column
157
190
  # @param [Integer] y The row
158
191
  # @return [Marker]
159
- def end_at(x, y=nil)
192
+ def end_at(x, y = nil)
160
193
  use_two_cell_anchor unless @anchor.is_a?(TwoCellAnchor)
161
194
  @anchor.end_at x, y
162
195
  @anchor.to
@@ -165,16 +198,16 @@ module Axlsx
165
198
  # Serializes the object
166
199
  # @param [String] str
167
200
  # @return [String]
168
- def to_xml_string(str = '')
201
+ def to_xml_string(str = +'')
169
202
  str << '<xdr:pic>'
170
203
  str << '<xdr:nvPicPr>'
171
- 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 << '">'
172
205
  hyperlink.to_xml_string(str) if hyperlink.is_a?(Hyperlink)
173
206
  str << '</xdr:cNvPr><xdr:cNvPicPr>'
174
207
  picture_locking.to_xml_string(str)
175
208
  str << '</xdr:cNvPicPr></xdr:nvPicPr>'
176
209
  str << '<xdr:blipFill>'
177
- str << ('<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '">')
210
+ str << relationship_xml_portion
178
211
  if opacity
179
212
  str << "<a:alphaModFix amt=\"#{opacity}\"/>"
180
213
  end
@@ -186,17 +219,28 @@ module Axlsx
186
219
 
187
220
  private
188
221
 
222
+ # Return correct xml relationship string portion
223
+ def relationship_xml_portion
224
+ if remote?
225
+ (+'<a:blip xmlns:r="' << XML_NS_R << '" r:link="' << relationship.Id << '">')
226
+ else
227
+ (+'<a:blip xmlns:r="' << XML_NS_R << '" r:embed="' << relationship.Id << '">')
228
+ end
229
+ end
230
+
189
231
  # Changes the anchor to a one cell anchor.
190
232
  def use_one_cell_anchor
191
233
  return if @anchor.is_a?(OneCellAnchor)
192
- new_anchor = OneCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row])
234
+
235
+ new_anchor = OneCellAnchor.new(@anchor.drawing, start_at: [@anchor.from.col, @anchor.from.row])
193
236
  swap_anchor(new_anchor)
194
237
  end
195
238
 
196
- #changes the anchor type to a two cell anchor
239
+ # changes the anchor type to a two cell anchor
197
240
  def use_two_cell_anchor
198
241
  return if @anchor.is_a?(TwoCellAnchor)
199
- new_anchor = TwoCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row])
242
+
243
+ new_anchor = TwoCellAnchor.new(@anchor.drawing, start_at: [@anchor.from.col, @anchor.from.row])
200
244
  swap_anchor(new_anchor)
201
245
  end
202
246
 
@@ -204,7 +248,7 @@ module Axlsx
204
248
  def swap_anchor(new_anchor)
205
249
  new_anchor.drawing.anchors.delete(new_anchor)
206
250
  @anchor.drawing.anchors[@anchor.drawing.anchors.index(@anchor)] = new_anchor
207
- new_anchor.instance_variable_set "@object", @anchor.object
251
+ new_anchor.instance_variable_set :@object, @anchor.object
208
252
  @anchor = new_anchor
209
253
  end
210
254
  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
 
5
- # The Pie3DChart is a three dimentional piechart (who would have guessed?) that you can add to your worksheet.
3
+ module Axlsx
4
+ # The Pie3DChart is a three dimensional pie chart (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
- super(frame, options)
25
+ super
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 = '')
37
- super(str) do
34
+ def to_xml_string(str = +'')
35
+ super 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
@@ -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
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 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,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,31 +27,37 @@ 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
- super(chart, options)
35
- self.labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
33
+ super
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
 
39
38
  # @see colors
40
- 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
41
43
 
42
44
  # @see explosion
43
- 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
44
49
 
45
50
  # Serializes the object
46
51
  # @param [String] str
47
52
  # @return [String]
48
- def to_xml_string(str = '')
49
- super(str) do
50
- str << '<c:explosion val="' + @explosion.to_s + '"/>' unless @explosion.nil?
53
+ def to_xml_string(str = +'')
54
+ super do
55
+ str << '<c:explosion val="' << @explosion.to_s << '"/>' unless @explosion.nil?
51
56
  colors.each_with_index do |c, index|
52
57
  str << '<c:dPt>'
53
- str << ('<c:idx val="' << index.to_s << '"/>')
58
+ str << '<c:idx val="' << index.to_s << '"/>'
54
59
  str << '<c:spPr><a:solidFill>'
55
- str << ('<a:srgbClr val="' << c << '"/>')
60
+ str << '<a:srgbClr val="' << c << '"/>'
56
61
  str << '</a:solidFill></c:spPr></c:dPt>'
57
62
  end
58
63
  @labels.to_xml_string str unless @labels.nil?
@@ -64,11 +69,15 @@ module Axlsx
64
69
  private
65
70
 
66
71
  # assigns the data for this series
67
- 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
68
76
 
69
77
  # assigns the labels for this series
70
- def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
71
-
78
+ def labels=(v)
79
+ DataTypeValidator.validate "Series.labels", [AxDataSource], v
80
+ @labels = v
81
+ end
72
82
  end
73
-
74
83
  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,26 +35,39 @@ 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)
39
+ DataTypeValidator.validate "Scaling.logBase", [Integer], v, ->(arg) { arg >= 2 && arg <= 1000 }
40
+ @logBase = v
41
+ end
42
+
39
43
  # @see orientation
40
- 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
+
41
49
  # @see max
42
- 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
43
54
 
44
55
  # @see min
45
- 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
46
60
 
47
61
  # Serializes the object
48
62
  # @param [String] str
49
63
  # @return [String]
50
- def to_xml_string(str = '')
64
+ def to_xml_string(str = +'')
51
65
  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?
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?
56
70
  str << '</c:scaling>'
57
71
  end
58
-
59
72
  end
60
73
  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
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 = '')
54
- super(str) do
52
+ def to_xml_string(str = +'')
53
+ super 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