caxlsx 3.3.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +25 -7
- data/Rakefile +7 -6
- data/lib/axlsx/content_type/abstract_content_type.rb +11 -9
- data/lib/axlsx/content_type/content_type.rb +7 -9
- data/lib/axlsx/content_type/default.rb +4 -6
- data/lib/axlsx/content_type/override.rb +3 -5
- data/lib/axlsx/doc_props/app.rb +27 -30
- data/lib/axlsx/doc_props/core.rb +9 -12
- data/lib/axlsx/drawing/area_chart.rb +13 -14
- data/lib/axlsx/drawing/area_series.rb +13 -14
- data/lib/axlsx/drawing/ax_data_source.rb +3 -6
- data/lib/axlsx/drawing/axes.rb +10 -9
- data/lib/axlsx/drawing/axis.rb +27 -30
- data/lib/axlsx/drawing/bar_3D_chart.rb +17 -18
- data/lib/axlsx/drawing/bar_chart.rb +16 -17
- data/lib/axlsx/drawing/bar_series.rb +9 -13
- data/lib/axlsx/drawing/bubble_chart.rb +8 -9
- data/lib/axlsx/drawing/bubble_series.rb +9 -10
- data/lib/axlsx/drawing/cat_axis.rb +14 -17
- data/lib/axlsx/drawing/chart.rb +25 -28
- data/lib/axlsx/drawing/d_lbls.rb +29 -26
- data/lib/axlsx/drawing/drawing.rb +60 -62
- data/lib/axlsx/drawing/graphic_frame.rb +6 -7
- data/lib/axlsx/drawing/hyperlink.rb +12 -13
- data/lib/axlsx/drawing/line_3D_chart.rb +13 -15
- data/lib/axlsx/drawing/line_chart.rb +13 -14
- data/lib/axlsx/drawing/line_series.rb +13 -14
- data/lib/axlsx/drawing/marker.rb +14 -16
- data/lib/axlsx/drawing/num_data.rb +13 -16
- data/lib/axlsx/drawing/num_data_source.rb +11 -13
- data/lib/axlsx/drawing/num_val.rb +9 -10
- data/lib/axlsx/drawing/one_cell_anchor.rb +10 -10
- data/lib/axlsx/drawing/pic.rb +57 -22
- data/lib/axlsx/drawing/picture_locking.rb +6 -7
- data/lib/axlsx/drawing/pie_3D_chart.rb +6 -9
- data/lib/axlsx/drawing/pie_series.rb +9 -12
- data/lib/axlsx/drawing/scaling.rb +9 -10
- data/lib/axlsx/drawing/scatter_chart.rb +9 -10
- data/lib/axlsx/drawing/scatter_series.rb +15 -16
- data/lib/axlsx/drawing/ser_axis.rb +9 -11
- data/lib/axlsx/drawing/series.rb +8 -8
- data/lib/axlsx/drawing/series_title.rb +6 -6
- data/lib/axlsx/drawing/str_data.rb +10 -13
- data/lib/axlsx/drawing/str_val.rb +8 -9
- data/lib/axlsx/drawing/title.rb +23 -27
- data/lib/axlsx/drawing/two_cell_anchor.rb +8 -8
- data/lib/axlsx/drawing/val_axis.rb +5 -6
- data/lib/axlsx/drawing/view_3D.rb +32 -30
- data/lib/axlsx/drawing/vml_drawing.rb +19 -20
- data/lib/axlsx/drawing/vml_shape.rb +25 -26
- data/lib/axlsx/package.rb +81 -79
- data/lib/axlsx/rels/relationship.rb +30 -28
- data/lib/axlsx/rels/relationships.rb +7 -8
- data/lib/axlsx/stylesheet/border.rb +7 -8
- data/lib/axlsx/stylesheet/border_pr.rb +8 -8
- data/lib/axlsx/stylesheet/cell_alignment.rb +14 -20
- data/lib/axlsx/stylesheet/cell_protection.rb +6 -7
- data/lib/axlsx/stylesheet/cell_style.rb +12 -14
- data/lib/axlsx/stylesheet/color.rb +15 -12
- data/lib/axlsx/stylesheet/dxf.rb +7 -9
- data/lib/axlsx/stylesheet/fill.rb +3 -5
- data/lib/axlsx/stylesheet/font.rb +24 -21
- data/lib/axlsx/stylesheet/gradient_fill.rb +9 -9
- data/lib/axlsx/stylesheet/gradient_stop.rb +7 -6
- data/lib/axlsx/stylesheet/num_fmt.rb +9 -14
- data/lib/axlsx/stylesheet/pattern_fill.rb +8 -8
- data/lib/axlsx/stylesheet/styles.rb +104 -98
- data/lib/axlsx/stylesheet/table_style.rb +8 -9
- data/lib/axlsx/stylesheet/table_style_element.rb +7 -8
- data/lib/axlsx/stylesheet/table_styles.rb +8 -10
- data/lib/axlsx/stylesheet/xf.rb +21 -22
- data/lib/axlsx/util/accessors.rb +6 -6
- data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
- data/lib/axlsx/util/constants.rb +119 -108
- data/lib/axlsx/util/mime_type_utils.rb +11 -0
- data/lib/axlsx/util/options_parser.rb +4 -3
- data/lib/axlsx/util/serialized_attributes.rb +45 -21
- data/lib/axlsx/util/simple_typed_list.rb +58 -57
- data/lib/axlsx/util/storage.rb +38 -41
- data/lib/axlsx/util/validators.rb +107 -44
- data/lib/axlsx/util/zip_command.rb +10 -12
- data/lib/axlsx/version.rb +3 -2
- data/lib/axlsx/workbook/defined_name.rb +11 -8
- data/lib/axlsx/workbook/defined_names.rb +4 -3
- data/lib/axlsx/workbook/shared_strings_table.rb +10 -11
- data/lib/axlsx/workbook/workbook.rb +121 -114
- data/lib/axlsx/workbook/workbook_view.rb +8 -11
- data/lib/axlsx/workbook/workbook_views.rb +4 -4
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +72 -14
- data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -7
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +24 -21
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
- data/lib/axlsx/workbook/worksheet/border_creator.rb +30 -25
- data/lib/axlsx/workbook/worksheet/break.rb +4 -5
- data/lib/axlsx/workbook/worksheet/cell.rb +92 -65
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +32 -28
- data/lib/axlsx/workbook/worksheet/cfvo.rb +7 -5
- data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
- data/lib/axlsx/workbook/worksheet/col.rb +9 -10
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +8 -7
- data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
- data/lib/axlsx/workbook/worksheet/cols.rb +9 -7
- data/lib/axlsx/workbook/worksheet/comment.rb +12 -11
- data/lib/axlsx/workbook/worksheet/comments.rb +10 -12
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +12 -8
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +19 -21
- data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +5 -5
- data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
- data/lib/axlsx/workbook/worksheet/data_validation.rb +34 -33
- data/lib/axlsx/workbook/worksheet/data_validations.rb +5 -6
- data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
- data/lib/axlsx/workbook/worksheet/dimension.rb +9 -6
- data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -3
- data/lib/axlsx/workbook/worksheet/icon_set.rb +24 -8
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +10 -10
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -3
- data/lib/axlsx/workbook/worksheet/page_margins.rb +17 -12
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -4
- data/lib/axlsx/workbook/worksheet/page_setup.rb +128 -129
- data/lib/axlsx/workbook/worksheet/pane.rb +27 -26
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +23 -25
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
- data/lib/axlsx/workbook/worksheet/pivot_tables.rb +5 -4
- data/lib/axlsx/workbook/worksheet/print_options.rb +3 -2
- data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +12 -10
- data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +35 -17
- data/lib/axlsx/workbook/worksheet/row.rb +30 -22
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +8 -7
- data/lib/axlsx/workbook/worksheet/selection.rb +16 -16
- data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +10 -7
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
- data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +11 -7
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +21 -20
- data/lib/axlsx/workbook/worksheet/sheet_view.rb +48 -53
- data/lib/axlsx/workbook/worksheet/table.rb +13 -13
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +6 -5
- data/lib/axlsx/workbook/worksheet/tables.rb +7 -5
- data/lib/axlsx/workbook/worksheet/worksheet.rb +92 -63
- data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +10 -8
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +9 -8
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +7 -5
- data/lib/axlsx.rb +75 -47
- data/lib/caxlsx.rb +3 -2
- metadata +50 -44
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module Axlsx
|
3
4
|
# An axis data source that can contain referenced or literal strings or numbers
|
4
5
|
# @note only string data types are supported - mainly because we have not implemented a chart type that requires a numerical axis value
|
5
6
|
class AxDataSource < NumDataSource
|
6
|
-
|
7
7
|
# creates a new NumDataSource object
|
8
8
|
# @option options [Array] data An array of Cells or Numeric objects
|
9
9
|
# @option options [Symbol] tag_name see tag_name
|
10
|
-
def initialize(options={})
|
10
|
+
def initialize(options = {})
|
11
11
|
@tag_name = :cat
|
12
12
|
@data_type = StrData
|
13
13
|
@ref_tag_name = :strRef
|
@@ -19,8 +19,5 @@ module Axlsx
|
|
19
19
|
def self.allowed_tag_names
|
20
20
|
[:xVal, :cat]
|
21
21
|
end
|
22
|
-
|
23
22
|
end
|
24
|
-
|
25
23
|
end
|
26
|
-
|
data/lib/axlsx/drawing/axes.rb
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Axlsx
|
2
|
-
|
3
4
|
# The Axes class creates and manages axis information and
|
4
5
|
# serialization for charts.
|
5
6
|
class Axes
|
6
|
-
|
7
7
|
# @param [Hash] options options used to generate axis each key
|
8
8
|
# should be an axis name like :val_axis and its value should be the
|
9
9
|
# class of the axis type to construct. The :cat_axis, if there is one,
|
10
10
|
# must come first (we assume a Ruby 1.9+ Hash or an OrderedHash).
|
11
|
-
def initialize(options={})
|
12
|
-
raise(ArgumentError, "CatAxis must come first") if options.
|
11
|
+
def initialize(options = {})
|
12
|
+
raise(ArgumentError, "CatAxis must come first") if options.key?(:cat_axis) && options.keys.first != :cat_axis
|
13
|
+
|
13
14
|
options.each do |name, axis_class|
|
14
15
|
add_axis(name, axis_class)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
# [] provides assiciative access to a specic axis store in an axes
|
19
|
-
# instance.
|
20
|
+
# instance.
|
20
21
|
# @return [Axis]
|
21
22
|
def [](name)
|
22
23
|
axes.assoc(name)[1]
|
@@ -27,12 +28,12 @@ module Axlsx
|
|
27
28
|
# @param [Hash] options
|
28
29
|
# @option options ids
|
29
30
|
# If the ids option is specified only the axis identifier is
|
30
|
-
# serialized. Otherwise, each axis is serialized in full.
|
31
|
-
def to_xml_string(str = '', options = {})
|
31
|
+
# serialized. Otherwise, each axis is serialized in full.
|
32
|
+
def to_xml_string(str = +'', options = {})
|
32
33
|
if options[:ids]
|
33
34
|
# CatAxis must come first in the XML (for Microsoft Excel at least)
|
34
|
-
sorted = axes.sort_by { |
|
35
|
-
sorted.each { |axis| str <<
|
35
|
+
sorted = axes.sort_by { |_name, axis| axis.is_a?(CatAxis) ? 0 : 1 }
|
36
|
+
sorted.each { |axis| str << '<c:axId val="' << axis[1].id.to_s << '"/>' }
|
36
37
|
else
|
37
38
|
axes.each { |axis| axis[1].to_xml_string(str) }
|
38
39
|
end
|
data/lib/axlsx/drawing/axis.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
#
|
2
|
-
module Axlsx
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
module Axlsx
|
4
4
|
# the access class defines common properties and values for a chart axis.
|
5
5
|
class Axis
|
6
|
-
|
7
6
|
include Axlsx::OptionsParser
|
8
7
|
|
9
8
|
# Creates an Axis object
|
@@ -12,11 +11,11 @@ module Axlsx
|
|
12
11
|
# @option options [Symbol] crosses
|
13
12
|
# @option options [Symbol] tick_lbl_pos
|
14
13
|
# @raise [ArgumentError] If axi_id or cross_ax are not unsigned integers
|
15
|
-
def initialize(options={})
|
16
|
-
@id = rand(8
|
14
|
+
def initialize(options = {})
|
15
|
+
@id = rand(8**8)
|
17
16
|
@format_code = "General"
|
18
17
|
@delete = @label_rotation = 0
|
19
|
-
@scaling = Scaling.new(:
|
18
|
+
@scaling = Scaling.new(orientation: :minMax)
|
20
19
|
@title = @color = nil
|
21
20
|
self.ax_pos = :b
|
22
21
|
self.tick_lbl_pos = :nextTo
|
@@ -83,19 +82,19 @@ module Axlsx
|
|
83
82
|
# the title for the axis. This can be a cell or a fixed string.
|
84
83
|
attr_reader :title
|
85
84
|
|
86
|
-
# The color for this axis. This value is used when rendering the axis line in the chart.
|
85
|
+
# The color for this axis. This value is used when rendering the axis line in the chart.
|
87
86
|
# colors should be in 6 character rbg format
|
88
87
|
# @return [String] the rbg color assinged.
|
89
88
|
# @see color
|
90
89
|
def color=(color_rgb)
|
91
90
|
@color = color_rgb
|
92
91
|
end
|
93
|
-
|
92
|
+
|
94
93
|
# The crossing axis for this axis
|
95
94
|
# @param [Axis] axis
|
96
95
|
def cross_axis=(axis)
|
97
|
-
|
98
|
-
|
96
|
+
DataTypeValidator.validate "#{self.class}.cross_axis", [Axis], axis
|
97
|
+
@cross_axis = axis
|
99
98
|
end
|
100
99
|
|
101
100
|
# The position of the axis
|
@@ -110,15 +109,15 @@ module Axlsx
|
|
110
109
|
|
111
110
|
# The number format format code for this axis
|
112
111
|
# default :General
|
113
|
-
def format_code=(v) Axlsx
|
112
|
+
def format_code=(v) Axlsx.validate_string(v); @format_code = v; end
|
114
113
|
|
115
114
|
# Specify if gridlines should be shown for this axis
|
116
115
|
# default true
|
117
|
-
def gridlines=(v) Axlsx
|
116
|
+
def gridlines=(v) Axlsx.validate_boolean(v); @gridlines = v; end
|
118
117
|
|
119
118
|
# Specify if axis should be removed from the chart
|
120
119
|
# default false
|
121
|
-
def delete=(v) Axlsx
|
120
|
+
def delete=(v) Axlsx.validate_boolean(v); @delete = v; end
|
122
121
|
|
123
122
|
# specifies how the perpendicular axis is crossed
|
124
123
|
# must be one of [:autoZero, :min, :max]
|
@@ -127,9 +126,9 @@ module Axlsx
|
|
127
126
|
# Specify the degree of label rotation to apply to labels
|
128
127
|
# default true
|
129
128
|
def label_rotation=(v)
|
130
|
-
Axlsx
|
129
|
+
Axlsx.validate_int(v)
|
131
130
|
adjusted = v.to_i * 60000
|
132
|
-
Axlsx
|
131
|
+
Axlsx.validate_angle(adjusted)
|
133
132
|
@label_rotation = adjusted
|
134
133
|
end
|
135
134
|
|
@@ -149,13 +148,13 @@ module Axlsx
|
|
149
148
|
# Serializes the object
|
150
149
|
# @param [String] str
|
151
150
|
# @return [String]
|
152
|
-
def to_xml_string(str = '')
|
153
|
-
str <<
|
151
|
+
def to_xml_string(str = +'')
|
152
|
+
str << '<c:axId val="' << @id.to_s << '"/>'
|
154
153
|
@scaling.to_xml_string str
|
155
|
-
str <<
|
156
|
-
str <<
|
154
|
+
str << '<c:delete val="' << @delete.to_s << '"/>'
|
155
|
+
str << '<c:axPos val="' << @ax_pos.to_s << '"/>'
|
157
156
|
str << '<c:majorGridlines>'
|
158
|
-
# TODO shape properties need to be extracted into a class
|
157
|
+
# TODO: shape properties need to be extracted into a class
|
159
158
|
if gridlines == false
|
160
159
|
str << '<c:spPr>'
|
161
160
|
str << '<a:ln>'
|
@@ -164,27 +163,25 @@ module Axlsx
|
|
164
163
|
str << '</c:spPr>'
|
165
164
|
end
|
166
165
|
str << '</c:majorGridlines>'
|
167
|
-
@title.to_xml_string(str) unless @title
|
166
|
+
@title.to_xml_string(str) unless @title.nil?
|
168
167
|
# Need to set sourceLinked to 0 if we're setting a format code on this row
|
169
168
|
# otherwise it will never take, as it will always prefer the 'General' formatting
|
170
169
|
# of the cells themselves
|
171
|
-
str <<
|
170
|
+
str << '<c:numFmt formatCode="' << @format_code << '" sourceLinked="' << (@format_code.eql?('General') ? '1' : '0') << '"/>'
|
172
171
|
str << '<c:majorTickMark val="none"/>'
|
173
172
|
str << '<c:minorTickMark val="none"/>'
|
174
|
-
str <<
|
175
|
-
# TODO
|
173
|
+
str << '<c:tickLblPos val="' << @tick_lbl_pos.to_s << '"/>'
|
174
|
+
# TODO: this is also being used for series colors
|
176
175
|
# time to extract this into a class spPr - Shape Properties
|
177
176
|
if @color
|
178
177
|
str << '<c:spPr><a:ln><a:solidFill>'
|
179
|
-
str <<
|
178
|
+
str << '<a:srgbClr val="' << @color << '"/>'
|
180
179
|
str << '</a:solidFill></a:ln></c:spPr>'
|
181
180
|
end
|
182
181
|
# some potential value in implementing this in full. Very detailed!
|
183
|
-
str <<
|
184
|
-
str <<
|
185
|
-
str <<
|
182
|
+
str << '<c:txPr><a:bodyPr rot="' << @label_rotation.to_s << '"/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr/></a:p></c:txPr>'
|
183
|
+
str << '<c:crossAx val="' << @cross_axis.id.to_s << '"/>'
|
184
|
+
str << '<c:crosses val="' << @crosses.to_s << '"/>'
|
186
185
|
end
|
187
|
-
|
188
186
|
end
|
189
|
-
|
190
187
|
end
|
@@ -1,13 +1,12 @@
|
|
1
|
-
#
|
2
|
-
module Axlsx
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
module Axlsx
|
4
4
|
# The Bar3DChart is a three dimentional barchart (who would have guessed?) that you can add to your worksheet.
|
5
5
|
# @see Worksheet#add_chart
|
6
6
|
# @see Chart#add_series
|
7
7
|
# @see Package#serialize
|
8
8
|
# @see README for an example
|
9
9
|
class Bar3DChart < Chart
|
10
|
-
|
11
10
|
# the category axis
|
12
11
|
# @return [CatAxis]
|
13
12
|
def cat_axis
|
@@ -42,7 +41,7 @@ module Axlsx
|
|
42
41
|
end
|
43
42
|
alias :gapWidth :gap_width
|
44
43
|
|
45
|
-
#grouping for a column, line, or area chart.
|
44
|
+
# grouping for a column, line, or area chart.
|
46
45
|
# must be one of [:percentStacked, :clustered, :standard, :stacked]
|
47
46
|
# @return [Symbol]
|
48
47
|
def grouping
|
@@ -73,12 +72,12 @@ module Axlsx
|
|
73
72
|
# @option options [Integer] perspective
|
74
73
|
# @see Chart
|
75
74
|
# @see View3D
|
76
|
-
def initialize(frame, options={})
|
75
|
+
def initialize(frame, options = {})
|
77
76
|
@vary_colors = true
|
78
77
|
@gap_width, @gap_depth, @shape = nil, nil, nil
|
79
78
|
super(frame, options)
|
80
79
|
@series_type = BarSeries
|
81
|
-
@view_3D = View3D.new({:
|
80
|
+
@view_3D = View3D.new({ r_ang_ax: 1 }.merge(options))
|
82
81
|
@d_lbls = nil
|
83
82
|
end
|
84
83
|
|
@@ -90,7 +89,7 @@ module Axlsx
|
|
90
89
|
end
|
91
90
|
alias :barDir= :bar_dir=
|
92
91
|
|
93
|
-
#grouping for a column, line, or area chart.
|
92
|
+
# grouping for a column, line, or area chart.
|
94
93
|
# must be one of [:percentStacked, :clustered, :standard, :stacked]
|
95
94
|
def grouping=(v)
|
96
95
|
RestrictionValidator.validate "Bar3DChart.grouping", [:percentStacked, :clustered, :standard, :stacked], v
|
@@ -100,14 +99,14 @@ module Axlsx
|
|
100
99
|
# space between bar or column clusters, as a percentage of the bar or column width.
|
101
100
|
def gap_width=(v)
|
102
101
|
RangeValidator.validate "Bar3DChart.gap_width", 0, 500, v
|
103
|
-
@gap_width=
|
102
|
+
@gap_width = v
|
104
103
|
end
|
105
104
|
alias :gapWidth= :gap_width=
|
106
105
|
|
107
106
|
# space between bar or column clusters, as a percentage of the bar or column width.
|
108
107
|
def gap_depth=(v)
|
109
108
|
RangeValidator.validate "Bar3DChart.gap_depth", 0, 500, v
|
110
|
-
@gap_depth=
|
109
|
+
@gap_depth = v
|
111
110
|
end
|
112
111
|
alias :gapDepth= :gap_depth=
|
113
112
|
|
@@ -121,18 +120,18 @@ module Axlsx
|
|
121
120
|
# Serializes the object
|
122
121
|
# @param [String] str
|
123
122
|
# @return [String]
|
124
|
-
def to_xml_string(str = '')
|
123
|
+
def to_xml_string(str = +'')
|
125
124
|
super(str) do
|
126
125
|
str << '<c:bar3DChart>'
|
127
|
-
str <<
|
128
|
-
str <<
|
129
|
-
str <<
|
126
|
+
str << '<c:barDir val="' << bar_dir.to_s << '"/>'
|
127
|
+
str << '<c:grouping val="' << grouping.to_s << '"/>'
|
128
|
+
str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
|
130
129
|
@series.each { |ser| ser.to_xml_string(str) }
|
131
130
|
@d_lbls.to_xml_string(str) if @d_lbls
|
132
|
-
str <<
|
133
|
-
str <<
|
134
|
-
str <<
|
135
|
-
axes.to_xml_string(str, :
|
131
|
+
str << '<c:gapWidth val="' << @gap_width.to_s << '"/>' unless @gap_width.nil?
|
132
|
+
str << '<c:gapDepth val="' << @gap_depth.to_s << '"/>' unless @gap_depth.nil?
|
133
|
+
str << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
|
134
|
+
axes.to_xml_string(str, ids: true)
|
136
135
|
str << '</c:bar3DChart>'
|
137
136
|
axes.to_xml_string(str)
|
138
137
|
end
|
@@ -142,7 +141,7 @@ module Axlsx
|
|
142
141
|
# category axes specified via axes[:val_axes] and axes[:cat_axis]
|
143
142
|
# @return [Axes]
|
144
143
|
def axes
|
145
|
-
|
144
|
+
@axes ||= Axes.new(cat_axis: CatAxis, val_axis: ValAxis)
|
146
145
|
end
|
147
146
|
end
|
148
147
|
end
|
@@ -1,13 +1,12 @@
|
|
1
|
-
#
|
2
|
-
module Axlsx
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
module Axlsx
|
4
4
|
# The BarChart is a two dimentional barchart that you can add to your worksheet.
|
5
5
|
# @see Worksheet#add_chart
|
6
6
|
# @see Chart#add_series
|
7
7
|
# @see Package#serialize
|
8
8
|
# @see README for an example
|
9
9
|
class BarChart < Chart
|
10
|
-
|
11
10
|
# the category axis
|
12
11
|
# @return [CatAxis]
|
13
12
|
def cat_axis
|
@@ -37,7 +36,7 @@ module Axlsx
|
|
37
36
|
end
|
38
37
|
alias :gapWidth :gap_width
|
39
38
|
|
40
|
-
#grouping for a column, line, or area chart.
|
39
|
+
# grouping for a column, line, or area chart.
|
41
40
|
# must be one of [:percentStacked, :clustered, :standard, :stacked]
|
42
41
|
# @return [Symbol]
|
43
42
|
def grouping
|
@@ -66,7 +65,7 @@ module Axlsx
|
|
66
65
|
# @option options [String] gap_width
|
67
66
|
# @option options [Symbol] shape
|
68
67
|
# @see Chart
|
69
|
-
def initialize(frame, options={})
|
68
|
+
def initialize(frame, options = {})
|
70
69
|
@vary_colors = true
|
71
70
|
@gap_width, @overlap, @shape = nil, nil, nil
|
72
71
|
super(frame, options)
|
@@ -82,7 +81,7 @@ module Axlsx
|
|
82
81
|
end
|
83
82
|
alias :barDir= :bar_dir=
|
84
83
|
|
85
|
-
#grouping for a column, line, or area chart.
|
84
|
+
# grouping for a column, line, or area chart.
|
86
85
|
# must be one of [:percentStacked, :clustered, :standard, :stacked]
|
87
86
|
def grouping=(v)
|
88
87
|
RestrictionValidator.validate "BarChart.grouping", [:percentStacked, :clustered, :standard, :stacked], v
|
@@ -92,13 +91,13 @@ module Axlsx
|
|
92
91
|
# space between bar or column clusters, as a percentage of the bar or column width.
|
93
92
|
def gap_width=(v)
|
94
93
|
RangeValidator.validate "BarChart.gap_width", 0, 500, v
|
95
|
-
@gap_width=
|
94
|
+
@gap_width = v
|
96
95
|
end
|
97
96
|
alias :gapWidth= :gap_width=
|
98
97
|
|
99
98
|
def overlap=(v)
|
100
99
|
RangeValidator.validate "BarChart.overlap", -100, 100, v
|
101
|
-
@overlap=
|
100
|
+
@overlap = v
|
102
101
|
end
|
103
102
|
|
104
103
|
# The shape of the bars or columns
|
@@ -111,18 +110,18 @@ module Axlsx
|
|
111
110
|
# Serializes the object
|
112
111
|
# @param [String] str
|
113
112
|
# @return [String]
|
114
|
-
def to_xml_string(str = '')
|
113
|
+
def to_xml_string(str = +'')
|
115
114
|
super(str) do
|
116
115
|
str << '<c:barChart>'
|
117
|
-
str <<
|
118
|
-
str <<
|
119
|
-
str <<
|
116
|
+
str << '<c:barDir val="' << bar_dir.to_s << '"/>'
|
117
|
+
str << '<c:grouping val="' << grouping.to_s << '"/>'
|
118
|
+
str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
|
120
119
|
@series.each { |ser| ser.to_xml_string(str) }
|
121
120
|
@d_lbls.to_xml_string(str) if @d_lbls
|
122
|
-
str <<
|
123
|
-
str <<
|
124
|
-
str <<
|
125
|
-
axes.to_xml_string(str, :
|
121
|
+
str << '<c:overlap val="' << @overlap.to_s << '"/>' unless @overlap.nil?
|
122
|
+
str << '<c:gapWidth val="' << @gap_width.to_s << '"/>' unless @gap_width.nil?
|
123
|
+
str << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
|
124
|
+
axes.to_xml_string(str, ids: true)
|
126
125
|
str << '</c:barChart>'
|
127
126
|
axes.to_xml_string(str)
|
128
127
|
end
|
@@ -132,7 +131,7 @@ module Axlsx
|
|
132
131
|
# category axes specified via axes[:val_axes] and axes[:cat_axis]
|
133
132
|
# @return [Axes]
|
134
133
|
def axes
|
135
|
-
|
134
|
+
@axes ||= Axes.new(cat_axis: CatAxis, val_axis: ValAxis)
|
136
135
|
end
|
137
136
|
end
|
138
137
|
end
|
@@ -1,12 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Axlsx
|
3
4
|
# A BarSeries defines the title, data and labels for bar charts
|
4
5
|
# @note The recommended way to manage series is to use Chart#add_series
|
5
6
|
# @see Worksheet#add_chart
|
6
7
|
# @see Chart#add_series
|
7
8
|
class BarSeries < Series
|
8
|
-
|
9
|
-
|
10
9
|
# The data for this series.
|
11
10
|
# @return [NumDataSource]
|
12
11
|
attr_reader :data
|
@@ -35,11 +34,11 @@ module Axlsx
|
|
35
34
|
# @option options [String] colors an array of colors to use when rendering each data point
|
36
35
|
# @option options [String] series_color a color to use when rendering series
|
37
36
|
# @param [Chart] chart
|
38
|
-
def initialize(chart, options={})
|
37
|
+
def initialize(chart, options = {})
|
39
38
|
@shape = :box
|
40
39
|
@colors = []
|
41
40
|
super(chart, options)
|
42
|
-
self.labels = AxDataSource.new({:
|
41
|
+
self.labels = AxDataSource.new({ data: options[:labels] }) unless options[:labels].nil?
|
43
42
|
self.data = NumDataSource.new(options) unless options[:data].nil?
|
44
43
|
end
|
45
44
|
|
@@ -59,20 +58,19 @@ module Axlsx
|
|
59
58
|
# Serializes the object
|
60
59
|
# @param [String] str
|
61
60
|
# @return [String]
|
62
|
-
def to_xml_string(str = '')
|
61
|
+
def to_xml_string(str = +'')
|
63
62
|
super(str) do
|
64
|
-
|
65
63
|
colors.each_with_index do |c, index|
|
66
64
|
str << '<c:dPt>'
|
67
|
-
str <<
|
65
|
+
str << '<c:idx val="' << index.to_s << '"/>'
|
68
66
|
str << '<c:spPr><a:solidFill>'
|
69
|
-
str <<
|
67
|
+
str << '<a:srgbClr val="' << c << '"/>'
|
70
68
|
str << '</a:solidFill></c:spPr></c:dPt>'
|
71
69
|
end
|
72
70
|
|
73
71
|
if series_color
|
74
72
|
str << '<c:spPr><a:solidFill>'
|
75
|
-
str <<
|
73
|
+
str << '<a:srgbClr val="' << series_color << '"/>'
|
76
74
|
str << '</a:solidFill>'
|
77
75
|
str << '</c:spPr>'
|
78
76
|
end
|
@@ -80,7 +78,7 @@ module Axlsx
|
|
80
78
|
@labels.to_xml_string(str) unless @labels.nil?
|
81
79
|
@data.to_xml_string(str) unless @data.nil?
|
82
80
|
# this is actually only required for shapes other than box
|
83
|
-
str <<
|
81
|
+
str << '<c:shape val="' << shape.to_s << '"></c:shape>'
|
84
82
|
end
|
85
83
|
end
|
86
84
|
|
@@ -91,7 +89,5 @@ module Axlsx
|
|
91
89
|
|
92
90
|
# assigns the labels for this series
|
93
91
|
def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
|
94
|
-
|
95
92
|
end
|
96
|
-
|
97
93
|
end
|
@@ -1,12 +1,11 @@
|
|
1
|
-
#
|
2
|
-
module Axlsx
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
module Axlsx
|
4
4
|
# The BubbleChart allows you to insert a bubble chart into your worksheet
|
5
5
|
# @see Worksheet#add_chart
|
6
6
|
# @see Chart#add_series
|
7
7
|
# @see README for an example
|
8
8
|
class BubbleChart < Chart
|
9
|
-
|
10
9
|
include Axlsx::OptionsParser
|
11
10
|
|
12
11
|
# the x value axis
|
@@ -24,10 +23,10 @@ module Axlsx
|
|
24
23
|
alias :yValAxis :y_val_axis
|
25
24
|
|
26
25
|
# Creates a new bubble chart
|
27
|
-
def initialize(frame, options={})
|
26
|
+
def initialize(frame, options = {})
|
28
27
|
@vary_colors = 0
|
29
28
|
|
30
|
-
|
29
|
+
super(frame, options)
|
31
30
|
@series_type = BubbleSeries
|
32
31
|
@d_lbls = nil
|
33
32
|
parse_options options
|
@@ -36,13 +35,13 @@ module Axlsx
|
|
36
35
|
# Serializes the object
|
37
36
|
# @param [String] str
|
38
37
|
# @return [String]
|
39
|
-
def to_xml_string(str = '')
|
38
|
+
def to_xml_string(str = +'')
|
40
39
|
super(str) do
|
41
40
|
str << '<c:bubbleChart>'
|
42
|
-
str <<
|
41
|
+
str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
|
43
42
|
@series.each { |ser| ser.to_xml_string(str) }
|
44
43
|
d_lbls.to_xml_string(str) if @d_lbls
|
45
|
-
axes.to_xml_string(str, :
|
44
|
+
axes.to_xml_string(str, ids: true)
|
46
45
|
str << '</c:bubbleChart>'
|
47
46
|
axes.to_xml_string(str)
|
48
47
|
end
|
@@ -53,7 +52,7 @@ module Axlsx
|
|
53
52
|
# a y_val_axis
|
54
53
|
# @return [Axes]
|
55
54
|
def axes
|
56
|
-
@axes ||= Axes.new(:
|
55
|
+
@axes ||= Axes.new(x_val_axis: ValAxis, y_val_axis: ValAxis)
|
57
56
|
end
|
58
57
|
end
|
59
58
|
end
|
@@ -1,13 +1,12 @@
|
|
1
|
-
#
|
2
|
-
module Axlsx
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
module Axlsx
|
4
4
|
# A BubbleSeries defines the x/y position and bubble size of data in the chart
|
5
5
|
# @note The recommended way to manage series is to use Chart#add_series
|
6
6
|
# @see Worksheet#add_chart
|
7
7
|
# @see Chart#add_series
|
8
8
|
# @see examples/example.rb
|
9
9
|
class BubbleSeries < Series
|
10
|
-
|
11
10
|
# The x data for this series.
|
12
11
|
# @return [AxDataSource]
|
13
12
|
attr_reader :xData
|
@@ -26,12 +25,12 @@ module Axlsx
|
|
26
25
|
attr_reader :color
|
27
26
|
|
28
27
|
# Creates a new BubbleSeries
|
29
|
-
def initialize(chart, options={})
|
28
|
+
def initialize(chart, options = {})
|
30
29
|
@xData, @yData, @bubbleSize = nil
|
31
30
|
super(chart, options)
|
32
|
-
@xData = AxDataSource.new(:
|
33
|
-
@yData = NumDataSource.new({:
|
34
|
-
@bubbleSize = NumDataSource.new({:
|
31
|
+
@xData = AxDataSource.new(tag_name: :xVal, data: options[:xData]) unless options[:xData].nil?
|
32
|
+
@yData = NumDataSource.new({ tag_name: :yVal, data: options[:yData] }) unless options[:yData].nil?
|
33
|
+
@bubbleSize = NumDataSource.new({ tag_name: :bubbleSize, data: options[:bubbleSize] }) unless options[:bubbleSize].nil?
|
35
34
|
end
|
36
35
|
|
37
36
|
# @see color
|
@@ -42,15 +41,15 @@ module Axlsx
|
|
42
41
|
# Serializes the object
|
43
42
|
# @param [String] str
|
44
43
|
# @return [String]
|
45
|
-
def to_xml_string(str = '')
|
44
|
+
def to_xml_string(str = +'')
|
46
45
|
super(str) do
|
47
46
|
# needs to override the super color here to push in ln/and something else!
|
48
47
|
if color
|
49
48
|
str << '<c:spPr><a:solidFill>'
|
50
|
-
str <<
|
49
|
+
str << '<a:srgbClr val="' << color << '"/>'
|
51
50
|
str << '</a:solidFill>'
|
52
51
|
str << '<a:ln><a:solidFill>'
|
53
|
-
str <<
|
52
|
+
str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
|
54
53
|
str << '</c:spPr>'
|
55
54
|
end
|
56
55
|
@xData.to_xml_string(str) unless @xData.nil?
|
@@ -1,12 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Axlsx
|
3
|
-
#A CatAxis object defines a chart category axis
|
4
|
+
# A CatAxis object defines a chart category axis
|
4
5
|
class CatAxis < Axis
|
5
|
-
|
6
6
|
# Creates a new CatAxis object
|
7
7
|
# @option options [Integer] tick_lbl_skip
|
8
8
|
# @option options [Integer] tick_mark_skip
|
9
|
-
def initialize(options={})
|
9
|
+
def initialize(options = {})
|
10
10
|
@tick_lbl_skip = 1
|
11
11
|
@tick_mark_skip = 1
|
12
12
|
self.auto = 1
|
@@ -42,18 +42,18 @@ module Axlsx
|
|
42
42
|
alias :tickMarkSkip :tick_mark_skip
|
43
43
|
|
44
44
|
# regex for validating label offset
|
45
|
-
LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)
|
45
|
+
LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)/.freeze
|
46
46
|
|
47
47
|
# @see tick_lbl_skip
|
48
|
-
def tick_lbl_skip=(v) Axlsx
|
48
|
+
def tick_lbl_skip=(v) Axlsx.validate_unsigned_int(v); @tick_lbl_skip = v; end
|
49
49
|
alias :tickLblSkip= :tick_lbl_skip=
|
50
50
|
|
51
51
|
# @see tick_mark_skip
|
52
|
-
def tick_mark_skip=(v) Axlsx
|
52
|
+
def tick_mark_skip=(v) Axlsx.validate_unsigned_int(v); @tick_mark_skip = v; end
|
53
53
|
alias :tickMarkSkip= :tick_mark_skip=
|
54
54
|
|
55
55
|
# From the docs: This element specifies that this axis is a date or text axis based on the data that is used for the axis labels, not a specific choice.
|
56
|
-
def auto=(v) Axlsx
|
56
|
+
def auto=(v) Axlsx.validate_boolean(v); @auto = v; end
|
57
57
|
|
58
58
|
# specifies how the perpendicular axis is crossed
|
59
59
|
# must be one of [:ctr, :l, :r]
|
@@ -68,18 +68,15 @@ module Axlsx
|
|
68
68
|
# Serializes the object
|
69
69
|
# @param [String] str
|
70
70
|
# @return [String]
|
71
|
-
def to_xml_string(str = '')
|
71
|
+
def to_xml_string(str = +'')
|
72
72
|
str << '<c:catAx>'
|
73
73
|
super(str)
|
74
|
-
str <<
|
75
|
-
str <<
|
76
|
-
str <<
|
77
|
-
str <<
|
78
|
-
str <<
|
74
|
+
str << '<c:auto val="' << @auto.to_s << '"/>'
|
75
|
+
str << '<c:lblAlgn val="' << @lbl_algn.to_s << '"/>'
|
76
|
+
str << '<c:lblOffset val="' << @lbl_offset.to_i.to_s << '"/>'
|
77
|
+
str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>'
|
78
|
+
str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>'
|
79
79
|
str << '</c:catAx>'
|
80
80
|
end
|
81
|
-
|
82
81
|
end
|
83
|
-
|
84
|
-
|
85
82
|
end
|