axlsx 2.0.1 → 3.0.0.pre

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 (180) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +23 -23
  4. data/Rakefile +9 -11
  5. data/examples/auto_filter.rb +10 -1
  6. data/examples/conditional_formatting/example_conditional_formatting.rb +18 -3
  7. data/examples/example.rb +102 -4
  8. data/examples/merge_cells.rb +17 -0
  9. data/examples/no_grid_with_borders.rb +18 -0
  10. data/examples/pivot_test.rb +63 -0
  11. data/examples/split.rb +16 -0
  12. data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
  13. data/lib/axlsx/content_type/content_type.rb +1 -1
  14. data/lib/axlsx/doc_props/app.rb +1 -1
  15. data/lib/axlsx/doc_props/core.rb +5 -5
  16. data/lib/axlsx/drawing/area_chart.rb +99 -0
  17. data/lib/axlsx/drawing/area_series.rb +110 -0
  18. data/lib/axlsx/drawing/axes.rb +1 -1
  19. data/lib/axlsx/drawing/axis.rb +12 -9
  20. data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
  21. data/lib/axlsx/drawing/bar_chart.rb +143 -0
  22. data/lib/axlsx/drawing/bar_series.rb +9 -9
  23. data/lib/axlsx/drawing/bubble_chart.rb +59 -0
  24. data/lib/axlsx/drawing/bubble_series.rb +63 -0
  25. data/lib/axlsx/drawing/cat_axis.rb +5 -5
  26. data/lib/axlsx/drawing/chart.rb +52 -8
  27. data/lib/axlsx/drawing/d_lbls.rb +3 -3
  28. data/lib/axlsx/drawing/drawing.rb +6 -1
  29. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  30. data/lib/axlsx/drawing/hyperlink.rb +1 -3
  31. data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
  32. data/lib/axlsx/drawing/line_chart.rb +10 -10
  33. data/lib/axlsx/drawing/line_series.rb +32 -3
  34. data/lib/axlsx/drawing/marker.rb +1 -1
  35. data/lib/axlsx/drawing/num_data.rb +4 -4
  36. data/lib/axlsx/drawing/num_data_source.rb +6 -6
  37. data/lib/axlsx/drawing/num_val.rb +3 -1
  38. data/lib/axlsx/drawing/one_cell_anchor.rb +3 -2
  39. data/lib/axlsx/drawing/pic.rb +25 -19
  40. data/lib/axlsx/drawing/picture_locking.rb +1 -3
  41. data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
  42. data/lib/axlsx/drawing/pie_series.rb +6 -6
  43. data/lib/axlsx/drawing/scaling.rb +6 -6
  44. data/lib/axlsx/drawing/scatter_chart.rb +10 -10
  45. data/lib/axlsx/drawing/scatter_series.rb +40 -7
  46. data/lib/axlsx/drawing/ser_axis.rb +2 -2
  47. data/lib/axlsx/drawing/series.rb +3 -3
  48. data/lib/axlsx/drawing/series_title.rb +2 -2
  49. data/lib/axlsx/drawing/str_data.rb +3 -3
  50. data/lib/axlsx/drawing/str_val.rb +3 -1
  51. data/lib/axlsx/drawing/title.rb +22 -4
  52. data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
  53. data/lib/axlsx/drawing/val_axis.rb +1 -1
  54. data/lib/axlsx/drawing/view_3D.rb +2 -2
  55. data/lib/axlsx/drawing/vml_drawing.rb +1 -1
  56. data/lib/axlsx/package.rb +34 -32
  57. data/lib/axlsx/rels/relationship.rb +1 -1
  58. data/lib/axlsx/rels/relationships.rb +7 -4
  59. data/lib/axlsx/stylesheet/border_pr.rb +2 -2
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
  61. data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
  62. data/lib/axlsx/stylesheet/cell_style.rb +1 -3
  63. data/lib/axlsx/stylesheet/color.rb +1 -3
  64. data/lib/axlsx/stylesheet/font.rb +1 -1
  65. data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
  66. data/lib/axlsx/stylesheet/num_fmt.rb +10 -3
  67. data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
  68. data/lib/axlsx/stylesheet/styles.rb +7 -7
  69. data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
  70. data/lib/axlsx/util/accessors.rb +6 -6
  71. data/lib/axlsx/util/constants.rb +107 -99
  72. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  73. data/lib/axlsx/util/options_parser.rb +2 -1
  74. data/lib/axlsx/util/parser.rb +4 -4
  75. data/lib/axlsx/util/serialized_attributes.rb +16 -6
  76. data/lib/axlsx/util/simple_typed_list.rb +28 -52
  77. data/lib/axlsx/util/storage.rb +4 -4
  78. data/lib/axlsx/util/validators.rb +29 -17
  79. data/lib/axlsx/version.rb +1 -1
  80. data/lib/axlsx/workbook/defined_name.rb +11 -12
  81. data/lib/axlsx/workbook/defined_names.rb +2 -2
  82. data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
  83. data/lib/axlsx/workbook/workbook.rb +36 -11
  84. data/lib/axlsx/workbook/workbook_view.rb +80 -0
  85. data/lib/axlsx/workbook/workbook_views.rb +22 -0
  86. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
  87. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
  88. data/lib/axlsx/workbook/worksheet/break.rb +1 -3
  89. data/lib/axlsx/workbook/worksheet/cell.rb +136 -74
  90. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +63 -43
  91. data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
  92. data/lib/axlsx/workbook/worksheet/cfvos.rb +4 -1
  93. data/lib/axlsx/workbook/worksheet/col.rb +7 -10
  94. data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
  95. data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
  96. data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
  97. data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
  98. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
  99. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
  100. data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
  101. data/lib/axlsx/workbook/worksheet/data_validation.rb +6 -4
  102. data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
  103. data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
  104. data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
  105. data/lib/axlsx/workbook/worksheet/merged_cells.rb +4 -2
  106. data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
  107. data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
  108. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
  109. data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
  110. data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
  111. data/lib/axlsx/workbook/worksheet/pivot_table.rb +44 -28
  112. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
  113. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
  114. data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
  115. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -2
  116. data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -0
  117. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -0
  118. data/lib/axlsx/workbook/worksheet/row.rb +40 -51
  119. data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
  120. data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
  121. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  122. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
  123. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
  124. data/lib/axlsx/workbook/worksheet/table.rb +6 -6
  125. data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
  126. data/lib/axlsx/workbook/worksheet/tables.rb +4 -1
  127. data/lib/axlsx/workbook/worksheet/worksheet.rb +64 -78
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
  130. data/lib/axlsx.rb +34 -15
  131. data/test/drawing/tc_area_chart.rb +39 -0
  132. data/test/drawing/tc_area_series.rb +71 -0
  133. data/test/drawing/tc_axis.rb +27 -0
  134. data/test/drawing/tc_bar_chart.rb +71 -0
  135. data/test/drawing/tc_bubble_chart.rb +44 -0
  136. data/test/drawing/tc_bubble_series.rb +21 -0
  137. data/test/drawing/tc_chart.rb +23 -10
  138. data/test/drawing/tc_data_source.rb +6 -0
  139. data/test/drawing/tc_drawing.rb +2 -2
  140. data/test/drawing/tc_line_chart.rb +5 -5
  141. data/test/drawing/tc_line_series.rb +47 -6
  142. data/test/drawing/tc_pic.rb +11 -15
  143. data/test/drawing/tc_scatter_series.rb +36 -1
  144. data/test/drawing/tc_str_val.rb +9 -0
  145. data/test/drawing/tc_title.rb +5 -0
  146. data/test/stylesheet/tc_styles.rb +2 -2
  147. data/test/tc_axlsx.rb +31 -0
  148. data/test/tc_helper.rb +2 -0
  149. data/test/tc_package.rb +19 -1
  150. data/test/util/tc_mime_type_utils.rb +13 -0
  151. data/test/util/tc_simple_typed_list.rb +2 -3
  152. data/test/util/tc_validators.rb +34 -10
  153. data/test/workbook/tc_defined_name.rb +12 -4
  154. data/test/workbook/tc_shared_strings_table.rb +16 -1
  155. data/test/workbook/tc_workbook.rb +38 -3
  156. data/test/workbook/tc_workbook_view.rb +50 -0
  157. data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
  158. data/test/workbook/worksheet/tc_break.rb +1 -1
  159. data/test/workbook/worksheet/tc_cell.rb +76 -8
  160. data/test/workbook/worksheet/tc_col.rb +2 -2
  161. data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
  162. data/test/workbook/worksheet/tc_data_bar.rb +1 -1
  163. data/test/workbook/worksheet/tc_data_validation.rb +11 -11
  164. data/test/workbook/worksheet/tc_header_footer.rb +2 -2
  165. data/test/workbook/worksheet/tc_icon_set.rb +1 -1
  166. data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
  167. data/test/workbook/worksheet/tc_page_setup.rb +3 -3
  168. data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
  169. data/test/workbook/worksheet/tc_print_options.rb +1 -1
  170. data/test/workbook/worksheet/tc_rich_text.rb +44 -0
  171. data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
  172. data/test/workbook/worksheet/tc_row.rb +7 -2
  173. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
  174. data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
  175. data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
  176. data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
  177. data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
  178. data/test/workbook/worksheet/tc_table.rb +2 -3
  179. data/test/workbook/worksheet/tc_worksheet.rb +99 -45
  180. metadata +142 -64
@@ -11,6 +11,7 @@ module Axlsx
11
11
  # @param [GraphicalFrame] frame The frame that holds this chart.
12
12
  # @option options [Cell, String] title
13
13
  # @option options [Boolean] show_legend
14
+ # @option options [Symbol] legend_position
14
15
  # @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart.
15
16
  # @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.
16
17
  def initialize(frame, options={})
@@ -20,9 +21,11 @@ module Axlsx
20
21
  @graphic_frame.anchor.drawing.worksheet.workbook.charts << self
21
22
  @series = SimpleTypedList.new Series
22
23
  @show_legend = true
24
+ @legend_position = :r
23
25
  @display_blanks_as = :gap
24
26
  @series_type = Series
25
27
  @title = Title.new
28
+ @bg_color = nil
26
29
  parse_options options
27
30
  start_at(*options[:start_at]) if options[:start_at]
28
31
  end_at(*options[:end_at]) if options[:end_at]
@@ -53,7 +56,7 @@ module Axlsx
53
56
  # Indicates that colors should be varied by datum
54
57
  # @return [Boolean]
55
58
  attr_reader :vary_colors
56
-
59
+
57
60
  # Configures the vary_colors options for this chart
58
61
  # @param [Boolean] v The value to set
59
62
  def vary_colors=(v) Axlsx::validate_boolean(v); @vary_colors = v; end
@@ -71,6 +74,17 @@ module Axlsx
71
74
  # @return [Boolean]
72
75
  attr_reader :show_legend
73
76
 
77
+ # Set the location of the chart's legend
78
+ # @return [Symbol] The position of this legend
79
+ # @note
80
+ # The following are allowed
81
+ # :b
82
+ # :l
83
+ # :r
84
+ # :t
85
+ # :tr
86
+ attr_reader :legend_position
87
+
74
88
  # How to display blank values
75
89
  # Options are
76
90
  # * gap: Display nothing
@@ -80,6 +94,10 @@ module Axlsx
80
94
  # Default :gap (although this really should vary by chart type and grouping)
81
95
  attr_reader :display_blanks_as
82
96
 
97
+ # Background color for the chart
98
+ # @return [String]
99
+ attr_reader :bg_color
100
+
83
101
  # The relationship object for this chart.
84
102
  # @return [Relationship]
85
103
  def relationship
@@ -110,6 +128,13 @@ module Axlsx
110
128
  end
111
129
  end
112
130
 
131
+ # The size of the Title object of the chart.
132
+ # @param [String] v The size for the title object
133
+ # @see Title
134
+ def title_size=(v)
135
+ @title.text_size = v unless v.to_s.empty?
136
+ end
137
+
113
138
  # Show the legend in the chart
114
139
  # @param [Boolean] v
115
140
  # @return [Boolean]
@@ -126,6 +151,9 @@ module Axlsx
126
151
  # @param [Integer] v must be between 1 and 48
127
152
  def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, lambda { |arg| arg >= 1 && arg <= 48 }; @style = v; end
128
153
 
154
+ # @see legend_position
155
+ def legend_position=(v) RestrictionValidator.validate "Chart.legend_position", [:b, :l, :r, :t, :tr], v; @legend_position = v; end
156
+
129
157
  # backwards compatibility to allow chart.to and chart.from access to anchor markers
130
158
  # @note This will be disconinued in version 2.0.0. Please use the end_at method
131
159
  def to
@@ -146,36 +174,52 @@ module Axlsx
146
174
  @series.last
147
175
  end
148
176
 
177
+ # Assigns a background color to chart area
178
+ def bg_color=(v)
179
+ DataTypeValidator.validate(:color, Color, Color.new(:rgb => v))
180
+ @bg_color = v
181
+ end
182
+
149
183
  # Serializes the object
150
184
  # @param [String] str
151
185
  # @return [String]
152
186
  def to_xml_string(str = '')
153
187
  str << '<?xml version="1.0" encoding="UTF-8"?>'
154
- str << '<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '" xmlns:r="' << XML_NS_R << '">'
155
- str << '<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>'
156
- str << '<c:style val="' << style.to_s << '"/>'
188
+ str << ('<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '" xmlns:r="' << XML_NS_R << '">')
189
+ str << ('<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>')
190
+ str << ('<c:style val="' << style.to_s << '"/>')
157
191
  str << '<c:chart>'
158
192
  @title.to_xml_string str
159
- str << '<c:autoTitleDeleted val="' << (@title == nil).to_s << '"/>'
193
+ str << ('<c:autoTitleDeleted val="' << (@title == nil).to_s << '"/>')
160
194
  @view_3D.to_xml_string(str) if @view_3D
161
195
  str << '<c:floor><c:thickness val="0"/></c:floor>'
162
196
  str << '<c:sideWall><c:thickness val="0"/></c:sideWall>'
163
197
  str << '<c:backWall><c:thickness val="0"/></c:backWall>'
164
198
  str << '<c:plotArea>'
165
199
  str << '<c:layout/>'
166
- yield str if block_given?
200
+ yield if block_given?
167
201
  str << '</c:plotArea>'
168
202
  if @show_legend
169
203
  str << '<c:legend>'
170
- str << '<c:legendPos val="r"/>'
204
+ str << ('<c:legendPos val="' << @legend_position.to_s << '"/>')
171
205
  str << '<c:layout/>'
172
206
  str << '<c:overlay val="0"/>'
173
207
  str << '</c:legend>'
174
208
  end
175
209
  str << '<c:plotVisOnly val="1"/>'
176
- str << '<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>'
210
+ str << ('<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>')
177
211
  str << '<c:showDLblsOverMax val="1"/>'
178
212
  str << '</c:chart>'
213
+ if bg_color
214
+ str << '<c:spPr>'
215
+ str << '<a:solidFill>'
216
+ str << '<a:srgbClr val="' << bg_color << '"/>'
217
+ str << '</a:solidFill>'
218
+ str << '<a:ln>'
219
+ str << '<a:noFill/>'
220
+ str << '</a:ln>'
221
+ str << '</c:spPr>'
222
+ end
179
223
  str << '<c:printSettings>'
180
224
  str << '<c:headerFooter/>'
181
225
  str << '<c:pageMargins b="1.0" l="0.75" r="0.75" t="1.0" header="0.5" footer="0.5"/>'
@@ -49,7 +49,7 @@ module Axlsx
49
49
  # @see d_lbl_pos= for a list of allowed values
50
50
  # @return [Symbol]
51
51
  def d_lbl_pos
52
- return unless @chart_type == Pie3DChart
52
+ return unless [Pie3DChart, LineChart].include? @chart_type
53
53
  @d_lbl_pos ||= :bestFit
54
54
  end
55
55
 
@@ -60,7 +60,7 @@ module Axlsx
60
60
  # The default is :bestFit
61
61
  # @param [Symbol] label_position the postion you want to use.
62
62
  def d_lbl_pos=(label_position)
63
- return unless @chart_type == Pie3DChart
63
+ return unless [Pie3DChart, LineChart].include? @chart_type
64
64
  Axlsx::RestrictionValidator.validate 'DLbls#d_lbl_pos', [:bestFit, :b, :ctr, :inBase, :inEnd, :l, :outEnd, :r, :t], label_position
65
65
  @d_lbl_pos = label_position
66
66
  end
@@ -80,7 +80,7 @@ module Axlsx
80
80
 
81
81
  # 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.
82
82
  def validate_attributes_for_chart_type
83
- return if @chart_type == Pie3DChart
83
+ return if [Pie3DChart, LineChart].include? @chart_type
84
84
  @d_lbl_pos = nil
85
85
  @show_leader_lines = nil
86
86
  end
@@ -8,6 +8,8 @@ module Axlsx
8
8
  require 'axlsx/drawing/bar_series.rb'
9
9
  require 'axlsx/drawing/line_series.rb'
10
10
  require 'axlsx/drawing/scatter_series.rb'
11
+ require 'axlsx/drawing/bubble_series.rb'
12
+ require 'axlsx/drawing/area_series.rb'
11
13
 
12
14
  require 'axlsx/drawing/scaling.rb'
13
15
  require 'axlsx/drawing/axis.rb'
@@ -34,9 +36,12 @@ module Axlsx
34
36
  require 'axlsx/drawing/chart.rb'
35
37
  require 'axlsx/drawing/pie_3D_chart.rb'
36
38
  require 'axlsx/drawing/bar_3D_chart.rb'
39
+ require 'axlsx/drawing/bar_chart.rb'
37
40
  require 'axlsx/drawing/line_chart.rb'
38
41
  require 'axlsx/drawing/line_3D_chart.rb'
39
42
  require 'axlsx/drawing/scatter_chart.rb'
43
+ require 'axlsx/drawing/bubble_chart.rb'
44
+ require 'axlsx/drawing/area_chart.rb'
40
45
 
41
46
  require 'axlsx/drawing/picture_locking.rb'
42
47
  require 'axlsx/drawing/pic.rb'
@@ -153,7 +158,7 @@ module Axlsx
153
158
  # @return [String]
154
159
  def to_xml_string(str = '')
155
160
  str << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
156
- 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 << '">')
157
162
  anchors.each { |anchor| anchor.to_xml_string(str) }
158
163
  str << '</xdr:wsDr>'
159
164
  end
@@ -35,7 +35,7 @@ module Axlsx
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,8 +43,8 @@ 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>'
@@ -93,9 +93,7 @@ module Axlsx
93
93
  # @param [String] str
94
94
  # @return [String]
95
95
  def to_xml_string(str = '')
96
- str << '<a:hlinkClick '
97
- serialized_attributes str, {:'r:id' => relationship.Id, :'xmlns:r' => XML_NS_R }
98
- str << '/>'
96
+ serialized_tag 'a:hlinkClick', str, {:'r:id' => relationship.Id, :'xmlns:r' => XML_NS_R }
99
97
  end
100
98
 
101
99
  end
@@ -60,8 +60,8 @@ module Axlsx
60
60
  # @param [String] str
61
61
  # @return [String]
62
62
  def to_xml_string(str = '')
63
- super(str) do |str_inner|
64
- str_inner << '<c:gapDepth val="' << @gap_depth.to_s << '"/>' unless @gap_depth.nil?
63
+ super(str) do
64
+ str << ('<c:gapDepth val="' << @gap_depth.to_s << '"/>') unless @gap_depth.nil?
65
65
  end
66
66
  end
67
67
  end
@@ -76,16 +76,16 @@ module Axlsx
76
76
  # @param [String] str
77
77
  # @return [String]
78
78
  def to_xml_string(str = '')
79
- super(str) do |str_inner|
80
- str_inner << "<c:" << node_name << ">"
81
- str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
82
- str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
83
- @series.each { |ser| ser.to_xml_string(str_inner) }
84
- @d_lbls.to_xml_string(str_inner) if @d_lbls
85
- yield str_inner if block_given?
86
- axes.to_xml_string(str_inner, :ids => true)
87
- str_inner << "</c:" << node_name << ">"
88
- axes.to_xml_string(str_inner)
79
+ super(str) do
80
+ str << ("<c:" << node_name << ">")
81
+ str << ('<c:grouping val="' << grouping.to_s << '"/>')
82
+ str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
83
+ @series.each { |ser| ser.to_xml_string(str) }
84
+ @d_lbls.to_xml_string(str) if @d_lbls
85
+ yield if block_given?
86
+ axes.to_xml_string(str, :ids => true)
87
+ str << ("</c:" << node_name << ">")
88
+ axes.to_xml_string(str)
89
89
  end
90
90
  end
91
91
 
@@ -23,12 +23,22 @@ module Axlsx
23
23
  # @return [Boolean]
24
24
  attr_reader :show_marker
25
25
 
26
+ # custom marker symbol
27
+ # @return [String]
28
+ attr_reader :marker_symbol
29
+
30
+ # line smoothing on values
31
+ # @return [Boolean]
32
+ attr_reader :smooth
33
+
26
34
  # Creates a new series
27
35
  # @option options [Array, SimpleTypedList] data
28
36
  # @option options [Array, SimpleTypedList] labels
29
37
  # @param [Chart] chart
30
38
  def initialize(chart, options={})
31
39
  @show_marker = false
40
+ @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default
41
+ @smooth = false
32
42
  @labels, @data = nil, nil
33
43
  super(chart, options)
34
44
  @labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
@@ -46,6 +56,18 @@ module Axlsx
46
56
  @show_marker = v
47
57
  end
48
58
 
59
+ # @see marker_symbol
60
+ def marker_symbol=(v)
61
+ Axlsx::validate_marker_symbol(v)
62
+ @marker_symbol = v
63
+ end
64
+
65
+ # @see smooth
66
+ def smooth=(v)
67
+ Axlsx::validate_boolean(v)
68
+ @smooth = v
69
+ end
70
+
49
71
  # Serializes the object
50
72
  # @param [String] str
51
73
  # @return [String]
@@ -53,19 +75,26 @@ module Axlsx
53
75
  super(str) do
54
76
  if color
55
77
  str << '<c:spPr><a:solidFill>'
56
- str << '<a:srgbClr val="' << color << '"/>'
78
+ str << ('<a:srgbClr val="' << color << '"/>')
57
79
  str << '</a:solidFill>'
58
80
  str << '<a:ln w="28800">'
59
81
  str << '<a:solidFill>'
60
- str << '<a:srgbClr val="' << color << '"/>'
82
+ str << ('<a:srgbClr val="' << color << '"/>')
61
83
  str << '</a:solidFill>'
62
84
  str << '</a:ln>'
63
85
  str << '<a:round/>'
64
86
  str << '</c:spPr>'
65
87
  end
66
- str << '<c:marker><c:symbol val="none"/></c:marker>' unless @show_marker
88
+
89
+ if !@show_marker
90
+ str << '<c:marker><c:symbol val="none"/></c:marker>'
91
+ elsif @marker_symbol != :default
92
+ str << '<c:marker><c:symbol val="' + @marker_symbol.to_s + '"/></c:marker>'
93
+ end
94
+
67
95
  @labels.to_xml_string(str) unless @labels.nil?
68
96
  @data.to_xml_string(str) unless @data.nil?
97
+ str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
69
98
  end
70
99
  end
71
100
 
@@ -58,7 +58,7 @@ module Axlsx
58
58
  # @return [String]
59
59
  def to_xml_string(str = '')
60
60
  [:col, :colOff, :row, :rowOff].each do |k|
61
- str << '<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>'
61
+ str << ('<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>')
62
62
  end
63
63
  end
64
64
  private
@@ -38,13 +38,13 @@ module Axlsx
38
38
 
39
39
  # serialize the object
40
40
  def to_xml_string(str = "")
41
- str << '<c:' << @tag_name.to_s << '>'
42
- str << '<c:formatCode>' << format_code.to_s << '</c:formatCode>'
43
- str << '<c:ptCount val="' << @pt.size.to_s << '"/>'
41
+ str << ('<c:' << @tag_name.to_s << '>')
42
+ str << ('<c:formatCode>' << format_code.to_s << '</c:formatCode>')
43
+ str << ('<c:ptCount val="' << @pt.size.to_s << '"/>')
44
44
  @pt.each_with_index do |num_val, index|
45
45
  num_val.to_xml_string index, str
46
46
  end
47
- str << '</c:' << @tag_name.to_s << '>'
47
+ str << ('</c:' << @tag_name.to_s << '>')
48
48
  end
49
49
 
50
50
  end
@@ -33,7 +33,7 @@ module Axlsx
33
33
  # allowed element tag names
34
34
  # @return [Array]
35
35
  def self.allowed_tag_names
36
- [:yVal, :val]
36
+ [:yVal, :val, :bubbleSize]
37
37
  end
38
38
 
39
39
  # sets the tag name for this data source
@@ -46,16 +46,16 @@ module Axlsx
46
46
  # serialize the object
47
47
  # @param [String] str
48
48
  def to_xml_string(str="")
49
- str << '<c:' << tag_name.to_s << '>'
49
+ str << ('<c:' << tag_name.to_s << '>')
50
50
  if @f
51
- str << '<c:' << @ref_tag_name.to_s << '>'
52
- str << '<c:f>' << @f.to_s << '</c:f>'
51
+ str << ('<c:' << @ref_tag_name.to_s << '>')
52
+ str << ('<c:f>' << @f.to_s << '</c:f>')
53
53
  end
54
54
  @data.to_xml_string str
55
55
  if @f
56
- str << '</c:' << @ref_tag_name.to_s << '>'
56
+ str << ('</c:' << @ref_tag_name.to_s << '>')
57
57
  end
58
- str << '</c:' << tag_name.to_s << '>'
58
+ str << ('</c:' << tag_name.to_s << '>')
59
59
  end
60
60
  end
61
61
  end
@@ -26,7 +26,9 @@ module Axlsx
26
26
  # serialize the object
27
27
  def to_xml_string(idx, str = "")
28
28
  Axlsx::validate_unsigned_int(idx)
29
- str << '<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>'
29
+ if !v.to_s.empty?
30
+ str << ('<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>')
31
+ end
30
32
  end
31
33
  end
32
34
  end
@@ -7,7 +7,7 @@ module Axlsx
7
7
  class OneCellAnchor
8
8
 
9
9
  include Axlsx::OptionsParser
10
-
10
+
11
11
  # Creates a new OneCellAnchor object and an Pic associated with it.
12
12
  # @param [Drawing] drawing
13
13
  # @option options [Array] start_at the col, row to start at
@@ -23,6 +23,7 @@ module Axlsx
23
23
  drawing.anchors << self
24
24
  @from = Marker.new
25
25
  parse_options options
26
+ start_at(*options[:start_at]) if options[:start_at]
26
27
  @object = Pic.new(self, options)
27
28
  end
28
29
 
@@ -77,7 +78,7 @@ module Axlsx
77
78
  str << '<xdr:from>'
78
79
  from.to_xml_string(str)
79
80
  str << '</xdr:from>'
80
- str << '<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>'
81
+ str << ('<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>')
81
82
  @object.to_xml_string(str)
82
83
  str << '<xdr:clientData/>'
83
84
  str << '</xdr:oneCellAnchor>'
@@ -9,12 +9,13 @@ module Axlsx
9
9
 
10
10
  # Creates a new Pic(ture) object
11
11
  # @param [Anchor] anchor the anchor that holds this image
12
- # @option options [String] name
13
- # @option options [String] descr
14
- # @option options [String] image_src
15
- # @option options [Array] start_at
16
- # @option options [Intger] width
17
- # @option options [Intger] height
12
+ # @option options [String] :name
13
+ # @option options [String] :descr
14
+ # @option options [String] :image_src
15
+ # @option options [Array] :start_at
16
+ # @option options [Integer] :width
17
+ # @option options [Integer] :height
18
+ # @option options [Float] :opacity - set the picture opacity, accepts a value between 0.0 and 1.0
18
19
  def initialize(anchor, options={})
19
20
  @anchor = anchor
20
21
  @hyperlink = nil
@@ -23,10 +24,11 @@ module Axlsx
23
24
  start_at(*options[:start_at]) if options[:start_at]
24
25
  yield self if block_given?
25
26
  @picture_locking = PictureLocking.new(options)
27
+ @opacity = (options[:opacity] * 100000).round if options[:opacity]
26
28
  end
27
29
 
28
- # allowed file extenstions
29
- ALLOWED_EXTENSIONS = ['gif', 'jpeg', 'png', 'jpg']
30
+ # allowed mime types
31
+ ALLOWED_MIME_TYPES = %w(image/jpeg image/png image/gif)
30
32
 
31
33
  # The name to use for this picture
32
34
  # @return [String]
@@ -50,24 +52,28 @@ module Axlsx
50
52
 
51
53
  attr_reader :hyperlink
52
54
 
55
+ # Picture opacity
56
+ # @return [Integer]
57
+ attr_reader :opacity
58
+
53
59
  # sets or updates a hyperlink for this image.
54
60
  # @param [String] v The href value for the hyper link
55
61
  # @option options @see Hyperlink#initialize All options available to the Hyperlink class apply - however href will be overridden with the v parameter value.
56
62
  def hyperlink=(v, options={})
57
63
  options[:href] = v
58
- if @hyperlink.is_a?(Hyperlink)
64
+ if hyperlink.is_a?(Hyperlink)
59
65
  options.each do |o|
60
- @hyperlink.send("#{o[0]}=", o[1]) if @hyperlink.respond_to? "#{o[0]}="
66
+ hyperlink.send("#{o[0]}=", o[1]) if hyperlink.respond_to? "#{o[0]}="
61
67
  end
62
68
  else
63
69
  @hyperlink = Hyperlink.new(self, options)
64
70
  end
65
- @hyperlink
71
+ hyperlink
66
72
  end
67
73
 
68
74
  def image_src=(v)
69
75
  Axlsx::validate_string(v)
70
- RestrictionValidator.validate 'Pic.image_src', ALLOWED_EXTENSIONS, File.extname(v.downcase).delete('.')
76
+ RestrictionValidator.validate 'Pic.image_src', ALLOWED_MIME_TYPES, MimeTypeUtils.get_mime_type(v)
71
77
  raise ArgumentError, "File does not exist" unless File.exist?(v)
72
78
  @image_src = v
73
79
  end
@@ -78,7 +84,6 @@ module Axlsx
78
84
  # @see descr
79
85
  def descr=(v) Axlsx::validate_string(v); @descr = v; end
80
86
 
81
-
82
87
  # The file name of image_src without any path information
83
88
  # @return [String]
84
89
  def file_name
@@ -110,7 +115,6 @@ module Axlsx
110
115
  end
111
116
 
112
117
  # providing access to the anchor's width attribute
113
- # @param [Integer] v
114
118
  # @see OneCellAnchor.width
115
119
  def width
116
120
  return unless @anchor.is_a?(OneCellAnchor)
@@ -124,7 +128,6 @@ module Axlsx
124
128
  end
125
129
 
126
130
  # providing access to update the anchor's height attribute
127
- # @param [Integer] v
128
131
  # @see OneCellAnchor.width
129
132
  # @note this is a noop if you are using a TwoCellAnchor
130
133
  def height
@@ -165,17 +168,20 @@ module Axlsx
165
168
  def to_xml_string(str = '')
166
169
  str << '<xdr:pic>'
167
170
  str << '<xdr:nvPicPr>'
168
- str << '<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">'
169
- @hyperlink.to_xml_string(str) if @hyperlink.is_a?(Hyperlink)
171
+ str << ('<xdr:cNvPr id="2" name="' << name.to_s << '" descr="' << descr.to_s << '">')
172
+ hyperlink.to_xml_string(str) if hyperlink.is_a?(Hyperlink)
170
173
  str << '</xdr:cNvPr><xdr:cNvPicPr>'
171
174
  picture_locking.to_xml_string(str)
172
175
  str << '</xdr:cNvPicPr></xdr:nvPicPr>'
173
176
  str << '<xdr:blipFill>'
174
- str << '<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '"/>'
177
+ str << ('<a:blip xmlns:r ="' << XML_NS_R << '" r:embed="' << relationship.Id << '">')
178
+ if opacity
179
+ str << "<a:alphaModFix amt=\"#{opacity}\"/>"
180
+ end
181
+ str << '</a:blip>'
175
182
  str << '<a:stretch><a:fillRect/></a:stretch></xdr:blipFill><xdr:spPr>'
176
183
  str << '<a:xfrm><a:off x="0" y="0"/><a:ext cx="2336800" cy="2161540"/></a:xfrm>'
177
184
  str << '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>'
178
-
179
185
  end
180
186
 
181
187
  private
@@ -35,9 +35,7 @@ module Axlsx
35
35
  # @param [String] str
36
36
  # @return [String]
37
37
  def to_xml_string(str = '')
38
- str << '<a:picLocks '
39
- serialized_attributes str
40
- str << '/>'
38
+ serialized_tag('a:picLocks', str)
41
39
  end
42
40
 
43
41
  end
@@ -34,13 +34,12 @@ module Axlsx
34
34
  # @param [String] str
35
35
  # @return [String]
36
36
  def to_xml_string(str = '')
37
- super(str) do |str_inner|
38
-
39
- str_inner << '<c:pie3DChart>'
40
- str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
41
- @series.each { |ser| ser.to_xml_string(str_inner) }
37
+ super(str) do
38
+ str << '<c:pie3DChart>'
39
+ str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
40
+ @series.each { |ser| ser.to_xml_string(str) }
42
41
  d_lbls.to_xml_string(str) if @d_lbls
43
- str_inner << '</c:pie3DChart>'
42
+ str << '</c:pie3DChart>'
44
43
  end
45
44
  end
46
45
 
@@ -46,17 +46,17 @@ module Axlsx
46
46
  # @param [String] str
47
47
  # @return [String]
48
48
  def to_xml_string(str = '')
49
- super(str) do |str_inner|
50
- str_inner << '<c:explosion val="' << @explosion << '"/>' unless @explosion.nil?
49
+ super(str) do
50
+ str << '<c:explosion val="' + @explosion + '"/>' unless @explosion.nil?
51
51
  colors.each_with_index do |c, index|
52
52
  str << '<c:dPt>'
53
- str << '<c:idx val="' << index.to_s << '"/>'
53
+ str << ('<c:idx val="' << index.to_s << '"/>')
54
54
  str << '<c:spPr><a:solidFill>'
55
- str << '<a:srgbClr val="' << c << '"/>'
55
+ str << ('<a:srgbClr val="' << c << '"/>')
56
56
  str << '</a:solidFill></c:spPr></c:dPt>'
57
57
  end
58
- @labels.to_xml_string str_inner unless @labels.nil?
59
- @data.to_xml_string str_inner unless @data.nil?
58
+ @labels.to_xml_string str unless @labels.nil?
59
+ @data.to_xml_string str unless @data.nil?
60
60
  end
61
61
  str
62
62
  end
@@ -6,7 +6,7 @@ module Axlsx
6
6
  include Axlsx::OptionsParser
7
7
 
8
8
  # creates a new Scaling object
9
- # @option options [Integer, Fixnum] logBase
9
+ # @option options [Integer] logBase
10
10
  # @option options [Symbol] orientation
11
11
  # @option options [Float] max
12
12
  # @option options [Float] min
@@ -35,7 +35,7 @@ module Axlsx
35
35
  attr_reader :min
36
36
 
37
37
  # @see logBase
38
- def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer, Fixnum], v, lambda { |arg| arg >= 2 && arg <= 1000}; @logBase = v; end
38
+ def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer], v, lambda { |arg| arg >= 2 && arg <= 1000}; @logBase = v; end
39
39
  # @see orientation
40
40
  def orientation=(v) RestrictionValidator.validate "Scaling.orientation", [:minMax, :maxMin], v; @orientation = v; end
41
41
  # @see max
@@ -49,10 +49,10 @@ module Axlsx
49
49
  # @return [String]
50
50
  def to_xml_string(str = '')
51
51
  str << '<c:scaling>'
52
- str << '<c:logBase val="' << @logBase.to_s << '"/>' unless @logBase.nil?
53
- str << '<c:orientation val="' << @orientation.to_s << '"/>' unless @orientation.nil?
54
- str << '<c:min val="' << @min.to_s << '"/>' unless @min.nil?
55
- str << '<c:max val="' << @max.to_s << '"/>' unless @max.nil?
52
+ str << ('<c:logBase val="' << @logBase.to_s << '"/>') unless @logBase.nil?
53
+ str << ('<c:orientation val="' << @orientation.to_s << '"/>') unless @orientation.nil?
54
+ str << ('<c:min val="' << @min.to_s << '"/>') unless @min.nil?
55
+ str << ('<c:max val="' << @max.to_s << '"/>') unless @max.nil?
56
56
  str << '</c:scaling>'
57
57
  end
58
58