axlsx 1.1.7 → 1.2.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.
- data/.yardopts +5 -2
- data/CHANGELOG.md +39 -0
- data/README.md +84 -46
- data/Rakefile +3 -2
- data/examples/basic_charts.rb +8 -0
- data/examples/chart_colors.rb +18 -3
- data/examples/example.rb +106 -46
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/extractive.pdf +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/scraping_html.rb +91 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/lib/axlsx/content_type/content_type.rb +2 -0
- data/lib/axlsx/content_type/default.rb +21 -12
- data/lib/axlsx/content_type/override.rb +22 -11
- data/lib/axlsx/doc_props/app.rb +36 -32
- data/lib/axlsx/doc_props/core.rb +9 -5
- data/lib/axlsx/drawing/ax_data_source.rb +7 -6
- data/lib/axlsx/drawing/axis.rb +48 -27
- data/lib/axlsx/drawing/bar_3D_chart.rb +49 -45
- data/lib/axlsx/drawing/bar_series.rb +1 -0
- data/lib/axlsx/drawing/cat_axis.rb +42 -38
- data/lib/axlsx/drawing/chart.rb +63 -52
- data/lib/axlsx/drawing/d_lbls.rb +100 -0
- data/lib/axlsx/drawing/drawing.rb +7 -4
- data/lib/axlsx/drawing/line_3D_chart.rb +3 -10
- data/lib/axlsx/drawing/num_data_source.rb +1 -1
- data/lib/axlsx/drawing/pie_3D_chart.rb +10 -7
- data/lib/axlsx/drawing/scatter_chart.rb +2 -8
- data/lib/axlsx/drawing/two_cell_anchor.rb +41 -9
- data/lib/axlsx/drawing/view_3D.rb +41 -31
- data/lib/axlsx/drawing/vml_drawing.rb +1 -1
- data/lib/axlsx/package.rb +11 -11
- data/lib/axlsx/rels/relationship.rb +3 -3
- data/lib/axlsx/stylesheet/styles.rb +1 -1
- data/lib/axlsx/util/constants.rb +4 -0
- data/lib/axlsx/util/simple_typed_list.rb +15 -8
- data/lib/axlsx/util/validators.rb +2 -2
- data/lib/axlsx/version.rb +2 -7
- data/lib/axlsx/workbook/defined_name.rb +174 -0
- data/lib/axlsx/workbook/defined_names.rb +21 -0
- data/lib/axlsx/workbook/workbook.rb +39 -14
- data/lib/axlsx/workbook/worksheet/auto_filter.rb +34 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +25 -2
- data/lib/axlsx/workbook/worksheet/col.rb +15 -0
- data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
- data/lib/axlsx/workbook/worksheet/comments.rb +8 -0
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
- data/lib/axlsx/workbook/worksheet/data_bar.rb +1 -1
- data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
- data/lib/axlsx/workbook/worksheet/dimension.rb +65 -0
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +35 -0
- data/lib/axlsx/workbook/worksheet/page_setup.rb +9 -0
- data/lib/axlsx/workbook/worksheet/protected_range.rb +46 -0
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
- data/lib/axlsx/workbook/worksheet/row.rb +1 -1
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +25 -0
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +24 -0
- data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +300 -293
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +57 -0
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +64 -0
- data/lib/axlsx.rb +21 -14
- data/test/content_type/tc_content_type.rb +1 -6
- data/test/doc_props/tc_core.rb +1 -1
- data/test/drawing/tc_axis.rb +8 -0
- data/test/drawing/tc_bar_3D_chart.rb +12 -12
- data/test/drawing/tc_bar_series.rb +1 -2
- data/test/drawing/tc_chart.rb +8 -6
- data/test/drawing/tc_d_lbls.rb +47 -0
- data/test/drawing/tc_drawing.rb +5 -4
- data/test/drawing/tc_line_series.rb +1 -1
- data/test/drawing/tc_pie_3D_chart.rb +4 -8
- data/test/drawing/tc_pie_series.rb +1 -1
- data/test/drawing/tc_scatter_series.rb +1 -1
- data/test/drawing/tc_series.rb +1 -1
- data/test/drawing/tc_view_3D.rb +18 -18
- data/test/tc_package.rb +18 -1
- data/test/workbook/tc_defined_name.rb +41 -0
- data/test/workbook/tc_workbook.rb +5 -3
- data/test/workbook/worksheet/table/tc_table.rb +0 -8
- data/test/workbook/worksheet/tc_cell.rb +2 -4
- data/test/workbook/worksheet/tc_page_setup.rb +20 -3
- data/test/workbook/worksheet/tc_protected_range.rb +17 -0
- data/test/workbook/worksheet/tc_row.rb +2 -2
- data/test/workbook/worksheet/tc_selection.rb +1 -1
- data/test/workbook/worksheet/tc_worksheet.rb +53 -34
- metadata +93 -101
- data/examples/axis-titles.xlsx +0 -0
- data/examples/basic_charts.xlsx +0 -0
- data/examples/chart_colors.xlsx +0 -0
- data/examples/charts.xlsx +0 -0
- data/examples/conditional_formatting/getting_barred.xlsx +0 -0
- data/examples/doc/_index.html +0 -84
- data/examples/doc/class_list.html +0 -47
- data/examples/doc/css/common.css +0 -1
- data/examples/doc/css/full_list.css +0 -55
- data/examples/doc/css/style.css +0 -322
- data/examples/doc/file_list.html +0 -46
- data/examples/doc/frames.html +0 -13
- data/examples/doc/index.html +0 -84
- data/examples/doc/js/app.js +0 -205
- data/examples/doc/js/full_list.js +0 -173
- data/examples/doc/js/jquery.js +0 -16
- data/examples/doc/method_list.html +0 -46
- data/examples/doc/top-level-namespace.html +0 -95
- data/examples/examples_saved.xlsx +0 -0
- data/examples/extractive.xlsx +0 -0
- data/examples/fish.xlsx +0 -0
- data/examples/pareto.rb +0 -28
- data/examples/pareto.xlsx +0 -0
- data/examples/pie_chart_excel.xlsx +0 -0
- data/examples/pie_chart_saved.xlsx +0 -0
- data/examples/sheet_protection.xlsx +0 -0
- data/examples/sheet_view.xlsx +0 -0
- data/examples/two_cell_anchor_image.xlsx +0 -0
- data/examples/~$example.xlsx +0 -0
- data/lib/axlsx/drawing/ax_data_source.rb~ +0 -55
- data/lib/axlsx/drawing/data_source.rb~ +0 -51
- data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
- data/lib/axlsx/drawing/hyperlink.rb~ +0 -64
- data/lib/axlsx/drawing/num_data.rb~ +0 -51
- data/lib/axlsx/drawing/num_data_source.rb~ +0 -54
- data/lib/axlsx/drawing/num_val.rb~ +0 -40
- data/lib/axlsx/drawing/picture_locking.rb~ +0 -36
- data/lib/axlsx/drawing/ref.rb~ +0 -41
- data/lib/axlsx/drawing/str_data.rb~ +0 -58
- data/lib/axlsx/drawing/str_val.rb~ +0 -35
- data/lib/axlsx/drawing/vml_drawing.rb~ +0 -6
- data/lib/axlsx/drawing/vml_shape.rb~ +0 -61
- data/lib/axlsx/util/cbf.rb +0 -333
- data/lib/axlsx/util/cfb.rb~ +0 -201
- data/lib/axlsx/util/font_tables.rb~ +0 -0
- data/lib/axlsx/util/ms_off_crypto.rb +0 -189
- data/lib/axlsx/util/ms_off_crypto.rb~ +0 -3
- data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
- data/lib/axlsx/util/parser.rb~ +0 -6
- data/lib/axlsx/util/storage.rb~ +0 -0
- data/lib/axlsx/workbook/shared_strings_table.rb~ +0 -69
- data/lib/axlsx/workbook/worksheet/cfvo.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/color_scale.rb~ +0 -46
- data/lib/axlsx/workbook/worksheet/comment.rb~ +0 -91
- data/lib/axlsx/workbook/worksheet/comments.rb~ +0 -86
- data/lib/axlsx/workbook/worksheet/data_bar.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/icon_set.rb~ +0 -95
- data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/table.rb~ +0 -97
- data/lib/schema/dc.xsd~ +0 -118
- data/lib/schema/dcterms.xsd~ +0 -331
- data/lib/schema/opc-coreProperties.xsd~ +0 -50
- data/test/drawing/tc_data_source.rb~ +0 -30
- data/test/drawing/tc_num_data.rb~ +0 -35
- data/test/drawing/tc_num_val.rb~ +0 -29
- data/test/drawing/tc_str_data.rb~ +0 -30
- data/test/drawing/tc_str_val.rb~ +0 -26
- data/test/drawing/tc_vml_drawing.rb~ +0 -0
- data/test/workbook/worksheet/table/tc_table.rb~ +0 -72
- data/test/workbook/worksheet/tc_cfvo.rb~ +0 -20
- data/test/workbook/worksheet/tc_col.rb~ +0 -10
- data/test/workbook/worksheet/tc_color_scale.rb~ +0 -0
- data/test/workbook/worksheet/tc_data_bar.rb~ +0 -0
- data/test/workbook/worksheet/tc_icon_set.rb~ +0 -0
|
@@ -3,6 +3,26 @@ module Axlsx
|
|
|
3
3
|
#A CatAxis object defines a chart category axis
|
|
4
4
|
class CatAxis < Axis
|
|
5
5
|
|
|
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
|
+
# @option options [Integer] tick_lbl_skip
|
|
16
|
+
# @option options [Integer] tick_mark_skip
|
|
17
|
+
def initialize(ax_id, cross_ax, options={})
|
|
18
|
+
@tick_lbl_skip = 1
|
|
19
|
+
@tick_mark_skip = 1
|
|
20
|
+
self.auto = 1
|
|
21
|
+
self.lbl_algn = :ctr
|
|
22
|
+
self.lbl_offset = "100"
|
|
23
|
+
super(ax_id, cross_ax, options)
|
|
24
|
+
end
|
|
25
|
+
|
|
6
26
|
# 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.
|
|
7
27
|
# @return [Boolean]
|
|
8
28
|
attr_reader :auto
|
|
@@ -10,64 +30,48 @@ module Axlsx
|
|
|
10
30
|
# specifies how the perpendicular axis is crossed
|
|
11
31
|
# must be one of [:ctr, :l, :r]
|
|
12
32
|
# @return [Symbol]
|
|
13
|
-
attr_reader :
|
|
33
|
+
attr_reader :lbl_algn
|
|
34
|
+
alias :lblAlgn :lbl_algn
|
|
14
35
|
|
|
15
36
|
# The offset of the labels
|
|
16
37
|
# must be between a string between 0 and 1000
|
|
17
38
|
# @return [Integer]
|
|
18
|
-
attr_reader :
|
|
19
|
-
|
|
39
|
+
attr_reader :lbl_offset
|
|
40
|
+
alias :lblOffset :lbl_offset
|
|
20
41
|
|
|
21
42
|
# The number of tick lables to skip between labels
|
|
22
43
|
# @return [Integer]
|
|
23
|
-
attr_reader :
|
|
44
|
+
attr_reader :tick_lbl_skip
|
|
45
|
+
alias :tickLblSkip :tick_lbl_skip
|
|
24
46
|
|
|
25
47
|
# The number of tickmarks to be skipped before the next one is rendered.
|
|
26
48
|
# @return [Boolean]
|
|
27
|
-
attr_reader :
|
|
28
|
-
|
|
49
|
+
attr_reader :tick_mark_skip
|
|
50
|
+
alias :tickMarkSkip :tick_mark_skip
|
|
29
51
|
|
|
30
52
|
# regex for validating label offset
|
|
31
53
|
LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)/
|
|
32
54
|
|
|
33
|
-
#
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
# @option options [Symbol] axPos. Inherited
|
|
37
|
-
# @option options [Symbol] tickLblPos. Inherited
|
|
38
|
-
# @option options [Symbol] crosses. Inherited
|
|
39
|
-
# @option options [Boolean] auto
|
|
40
|
-
# @option options [Symbol] lblAlgn
|
|
41
|
-
# @option options [Integer] lblOffset
|
|
42
|
-
# @option options [Integer] tickLblSkip
|
|
43
|
-
# @option options [Integer] tickMarkSkip
|
|
44
|
-
def initialize(axId, crossAx, options={})
|
|
45
|
-
@tickLblSkip = 1
|
|
46
|
-
@tickMarkSkip = 1
|
|
47
|
-
self.auto = 1
|
|
48
|
-
self.lblAlgn = :ctr
|
|
49
|
-
self.lblOffset = "100"
|
|
50
|
-
super(axId, crossAx, options)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
# @see tickLblSkip
|
|
55
|
-
def tickLblSkip=(v) Axlsx::validate_unsigned_int(v); @tickLblSkip = v; end
|
|
56
|
-
|
|
57
|
-
# @see tickMarkSkip
|
|
58
|
-
def tickMarkSkip=(v) Axlsx::validate_unsigned_int(v); @tickMarkSkip = v; end
|
|
55
|
+
# @see tick_lbl_skip
|
|
56
|
+
def tick_lbl_skip=(v) Axlsx::validate_unsigned_int(v); @tick_lbl_skip = v; end
|
|
57
|
+
alias :tickLblSkip= :tick_lbl_skip=
|
|
59
58
|
|
|
59
|
+
# @see tick_mark_skip
|
|
60
|
+
def tick_mark_skip=(v) Axlsx::validate_unsigned_int(v); @tick_mark_skip = v; end
|
|
61
|
+
alias :tickMarkSkip= :tick_mark_skip=
|
|
60
62
|
|
|
61
63
|
# 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.
|
|
62
64
|
def auto=(v) Axlsx::validate_boolean(v); @auto = v; end
|
|
63
65
|
|
|
64
66
|
# specifies how the perpendicular axis is crossed
|
|
65
67
|
# must be one of [:ctr, :l, :r]
|
|
66
|
-
def
|
|
68
|
+
def lbl_algn=(v) RestrictionValidator.validate "#{self.class}.lbl_algn", [:ctr, :l, :r], v; @lbl_algn = v; end
|
|
69
|
+
alias :lblAlgn= :lbl_algn=
|
|
67
70
|
|
|
68
71
|
# The offset of the labels
|
|
69
72
|
# must be between a string between 0 and 1000
|
|
70
|
-
def
|
|
73
|
+
def lbl_offset=(v) RegexValidator.validate "#{self.class}.lbl_offset", LBL_OFFSET_REGEX, v; @lbl_offset = v; end
|
|
74
|
+
alias :lblOffset= :lbl_offset=
|
|
71
75
|
|
|
72
76
|
# Serializes the object
|
|
73
77
|
# @param [String] str
|
|
@@ -76,10 +80,10 @@ module Axlsx
|
|
|
76
80
|
str << '<c:catAx>'
|
|
77
81
|
super(str)
|
|
78
82
|
str << '<c:auto val="' << @auto.to_s << '"/>'
|
|
79
|
-
str << '<c:lblAlgn val="' << @
|
|
80
|
-
str << '<c:lblOffset val="' << @
|
|
81
|
-
str << '<c:tickLblSkip val="' << @
|
|
82
|
-
str << '<c:tickMarkSkip val="' << @
|
|
83
|
+
str << '<c:lblAlgn val="' << @lbl_algn.to_s << '"/>'
|
|
84
|
+
str << '<c:lblOffset val="' << @lbl_offset.to_i.to_s << '"/>'
|
|
85
|
+
str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>'
|
|
86
|
+
str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>'
|
|
83
87
|
str << '</c:catAx>'
|
|
84
88
|
end
|
|
85
89
|
|
data/lib/axlsx/drawing/chart.rb
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
2
|
module Axlsx
|
|
3
|
+
|
|
3
4
|
# A Chart is the superclass for specific charts
|
|
4
5
|
# @note Worksheet#add_chart is the recommended way to create charts for your worksheets.
|
|
5
6
|
# @see README for examples
|
|
6
7
|
class Chart
|
|
7
8
|
|
|
9
|
+
# Creates a new chart object
|
|
10
|
+
# @param [GraphicalFrame] frame The frame that holds this chart.
|
|
11
|
+
# @option options [Cell, String] title
|
|
12
|
+
# @option options [Boolean] show_legend
|
|
13
|
+
# @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart.
|
|
14
|
+
# @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.
|
|
15
|
+
def initialize(frame, options={})
|
|
16
|
+
@style = 18
|
|
17
|
+
@view_3D = nil
|
|
18
|
+
@graphic_frame=frame
|
|
19
|
+
@graphic_frame.anchor.drawing.worksheet.workbook.charts << self
|
|
20
|
+
@series = SimpleTypedList.new Series
|
|
21
|
+
@show_legend = true
|
|
22
|
+
@series_type = Series
|
|
23
|
+
@title = Title.new
|
|
24
|
+
options.each do |o|
|
|
25
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
26
|
+
end
|
|
27
|
+
start_at(*options[:start_at]) if options[:start_at]
|
|
28
|
+
end_at(*options[:end_at]) if options[:end_at]
|
|
29
|
+
yield self if block_given?
|
|
30
|
+
end
|
|
8
31
|
|
|
9
32
|
# The 3D view properties for the chart
|
|
10
|
-
attr_reader :
|
|
33
|
+
attr_reader :view_3D
|
|
34
|
+
alias :view3D :view_3D
|
|
11
35
|
|
|
12
36
|
# A reference to the graphic frame that owns this chart
|
|
13
37
|
# @return [GraphicFrame]
|
|
@@ -22,7 +46,10 @@ module Axlsx
|
|
|
22
46
|
attr_reader :series_type
|
|
23
47
|
|
|
24
48
|
#TODO data labels!
|
|
25
|
-
|
|
49
|
+
def d_lbls
|
|
50
|
+
@d_lbls ||= DLbls.new(self.class)
|
|
51
|
+
end
|
|
52
|
+
|
|
26
53
|
|
|
27
54
|
# The title object for the chart.
|
|
28
55
|
# @return [Title]
|
|
@@ -37,29 +64,6 @@ module Axlsx
|
|
|
37
64
|
# @return [Boolean]
|
|
38
65
|
attr_reader :show_legend
|
|
39
66
|
|
|
40
|
-
# Creates a new chart object
|
|
41
|
-
# @param [GraphicalFrame] frame The frame that holds this chart.
|
|
42
|
-
# @option options [Cell, String] title
|
|
43
|
-
# @option options [Boolean] show_legend
|
|
44
|
-
# @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart.
|
|
45
|
-
# @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart.
|
|
46
|
-
def initialize(frame, options={})
|
|
47
|
-
@style = 18
|
|
48
|
-
@view3D = nil
|
|
49
|
-
@graphic_frame=frame
|
|
50
|
-
@graphic_frame.anchor.drawing.worksheet.workbook.charts << self
|
|
51
|
-
@series = SimpleTypedList.new Series
|
|
52
|
-
@show_legend = true
|
|
53
|
-
@series_type = Series
|
|
54
|
-
@title = Title.new
|
|
55
|
-
options.each do |o|
|
|
56
|
-
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
57
|
-
end
|
|
58
|
-
start_at(*options[:start_at]) if options[:start_at]
|
|
59
|
-
end_at(*options[:end_at]) if options[:end_at]
|
|
60
|
-
yield self if block_given?
|
|
61
|
-
end
|
|
62
|
-
|
|
63
67
|
# The index of this chart in the workbooks charts collection
|
|
64
68
|
# @return [Integer]
|
|
65
69
|
def index
|
|
@@ -89,7 +93,6 @@ module Axlsx
|
|
|
89
93
|
# @return [Boolean]
|
|
90
94
|
def show_legend=(v) Axlsx::validate_boolean(v); @show_legend = v; end
|
|
91
95
|
|
|
92
|
-
|
|
93
96
|
# The style for the chart.
|
|
94
97
|
# see ECMA Part 1 §21.2.2.196
|
|
95
98
|
# @param [Integer] v must be between 1 and 48
|
|
@@ -127,7 +130,7 @@ module Axlsx
|
|
|
127
130
|
@title.to_xml_string str
|
|
128
131
|
# do these need the c: namespace as well???
|
|
129
132
|
str << '<c:autoTitleDeleted val="' << (@title == nil).to_s << '"/>'
|
|
130
|
-
@
|
|
133
|
+
@view_3D.to_xml_string(str) if @view_3D
|
|
131
134
|
str << '<c:floor><c:thickness val="0"/></c:floor>'
|
|
132
135
|
str << '<c:sideWall><c:thickness val="0"/></c:sideWall>'
|
|
133
136
|
str << '<c:backWall><c:thickness val="0"/></c:backWall>'
|
|
@@ -146,19 +149,40 @@ module Axlsx
|
|
|
146
149
|
str << '<c:dispBlanksAs val="zero"/>'
|
|
147
150
|
str << '<c:showDLblsOverMax val="1"/>'
|
|
148
151
|
str << '</c:chart>'
|
|
152
|
+
str << '<c:printSettings>'
|
|
153
|
+
str << '<c:headerFooter/>'
|
|
154
|
+
str << '<c:pageMargins b="1.0" l="0.75" r="0.75" t="1.0" header="0.5" footer="0.5"/>'
|
|
155
|
+
str << '<c:pageSetup/>'
|
|
156
|
+
str << '</c:printSettings>'
|
|
149
157
|
str << '</c:chartSpace>'
|
|
150
158
|
end
|
|
151
159
|
|
|
152
|
-
# This is a short cut method to set the start
|
|
160
|
+
# This is a short cut method to set the anchor start marker position
|
|
153
161
|
# If you need finer granularity in positioning use
|
|
154
|
-
#
|
|
155
|
-
#
|
|
162
|
+
#
|
|
163
|
+
# This helper method acceps a fairly wide range of inputs exampled
|
|
164
|
+
# below
|
|
165
|
+
#
|
|
166
|
+
# @example
|
|
167
|
+
#
|
|
168
|
+
# start_at 0, 5 # The anchor start marker is set to 6th row of
|
|
169
|
+
# the first column
|
|
170
|
+
#
|
|
171
|
+
# start_at [0, 5] # The anchor start marker is set to start on the 6th row
|
|
172
|
+
# of the first column
|
|
173
|
+
#
|
|
174
|
+
# start_at "C1" # The anchor start marker is set to start on the first row
|
|
175
|
+
# of the third column
|
|
176
|
+
#
|
|
177
|
+
# start_at sheet.rows.first.cells.last # The anchor start
|
|
178
|
+
# marker is set to the location of a specific cell.
|
|
179
|
+
#
|
|
180
|
+
# @param [Array|String|Cell] x the column, coordinates, string
|
|
181
|
+
# reference or cell to use in setting the start marker position.
|
|
156
182
|
# @param [Integer] y The row
|
|
157
183
|
# @return [Marker]
|
|
158
184
|
def start_at(x=0, y=0)
|
|
159
|
-
|
|
160
|
-
@graphic_frame.anchor.from.col = x
|
|
161
|
-
@graphic_frame.anchor.from.row = y
|
|
185
|
+
@graphic_frame.anchor.start_at(x, y)
|
|
162
186
|
end
|
|
163
187
|
|
|
164
188
|
# This is a short cut method to set the end anchor position
|
|
@@ -167,28 +191,15 @@ module Axlsx
|
|
|
167
191
|
# @param [Integer] x The column - default 10
|
|
168
192
|
# @param [Integer] y The row - default 10
|
|
169
193
|
# @return [Marker]
|
|
194
|
+
# @see start_at
|
|
170
195
|
def end_at(x=10, y=10)
|
|
171
|
-
|
|
172
|
-
@graphic_frame.anchor.to.col = x
|
|
173
|
-
@graphic_frame.anchor.to.row = y
|
|
196
|
+
@graphic_frame.anchor.end_at(x, y)
|
|
174
197
|
end
|
|
175
198
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if x.is_a?(String)
|
|
180
|
-
x, y = *Axlsx::name_to_indices(x)
|
|
181
|
-
end
|
|
182
|
-
if x.is_a?(Cell)
|
|
183
|
-
x, y = *x.pos
|
|
184
|
-
end
|
|
185
|
-
if x.is_a?(Array)
|
|
186
|
-
x, y = *x
|
|
187
|
-
end
|
|
188
|
-
[x, y]
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def view3D=(v) DataTypeValidator.validate "#{self.class}.view3D", View3D, v; @view3D = v; end
|
|
199
|
+
# sets the view_3D object for the chart
|
|
200
|
+
def view_3D=(v) DataTypeValidator.validate "#{self.class}.view_3D", View3D, v; @view_3D = v; end
|
|
201
|
+
alias :view3D= :view_3D=
|
|
192
202
|
|
|
193
203
|
end
|
|
204
|
+
|
|
194
205
|
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
module Axlsx
|
|
2
|
+
# There are more elements in the dLbls spec that allow for
|
|
3
|
+
# customizations and formatting. For now, I am just implementing the
|
|
4
|
+
# basics.
|
|
5
|
+
|
|
6
|
+
#The DLbls class manages serialization of data labels
|
|
7
|
+
# showLeaderLines and leaderLines are not currently implemented
|
|
8
|
+
class DLbls
|
|
9
|
+
|
|
10
|
+
# These attributes are all boolean so I'm doing a bit of a hand
|
|
11
|
+
# waving magic show to set up the attriubte accessors
|
|
12
|
+
# @note
|
|
13
|
+
# not all charts support all methods!
|
|
14
|
+
# Bar3DChart and Line3DChart and ScatterChart do not support d_lbl_pos or show_leader_lines
|
|
15
|
+
#
|
|
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
|
|
27
|
+
|
|
28
|
+
# Initialize all the values to false as Excel requires them to
|
|
29
|
+
# explicitly be disabled or all will show.
|
|
30
|
+
def initialize_defaults
|
|
31
|
+
BOOLEAN_ATTRIBUTES.each do |attr|
|
|
32
|
+
self.send("#{attr}=", false)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The chart type that is using this data lables instance.
|
|
37
|
+
# This affects the xml output as not all chart types support the
|
|
38
|
+
# same data label attributes.
|
|
39
|
+
attr_reader :chart_type
|
|
40
|
+
|
|
41
|
+
# The position of the data labels in the chart
|
|
42
|
+
# @see d_lbl_pos= for a list of allowed values
|
|
43
|
+
# @return [Symbol]
|
|
44
|
+
def d_lbl_pos
|
|
45
|
+
return unless @chart_type == Pie3DChart
|
|
46
|
+
@d_lbl_pos ||= :bestFit
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# @see DLbls#d_lbl_pos
|
|
50
|
+
# Assigns the label postion for this data labels on this chart.
|
|
51
|
+
# Allowed positions are :bestFilt, :b, :ctr, :inBase, :inEnd, :l,
|
|
52
|
+
# :outEnd, :r and :t
|
|
53
|
+
# The default is :bestFit
|
|
54
|
+
# @param [Symbol] label_position the postion you want to use.
|
|
55
|
+
def d_lbl_pos=(label_position)
|
|
56
|
+
return unless @chart_type == Pie3DChart
|
|
57
|
+
Axlsx::RestrictionValidator.validate 'DLbls#d_lbl_pos', [:bestFit, :b, :ctr, :inBase, :inEnd, :l, :outEnd, :r, :t], label_position
|
|
58
|
+
@d_lbl_pos = label_position
|
|
59
|
+
end
|
|
60
|
+
|
|
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
|
+
|
|
79
|
+
# serializes the data labels
|
|
80
|
+
# @return [String]
|
|
81
|
+
def to_xml_string(str = '')
|
|
82
|
+
validate_attributes_for_chart_type
|
|
83
|
+
str << '<c:dLbls>'
|
|
84
|
+
%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|
|
|
85
|
+
next unless instance_values.keys.include?(key) && instance_values[key] != nil
|
|
86
|
+
str << "<c:#{Axlsx::camel(key, false)} val='#{instance_values[key]}' />"
|
|
87
|
+
end
|
|
88
|
+
str << '</c:dLbls>'
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# 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.
|
|
92
|
+
def validate_attributes_for_chart_type
|
|
93
|
+
return if @chart_type == Pie3DChart
|
|
94
|
+
@d_lbl_pos = nil
|
|
95
|
+
@show_leader_lines = nil
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
2
|
module Axlsx
|
|
3
|
+
require 'axlsx/drawing/d_lbls.rb'
|
|
3
4
|
require 'axlsx/drawing/title.rb'
|
|
4
5
|
require 'axlsx/drawing/series_title.rb'
|
|
5
6
|
require 'axlsx/drawing/series.rb'
|
|
@@ -42,12 +43,13 @@ module Axlsx
|
|
|
42
43
|
require 'axlsx/drawing/vml_drawing.rb'
|
|
43
44
|
require 'axlsx/drawing/vml_shape.rb'
|
|
44
45
|
|
|
45
|
-
# A Drawing is a canvas for charts. Each worksheet has a single drawing that manages anchors.
|
|
46
|
-
# The anchors reference the charts via graphical frames. This is not a trivial relationship so please do follow the advice in the note.
|
|
47
|
-
# @note The recommended way to manage drawings is to use the Worksheet.add_chart
|
|
46
|
+
# A Drawing is a canvas for charts and images. Each worksheet has a single drawing that manages anchors.
|
|
47
|
+
# 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.
|
|
48
|
+
# @note The recommended way to manage drawings is to use the Worksheet.add_chart and Worksheet.add_image methods.
|
|
48
49
|
# @see Worksheet#add_chart
|
|
50
|
+
# @see Worksheet#add_image
|
|
49
51
|
# @see Chart
|
|
50
|
-
# see
|
|
52
|
+
# see examples/example.rb for an example of how to create a chart.
|
|
51
53
|
class Drawing
|
|
52
54
|
|
|
53
55
|
# The worksheet that owns the drawing
|
|
@@ -68,6 +70,7 @@ module Axlsx
|
|
|
68
70
|
@anchors = SimpleTypedList.new [TwoCellAnchor, OneCellAnchor]
|
|
69
71
|
end
|
|
70
72
|
|
|
73
|
+
|
|
71
74
|
# 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.
|
|
72
75
|
# @note The recommended way to manage images is to use Worksheet.add_image. Please refer to that method for documentation.
|
|
73
76
|
# @see Worksheet#add_image
|
|
@@ -70,7 +70,8 @@ module Axlsx
|
|
|
70
70
|
@serAxis = SerAxis.new(@serAxId, @valAxId)
|
|
71
71
|
super(frame, options)
|
|
72
72
|
@series_type = LineSeries
|
|
73
|
-
@
|
|
73
|
+
@view_3D = View3D.new({:perspective=>30}.merge(options))
|
|
74
|
+
@d_lbls = nil
|
|
74
75
|
end
|
|
75
76
|
|
|
76
77
|
# @see grouping
|
|
@@ -94,14 +95,7 @@ module Axlsx
|
|
|
94
95
|
str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
|
|
95
96
|
str_inner << '<c:varyColors val="1"/>'
|
|
96
97
|
@series.each { |ser| ser.to_xml_string(str_inner) }
|
|
97
|
-
|
|
98
|
-
str_inner << '<c:showLegendKey val="0"/>'
|
|
99
|
-
str_inner << '<c:showVal val="0"/>'
|
|
100
|
-
str_inner << '<c:showCatName val="0"/>'
|
|
101
|
-
str_inner << '<c:showSerName val="0"/>'
|
|
102
|
-
str_inner << '<c:showPercent val="0"/>'
|
|
103
|
-
str_inner << '<c:showBubbleSize val="0"/>'
|
|
104
|
-
str_inner << '</c:dLbls>'
|
|
98
|
+
@d_lbls.to_xml_string(str) if @d_lbls
|
|
105
99
|
str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
|
|
106
100
|
str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
|
|
107
101
|
str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
|
|
@@ -112,6 +106,5 @@ module Axlsx
|
|
|
112
106
|
@serAxis.to_xml_string str_inner
|
|
113
107
|
end
|
|
114
108
|
end
|
|
115
|
-
|
|
116
109
|
end
|
|
117
110
|
end
|
|
@@ -36,7 +36,7 @@ module Axlsx
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# sets the tag name for this data source
|
|
39
|
-
# @param [Symbol] One of the allowed_tag_names
|
|
39
|
+
# @param [Symbol] v One of the allowed_tag_names
|
|
40
40
|
def tag_name=(v)
|
|
41
41
|
Axlsx::RestrictionValidator.validate "#{self.class.name}.tag_name", self.class.allowed_tag_names, v
|
|
42
42
|
@tag_name = v
|
|
@@ -13,19 +13,20 @@ module Axlsx
|
|
|
13
13
|
# @option options [Cell, String] title
|
|
14
14
|
# @option options [Boolean] show_legend
|
|
15
15
|
# @option options [Symbol] grouping
|
|
16
|
-
# @option options [String]
|
|
17
|
-
# @option options [Integer]
|
|
18
|
-
# @option options [String]
|
|
19
|
-
# @option options [Integer]
|
|
20
|
-
# @option options [String]
|
|
21
|
-
# @option options [Boolean]
|
|
16
|
+
# @option options [String] gap_depth
|
|
17
|
+
# @option options [Integer] rot_x
|
|
18
|
+
# @option options [String] h_percent
|
|
19
|
+
# @option options [Integer] rot_y
|
|
20
|
+
# @option options [String] depth_percent
|
|
21
|
+
# @option options [Boolean] r_ang_ax
|
|
22
22
|
# @option options [Integer] perspective
|
|
23
23
|
# @see Chart
|
|
24
24
|
# @see View3D
|
|
25
25
|
def initialize(frame, options={})
|
|
26
26
|
super(frame, options)
|
|
27
27
|
@series_type = PieSeries
|
|
28
|
-
@
|
|
28
|
+
@view_3D = View3D.new({:rot_x =>30, :perspective=>30}.merge(options))
|
|
29
|
+
@d_lbls = nil
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
# Serializes the object
|
|
@@ -33,9 +34,11 @@ module Axlsx
|
|
|
33
34
|
# @return [String]
|
|
34
35
|
def to_xml_string(str = '')
|
|
35
36
|
super(str) do |str_inner|
|
|
37
|
+
|
|
36
38
|
str_inner << '<c:pie3DChart>'
|
|
37
39
|
str_inner << '<c:varyColors val="1"/>'
|
|
38
40
|
@series.each { |ser| ser.to_xml_string(str_inner) }
|
|
41
|
+
d_lbls.to_xml_string(str) if @d_lbls
|
|
39
42
|
str_inner << '</c:pie3DChart>'
|
|
40
43
|
end
|
|
41
44
|
end
|
|
@@ -29,6 +29,7 @@ module Axlsx
|
|
|
29
29
|
@yValAxis = ValAxis.new(@yValAxId, @xValAxId)
|
|
30
30
|
super(frame, options)
|
|
31
31
|
@series_type = ScatterSeries
|
|
32
|
+
@d_lbls = nil
|
|
32
33
|
options.each do |o|
|
|
33
34
|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
34
35
|
end
|
|
@@ -49,14 +50,7 @@ module Axlsx
|
|
|
49
50
|
str_inner << '<c:scatterStyle val="' << scatterStyle.to_s << '"/>'
|
|
50
51
|
str_inner << '<c:varyColors val="1"/>'
|
|
51
52
|
@series.each { |ser| ser.to_xml_string(str_inner) }
|
|
52
|
-
|
|
53
|
-
str_inner << '<c:showLegendKey val="0"/>'
|
|
54
|
-
str_inner << '<c:showVal val="0"/>'
|
|
55
|
-
str_inner << '<c:showCatName val="0"/>'
|
|
56
|
-
str_inner << '<c:showSerName val="0"/>'
|
|
57
|
-
str_inner << '<c:showPercent val="0"/>'
|
|
58
|
-
str_inner << '<c:showBubbleSize val="0"/>'
|
|
59
|
-
str_inner << '</c:dLbls>'
|
|
53
|
+
d_lbls.to_xml_string(str) if @d_lbls
|
|
60
54
|
str_inner << '<c:axId val="' << @xValAxId.to_s << '"/>'
|
|
61
55
|
str_inner << '<c:axId val="' << @yValAxId.to_s << '"/>'
|
|
62
56
|
str_inner << '</c:scatterChart>'
|
|
@@ -25,23 +25,33 @@ module Axlsx
|
|
|
25
25
|
# @return [Drawing]
|
|
26
26
|
attr_reader :drawing
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
# Creates a new TwoCellAnchor object and sets up a reference to the from and to markers in the
|
|
30
|
-
# graphic_frame's chart. That means that you can do stuff like
|
|
31
|
-
# c = worksheet.add_chart Axlsx::Chart
|
|
28
|
+
# Creates a new TwoCellAnchor object
|
|
32
29
|
# c.start_at 5, 9
|
|
33
|
-
# @note the chart_type parameter will be replaced with object in v. 2.0.0
|
|
34
30
|
# @param [Drawing] drawing
|
|
35
|
-
# @
|
|
36
|
-
# @
|
|
37
|
-
# @option options [Array] start_at the col, row to start at THIS IS DOCUMENTED BUT NOT IMPLEMENTED HERE!
|
|
38
|
-
# @option options [Array] end_at the col, row to end at
|
|
31
|
+
# @option options [Array] :start_at the col, row to start at THIS IS DOCUMENTED BUT NOT IMPLEMENTED HERE!
|
|
32
|
+
# @option options [Array] :end_at the col, row to end at
|
|
39
33
|
def initialize(drawing, options={})
|
|
40
34
|
@drawing = drawing
|
|
41
35
|
drawing.anchors << self
|
|
42
36
|
@from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
|
|
43
37
|
end
|
|
44
38
|
|
|
39
|
+
# sets the col, row attributes for the from marker.
|
|
40
|
+
# @note The recommended way to set the start position for graphical
|
|
41
|
+
# objects is directly thru the object.
|
|
42
|
+
# @see Chart#start_at
|
|
43
|
+
def start_at(x, y)
|
|
44
|
+
set_marker_coords(x, y, from)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# sets the col, row attributes for the to marker
|
|
48
|
+
# @note the recommended way to set the to position for graphical
|
|
49
|
+
# objects is directly thru the object
|
|
50
|
+
# @see Char#end_at
|
|
51
|
+
def end_at(x, y)
|
|
52
|
+
set_marker_coords(x, y, to)
|
|
53
|
+
end
|
|
54
|
+
|
|
45
55
|
# Creates a graphic frame and chart object associated with this anchor
|
|
46
56
|
# @return [Chart]
|
|
47
57
|
def add_chart(chart_type, options)
|
|
@@ -75,6 +85,28 @@ module Axlsx
|
|
|
75
85
|
str << '<xdr:clientData/>'
|
|
76
86
|
str << '</xdr:twoCellAnchor>'
|
|
77
87
|
end
|
|
88
|
+
private
|
|
89
|
+
|
|
90
|
+
# parses coordinates and sets up a marker's row/col propery
|
|
91
|
+
def set_marker_coords(x, y, marker)
|
|
92
|
+
marker.col, marker.row = *parse_coord_args(x, y)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# handles multiple inputs for setting the position of a marker
|
|
96
|
+
# @see Chart#start_at
|
|
97
|
+
def parse_coord_args(x, y=0)
|
|
98
|
+
if x.is_a?(String)
|
|
99
|
+
x, y = *Axlsx::name_to_indices(x)
|
|
100
|
+
end
|
|
101
|
+
if x.is_a?(Cell)
|
|
102
|
+
x, y = *x.pos
|
|
103
|
+
end
|
|
104
|
+
if x.is_a?(Array)
|
|
105
|
+
x, y = *x
|
|
106
|
+
end
|
|
107
|
+
[x, y]
|
|
108
|
+
end
|
|
109
|
+
|
|
78
110
|
|
|
79
111
|
end
|
|
80
112
|
end
|