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,11 +1,10 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # A Chart is the superclass for specific charts
5
5
  # @note Worksheet#add_chart is the recommended way to create charts for your worksheets.
6
6
  # @see README for examples
7
7
  class Chart
8
-
9
8
  include Axlsx::OptionsParser
10
9
  # Creates a new chart object
11
10
  # @param [GraphicalFrame] frame The frame that holds this chart.
@@ -16,10 +15,10 @@ module Axlsx
16
15
  # @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.
17
16
  # @option options [Boolean] plot_visible_only (true) Whether only data from visible cells should be plotted.
18
17
  # @option options [Boolean] rounded_corners (true) Whether the chart area shall have rounded corners.
19
- def initialize(frame, options={})
18
+ def initialize(frame, options = {})
20
19
  @style = 18
21
20
  @view_3D = nil
22
- @graphic_frame=frame
21
+ @graphic_frame = frame
23
22
  @graphic_frame.anchor.drawing.worksheet.workbook.charts << self
24
23
  @series = SimpleTypedList.new Series
25
24
  @show_legend = true
@@ -52,7 +51,7 @@ module Axlsx
52
51
  # @return [Series]
53
52
  attr_reader :series_type
54
53
 
55
- #TODO data labels!
54
+ # TODO: data labels!
56
55
  def d_lbls
57
56
  @d_lbls ||= DLbls.new(self.class)
58
57
  end
@@ -63,7 +62,7 @@ module Axlsx
63
62
 
64
63
  # Configures the vary_colors options for this chart
65
64
  # @param [Boolean] v The value to set
66
- def vary_colors=(v) Axlsx::validate_boolean(v); @vary_colors = v; end
65
+ def vary_colors=(v) Axlsx.validate_boolean(v); @vary_colors = v; end
67
66
 
68
67
  # The title object for the chart.
69
68
  # @return [Title]
@@ -125,7 +124,7 @@ module Axlsx
125
124
  # The part name for this chart
126
125
  # @return [String]
127
126
  def pn
128
- "#{CHART_PN % (index+1)}"
127
+ format(CHART_PN, index + 1)
129
128
  end
130
129
 
131
130
  # The title object for the chart.
@@ -150,18 +149,18 @@ module Axlsx
150
149
  # Show the legend in the chart
151
150
  # @param [Boolean] v
152
151
  # @return [Boolean]
153
- def show_legend=(v) Axlsx::validate_boolean(v); @show_legend = v; end
152
+ def show_legend=(v) Axlsx.validate_boolean(v); @show_legend = v; end
154
153
 
155
154
  # How to display blank values
156
155
  # @see display_blanks_as
157
156
  # @param [Symbol] v
158
157
  # @return [Symbol]
159
- def display_blanks_as=(v) Axlsx::validate_display_blanks_as(v); @display_blanks_as = v; end
158
+ def display_blanks_as=(v) Axlsx.validate_display_blanks_as(v); @display_blanks_as = v; end
160
159
 
161
160
  # The style for the chart.
162
161
  # see ECMA Part 1 §21.2.2.196
163
162
  # @param [Integer] v must be between 1 and 48
164
- def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, lambda { |arg| arg >= 1 && arg <= 48 }; @style = v; end
163
+ def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, ->(arg) { arg >= 1 && arg <= 48 }; @style = v; end
165
164
 
166
165
  # @see legend_position
167
166
  def legend_position=(v) RestrictionValidator.validate "Chart.legend_position", [:b, :l, :r, :t, :tr], v; @legend_position = v; end
@@ -181,39 +180,39 @@ module Axlsx
181
180
  # Adds a new series to the chart's series collection.
182
181
  # @return [Series]
183
182
  # @see Series
184
- def add_series(options={})
183
+ def add_series(options = {})
185
184
  @series_type.new(self, options)
186
185
  @series.last
187
186
  end
188
187
 
189
188
  # Assigns a background color to chart area
190
189
  def bg_color=(v)
191
- DataTypeValidator.validate(:color, Color, Color.new(:rgb => v))
190
+ DataTypeValidator.validate(:color, Color, Color.new(rgb: v))
192
191
  @bg_color = v
193
192
  end
194
193
 
195
194
  # Whether only data from visible cells should be plotted.
196
195
  # @param [Boolean] v
197
196
  # @return [Boolean]
198
- def plot_visible_only=(v) Axlsx::validate_boolean(v); @plot_visible_only = v; end
197
+ def plot_visible_only=(v) Axlsx.validate_boolean(v); @plot_visible_only = v; end
199
198
 
200
199
  # Whether the chart area shall have rounded corners.
201
200
  # @param [Boolean] v
202
201
  # @return [Boolean]
203
- def rounded_corners=(v) Axlsx::validate_boolean(v); @rounded_corners = v; end
202
+ def rounded_corners=(v) Axlsx.validate_boolean(v); @rounded_corners = v; end
204
203
 
205
204
  # Serializes the object
206
205
  # @param [String] str
207
206
  # @return [String]
208
- def to_xml_string(str = '')
207
+ def to_xml_string(str = +'')
209
208
  str << '<?xml version="1.0" encoding="UTF-8"?>'
210
- str << ('<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '" xmlns:r="' << XML_NS_R << '">')
211
- str << ('<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>')
212
- str << ('<c:roundedCorners val="' << rounded_corners.to_s << '"/>')
213
- str << ('<c:style val="' << style.to_s << '"/>')
209
+ str << '<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '" xmlns:r="' << XML_NS_R << '">'
210
+ str << '<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>'
211
+ str << '<c:roundedCorners val="' << rounded_corners.to_s << '"/>'
212
+ str << '<c:style val="' << style.to_s << '"/>'
214
213
  str << '<c:chart>'
215
214
  @title.to_xml_string(str) unless @title.empty?
216
- str << ('<c:autoTitleDeleted val="' << (@title == nil).to_s << '"/>')
215
+ str << '<c:autoTitleDeleted val="' << @title.nil?.to_s << '"/>'
217
216
  @view_3D.to_xml_string(str) if @view_3D
218
217
  str << '<c:floor><c:thickness val="0"/></c:floor>'
219
218
  str << '<c:sideWall><c:thickness val="0"/></c:sideWall>'
@@ -224,13 +223,13 @@ module Axlsx
224
223
  str << '</c:plotArea>'
225
224
  if @show_legend
226
225
  str << '<c:legend>'
227
- str << ('<c:legendPos val="' << @legend_position.to_s << '"/>')
226
+ str << '<c:legendPos val="' << @legend_position.to_s << '"/>'
228
227
  str << '<c:layout/>'
229
228
  str << '<c:overlay val="0"/>'
230
229
  str << '</c:legend>'
231
230
  end
232
- str << ('<c:plotVisOnly val="' << @plot_visible_only.to_s << '"/>')
233
- str << ('<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>')
231
+ str << '<c:plotVisOnly val="' << @plot_visible_only.to_s << '"/>'
232
+ str << '<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>'
234
233
  str << '<c:showDLblsOverMax val="1"/>'
235
234
  str << '</c:chart>'
236
235
  if bg_color
@@ -275,7 +274,7 @@ module Axlsx
275
274
  # reference or cell to use in setting the start marker position.
276
275
  # @param [Integer] y The row
277
276
  # @return [Marker]
278
- def start_at(x=0, y=0)
277
+ def start_at(x = 0, y = 0)
279
278
  @graphic_frame.anchor.start_at(x, y)
280
279
  end
281
280
 
@@ -286,14 +285,12 @@ module Axlsx
286
285
  # @param [Integer] y The row - default 10
287
286
  # @return [Marker]
288
287
  # @see start_at
289
- def end_at(x=10, y=10)
288
+ def end_at(x = 10, y = 10)
290
289
  @graphic_frame.anchor.end_at(x, y)
291
290
  end
292
291
 
293
292
  # sets the view_3D object for the chart
294
293
  def view_3D=(v) DataTypeValidator.validate "#{self.class}.view_3D", View3D, v; @view_3D = v; end
295
294
  alias :view3D= :view_3D=
296
-
297
295
  end
298
-
299
296
  end
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # There are more elements in the dLbls spec that allow for
3
5
  # customizations and formatting. For now, I am just implementing the
4
6
  # basics.
5
- #The DLbls class manages serialization of data labels
7
+ # The DLbls class manages serialization of data labels
6
8
  # showLeaderLines and leaderLines are not currently implemented
7
9
  class DLbls
8
-
9
10
  include Axlsx::Accessors
10
- include Axlsx::OptionsParser
11
+ include Axlsx::OptionsParser
11
12
  # creates a new DLbls object
12
- def initialize(chart_type, options={})
13
+ def initialize(chart_type, options = {})
13
14
  raise ArgumentError, 'chart_type must inherit from Chart' unless [Chart, LineChart].include?(chart_type.superclass)
15
+
14
16
  @chart_type = chart_type
15
17
  initialize_defaults
16
18
  parse_options options
@@ -18,31 +20,31 @@ module Axlsx
18
20
 
19
21
  # These attributes are all boolean so I'm doing a bit of a hand
20
22
  # waving magic show to set up the attriubte accessors
21
- # @note
22
- # not all charts support all methods!
23
+ # @note
24
+ # not all charts support all methods!
23
25
  # Bar3DChart and Line3DChart and ScatterChart do not support d_lbl_pos or show_leader_lines
24
- #
25
- boolean_attr_accessor :show_legend_key,
26
- :show_val,
27
- :show_cat_name,
28
- :show_ser_name,
29
- :show_percent,
30
- :show_bubble_size,
26
+ #
27
+ boolean_attr_accessor :show_legend_key,
28
+ :show_val,
29
+ :show_cat_name,
30
+ :show_ser_name,
31
+ :show_percent,
32
+ :show_bubble_size,
31
33
  :show_leader_lines
32
34
 
33
35
  # Initialize all the values to false as Excel requires them to
34
36
  # explicitly be disabled or all will show.
35
37
  def initialize_defaults
36
- [:show_legend_key, :show_val, :show_cat_name,
37
- :show_ser_name, :show_percent, :show_bubble_size,
38
+ [:show_legend_key, :show_val, :show_cat_name,
39
+ :show_ser_name, :show_percent, :show_bubble_size,
38
40
  :show_leader_lines].each do |attr|
39
- self.send("#{attr}=", false)
41
+ send("#{attr}=", false)
40
42
  end
41
43
  end
42
44
 
43
- # The chart type that is using this data lables instance.
45
+ # The chart type that is using this data lables instance.
44
46
  # This affects the xml output as not all chart types support the
45
- # same data label attributes.
47
+ # same data label attributes.
46
48
  attr_reader :chart_type
47
49
 
48
50
  # The position of the data labels in the chart
@@ -50,6 +52,7 @@ module Axlsx
50
52
  # @return [Symbol]
51
53
  def d_lbl_pos
52
54
  return unless [Pie3DChart, LineChart].include? @chart_type
55
+
53
56
  @d_lbl_pos ||= :bestFit
54
57
  end
55
58
 
@@ -61,31 +64,31 @@ module Axlsx
61
64
  # @param [Symbol] label_position the postion you want to use.
62
65
  def d_lbl_pos=(label_position)
63
66
  return unless [Pie3DChart, LineChart].include? @chart_type
64
- Axlsx::RestrictionValidator.validate 'DLbls#d_lbl_pos', [:bestFit, :b, :ctr, :inBase, :inEnd, :l, :outEnd, :r, :t], label_position
67
+
68
+ Axlsx::RestrictionValidator.validate 'DLbls#d_lbl_pos', [:bestFit, :b, :ctr, :inBase, :inEnd, :l, :outEnd, :r, :t], label_position
65
69
  @d_lbl_pos = label_position
66
70
  end
67
71
 
68
-
69
72
  # serializes the data labels
70
73
  # @return [String]
71
- def to_xml_string(str = '')
74
+ def to_xml_string(str = +'')
72
75
  validate_attributes_for_chart_type
73
76
  str << '<c:dLbls>'
74
77
  instance_vals = Axlsx.instance_values_for(self)
75
78
  %w(d_lbl_pos show_legend_key show_val show_cat_name show_ser_name show_percent show_bubble_size show_leader_lines).each do |key|
76
- next unless instance_vals.keys.include?(key) && instance_vals[key] != nil
77
- str << "<c:#{Axlsx::camel(key, false)} val='#{instance_vals[key]}' />"
79
+ next unless instance_vals.key?(key) && !instance_vals[key].nil?
80
+
81
+ str << "<c:#{Axlsx.camel(key, false)} val='#{instance_vals[key]}' />"
78
82
  end
79
83
  str << '</c:dLbls>'
80
84
  end
81
85
 
82
- # nills out d_lbl_pos and show_leader_lines as these attributes, while valid in the spec actually chrash excel for any chart type other than pie charts.
86
+ # nills out d_lbl_pos and show_leader_lines as these attributes, while valid in the spec actually crash Excel for any chart type other than pie charts.
83
87
  def validate_attributes_for_chart_type
84
88
  return if [Pie3DChart, LineChart].include? @chart_type
89
+
85
90
  @d_lbl_pos = nil
86
91
  @show_leader_lines = nil
87
92
  end
88
-
89
-
90
93
  end
91
94
  end
@@ -1,54 +1,55 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
- require 'axlsx/drawing/d_lbls.rb'
4
- require 'axlsx/drawing/title.rb'
5
- require 'axlsx/drawing/series_title.rb'
6
- require 'axlsx/drawing/series.rb'
7
- require 'axlsx/drawing/pie_series.rb'
8
- require 'axlsx/drawing/bar_series.rb'
9
- require 'axlsx/drawing/line_series.rb'
10
- require 'axlsx/drawing/scatter_series.rb'
11
- require 'axlsx/drawing/bubble_series.rb'
12
- require 'axlsx/drawing/area_series.rb'
13
-
14
- require 'axlsx/drawing/scaling.rb'
15
- require 'axlsx/drawing/axis.rb'
16
-
17
- require 'axlsx/drawing/str_val.rb'
18
- require 'axlsx/drawing/num_val.rb'
19
- require 'axlsx/drawing/str_data.rb'
20
- require 'axlsx/drawing/num_data.rb'
21
- require 'axlsx/drawing/num_data_source.rb'
22
- require 'axlsx/drawing/ax_data_source.rb'
23
-
24
- require 'axlsx/drawing/ser_axis.rb'
25
- require 'axlsx/drawing/cat_axis.rb'
26
- require 'axlsx/drawing/val_axis.rb'
27
- require 'axlsx/drawing/axes.rb'
28
-
29
- require 'axlsx/drawing/marker.rb'
30
-
31
- require 'axlsx/drawing/one_cell_anchor.rb'
32
- require 'axlsx/drawing/two_cell_anchor.rb'
33
- require 'axlsx/drawing/graphic_frame.rb'
34
-
35
- require 'axlsx/drawing/view_3D.rb'
36
- require 'axlsx/drawing/chart.rb'
37
- require 'axlsx/drawing/pie_3D_chart.rb'
38
- require 'axlsx/drawing/bar_3D_chart.rb'
39
- require 'axlsx/drawing/bar_chart.rb'
40
- require 'axlsx/drawing/line_chart.rb'
41
- require 'axlsx/drawing/line_3D_chart.rb'
42
- require 'axlsx/drawing/scatter_chart.rb'
43
- require 'axlsx/drawing/bubble_chart.rb'
44
- require 'axlsx/drawing/area_chart.rb'
45
-
46
- require 'axlsx/drawing/picture_locking.rb'
47
- require 'axlsx/drawing/pic.rb'
48
- require 'axlsx/drawing/hyperlink.rb'
49
-
50
- require 'axlsx/drawing/vml_drawing.rb'
51
- require 'axlsx/drawing/vml_shape.rb'
4
+ require 'axlsx/drawing/d_lbls'
5
+ require 'axlsx/drawing/title'
6
+ require 'axlsx/drawing/series_title'
7
+ require 'axlsx/drawing/series'
8
+ require 'axlsx/drawing/pie_series'
9
+ require 'axlsx/drawing/bar_series'
10
+ require 'axlsx/drawing/line_series'
11
+ require 'axlsx/drawing/scatter_series'
12
+ require 'axlsx/drawing/bubble_series'
13
+ require 'axlsx/drawing/area_series'
14
+
15
+ require 'axlsx/drawing/scaling'
16
+ require 'axlsx/drawing/axis'
17
+
18
+ require 'axlsx/drawing/str_val'
19
+ require 'axlsx/drawing/num_val'
20
+ require 'axlsx/drawing/str_data'
21
+ require 'axlsx/drawing/num_data'
22
+ require 'axlsx/drawing/num_data_source'
23
+ require 'axlsx/drawing/ax_data_source'
24
+
25
+ require 'axlsx/drawing/ser_axis'
26
+ require 'axlsx/drawing/cat_axis'
27
+ require 'axlsx/drawing/val_axis'
28
+ require 'axlsx/drawing/axes'
29
+
30
+ require 'axlsx/drawing/marker'
31
+
32
+ require 'axlsx/drawing/one_cell_anchor'
33
+ require 'axlsx/drawing/two_cell_anchor'
34
+ require 'axlsx/drawing/graphic_frame'
35
+
36
+ require 'axlsx/drawing/view_3D'
37
+ require 'axlsx/drawing/chart'
38
+ require 'axlsx/drawing/pie_3D_chart'
39
+ require 'axlsx/drawing/bar_3D_chart'
40
+ require 'axlsx/drawing/bar_chart'
41
+ require 'axlsx/drawing/line_chart'
42
+ require 'axlsx/drawing/line_3D_chart'
43
+ require 'axlsx/drawing/scatter_chart'
44
+ require 'axlsx/drawing/bubble_chart'
45
+ require 'axlsx/drawing/area_chart'
46
+
47
+ require 'axlsx/drawing/picture_locking'
48
+ require 'axlsx/drawing/pic'
49
+ require 'axlsx/drawing/hyperlink'
50
+
51
+ require 'axlsx/drawing/vml_drawing'
52
+ require 'axlsx/drawing/vml_shape'
52
53
 
53
54
  # A Drawing is a canvas for charts and images. Each worksheet has a single drawing that manages anchors.
54
55
  # The anchors reference the charts or images via graphical frames. This is not a trivial relationship so please do follow the advice in the note.
@@ -58,7 +59,6 @@ module Axlsx
58
59
  # @see Chart
59
60
  # see examples/example.rb for an example of how to create a chart.
60
61
  class Drawing
61
-
62
62
  # The worksheet that owns the drawing
63
63
  # @return [Worksheet]
64
64
  attr_reader :worksheet
@@ -77,12 +77,11 @@ module Axlsx
77
77
  @anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor]
78
78
  end
79
79
 
80
-
81
80
  # Adds an image to the chart If th end_at option is specified we create a two cell anchor. By default we use a one cell anchor.
82
81
  # @note The recommended way to manage images is to use Worksheet.add_image. Please refer to that method for documentation.
83
82
  # @see Worksheet#add_image
84
83
  # @return [Pic]
85
- def add_image(options={})
84
+ def add_image(options = {})
86
85
  if options[:end_at]
87
86
  TwoCellAnchor.new(self, options).add_pic(options)
88
87
  else
@@ -94,7 +93,7 @@ module Axlsx
94
93
  # Adds a chart to the drawing.
95
94
  # @note The recommended way to manage charts is to use Worksheet.add_chart. Please refer to that method for documentation.
96
95
  # @see Worksheet#add_chart
97
- def add_chart(chart_type, options={})
96
+ def add_chart(chart_type, options = {})
98
97
  TwoCellAnchor.new(self, options)
99
98
  @anchors.last.add_chart(chart_type, options)
100
99
  end
@@ -109,15 +108,15 @@ module Axlsx
109
108
  # An array of hyperlink objects associated with this drawings images
110
109
  # @return [Array]
111
110
  def hyperlinks
112
- links = self.images.select { |a| a.hyperlink.is_a?(Hyperlink) }
113
- links.map { |a| a.hyperlink }
111
+ links = images.select { |a| a.hyperlink.is_a?(Hyperlink) }
112
+ links.map(&:hyperlink)
114
113
  end
115
114
 
116
115
  # An array of image objects that are associated with this drawing's anchors
117
116
  # @return [Array]
118
117
  def images
119
118
  images = @anchors.select { |a| a.object.is_a?(Pic) }
120
- images.map { |a| a.object }
119
+ images.map(&:object)
121
120
  end
122
121
 
123
122
  # The index of this drawing in the owning workbooks's drawings collection.
@@ -129,14 +128,14 @@ module Axlsx
129
128
  # The part name for this drawing
130
129
  # @return [String]
131
130
  def pn
132
- "#{DRAWING_PN % (index+1)}"
131
+ format(DRAWING_PN, index + 1)
133
132
  end
134
133
 
135
134
  # The relational part name for this drawing
136
135
  # #NOTE This should be rewritten to return an Axlsx::Relationship object.
137
136
  # @return [String]
138
137
  def rels_pn
139
- "#{DRAWING_RELS_PN % (index+1)}"
138
+ format(DRAWING_RELS_PN, index + 1)
140
139
  end
141
140
 
142
141
  # A list of objects this drawing holds.
@@ -156,12 +155,11 @@ module Axlsx
156
155
  # Serializes the object
157
156
  # @param [String] str
158
157
  # @return [String]
159
- def to_xml_string(str = '')
158
+ def to_xml_string(str = +'')
160
159
  str << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
161
- str << ('<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '">')
160
+ str << '<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '">'
162
161
  anchors.each { |anchor| anchor.to_xml_string(str) }
163
162
  str << '</xdr:wsDr>'
164
163
  end
165
-
166
164
  end
167
165
  end
@@ -1,10 +1,10 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # A graphic frame defines a container for a chart object
4
5
  # @note The recommended way to manage charts is Worksheet#add_chart
5
6
  # @see Worksheet#add_chart
6
7
  class GraphicFrame
7
-
8
8
  # A reference to the chart object associated with this frame
9
9
  # @return [Chart]
10
10
  attr_reader :chart
@@ -31,11 +31,11 @@ module Axlsx
31
31
  # Serializes the object
32
32
  # @param [String] str
33
33
  # @return [String]
34
- def to_xml_string(str = '')
34
+ def to_xml_string(str = +'')
35
35
  # macro attribute should be optional!
36
36
  str << '<xdr:graphicFrame>'
37
37
  str << '<xdr:nvGraphicFramePr>'
38
- str << ('<xdr:cNvPr id="' << @anchor.drawing.index.to_s << '" name="' << 'item_' << @anchor.drawing.index.to_s << '"/>')
38
+ str << '<xdr:cNvPr id="' << @anchor.drawing.index.to_s << '" name="' << 'item_' << @anchor.drawing.index.to_s << '"/>'
39
39
  str << '<xdr:cNvGraphicFramePr/>'
40
40
  str << '</xdr:nvGraphicFramePr>'
41
41
  str << '<xdr:xfrm>'
@@ -43,12 +43,11 @@ module Axlsx
43
43
  str << '<a:ext cx="0" cy="0"/>'
44
44
  str << '</xdr:xfrm>'
45
45
  str << '<a:graphic>'
46
- str << ('<a:graphicData uri="' << XML_NS_C << '">')
47
- str << ('<c:chart xmlns:c="' << XML_NS_C << '" xmlns:r="' << XML_NS_R << '" r:id="' << rId << '"/>')
46
+ str << '<a:graphicData uri="' << XML_NS_C << '">'
47
+ str << '<c:chart xmlns:c="' << XML_NS_C << '" xmlns:r="' << XML_NS_R << '" r:id="' << rId << '"/>'
48
48
  str << '</a:graphicData>'
49
49
  str << '</a:graphic>'
50
50
  str << '</xdr:graphicFrame>'
51
51
  end
52
-
53
52
  end
54
53
  end
@@ -1,25 +1,25 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # a hyperlink object adds an action to an image when clicked so that when the image is clicked the link is fecthed.
4
5
  # @note using the hyperlink option when calling add_image on a drawing object is the recommended way to manage hyperlinks
5
6
  # @see {file:README} README
6
7
  class Hyperlink
7
-
8
8
  include Axlsx::SerializedAttributes
9
9
  include Axlsx::OptionsParser
10
10
 
11
- #Creates a hyperlink object
11
+ # Creates a hyperlink object
12
12
  # parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent
13
13
  # @param [Pic] parent
14
14
  # @option options [String] tooltip message shown when hyperlinked object is hovered over with mouse.
15
15
  # @option options [String] tgtFrame Target frame for opening hyperlink
16
16
  # @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource.
17
17
  # @option options [String] href the target resource this hyperlink links to. This is actually stored on the relationship.
18
- # @option options [String] action A string that can be used to perform specific actions. For excel please see this reference: http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
18
+ # @option options [String] action A string that can be used to perform specific actions. For Excel please see this reference: https://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
19
19
  # @option options [Boolean] endSnd terminate any sound events when processing this link
20
20
  # @option options [Boolean] history include this link in the list of visited links for the applications history.
21
21
  # @option options [Boolean] highlightClick indicate that the link has already been visited.
22
- def initialize(parent, options={})
22
+ def initialize(parent, options = {})
23
23
  DataTypeValidator.validate "Hyperlink.parent", [Pic], parent
24
24
  @parent = parent
25
25
  parse_options options
@@ -40,7 +40,7 @@ module Axlsx
40
40
  alias :invalidUrl :invalid_url
41
41
  alias :invalidUrl= :invalid_url=
42
42
 
43
- #An action to take when the link is clicked. The specification says "This can be used to specify a slide to be navigated to or a script of code to be run." but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
43
+ # An action to take when the link is clicked. The specification says "This can be used to specify a slide to be navigated to or a script of code to be run." but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see https://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
44
44
  # @return [String]
45
45
  attr_accessor :action
46
46
 
@@ -52,7 +52,7 @@ module Axlsx
52
52
  # @see endSnd
53
53
  # @param [Boolean] v The boolean value indicating the termination of playing sounds on click
54
54
  # @return [Boolean]
55
- def end_snd=(v) Axlsx::validate_boolean(v); @end_snd = v end
55
+ def end_snd=(v) Axlsx.validate_boolean(v); @end_snd = v end
56
56
  alias :endSnd= :end_snd=
57
57
 
58
58
  # indicates that the link has already been clicked.
@@ -62,7 +62,7 @@ module Axlsx
62
62
 
63
63
  # @see highlightClick
64
64
  # @param [Boolean] v The value to assign
65
- def highlight_click=(v) Axlsx::validate_boolean(v); @highlight_click = v end
65
+ def highlight_click=(v) Axlsx.validate_boolean(v); @highlight_click = v end
66
66
  alias :highlightClick= :highlight_click=
67
67
 
68
68
  # From the specs: Specifies whether to add this URI to the history when navigating to it. This allows for the viewing of this presentation without the storing of history information on the viewing machine. If this attribute is omitted, then a value of 1 or true is assumed.
@@ -71,7 +71,7 @@ module Axlsx
71
71
 
72
72
  # @see history
73
73
  # param [Boolean] v The value to assing
74
- def history=(v) Axlsx::validate_boolean(v); @history = v end
74
+ def history=(v) Axlsx.validate_boolean(v); @history = v end
75
75
 
76
76
  # From the specs: Specifies the target frame that is to be used when opening this hyperlink. When the hyperlink is activated this attribute is used to determine if a new window is launched for viewing or if an existing one can be used. If this attribute is omitted, than a new window is opened.
77
77
  # @return [String]
@@ -86,15 +86,14 @@ module Axlsx
86
86
  # The relationship object for this hyperlink.
87
87
  # @return [Relationship]
88
88
  def relationship
89
- Relationship.new(self, HYPERLINK_R, href, :target_mode => :External)
89
+ Relationship.new(self, HYPERLINK_R, href, target_mode: :External)
90
90
  end
91
91
 
92
92
  # Serializes the object
93
93
  # @param [String] str
94
94
  # @return [String]
95
- def to_xml_string(str = '')
96
- serialized_tag 'a:hlinkClick', str, {:'r:id' => relationship.Id, :'xmlns:r' => XML_NS_R }
95
+ def to_xml_string(str = +'')
96
+ serialized_tag 'a:hlinkClick', str, { 'r:id': relationship.Id, 'xmlns:r': XML_NS_R }
97
97
  end
98
-
99
98
  end
100
99
  end
@@ -1,6 +1,6 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # The Line3DChart is a three dimentional line chart (who would have guessed?) that you can add to your worksheet.
5
5
  # @example Creating a chart
6
6
  # # This example creates a line in a single sheet.
@@ -20,14 +20,13 @@ module Axlsx
20
20
  # @see Series
21
21
  # @see Package#serialize
22
22
  class Line3DChart < Axlsx::LineChart
23
-
24
23
  # space between bar or column clusters, as a percentage of the bar or column width.
25
24
  # @return [String]
26
25
  attr_reader :gap_depth
27
26
  alias :gapDepth :gap_depth
28
27
 
29
28
  # validation regex for gap amount percent
30
- GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
29
+ GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/.freeze
31
30
 
32
31
  # the category axis
33
32
  # @return [Axis]
@@ -41,28 +40,27 @@ module Axlsx
41
40
  # @see Chart
42
41
  # @see lineChart
43
42
  # @see View3D
44
- def initialize(frame, options={})
43
+ def initialize(frame, options = {})
45
44
  @gap_depth = nil
46
- @view_3D = View3D.new({:r_ang_ax=>1}.merge(options))
45
+ @view_3D = View3D.new({ r_ang_ax: 1 }.merge(options))
47
46
  super(frame, options)
48
47
  axes.add_axis :ser_axis, SerAxis
49
48
  end
50
49
 
51
-
52
50
  # @see gapDepth
53
51
  def gap_depth=(v)
54
52
  RegexValidator.validate "Line3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
55
- @gap_depth=(v)
53
+ @gap_depth = v
56
54
  end
57
55
  alias :gapDepth= :gap_depth=
58
56
 
59
- # Serializes the object
60
- # @param [String] str
61
- # @return [String]
62
- def to_xml_string(str = '')
63
- super(str) do
64
- str << ('<c:gapDepth val="' << @gap_depth.to_s << '"/>') unless @gap_depth.nil?
65
- end
57
+ # Serializes the object
58
+ # @param [String] str
59
+ # @return [String]
60
+ def to_xml_string(str = +'')
61
+ super(str) do
62
+ str << '<c:gapDepth val="' << @gap_depth.to_s << '"/>' unless @gap_depth.nil?
66
63
  end
64
+ end
67
65
  end
68
66
  end