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,18 +1,16 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
- #A CatAxis object defines a chart category axis
4
+ # A CatAxis object defines a chart category axis
4
5
  class CatAxis < Axis
5
-
6
6
  # Creates a new CatAxis object
7
- # @option options [Integer] tick_lbl_skip
8
- # @option options [Integer] tick_mark_skip
9
- def initialize(options={})
10
- @tick_lbl_skip = 1
11
- @tick_mark_skip = 1
7
+ # @option options [Integer, nil] tick_lbl_skip
8
+ # @option options [Integer, nil] tick_mark_skip
9
+ def initialize(options = {})
12
10
  self.auto = 1
13
11
  self.lbl_algn = :ctr
14
12
  self.lbl_offset = "100"
15
- super(options)
13
+ super
16
14
  end
17
15
 
18
16
  # From the docs: This element specifies that this axis is a date or text axis based on the data that is used for the axis labels, not a specific choice.
@@ -31,55 +29,67 @@ module Axlsx
31
29
  attr_reader :lbl_offset
32
30
  alias :lblOffset :lbl_offset
33
31
 
34
- # The number of tick lables to skip between labels
35
- # @return [Integer]
32
+ # The number of tick labels to skip between labels
33
+ # @return [Integer, nil]
36
34
  attr_reader :tick_lbl_skip
37
35
  alias :tickLblSkip :tick_lbl_skip
38
36
 
39
37
  # The number of tickmarks to be skipped before the next one is rendered.
40
- # @return [Boolean]
38
+ # @return [Integer, nil]
41
39
  attr_reader :tick_mark_skip
42
40
  alias :tickMarkSkip :tick_mark_skip
43
41
 
44
42
  # regex for validating label offset
45
- LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)/
43
+ LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)/.freeze
46
44
 
47
45
  # @see tick_lbl_skip
48
- def tick_lbl_skip=(v) Axlsx::validate_unsigned_int(v); @tick_lbl_skip = v; end
46
+ def tick_lbl_skip=(v)
47
+ Axlsx.validate_unsigned_int(v) unless v.nil?
48
+ @tick_lbl_skip = v
49
+ end
49
50
  alias :tickLblSkip= :tick_lbl_skip=
50
51
 
51
52
  # @see tick_mark_skip
52
- def tick_mark_skip=(v) Axlsx::validate_unsigned_int(v); @tick_mark_skip = v; end
53
+ def tick_mark_skip=(v)
54
+ Axlsx.validate_unsigned_int(v) unless v.nil?
55
+ @tick_mark_skip = v
56
+ end
53
57
  alias :tickMarkSkip= :tick_mark_skip=
54
58
 
55
59
  # From the docs: This element specifies that this axis is a date or text axis based on the data that is used for the axis labels, not a specific choice.
56
- def auto=(v) Axlsx::validate_boolean(v); @auto = v; end
60
+ def auto=(v)
61
+ Axlsx.validate_boolean(v)
62
+ @auto = v
63
+ end
57
64
 
58
65
  # specifies how the perpendicular axis is crossed
59
66
  # must be one of [:ctr, :l, :r]
60
- def lbl_algn=(v) RestrictionValidator.validate "#{self.class}.lbl_algn", [:ctr, :l, :r], v; @lbl_algn = v; end
67
+ def lbl_algn=(v)
68
+ RestrictionValidator.validate "#{self.class}.lbl_algn", [:ctr, :l, :r], v
69
+ @lbl_algn = v
70
+ end
61
71
  alias :lblAlgn= :lbl_algn=
62
72
 
63
73
  # The offset of the labels
64
74
  # must be between a string between 0 and 1000
65
- def lbl_offset=(v) RegexValidator.validate "#{self.class}.lbl_offset", LBL_OFFSET_REGEX, v; @lbl_offset = v; end
75
+ def lbl_offset=(v)
76
+ RegexValidator.validate "#{self.class}.lbl_offset", LBL_OFFSET_REGEX, v
77
+ @lbl_offset = v
78
+ end
66
79
  alias :lblOffset= :lbl_offset=
67
80
 
68
81
  # Serializes the object
69
82
  # @param [String] str
70
83
  # @return [String]
71
- def to_xml_string(str = '')
84
+ def to_xml_string(str = +'')
72
85
  str << '<c:catAx>'
73
- super(str)
74
- str << ('<c:auto val="' << @auto.to_s << '"/>')
75
- str << ('<c:lblAlgn val="' << @lbl_algn.to_s << '"/>')
76
- str << ('<c:lblOffset val="' << @lbl_offset.to_i.to_s << '"/>')
77
- str << ('<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>')
78
- str << ('<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>')
86
+ super
87
+ str << '<c:auto val="' << @auto.to_s << '"/>'
88
+ str << '<c:lblAlgn val="' << @lbl_algn.to_s << '"/>'
89
+ str << '<c:lblOffset val="' << @lbl_offset.to_i.to_s << '"/>'
90
+ str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>' unless @tick_lbl_skip.nil?
91
+ str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>' unless @tick_mark_skip.nil?
79
92
  str << '</c:catAx>'
80
93
  end
81
-
82
94
  end
83
-
84
-
85
95
  end
@@ -1,12 +1,12 @@
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
9
+
10
10
  # Creates a new chart object
11
11
  # @param [GraphicalFrame] frame The frame that holds this chart.
12
12
  # @option options [Cell, String] title
@@ -16,10 +16,10 @@ module Axlsx
16
16
  # @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.
17
17
  # @option options [Boolean] plot_visible_only (true) Whether only data from visible cells should be plotted.
18
18
  # @option options [Boolean] rounded_corners (true) Whether the chart area shall have rounded corners.
19
- def initialize(frame, options={})
19
+ def initialize(frame, options = {})
20
20
  @style = 18
21
21
  @view_3D = nil
22
- @graphic_frame=frame
22
+ @graphic_frame = frame
23
23
  @graphic_frame.anchor.drawing.worksheet.workbook.charts << self
24
24
  @series = SimpleTypedList.new Series
25
25
  @show_legend = true
@@ -52,7 +52,7 @@ module Axlsx
52
52
  # @return [Series]
53
53
  attr_reader :series_type
54
54
 
55
- #TODO data labels!
55
+ # TODO: data labels!
56
56
  def d_lbls
57
57
  @d_lbls ||= DLbls.new(self.class)
58
58
  end
@@ -63,7 +63,10 @@ module Axlsx
63
63
 
64
64
  # Configures the vary_colors options for this chart
65
65
  # @param [Boolean] v The value to set
66
- def vary_colors=(v) Axlsx::validate_boolean(v); @vary_colors = v; end
66
+ def vary_colors=(v)
67
+ Axlsx.validate_boolean(v)
68
+ @vary_colors = v
69
+ end
67
70
 
68
71
  # The title object for the chart.
69
72
  # @return [Title]
@@ -125,7 +128,7 @@ module Axlsx
125
128
  # The part name for this chart
126
129
  # @return [String]
127
130
  def pn
128
- "#{CHART_PN % (index+1)}"
131
+ format(CHART_PN, index + 1)
129
132
  end
130
133
 
131
134
  # The title object for the chart.
@@ -150,21 +153,33 @@ module Axlsx
150
153
  # Show the legend in the chart
151
154
  # @param [Boolean] v
152
155
  # @return [Boolean]
153
- def show_legend=(v) Axlsx::validate_boolean(v); @show_legend = v; end
156
+ def show_legend=(v)
157
+ Axlsx.validate_boolean(v)
158
+ @show_legend = v
159
+ end
154
160
 
155
161
  # How to display blank values
156
162
  # @see display_blanks_as
157
163
  # @param [Symbol] v
158
164
  # @return [Symbol]
159
- def display_blanks_as=(v) Axlsx::validate_display_blanks_as(v); @display_blanks_as = v; end
165
+ def display_blanks_as=(v)
166
+ Axlsx.validate_display_blanks_as(v)
167
+ @display_blanks_as = v
168
+ end
160
169
 
161
170
  # The style for the chart.
162
171
  # see ECMA Part 1 §21.2.2.196
163
172
  # @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
173
+ def style=(v)
174
+ DataTypeValidator.validate "Chart.style", Integer, v, ->(arg) { arg >= 1 && arg <= 48 }
175
+ @style = v
176
+ end
165
177
 
166
178
  # @see legend_position
167
- def legend_position=(v) RestrictionValidator.validate "Chart.legend_position", [:b, :l, :r, :t, :tr], v; @legend_position = v; end
179
+ def legend_position=(v)
180
+ RestrictionValidator.validate "Chart.legend_position", [:b, :l, :r, :t, :tr], v
181
+ @legend_position = v
182
+ end
168
183
 
169
184
  # backwards compatibility to allow chart.to and chart.from access to anchor markers
170
185
  # @note This will be disconinued in version 2.0.0. Please use the end_at method
@@ -181,39 +196,45 @@ module Axlsx
181
196
  # Adds a new series to the chart's series collection.
182
197
  # @return [Series]
183
198
  # @see Series
184
- def add_series(options={})
199
+ def add_series(options = {})
185
200
  @series_type.new(self, options)
186
201
  @series.last
187
202
  end
188
203
 
189
204
  # Assigns a background color to chart area
190
205
  def bg_color=(v)
191
- DataTypeValidator.validate(:color, Color, Color.new(:rgb => v))
206
+ DataTypeValidator.validate(:color, Color, Color.new(rgb: v))
192
207
  @bg_color = v
193
208
  end
194
209
 
195
210
  # Whether only data from visible cells should be plotted.
196
211
  # @param [Boolean] v
197
212
  # @return [Boolean]
198
- def plot_visible_only=(v) Axlsx::validate_boolean(v); @plot_visible_only = v; end
213
+ def plot_visible_only=(v)
214
+ Axlsx.validate_boolean(v)
215
+ @plot_visible_only = v
216
+ end
199
217
 
200
218
  # Whether the chart area shall have rounded corners.
201
219
  # @param [Boolean] v
202
220
  # @return [Boolean]
203
- def rounded_corners=(v) Axlsx::validate_boolean(v); @rounded_corners = v; end
221
+ def rounded_corners=(v)
222
+ Axlsx.validate_boolean(v)
223
+ @rounded_corners = v
224
+ end
204
225
 
205
226
  # Serializes the object
206
227
  # @param [String] str
207
228
  # @return [String]
208
- def to_xml_string(str = '')
229
+ def to_xml_string(str = +'')
209
230
  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 << '"/>')
231
+ str << '<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '" xmlns:r="' << XML_NS_R << '">'
232
+ str << '<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>'
233
+ str << '<c:roundedCorners val="' << rounded_corners.to_s << '"/>'
234
+ str << '<c:style val="' << style.to_s << '"/>'
214
235
  str << '<c:chart>'
215
236
  @title.to_xml_string(str) unless @title.empty?
216
- str << ('<c:autoTitleDeleted val="' << (@title == nil).to_s << '"/>')
237
+ str << '<c:autoTitleDeleted val="' << @title.nil?.to_s << '"/>'
217
238
  @view_3D.to_xml_string(str) if @view_3D
218
239
  str << '<c:floor><c:thickness val="0"/></c:floor>'
219
240
  str << '<c:sideWall><c:thickness val="0"/></c:sideWall>'
@@ -224,13 +245,13 @@ module Axlsx
224
245
  str << '</c:plotArea>'
225
246
  if @show_legend
226
247
  str << '<c:legend>'
227
- str << ('<c:legendPos val="' << @legend_position.to_s << '"/>')
248
+ str << '<c:legendPos val="' << @legend_position.to_s << '"/>'
228
249
  str << '<c:layout/>'
229
250
  str << '<c:overlay val="0"/>'
230
251
  str << '</c:legend>'
231
252
  end
232
- str << ('<c:plotVisOnly val="' << @plot_visible_only.to_s << '"/>')
233
- str << ('<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>')
253
+ str << '<c:plotVisOnly val="' << @plot_visible_only.to_s << '"/>'
254
+ str << '<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>'
234
255
  str << '<c:showDLblsOverMax val="1"/>'
235
256
  str << '</c:chart>'
236
257
  if bg_color
@@ -275,7 +296,7 @@ module Axlsx
275
296
  # reference or cell to use in setting the start marker position.
276
297
  # @param [Integer] y The row
277
298
  # @return [Marker]
278
- def start_at(x=0, y=0)
299
+ def start_at(x = 0, y = 0)
279
300
  @graphic_frame.anchor.start_at(x, y)
280
301
  end
281
302
 
@@ -286,14 +307,15 @@ module Axlsx
286
307
  # @param [Integer] y The row - default 10
287
308
  # @return [Marker]
288
309
  # @see start_at
289
- def end_at(x=10, y=10)
310
+ def end_at(x = 10, y = 10)
290
311
  @graphic_frame.anchor.end_at(x, y)
291
312
  end
292
313
 
293
314
  # sets the view_3D object for the chart
294
- def view_3D=(v) DataTypeValidator.validate "#{self.class}.view_3D", View3D, v; @view_3D = v; end
315
+ def view_3D=(v)
316
+ DataTypeValidator.validate "#{self.class}.view_3D", View3D, v
317
+ @view_3D = v
318
+ end
295
319
  alias :view3D= :view_3D=
296
-
297
320
  end
298
-
299
321
  end
@@ -1,91 +1,95 @@
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
12
+
11
13
  # creates a new DLbls object
12
- def initialize(chart_type, options={})
14
+ def initialize(chart_type, options = {})
13
15
  raise ArgumentError, 'chart_type must inherit from Chart' unless [Chart, LineChart].include?(chart_type.superclass)
16
+
14
17
  @chart_type = chart_type
15
18
  initialize_defaults
16
19
  parse_options options
17
20
  end
18
21
 
19
22
  # These attributes are all boolean so I'm doing a bit of a hand
20
- # waving magic show to set up the attriubte accessors
21
- # @note
22
- # not all charts support all methods!
23
+ # waving magic show to set up the attribute accessors
24
+ # @note
25
+ # not all charts support all methods!
23
26
  # 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,
27
+ #
28
+ boolean_attr_accessor :show_legend_key,
29
+ :show_val,
30
+ :show_cat_name,
31
+ :show_ser_name,
32
+ :show_percent,
33
+ :show_bubble_size,
31
34
  :show_leader_lines
32
35
 
33
36
  # Initialize all the values to false as Excel requires them to
34
37
  # explicitly be disabled or all will show.
35
38
  def initialize_defaults
36
- [:show_legend_key, :show_val, :show_cat_name,
37
- :show_ser_name, :show_percent, :show_bubble_size,
39
+ [:show_legend_key, :show_val, :show_cat_name,
40
+ :show_ser_name, :show_percent, :show_bubble_size,
38
41
  :show_leader_lines].each do |attr|
39
- self.send("#{attr}=", false)
42
+ send(:"#{attr}=", false)
40
43
  end
41
44
  end
42
45
 
43
- # The chart type that is using this data lables instance.
46
+ # The chart type that is using this data labels instance.
44
47
  # This affects the xml output as not all chart types support the
45
- # same data label attributes.
48
+ # same data label attributes.
46
49
  attr_reader :chart_type
47
50
 
48
51
  # The position of the data labels in the chart
49
52
  # @see d_lbl_pos= for a list of allowed values
50
53
  # @return [Symbol]
51
54
  def d_lbl_pos
52
- return unless [Pie3DChart, LineChart].include? @chart_type
55
+ return unless [PieChart, Pie3DChart, LineChart].include? @chart_type
56
+
53
57
  @d_lbl_pos ||= :bestFit
54
58
  end
55
59
 
56
60
  # @see DLbls#d_lbl_pos
57
- # Assigns the label postion for this data labels on this chart.
61
+ # Assigns the label position for this data labels on this chart.
58
62
  # Allowed positions are :bestFit, :b, :ctr, :inBase, :inEnd, :l,
59
63
  # :outEnd, :r and :t
60
64
  # The default is :bestFit
61
- # @param [Symbol] label_position the postion you want to use.
65
+ # @param [Symbol] label_position the position you want to use.
62
66
  def d_lbl_pos=(label_position)
63
- 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
+ return unless [PieChart, Pie3DChart, LineChart].include? @chart_type
68
+
69
+ Axlsx::RestrictionValidator.validate 'DLbls#d_lbl_pos', [:bestFit, :b, :ctr, :inBase, :inEnd, :l, :outEnd, :r, :t], label_position
65
70
  @d_lbl_pos = label_position
66
71
  end
67
72
 
68
-
69
73
  # serializes the data labels
70
74
  # @return [String]
71
- def to_xml_string(str = '')
75
+ def to_xml_string(str = +'')
72
76
  validate_attributes_for_chart_type
73
77
  str << '<c:dLbls>'
74
78
  instance_vals = Axlsx.instance_values_for(self)
75
79
  %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]}' />"
80
+ next unless instance_vals.key?(key) && !instance_vals[key].nil?
81
+
82
+ str << "<c:#{Axlsx.camel(key, false)} val='#{instance_vals[key]}' />"
78
83
  end
79
84
  str << '</c:dLbls>'
80
85
  end
81
86
 
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.
87
+ # 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
88
  def validate_attributes_for_chart_type
84
- return if [Pie3DChart, LineChart].include? @chart_type
89
+ return if [PieChart, Pie3DChart, LineChart].include? @chart_type
90
+
85
91
  @d_lbl_pos = nil
86
92
  @show_leader_lines = nil
87
93
  end
88
-
89
-
90
94
  end
91
95
  end
@@ -1,54 +1,56 @@
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
+ autoload :DLbls, 'axlsx/drawing/d_lbls'
5
+ autoload :Title, 'axlsx/drawing/title'
6
+ autoload :SeriesTitle, 'axlsx/drawing/series_title'
7
+ autoload :Series, 'axlsx/drawing/series'
8
+ autoload :PieSeries, 'axlsx/drawing/pie_series'
9
+ autoload :BarSeries, 'axlsx/drawing/bar_series'
10
+ autoload :LineSeries, 'axlsx/drawing/line_series'
11
+ autoload :ScatterSeries, 'axlsx/drawing/scatter_series'
12
+ autoload :BubbleSeries, 'axlsx/drawing/bubble_series'
13
+ autoload :AreaSeries, 'axlsx/drawing/area_series'
14
+
15
+ autoload :Scaling, 'axlsx/drawing/scaling'
16
+ autoload :Axis, 'axlsx/drawing/axis'
17
+
18
+ autoload :StrVal, 'axlsx/drawing/str_val'
19
+ autoload :NumVal, 'axlsx/drawing/num_val'
20
+ autoload :StrData, 'axlsx/drawing/str_data'
21
+ autoload :NumData, 'axlsx/drawing/num_data'
22
+ autoload :NumDataSource, 'axlsx/drawing/num_data_source'
23
+ autoload :AxDataSource, 'axlsx/drawing/ax_data_source'
24
+
25
+ autoload :SerAxis, 'axlsx/drawing/ser_axis'
26
+ autoload :CatAxis, 'axlsx/drawing/cat_axis'
27
+ autoload :ValAxis, 'axlsx/drawing/val_axis'
28
+ autoload :Axes, 'axlsx/drawing/axes'
29
+
30
+ autoload :Marker, 'axlsx/drawing/marker'
31
+
32
+ autoload :OneCellAnchor, 'axlsx/drawing/one_cell_anchor'
33
+ autoload :TwoCellAnchor, 'axlsx/drawing/two_cell_anchor'
34
+ autoload :GraphicFrame, 'axlsx/drawing/graphic_frame'
35
+
36
+ autoload :View3D, 'axlsx/drawing/view_3D'
37
+ autoload :Chart, 'axlsx/drawing/chart'
38
+ autoload :Pie3DChart, 'axlsx/drawing/pie_3D_chart'
39
+ autoload :PieChart, 'axlsx/drawing/pie_chart'
40
+ autoload :Bar3DChart, 'axlsx/drawing/bar_3D_chart'
41
+ autoload :BarChart, 'axlsx/drawing/bar_chart'
42
+ autoload :LineChart, 'axlsx/drawing/line_chart'
43
+ autoload :Line3DChart, 'axlsx/drawing/line_3D_chart'
44
+ autoload :ScatterChart, 'axlsx/drawing/scatter_chart'
45
+ autoload :BubbleChart, 'axlsx/drawing/bubble_chart'
46
+ autoload :AreaChart, 'axlsx/drawing/area_chart'
47
+
48
+ autoload :PictureLocking, 'axlsx/drawing/picture_locking'
49
+ autoload :Pic, 'axlsx/drawing/pic'
50
+ autoload :Hyperlink, 'axlsx/drawing/hyperlink'
51
+
52
+ autoload :VmlDrawing, 'axlsx/drawing/vml_drawing'
53
+ autoload :VmlShape, 'axlsx/drawing/vml_shape'
52
54
 
53
55
  # A Drawing is a canvas for charts and images. Each worksheet has a single drawing that manages anchors.
54
56
  # 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 +60,6 @@ module Axlsx
58
60
  # @see Chart
59
61
  # see examples/example.rb for an example of how to create a chart.
60
62
  class Drawing
61
-
62
63
  # The worksheet that owns the drawing
63
64
  # @return [Worksheet]
64
65
  attr_reader :worksheet
@@ -77,12 +78,11 @@ module Axlsx
77
78
  @anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor]
78
79
  end
79
80
 
80
-
81
81
  # 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
82
  # @note The recommended way to manage images is to use Worksheet.add_image. Please refer to that method for documentation.
83
83
  # @see Worksheet#add_image
84
84
  # @return [Pic]
85
- def add_image(options={})
85
+ def add_image(options = {})
86
86
  if options[:end_at]
87
87
  TwoCellAnchor.new(self, options).add_pic(options)
88
88
  else
@@ -94,7 +94,7 @@ module Axlsx
94
94
  # Adds a chart to the drawing.
95
95
  # @note The recommended way to manage charts is to use Worksheet.add_chart. Please refer to that method for documentation.
96
96
  # @see Worksheet#add_chart
97
- def add_chart(chart_type, options={})
97
+ def add_chart(chart_type, options = {})
98
98
  TwoCellAnchor.new(self, options)
99
99
  @anchors.last.add_chart(chart_type, options)
100
100
  end
@@ -109,15 +109,15 @@ module Axlsx
109
109
  # An array of hyperlink objects associated with this drawings images
110
110
  # @return [Array]
111
111
  def hyperlinks
112
- links = self.images.select { |a| a.hyperlink.is_a?(Hyperlink) }
113
- links.map { |a| a.hyperlink }
112
+ links = images.select { |a| a.hyperlink.is_a?(Hyperlink) }
113
+ links.map(&:hyperlink)
114
114
  end
115
115
 
116
116
  # An array of image objects that are associated with this drawing's anchors
117
117
  # @return [Array]
118
118
  def images
119
119
  images = @anchors.select { |a| a.object.is_a?(Pic) }
120
- images.map { |a| a.object }
120
+ images.map(&:object)
121
121
  end
122
122
 
123
123
  # The index of this drawing in the owning workbooks's drawings collection.
@@ -129,14 +129,14 @@ module Axlsx
129
129
  # The part name for this drawing
130
130
  # @return [String]
131
131
  def pn
132
- "#{DRAWING_PN % (index+1)}"
132
+ format(DRAWING_PN, index + 1)
133
133
  end
134
134
 
135
135
  # The relational part name for this drawing
136
136
  # #NOTE This should be rewritten to return an Axlsx::Relationship object.
137
137
  # @return [String]
138
138
  def rels_pn
139
- "#{DRAWING_RELS_PN % (index+1)}"
139
+ format(DRAWING_RELS_PN, index + 1)
140
140
  end
141
141
 
142
142
  # A list of objects this drawing holds.
@@ -156,12 +156,11 @@ module Axlsx
156
156
  # Serializes the object
157
157
  # @param [String] str
158
158
  # @return [String]
159
- def to_xml_string(str = '')
159
+ def to_xml_string(str = +'')
160
160
  str << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
161
- str << ('<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '">')
161
+ str << '<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '">'
162
162
  anchors.each { |anchor| anchor.to_xml_string(str) }
163
163
  str << '</xdr:wsDr>'
164
164
  end
165
-
166
165
  end
167
166
  end