axlsx 1.2.0 → 2.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 (208) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +3 -2
  3. data/.yardopts_guide +19 -0
  4. data/CHANGELOG.md +64 -1
  5. data/README.md +105 -87
  6. data/Rakefile +0 -5
  7. data/examples/2010_comments.rb +17 -0
  8. data/examples/anchor_swapping.rb +28 -0
  9. data/examples/auto_filter.rb +16 -0
  10. data/examples/basic_charts.rb +4 -0
  11. data/examples/colored_links.rb +59 -0
  12. data/examples/conditional_formatting/example_conditional_formatting.rb +4 -2
  13. data/examples/example.rb +569 -258
  14. data/examples/ios_preview.rb +14 -0
  15. data/examples/page_setup.rb +11 -0
  16. data/examples/pivot_table.rb +39 -0
  17. data/examples/skydrive/real_example.rb +8 -8
  18. data/examples/styles.rb +66 -0
  19. data/examples/underline.rb +13 -0
  20. data/examples/wrap_text.rb +21 -0
  21. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  22. data/lib/axlsx/content_type/content_type.rb +1 -1
  23. data/lib/axlsx/content_type/default.rb +6 -37
  24. data/lib/axlsx/content_type/override.rb +6 -38
  25. data/lib/axlsx/doc_props/app.rb +10 -7
  26. data/lib/axlsx/doc_props/core.rb +6 -1
  27. data/lib/axlsx/drawing/axes.rb +61 -0
  28. data/lib/axlsx/drawing/axis.rb +20 -17
  29. data/lib/axlsx/drawing/bar_3D_chart.rb +31 -22
  30. data/lib/axlsx/drawing/cat_axis.rb +2 -10
  31. data/lib/axlsx/drawing/chart.rb +33 -6
  32. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  33. data/lib/axlsx/drawing/drawing.rb +11 -17
  34. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  35. data/lib/axlsx/drawing/hyperlink.rb +42 -36
  36. data/lib/axlsx/drawing/line_3D_chart.rb +28 -70
  37. data/lib/axlsx/drawing/line_chart.rb +99 -0
  38. data/lib/axlsx/drawing/line_series.rb +20 -2
  39. data/lib/axlsx/drawing/marker.rb +38 -18
  40. data/lib/axlsx/drawing/num_data.rb +6 -6
  41. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  42. data/lib/axlsx/drawing/one_cell_anchor.rb +28 -21
  43. data/lib/axlsx/drawing/pic.rb +43 -45
  44. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  45. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -1
  46. data/lib/axlsx/drawing/scaling.rb +13 -13
  47. data/lib/axlsx/drawing/scatter_chart.rb +32 -21
  48. data/lib/axlsx/drawing/ser_axis.rb +15 -16
  49. data/lib/axlsx/drawing/series.rb +3 -6
  50. data/lib/axlsx/drawing/str_data.rb +3 -3
  51. data/lib/axlsx/drawing/str_val.rb +7 -8
  52. data/lib/axlsx/drawing/two_cell_anchor.rb +7 -27
  53. data/lib/axlsx/drawing/val_axis.rb +14 -13
  54. data/lib/axlsx/drawing/view_3D.rb +52 -38
  55. data/lib/axlsx/drawing/vml_shape.rb +20 -79
  56. data/lib/axlsx/package.rb +58 -28
  57. data/lib/axlsx/rels/relationship.rb +75 -9
  58. data/lib/axlsx/rels/relationships.rb +8 -1
  59. data/lib/axlsx/stylesheet/border.rb +29 -20
  60. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  61. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  62. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  63. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  64. data/lib/axlsx/stylesheet/color.rb +20 -17
  65. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  66. data/lib/axlsx/stylesheet/font.rb +22 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  68. data/lib/axlsx/stylesheet/num_fmt.rb +23 -14
  69. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  70. data/lib/axlsx/stylesheet/styles.rb +37 -22
  71. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  72. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  73. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  74. data/lib/axlsx/stylesheet/xf.rb +28 -26
  75. data/lib/axlsx/util/accessors.rb +64 -0
  76. data/lib/axlsx/util/constants.rb +127 -6
  77. data/lib/axlsx/util/options_parser.rb +15 -0
  78. data/lib/axlsx/util/serialized_attributes.rb +79 -0
  79. data/lib/axlsx/util/simple_typed_list.rb +50 -15
  80. data/lib/axlsx/util/validators.rb +51 -16
  81. data/lib/axlsx/version.rb +2 -2
  82. data/lib/axlsx/workbook/defined_name.rb +14 -59
  83. data/lib/axlsx/workbook/shared_strings_table.rb +13 -4
  84. data/lib/axlsx/workbook/workbook.rb +85 -6
  85. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +77 -0
  86. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +94 -0
  87. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +246 -0
  88. data/lib/axlsx/workbook/worksheet/break.rb +37 -0
  89. data/lib/axlsx/workbook/worksheet/cell.rb +109 -107
  90. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +144 -0
  91. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  92. data/lib/axlsx/workbook/worksheet/cfvos.rb +15 -0
  93. data/lib/axlsx/workbook/worksheet/col.rb +43 -29
  94. data/lib/axlsx/workbook/worksheet/col_breaks.rb +35 -0
  95. data/lib/axlsx/workbook/worksheet/color_scale.rb +62 -28
  96. data/lib/axlsx/workbook/worksheet/comment.rb +28 -37
  97. data/lib/axlsx/workbook/worksheet/comments.rb +3 -3
  98. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  99. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +31 -27
  100. data/lib/axlsx/workbook/worksheet/data_bar.rb +75 -41
  101. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  102. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +6 -5
  103. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  104. data/lib/axlsx/workbook/worksheet/header_footer.rb +54 -0
  105. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  106. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  107. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +44 -0
  108. data/lib/axlsx/workbook/worksheet/page_setup.rb +152 -23
  109. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  110. data/lib/axlsx/workbook/worksheet/pivot_table.rb +273 -0
  111. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +66 -0
  112. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +24 -0
  113. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  114. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  115. data/lib/axlsx/workbook/worksheet/row.rb +59 -83
  116. data/lib/axlsx/workbook/worksheet/row_breaks.rb +33 -0
  117. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  118. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +29 -0
  119. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +60 -0
  120. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +49 -4
  121. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  122. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  123. data/lib/axlsx/workbook/worksheet/table.rb +25 -19
  124. data/lib/axlsx/workbook/worksheet/table_style_info.rb +51 -0
  125. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  126. data/lib/axlsx/workbook/worksheet/worksheet.rb +174 -35
  127. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -5
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +4 -10
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +74 -0
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +38 -0
  131. data/lib/axlsx.rb +55 -5
  132. data/lib/schema/sml.xsd +4 -0
  133. data/test/axlsx.qcachegrind +2226 -0
  134. data/test/benchmark.rb +2 -3
  135. data/test/content_type/tc_default.rb +0 -11
  136. data/test/content_type/tc_override.rb +0 -13
  137. data/test/doc_props/tc_core.rb +7 -0
  138. data/test/drawing/tc_axes.rb +8 -0
  139. data/test/drawing/tc_axis.rb +15 -17
  140. data/test/drawing/tc_bar_3D_chart.rb +6 -0
  141. data/test/drawing/tc_cat_axis.rb +9 -9
  142. data/test/drawing/tc_chart.rb +20 -0
  143. data/test/drawing/tc_d_lbls.rb +14 -4
  144. data/test/drawing/tc_drawing.rb +0 -5
  145. data/test/drawing/tc_graphic_frame.rb +5 -3
  146. data/test/drawing/tc_hyperlink.rb +0 -4
  147. data/test/drawing/tc_line_chart.rb +39 -0
  148. data/test/drawing/tc_line_series.rb +8 -2
  149. data/test/drawing/tc_pic.rb +14 -3
  150. data/test/drawing/tc_ser_axis.rb +13 -12
  151. data/test/drawing/tc_two_cell_anchor.rb +3 -3
  152. data/test/drawing/tc_val_axis.rb +6 -6
  153. data/test/drawing/tc_vml_shape.rb +9 -3
  154. data/test/profile.rb +11 -21
  155. data/test/rels/tc_relationship.rb +32 -9
  156. data/test/rels/tc_relationships.rb +12 -1
  157. data/test/stylesheet/tc_color.rb +6 -0
  158. data/test/stylesheet/tc_styles.rb +15 -2
  159. data/test/tc_axlsx.rb +35 -2
  160. data/test/tc_helper.rb +7 -1
  161. data/test/tc_package.rb +44 -5
  162. data/test/util/tc_serialized_attributes.rb +19 -0
  163. data/test/util/tc_validators.rb +26 -1
  164. data/test/workbook/tc_defined_name.rb +2 -2
  165. data/test/workbook/tc_shared_strings_table.rb +6 -0
  166. data/test/workbook/tc_workbook.rb +38 -1
  167. data/test/workbook/worksheet/auto_filter/tc_auto_filter.rb +38 -0
  168. data/test/workbook/worksheet/auto_filter/tc_filter_column.rb +76 -0
  169. data/test/workbook/worksheet/auto_filter/tc_filters.rb +50 -0
  170. data/test/workbook/worksheet/tc_break.rb +49 -0
  171. data/test/workbook/worksheet/tc_cell.rb +40 -6
  172. data/test/workbook/worksheet/tc_col.rb +11 -1
  173. data/test/workbook/worksheet/tc_color_scale.rb +31 -2
  174. data/test/workbook/worksheet/tc_comment.rb +21 -6
  175. data/test/workbook/worksheet/tc_comments.rb +2 -2
  176. data/test/workbook/worksheet/tc_conditional_formatting.rb +7 -0
  177. data/test/workbook/worksheet/tc_data_bar.rb +7 -0
  178. data/test/workbook/worksheet/tc_date_time_converter.rb +3 -11
  179. data/test/workbook/worksheet/tc_header_footer.rb +151 -0
  180. data/test/workbook/worksheet/tc_page_set_up_pr.rb +15 -0
  181. data/test/workbook/worksheet/tc_page_setup.rb +6 -1
  182. data/test/workbook/worksheet/tc_pane.rb +5 -45
  183. data/test/workbook/worksheet/tc_pivot_table.rb +120 -0
  184. data/test/workbook/worksheet/tc_pivot_table_cache_definition.rb +54 -0
  185. data/test/workbook/worksheet/tc_row.rb +4 -4
  186. data/test/workbook/worksheet/tc_selection.rb +9 -48
  187. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +18 -0
  188. data/test/workbook/worksheet/tc_sheet_format_pr.rb +88 -0
  189. data/test/workbook/worksheet/tc_sheet_pr.rb +27 -0
  190. data/test/workbook/worksheet/tc_sheet_view.rb +39 -39
  191. data/test/workbook/worksheet/{table/tc_table.rb → tc_table.rb} +8 -3
  192. data/test/workbook/worksheet/tc_table_style_info.rb +53 -0
  193. data/test/workbook/worksheet/tc_worksheet.rb +131 -16
  194. data/test/workbook/worksheet/tc_worksheet_hyperlink.rb +55 -0
  195. metadata +97 -64
  196. data/examples/example.xlsx +0 -0
  197. data/examples/example_streamed.xlsx +0 -0
  198. data/examples/extractive.pdf +0 -0
  199. data/examples/image1.gif +0 -0
  200. data/examples/image1.jpg +0 -0
  201. data/examples/image1.png +0 -0
  202. data/examples/no-use_autowidth.xlsx +0 -0
  203. data/examples/sample.png +0 -0
  204. data/examples/scraping_html.rb +0 -91
  205. data/examples/shared_strings_example.xlsx +0 -0
  206. data/examples/sheet_view.rb +0 -34
  207. data/examples/two_cell_anchor_image.rb +0 -11
  208. data/lib/axlsx/workbook/worksheet/auto_filter.rb +0 -34
@@ -10,18 +10,24 @@ module Axlsx
10
10
 
11
11
  # the category axis
12
12
  # @return [CatAxis]
13
- attr_reader :cat_axis
13
+ def cat_axis
14
+ axes[:cat_axis]
15
+ end
14
16
  alias :catAxis :cat_axis
15
17
 
16
18
  # the value axis
17
19
  # @return [ValAxis]
18
- attr_reader :val_axis
20
+ def val_axis
21
+ axes[:val_axis]
22
+ end
19
23
  alias :valAxis :val_axis
20
24
 
21
25
  # The direction of the bars in the chart
22
26
  # must be one of [:bar, :col]
23
27
  # @return [Symbol]
24
- attr_reader :bar_dir
28
+ def bar_dir
29
+ @bar_dir ||= :bar
30
+ end
25
31
  alias :barDir :bar_dir
26
32
 
27
33
  # space between bar or column clusters, as a percentage of the bar or column width.
@@ -31,18 +37,24 @@ module Axlsx
31
37
 
32
38
  # space between bar or column clusters, as a percentage of the bar or column width.
33
39
  # @return [String]
34
- attr_reader :gap_width
40
+ def gap_width
41
+ @gap_width ||= 150
42
+ end
35
43
  alias :gapWidth :gap_width
36
-
44
+
37
45
  #grouping for a column, line, or area chart.
38
46
  # must be one of [:percentStacked, :clustered, :standard, :stacked]
39
47
  # @return [Symbol]
40
- attr_reader :grouping
48
+ def grouping
49
+ @grouping ||= :clustered
50
+ end
41
51
 
42
52
  # The shabe of the bars or columns
43
53
  # must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]
44
54
  # @return [Symbol]
45
- attr_reader :shape
55
+ def shape
56
+ @shape ||= :box
57
+ end
46
58
 
47
59
  # validation regex for gap amount percent
48
60
  GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
@@ -65,15 +77,8 @@ module Axlsx
65
77
  # @see Chart
66
78
  # @see View3D
67
79
  def initialize(frame, options={})
68
- @bar_dir = :bar
69
- @grouping = :clustered
70
- @shape = :box
71
- @gap_width = 150
80
+ @vary_colors = true
72
81
  @gap_width, @gap_depth, @shape = nil, nil, nil
73
- @cat_ax_id = rand(8 ** 8)
74
- @val_ax_id = rand(8 ** 8)
75
- @cat_axis = CatAxis.new(@cat_ax_id, @val_ax_id)
76
- @val_axis = ValAxis.new(@val_ax_id, @cat_ax_id, :tick_lbl_pos => :low, :ax_pos => :l)
77
82
  super(frame, options)
78
83
  @series_type = BarSeries
79
84
  @view_3D = View3D.new({:r_ang_ax=>1}.merge(options))
@@ -124,19 +129,23 @@ module Axlsx
124
129
  str_inner << '<c:bar3DChart>'
125
130
  str_inner << '<c:barDir val="' << bar_dir.to_s << '"/>'
126
131
  str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
127
- str_inner << '<c:varyColors val="1"/>'
132
+ str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
128
133
  @series.each { |ser| ser.to_xml_string(str_inner) }
129
- @d_lbls.to_xml_string(str) if @d_lbls
134
+ @d_lbls.to_xml_string(str_inner) if @d_lbls
130
135
  str_inner << '<c:gapWidth val="' << @gap_width.to_s << '"/>' unless @gap_width.nil?
131
136
  str_inner << '<c:gapDepth val="' << @gap_depth.to_s << '"/>' unless @gap_depth.nil?
132
137
  str_inner << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
133
- str_inner << '<c:axId val="' << @cat_ax_id.to_s << '"/>'
134
- str_inner << '<c:axId val="' << @val_ax_id.to_s << '"/>'
135
- str_inner << '<c:axId val="0"/>'
138
+ axes.to_xml_string(str_inner, :ids => true)
136
139
  str_inner << '</c:bar3DChart>'
137
- @cat_axis.to_xml_string str_inner
138
- @val_axis.to_xml_string str_inner
140
+ axes.to_xml_string(str_inner)
139
141
  end
140
142
  end
143
+
144
+ # A hash of axes used by this chart. Bar charts have a value and
145
+ # category axes specified via axes[:val_axes] and axes[:cat_axis]
146
+ # @return [Axes]
147
+ def axes
148
+ @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
149
+ end
141
150
  end
142
151
  end
@@ -4,23 +4,15 @@ module Axlsx
4
4
  class CatAxis < Axis
5
5
 
6
6
  # Creates a new CatAxis object
7
- # @param [Integer] ax_id the id of this axis. Inherited
8
- # @param [Integer] cross_ax the id of the perpendicular axis. Inherited
9
- # @option options [Symbol] ax_pos. Inherited
10
- # @option options [Symbol] tick_lbl_pos. Inherited
11
- # @option options [Symbol] crosses. Inherited
12
- # @option options [Boolean] auto
13
- # @option options [Symbol] lbl_algn
14
- # @option options [Integer] lbl_offset
15
7
  # @option options [Integer] tick_lbl_skip
16
8
  # @option options [Integer] tick_mark_skip
17
- def initialize(ax_id, cross_ax, options={})
9
+ def initialize(options={})
18
10
  @tick_lbl_skip = 1
19
11
  @tick_mark_skip = 1
20
12
  self.auto = 1
21
13
  self.lbl_algn = :ctr
22
14
  self.lbl_offset = "100"
23
- super(ax_id, cross_ax, options)
15
+ super(options)
24
16
  end
25
17
 
26
18
  # 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.
@@ -6,6 +6,7 @@ module Axlsx
6
6
  # @see README for examples
7
7
  class Chart
8
8
 
9
+ include Axlsx::OptionsParser
9
10
  # Creates a new chart object
10
11
  # @param [GraphicalFrame] frame The frame that holds this chart.
11
12
  # @option options [Cell, String] title
@@ -13,17 +14,16 @@ module Axlsx
13
14
  # @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart.
14
15
  # @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.
15
16
  def initialize(frame, options={})
16
- @style = 18
17
+ @style = 18
17
18
  @view_3D = nil
18
19
  @graphic_frame=frame
19
20
  @graphic_frame.anchor.drawing.worksheet.workbook.charts << self
20
21
  @series = SimpleTypedList.new Series
21
22
  @show_legend = true
23
+ @display_blanks_as = :gap
22
24
  @series_type = Series
23
25
  @title = Title.new
24
- options.each do |o|
25
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
26
- end
26
+ parse_options options
27
27
  start_at(*options[:start_at]) if options[:start_at]
28
28
  end_at(*options[:end_at]) if options[:end_at]
29
29
  yield self if block_given?
@@ -50,6 +50,13 @@ module Axlsx
50
50
  @d_lbls ||= DLbls.new(self.class)
51
51
  end
52
52
 
53
+ # Indicates that colors should be varied by datum
54
+ # @return [Boolean]
55
+ attr_reader :vary_colors
56
+
57
+ # Configures the vary_colors options for this chart
58
+ # @param [Boolean] v The value to set
59
+ def vary_colors=(v) Axlsx::validate_boolean(v); @vary_colors = v; end
53
60
 
54
61
  # The title object for the chart.
55
62
  # @return [Title]
@@ -64,6 +71,21 @@ module Axlsx
64
71
  # @return [Boolean]
65
72
  attr_reader :show_legend
66
73
 
74
+ # How to display blank values
75
+ # Options are
76
+ # * gap: Display nothing
77
+ # * span: Not sure what this does
78
+ # * zero: Display as if the value were zero, not blank
79
+ # @return [Symbol]
80
+ # Default :gap (although this really should vary by chart type and grouping)
81
+ attr_reader :display_blanks_as
82
+
83
+ # The relationship object for this chart.
84
+ # @return [Relationship]
85
+ def relationship
86
+ Relationship.new(self, CHART_R, "../#{pn}")
87
+ end
88
+
67
89
  # The index of this chart in the workbooks charts collection
68
90
  # @return [Integer]
69
91
  def index
@@ -93,6 +115,12 @@ module Axlsx
93
115
  # @return [Boolean]
94
116
  def show_legend=(v) Axlsx::validate_boolean(v); @show_legend = v; end
95
117
 
118
+ # How to display blank values
119
+ # @see display_blanks_as
120
+ # @param [Symbol] v
121
+ # @return [Symbol]
122
+ def display_blanks_as=(v) Axlsx::validate_display_blanks_as(v); @display_blanks_as = v; end
123
+
96
124
  # The style for the chart.
97
125
  # see ECMA Part 1 §21.2.2.196
98
126
  # @param [Integer] v must be between 1 and 48
@@ -128,7 +156,6 @@ module Axlsx
128
156
  str << '<c:style val="' << style.to_s << '"/>'
129
157
  str << '<c:chart>'
130
158
  @title.to_xml_string str
131
- # do these need the c: namespace as well???
132
159
  str << '<c:autoTitleDeleted val="' << (@title == nil).to_s << '"/>'
133
160
  @view_3D.to_xml_string(str) if @view_3D
134
161
  str << '<c:floor><c:thickness val="0"/></c:floor>'
@@ -146,7 +173,7 @@ module Axlsx
146
173
  str << '</c:legend>'
147
174
  end
148
175
  str << '<c:plotVisOnly val="1"/>'
149
- str << '<c:dispBlanksAs val="zero"/>'
176
+ str << '<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>'
150
177
  str << '<c:showDLblsOverMax val="1"/>'
151
178
  str << '</c:chart>'
152
179
  str << '<c:printSettings>'
@@ -2,33 +2,40 @@ module Axlsx
2
2
  # There are more elements in the dLbls spec that allow for
3
3
  # customizations and formatting. For now, I am just implementing the
4
4
  # basics.
5
-
6
5
  #The DLbls class manages serialization of data labels
7
6
  # showLeaderLines and leaderLines are not currently implemented
8
7
  class DLbls
9
8
 
9
+ include Axlsx::Accessors
10
+ include Axlsx::OptionsParser
11
+ # creates a new DLbls object
12
+ def initialize(chart_type, options={})
13
+ raise ArgumentError, 'chart_type must inherit from Chart' unless [Chart, LineChart].include?(chart_type.superclass)
14
+ @chart_type = chart_type
15
+ initialize_defaults
16
+ parse_options options
17
+ end
18
+
10
19
  # These attributes are all boolean so I'm doing a bit of a hand
11
20
  # waving magic show to set up the attriubte accessors
12
21
  # @note
13
22
  # not all charts support all methods!
14
23
  # Bar3DChart and Line3DChart and ScatterChart do not support d_lbl_pos or show_leader_lines
15
24
  #
16
- BOOLEAN_ATTRIBUTES = [:show_legend_key, :show_val, :show_cat_name, :show_ser_name, :show_percent, :show_bubble_size, :show_leader_lines]
17
-
18
- # creates a new DLbls object
19
- def initialize(chart_type, options={})
20
- raise ArgumentError, 'chart_type must inherit from Chart' unless chart_type.superclass == Chart
21
- @chart_type = chart_type
22
- initialize_defaults
23
- options.each do |o|
24
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
25
- end
26
- end
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,
31
+ :show_leader_lines
27
32
 
28
33
  # Initialize all the values to false as Excel requires them to
29
34
  # explicitly be disabled or all will show.
30
35
  def initialize_defaults
31
- BOOLEAN_ATTRIBUTES.each do |attr|
36
+ [:show_legend_key, :show_val, :show_cat_name,
37
+ :show_ser_name, :show_percent, :show_bubble_size,
38
+ :show_leader_lines].each do |attr|
32
39
  self.send("#{attr}=", false)
33
40
  end
34
41
  end
@@ -58,24 +65,7 @@ module Axlsx
58
65
  @d_lbl_pos = label_position
59
66
  end
60
67
 
61
- # Dynamically create accessors for boolean attriubtes
62
- BOOLEAN_ATTRIBUTES.each do |attr|
63
- class_eval %{
64
- # The #{attr} attribute reader
65
- # @return [Boolean]
66
- attr_reader :#{attr}
67
-
68
- # The #{attr} writer
69
- # @param [Boolean] value The value to assign to #{attr}
70
- # @return [Boolean]
71
- def #{attr}=(value)
72
- Axlsx::validate_boolean(value)
73
- @#{attr} = value
74
- end
75
- }
76
- end
77
-
78
-
68
+
79
69
  # serializes the data labels
80
70
  # @return [String]
81
71
  def to_xml_string(str = '')
@@ -22,6 +22,7 @@ module Axlsx
22
22
  require 'axlsx/drawing/ser_axis.rb'
23
23
  require 'axlsx/drawing/cat_axis.rb'
24
24
  require 'axlsx/drawing/val_axis.rb'
25
+ require 'axlsx/drawing/axes.rb'
25
26
 
26
27
  require 'axlsx/drawing/marker.rb'
27
28
 
@@ -33,6 +34,7 @@ module Axlsx
33
34
  require 'axlsx/drawing/chart.rb'
34
35
  require 'axlsx/drawing/pie_3D_chart.rb'
35
36
  require 'axlsx/drawing/bar_3D_chart.rb'
37
+ require 'axlsx/drawing/line_chart.rb'
36
38
  require 'axlsx/drawing/line_3D_chart.rb'
37
39
  require 'axlsx/drawing/scatter_chart.rb'
38
40
 
@@ -80,7 +82,7 @@ module Axlsx
80
82
  TwoCellAnchor.new(self, options).add_pic(options)
81
83
  else
82
84
  OneCellAnchor.new(self, options)
83
- end
85
+ end
84
86
  @anchors.last.object
85
87
  end
86
88
 
@@ -119,12 +121,6 @@ module Axlsx
119
121
  @worksheet.workbook.drawings.index(self)
120
122
  end
121
123
 
122
- # The relation reference id for this drawing
123
- # @return [String]
124
- def rId
125
- "rId#{index+1}"
126
- end
127
-
128
124
  # The part name for this drawing
129
125
  # @return [String]
130
126
  def pn
@@ -132,24 +128,23 @@ module Axlsx
132
128
  end
133
129
 
134
130
  # The relational part name for this drawing
131
+ # #NOTE This should be rewritten to return an Axlsx::Relationship object.
135
132
  # @return [String]
136
133
  def rels_pn
137
134
  "#{DRAWING_RELS_PN % (index+1)}"
138
135
  end
139
136
 
137
+ # A list of objects this drawing holds.
138
+ # @return [Array]
139
+ def child_objects
140
+ charts + images + hyperlinks
141
+ end
142
+
140
143
  # The drawing's relationships.
141
144
  # @return [Relationships]
142
145
  def relationships
143
146
  r = Relationships.new
144
- charts.each do |chart|
145
- r << Relationship.new(CHART_R, "../#{chart.pn}")
146
- end
147
- images.each do |image|
148
- r << Relationship.new(IMAGE_R, "../#{image.pn}")
149
- end
150
- hyperlinks.each do |hyperlink|
151
- r << Relationship.new(HYPERLINK_R, hyperlink.href, :target_mode => :External)
152
- end
147
+ child_objects.each { |child| r << child.relationship }
153
148
  r
154
149
  end
155
150
 
@@ -159,7 +154,6 @@ module Axlsx
159
154
  def to_xml_string(str = '')
160
155
  str << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
161
156
  str << '<xdr:wsDr xmlns:xdr="' << XML_NS_XDR << '" xmlns:a="' << XML_NS_A << '">'
162
-
163
157
  anchors.each { |anchor| anchor.to_xml_string(str) }
164
158
  str << '</xdr:wsDr>'
165
159
  end
@@ -22,10 +22,10 @@ module Axlsx
22
22
  @chart = chart_type.new(self, options)
23
23
  end
24
24
 
25
- # The relationship id for this graphic
25
+ # The relationship id for this graphic frame.
26
26
  # @return [String]
27
27
  def rId
28
- "rId#{@anchor.index+1}"
28
+ @anchor.drawing.relationships.for(chart).Id
29
29
  end
30
30
 
31
31
  # Serializes the object
@@ -44,7 +44,7 @@ module Axlsx
44
44
  str << '</xdr:xfrm>'
45
45
  str << '<a:graphic>'
46
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.to_s << '"/>'
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>'
@@ -5,6 +5,29 @@ module Axlsx
5
5
  # @see {file:README} README
6
6
  class Hyperlink
7
7
 
8
+ include Axlsx::SerializedAttributes
9
+ include Axlsx::OptionsParser
10
+
11
+ #Creates a hyperlink object
12
+ # parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent
13
+ # @param [Pic] parent
14
+ # @option options [String] tooltip message shown when hyperlinked object is hovered over with mouse.
15
+ # @option options [String] tgtFrame Target frame for opening hyperlink
16
+ # @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource.
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
19
+ # @option options [Boolean] endSnd terminate any sound events when processing this link
20
+ # @option options [Boolean] history include this link in the list of visited links for the applications history.
21
+ # @option options [Boolean] highlightClick indicate that the link has already been visited.
22
+ def initialize(parent, options={})
23
+ DataTypeValidator.validate "Hyperlink.parent", [Pic], parent
24
+ @parent = parent
25
+ parse_options options
26
+ yield self if block_given?
27
+ end
28
+
29
+ serializable_attributes :invalid_url, :action, :end_snd, :highlight_click, :history, :tgt_frame, :tooltip
30
+
8
31
  # The destination of the hyperlink stored in the drawing's relationships document.
9
32
  # @return [String]
10
33
  attr_accessor :href
@@ -13,7 +36,9 @@ module Axlsx
13
36
  #
14
37
  # What exactly that means is beyond me so if you ever use this, let me know!
15
38
  # @return [String]
16
- attr_accessor :invalidUrl
39
+ attr_accessor :invalid_url
40
+ alias :invalidUrl :invalid_url
41
+ alias :invalidUrl= :invalid_url=
17
42
 
18
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
19
44
  # @return [String]
@@ -21,20 +46,24 @@ module Axlsx
21
46
 
22
47
  # Specifies if all sound events should be terminated when this link is clicked.
23
48
  # @return [Boolean]
24
- attr_reader :endSnd
49
+ attr_reader :end_snd
50
+ alias :endSnd :end_snd
25
51
 
26
52
  # @see endSnd
27
53
  # @param [Boolean] v The boolean value indicating the termination of playing sounds on click
28
54
  # @return [Boolean]
29
- def endSnd=(v) Axlsx::validate_boolean(v); @endSnd = v end
55
+ def end_snd=(v) Axlsx::validate_boolean(v); @end_snd = v end
56
+ alias :endSnd= :end_snd=
30
57
 
31
58
  # indicates that the link has already been clicked.
32
59
  # @return [Boolean]
33
- attr_reader :highlightClick
60
+ attr_reader :highlight_click
61
+ alias :highlightClick :highlight_click
34
62
 
35
63
  # @see highlightClick
36
64
  # @param [Boolean] v The value to assign
37
- def highlightClick=(v) Axlsx::validate_boolean(v); @highlightClick = v end
65
+ def highlight_click=(v) Axlsx::validate_boolean(v); @highlight_click = v end
66
+ alias :highlightClick= :highlight_click=
38
67
 
39
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.
40
69
  # @return [Boolean]
@@ -46,51 +75,28 @@ module Axlsx
46
75
 
47
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.
48
77
  # @return [String]
49
- attr_accessor :tgtFrame
78
+ attr_accessor :tgt_frame
79
+ alias :tgtFrame :tgt_frame
80
+ alias :tgtFrame= :tgt_frame=
50
81
 
51
82
  # Text to show when you mouse over the hyperlink. If you do not set this, the href property will be shown.
52
83
  # @return [String]
53
84
  attr_accessor :tooltip
54
85
 
55
- #Creates a hyperlink object
56
- # parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent
57
- # @param [Pic] parent
58
- # @option options [String] tooltip message shown when hyperlinked object is hovered over with mouse.
59
- # @option options [String] tgtFrame Target frame for opening hyperlink
60
- # @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource.
61
- # @option options [String] href the target resource this hyperlink links to.
62
- # @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
63
- # @option options [Boolean] endSnd terminate any sound events when processing this link
64
- # @option options [Boolean] history include this link in the list of visited links for the applications history.
65
- # @option options [Boolean] highlightClick indicate that the link has already been visited.
66
- def initialize(parent, options={})
67
- DataTypeValidator.validate "Hyperlink.parent", [Pic], parent
68
- @parent = parent
69
- options.each do |o|
70
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
71
- end
72
- yield self if block_given?
73
-
86
+ # The relationship object for this hyperlink.
87
+ # @return [Relationship]
88
+ def relationship
89
+ Relationship.new(self, HYPERLINK_R, href, :target_mode => :External)
74
90
  end
75
91
 
76
92
  # Serializes the object
77
93
  # @param [String] str
78
94
  # @return [String]
79
95
  def to_xml_string(str = '')
80
- h = self.instance_values.merge({:'r:id' => "rId#{id}", :'xmlns:r' => XML_NS_R })
81
- h.delete('href')
82
- h.delete('parent')
83
96
  str << '<a:hlinkClick '
84
- str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
97
+ serialized_attributes str, {:'r:id' => relationship.Id, :'xmlns:r' => XML_NS_R }
85
98
  str << '/>'
86
99
  end
87
100
 
88
- private
89
- # The relational ID for this hyperlink
90
- # @return [Integer]
91
- def id
92
- @parent.anchor.drawing.charts.size + @parent.anchor.drawing.images.size + @parent.anchor.drawing.hyperlinks.index(self) + 1
93
- end
94
-
95
101
  end
96
102
  end
@@ -9,9 +9,9 @@ module Axlsx
9
9
  #
10
10
  # p = Axlsx::Package.new
11
11
  # ws = p.workbook.add_worksheet
12
- # ws.add_row :values => ["This is a chart with no data in the sheet"]
12
+ # ws.add_row ["This is a chart with no data in the sheet"]
13
13
  #
14
- # chart = ws.add_chart(Axlsx::Line3DChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
14
+ # chart = ws.add_chart(Axlsx::Line3DChart, :start_at=> [0,1], :end_at=>[0,6], :t#itle=>"Most Popular Pets")
15
15
  # chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]
16
16
  #
17
17
  # @see Worksheet#add_chart
@@ -19,92 +19,50 @@ module Axlsx
19
19
  # @see Chart#add_series
20
20
  # @see Series
21
21
  # @see Package#serialize
22
- class Line3DChart < Chart
23
-
24
- # the category axis
25
- # @return [CatAxis]
26
- attr_reader :catAxis
27
-
28
- # the category axis
29
- # @return [ValAxis]
30
- attr_reader :valAxis
31
-
32
- # the category axis
33
- # @return [Axis]
34
- attr_reader :serAxis
22
+ class Line3DChart < Axlsx::LineChart
35
23
 
36
24
  # space between bar or column clusters, as a percentage of the bar or column width.
37
25
  # @return [String]
38
- attr_reader :gapDepth
39
-
40
- #grouping for a column, line, or area chart.
41
- # must be one of [:percentStacked, :clustered, :standard, :stacked]
42
- # @return [Symbol]
43
- attr_reader :grouping
26
+ attr_reader :gap_depth
27
+ alias :gapDepth :gap_depth
44
28
 
45
29
  # validation regex for gap amount percent
46
30
  GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
47
31
 
32
+ # the category axis
33
+ # @return [Axis]
34
+ def ser_axis
35
+ axes[:ser_axis]
36
+ end
37
+ alias :serAxis :ser_axis
38
+
48
39
  # Creates a new line chart object
49
- # @param [GraphicFrame] frame The workbook that owns this chart.
50
- # @option options [Cell, String] title
51
- # @option options [Boolean] show_legend
52
- # @option options [Symbol] grouping
53
- # @option options [String] gapDepth
54
- # @option options [Integer] rotX
55
- # @option options [String] hPercent
56
- # @option options [Integer] rotY
57
- # @option options [String] depthPercent
58
- # @option options [Boolean] rAngAx
59
- # @option options [Integer] perspective
40
+ # @option options [String] gap_depth
60
41
  # @see Chart
42
+ # @see lineChart
61
43
  # @see View3D
62
44
  def initialize(frame, options={})
63
- @gapDepth = nil
64
- @grouping = :standard
65
- @catAxId = rand(8 ** 8)
66
- @valAxId = rand(8 ** 8)
67
- @serAxId = rand(8 ** 8)
68
- @catAxis = CatAxis.new(@catAxId, @valAxId)
69
- @valAxis = ValAxis.new(@valAxId, @catAxId)
70
- @serAxis = SerAxis.new(@serAxId, @valAxId)
45
+ @gap_depth = nil
46
+ @view_3D = View3D.new({:r_ang_ax=>1}.merge(options))
71
47
  super(frame, options)
72
- @series_type = LineSeries
73
- @view_3D = View3D.new({:perspective=>30}.merge(options))
74
- @d_lbls = nil
48
+ axes.add_axis :ser_axis, SerAxis
75
49
  end
76
50
 
77
- # @see grouping
78
- def grouping=(v)
79
- RestrictionValidator.validate "Bar3DChart.grouping", [:percentStacked, :standard, :stacked], v
80
- @grouping = v
81
- end
82
51
 
83
52
  # @see gapDepth
84
- def gapDepth=(v)
85
- RegexValidator.validate "Bar3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
86
- @gapDepth=(v)
53
+ def gap_depth=(v)
54
+ RegexValidator.validate "Line3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
55
+ @gap_depth=(v)
87
56
  end
57
+ alias :gapDepth= :gap_depth=
88
58
 
89
- # Serializes the object
90
- # @param [String] str
91
- # @return [String]
92
- def to_xml_string(str = '')
93
- super(str) do |str_inner|
94
- str_inner << '<c:line3DChart>'
95
- str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
96
- str_inner << '<c:varyColors val="1"/>'
97
- @series.each { |ser| ser.to_xml_string(str_inner) }
98
- @d_lbls.to_xml_string(str) if @d_lbls
99
- str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
100
- str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
101
- str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
102
- str_inner << '<c:axId val="' << @serAxId.to_s << '"/>'
103
- str_inner << '</c:line3DChart>'
104
- @catAxis.to_xml_string str_inner
105
- @valAxis.to_xml_string str_inner
106
- @serAxis.to_xml_string str_inner
59
+ # Serializes the object
60
+ # @param [String] str
61
+ # @return [String]
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?
65
+ end
107
66
  end
108
- end
109
67
  end
110
68
  end