axlsx 1.0.18 → 1.1.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/CHANGELOG.md +11 -3
- data/README.md +93 -18
- data/examples/example.csv +1000 -0
- data/examples/example.rb +97 -5
- data/examples/example.xlsx +0 -0
- data/examples/example_streamed.xlsx +0 -0
- data/examples/no-use_autowidth.xlsx +0 -0
- data/examples/shared_strings_example.xlsx +0 -0
- data/lib/axlsx.rb +30 -9
- data/lib/axlsx/content_type/content_type.rb +9 -9
- data/lib/axlsx/content_type/default.rb +9 -6
- data/lib/axlsx/content_type/override.rb +12 -8
- data/lib/axlsx/doc_props/app.rb +37 -40
- data/lib/axlsx/doc_props/core.rb +12 -17
- data/lib/axlsx/drawing/axis.rb +38 -19
- data/lib/axlsx/drawing/bar_3D_chart.rb +33 -32
- data/lib/axlsx/drawing/bar_series.rb +13 -14
- data/lib/axlsx/drawing/cat_axis.rb +15 -14
- data/lib/axlsx/drawing/cat_axis_data.rb +16 -18
- data/lib/axlsx/drawing/chart.rb +37 -38
- data/lib/axlsx/drawing/drawing.rb +15 -12
- data/lib/axlsx/drawing/graphic_frame.rb +21 -21
- data/lib/axlsx/drawing/hyperlink.rb +12 -11
- data/lib/axlsx/drawing/line_3D_chart.rb +30 -28
- data/lib/axlsx/drawing/line_series.rb +11 -11
- data/lib/axlsx/drawing/marker.rb +10 -8
- data/lib/axlsx/drawing/named_axis_data.rb +36 -0
- data/lib/axlsx/drawing/one_cell_anchor.rb +17 -16
- data/lib/axlsx/drawing/pic.rb +24 -37
- data/lib/axlsx/drawing/picture_locking.rb +21 -18
- data/lib/axlsx/drawing/pie_3D_chart.rb +10 -8
- data/lib/axlsx/drawing/pie_series.rb +15 -12
- data/lib/axlsx/drawing/scaling.rb +10 -10
- data/lib/axlsx/drawing/scatter_chart.rb +69 -0
- data/lib/axlsx/drawing/scatter_series.rb +39 -0
- data/lib/axlsx/drawing/ser_axis.rb +10 -10
- data/lib/axlsx/drawing/series.rb +15 -15
- data/lib/axlsx/drawing/series_title.rb +14 -14
- data/lib/axlsx/drawing/title.rb +26 -26
- data/lib/axlsx/drawing/two_cell_anchor.rb +18 -20
- data/lib/axlsx/drawing/val_axis.rb +8 -7
- data/lib/axlsx/drawing/val_axis_data.rb +17 -17
- data/lib/axlsx/drawing/view_3D.rb +22 -20
- data/lib/axlsx/package.rb +32 -15
- data/lib/axlsx/rels/relationship.rb +9 -6
- data/lib/axlsx/rels/relationships.rb +7 -1
- data/lib/axlsx/stylesheet/#num_fmt.rb# +69 -0
- data/lib/axlsx/stylesheet/border.rb +27 -23
- data/lib/axlsx/stylesheet/border_pr.rb +16 -15
- data/lib/axlsx/stylesheet/cell_alignment.rb +23 -21
- data/lib/axlsx/stylesheet/cell_protection.rb +10 -7
- data/lib/axlsx/stylesheet/cell_style.rb +8 -5
- data/lib/axlsx/stylesheet/color.rb +20 -14
- data/lib/axlsx/stylesheet/fill.rb +7 -5
- data/lib/axlsx/stylesheet/font.rb +14 -14
- data/lib/axlsx/stylesheet/gradient_fill.rb +19 -16
- data/lib/axlsx/stylesheet/gradient_stop.rb +9 -5
- data/lib/axlsx/stylesheet/num_fmt.rb +12 -6
- data/lib/axlsx/stylesheet/pattern_fill.rb +25 -10
- data/lib/axlsx/stylesheet/styles.rb +41 -32
- data/lib/axlsx/stylesheet/table_style.rb +9 -4
- data/lib/axlsx/stylesheet/table_style_element.rb +10 -7
- data/lib/axlsx/stylesheet/table_styles.rb +11 -8
- data/lib/axlsx/stylesheet/xf.rb +29 -25
- data/lib/axlsx/util/constants.rb +4 -0
- data/lib/axlsx/util/simple_typed_list.rb +18 -9
- data/lib/axlsx/util/validators.rb +13 -6
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/shared_strings_table.rb +19 -21
- data/lib/axlsx/workbook/workbook.rb +43 -19
- data/lib/axlsx/workbook/worksheet/cell.rb +93 -91
- data/lib/axlsx/workbook/worksheet/col.rb +114 -0
- data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +16 -13
- data/lib/axlsx/workbook/worksheet/row.rb +13 -13
- data/lib/axlsx/workbook/worksheet/table.rb +96 -0
- data/lib/axlsx/workbook/worksheet/table.rb~ +97 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +152 -118
- data/lib/schema/dc.xsd +5 -5
- data/lib/schema/dcmitype.xsd +5 -3
- data/lib/schema/dcterms.xsd +15 -15
- data/lib/schema/opc-coreProperties.xsd +6 -2
- data/lib/schema/xml.xsd +7 -8
- data/test/#benchmark.txt# +7 -0
- data/test/#tc_helper.rb# +3 -0
- data/test/benchmark.rb +81 -0
- data/test/benchmark.rb~ +0 -0
- data/test/benchmark.txt +6 -0
- data/test/benchmark.txt~ +6 -0
- data/test/content_type/tc_content_type.rb +30 -32
- data/test/content_type/tc_default.rb +8 -23
- data/test/content_type/tc_override.rb +7 -21
- data/test/doc_props/tc_app.rb +2 -8
- data/test/doc_props/tc_core.rb +6 -7
- data/test/drawing/tc_axis.rb +7 -3
- data/test/drawing/tc_bar_3D_chart.rb +6 -7
- data/test/drawing/tc_bar_series.rb +4 -5
- data/test/drawing/tc_cat_axis.rb +2 -3
- data/test/drawing/tc_cat_axis_data.rb +2 -3
- data/test/drawing/tc_chart.rb +11 -12
- data/test/drawing/tc_drawing.rb +7 -8
- data/test/drawing/tc_graphic_frame.rb +3 -4
- data/test/drawing/tc_hyperlink.rb +2 -3
- data/test/drawing/tc_line_3d_chart.rb +5 -6
- data/test/drawing/tc_line_series.rb +3 -4
- data/test/drawing/tc_marker.rb +3 -4
- data/test/drawing/tc_one_cell_anchor.rb +6 -7
- data/test/drawing/tc_pic.rb +8 -9
- data/test/drawing/tc_picture_locking.rb +2 -3
- data/test/drawing/tc_pie_3D_chart.rb +5 -6
- data/test/drawing/tc_pie_series.rb +4 -5
- data/test/drawing/tc_scaling.rb +3 -4
- data/test/drawing/tc_scatter_chart.rb +43 -0
- data/test/drawing/tc_scatter_series.rb +20 -0
- data/test/drawing/tc_ser_axis.rb +2 -3
- data/test/drawing/tc_series.rb +4 -5
- data/test/drawing/tc_series_title.rb +4 -5
- data/test/drawing/tc_title.rb +4 -5
- data/test/drawing/tc_two_cell_anchor.rb +4 -5
- data/test/drawing/tc_val_axis.rb +2 -3
- data/test/drawing/tc_val_axis_data.rb +2 -3
- data/test/drawing/tc_view_3D.rb +6 -7
- data/test/example.csv +1000 -0
- data/test/example.xlsx +0 -0
- data/test/example_streamed.xlsx +0 -0
- data/test/profile.rb +33 -0
- data/test/rels/tc_relationship.rb +5 -6
- data/test/rels/tc_relationships.rb +4 -5
- data/test/stylesheet/tc_border.rb +3 -4
- data/test/stylesheet/tc_border_pr.rb +3 -4
- data/test/stylesheet/tc_cell_alignment.rb +4 -5
- data/test/stylesheet/tc_cell_protection.rb +2 -3
- data/test/stylesheet/tc_cell_style.rb +2 -3
- data/test/stylesheet/tc_color.rb +2 -3
- data/test/stylesheet/tc_fill.rb +1 -2
- data/test/stylesheet/tc_font.rb +5 -6
- data/test/stylesheet/tc_gradient_fill.rb +1 -2
- data/test/stylesheet/tc_gradient_stop.rb +1 -2
- data/test/stylesheet/tc_num_fmt.rb +1 -2
- data/test/stylesheet/tc_pattern_fill.rb +3 -4
- data/test/stylesheet/tc_styles.rb +15 -9
- data/test/stylesheet/tc_table_style.rb +2 -3
- data/test/stylesheet/tc_table_style_element.rb +2 -3
- data/test/stylesheet/tc_table_styles.rb +3 -4
- data/test/stylesheet/tc_xf.rb +16 -17
- data/test/tc_axlsx.rb +39 -0
- data/test/tc_axlsx.rb~ +0 -0
- data/test/tc_helper.rb +3 -0
- data/test/tc_helper.rb~ +3 -0
- data/test/tc_package.rb +13 -10
- data/test/util/tc_simple_typed_list.rb +8 -9
- data/test/util/tc_validators.rb +7 -8
- data/test/workbook/tc_shared_strings_table.rb +5 -6
- data/test/workbook/tc_workbook.rb +24 -6
- data/test/workbook/worksheet/table/tc_table.rb +71 -0
- data/test/workbook/worksheet/table/tc_table.rb~ +72 -0
- data/test/workbook/worksheet/tc_cell.rb +24 -10
- data/test/workbook/worksheet/tc_col.rb +59 -0
- data/test/workbook/worksheet/tc_col.rb~ +10 -0
- data/test/workbook/worksheet/tc_date_time_converter.rb +1 -2
- data/test/workbook/worksheet/tc_page_margins.rb +6 -9
- data/test/workbook/worksheet/tc_row.rb +26 -12
- data/test/workbook/worksheet/tc_worksheet.rb +134 -68
- metadata +150 -90
- data/test/drawing/tc_hyperlink.rb~ +0 -71
- data/test/workbook/tc_shared_strings_table.rb~ +0 -8
- data/test/workbook/worksheet/tc_date_time_converter.rb~ +0 -69
data/lib/axlsx/doc_props/core.rb
CHANGED
|
@@ -7,29 +7,24 @@ module Axlsx
|
|
|
7
7
|
# The author of the document. By default this is 'axlsx'
|
|
8
8
|
# @return [String]
|
|
9
9
|
attr_accessor :creator
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
# Creates a new Core object.
|
|
12
12
|
# @option options [String] creator
|
|
13
13
|
def initialize(options={})
|
|
14
|
-
@creator = options[:creator] || 'axlsx'
|
|
14
|
+
@creator = options[:creator] || 'axlsx'
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
#
|
|
17
|
+
# serializes the core.xml document
|
|
18
18
|
# @return [String]
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
xml['dcterms'].created Time.now.strftime('%Y-%m-%dT%H:%M:%S'), :'xsi:type'=>"dcterms:W3CDTF"
|
|
29
|
-
xml['cp'].revision 0
|
|
30
|
-
}
|
|
31
|
-
end
|
|
32
|
-
builder.to_xml(:save_with => 0)
|
|
19
|
+
def to_xml_string(str = '')
|
|
20
|
+
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
|
21
|
+
str << '<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" '
|
|
22
|
+
str << 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" '
|
|
23
|
+
str << 'xmlns:xsi="' << CORE_NS_XSI << '">'
|
|
24
|
+
str << '<dc:creator>' << self.creator << '</dc:creator>'
|
|
25
|
+
str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << Time.now.strftime('%Y-%m-%dT%H:%M:%S') << '</dcterms:created>'
|
|
26
|
+
str << '<cp:revision>0</cp:revision>'
|
|
27
|
+
str << '</cp:coreProperties>'
|
|
33
28
|
end
|
|
34
29
|
end
|
|
35
30
|
end
|
data/lib/axlsx/drawing/axis.rb
CHANGED
|
@@ -3,7 +3,7 @@ module Axlsx
|
|
|
3
3
|
# the access class defines common properties and values for a chart axis.
|
|
4
4
|
class Axis
|
|
5
5
|
|
|
6
|
-
# the id of the axis.
|
|
6
|
+
# the id of the axis.
|
|
7
7
|
# @return [Integer]
|
|
8
8
|
attr_reader :axId
|
|
9
9
|
|
|
@@ -15,7 +15,7 @@ module Axlsx
|
|
|
15
15
|
# @see Scaling
|
|
16
16
|
# @return [Scaling]
|
|
17
17
|
attr_reader :scaling
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
# The position of the axis
|
|
20
20
|
# must be one of [:l, :r, :t, :b]
|
|
21
21
|
# @return [Symbol]
|
|
@@ -34,7 +34,11 @@ module Axlsx
|
|
|
34
34
|
# specifies how the perpendicular axis is crossed
|
|
35
35
|
# must be one of [:autoZero, :min, :max]
|
|
36
36
|
# @return [Symbol]
|
|
37
|
-
attr_reader :crosses
|
|
37
|
+
attr_reader :crosses
|
|
38
|
+
|
|
39
|
+
# specifies if gridlines should be shown in the chart
|
|
40
|
+
# @return [Boolean]
|
|
41
|
+
attr_reader :gridlines
|
|
38
42
|
|
|
39
43
|
# Creates an Axis object
|
|
40
44
|
# @param [Integer] axId the id of this axis
|
|
@@ -49,11 +53,12 @@ module Axlsx
|
|
|
49
53
|
@axId = axId
|
|
50
54
|
@crossAx = crossAx
|
|
51
55
|
@format_code = "General"
|
|
52
|
-
@scaling = Scaling.new(:orientation=>:minMax)
|
|
56
|
+
@scaling = Scaling.new(:orientation=>:minMax)
|
|
53
57
|
self.axPos = :b
|
|
54
58
|
self.tickLblPos = :nextTo
|
|
55
59
|
self.format_code = "General"
|
|
56
60
|
self.crosses = :autoZero
|
|
61
|
+
self.gridlines = true
|
|
57
62
|
options.each do |o|
|
|
58
63
|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
|
59
64
|
end
|
|
@@ -70,25 +75,39 @@ module Axlsx
|
|
|
70
75
|
# default :General
|
|
71
76
|
def format_code=(v) Axlsx::validate_string(v); @format_code = v; end
|
|
72
77
|
|
|
78
|
+
# Specify if gridlines should be shown for this axis
|
|
79
|
+
# default true
|
|
80
|
+
def gridlines=(v) Axlsx::validate_boolean(v); @gridlines = v; end
|
|
81
|
+
|
|
73
82
|
# specifies how the perpendicular axis is crossed
|
|
74
83
|
# must be one of [:autoZero, :min, :max]
|
|
75
84
|
def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end
|
|
76
85
|
|
|
77
|
-
|
|
78
|
-
#
|
|
86
|
+
|
|
87
|
+
# Serializes the object
|
|
88
|
+
# @param [String] str
|
|
79
89
|
# @return [String]
|
|
80
|
-
def
|
|
81
|
-
|
|
82
|
-
@scaling.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
def to_xml_string(str = '')
|
|
91
|
+
str << '<c:axId val="' << @axId.to_s << '"/>'
|
|
92
|
+
@scaling.to_xml_string str
|
|
93
|
+
str << '<c:delete val="0"/>'
|
|
94
|
+
str << '<c:axPos val="' << @axPos.to_s << '"/>'
|
|
95
|
+
str << '<c:majorGridlines>'
|
|
96
|
+
if self.gridlines == false
|
|
97
|
+
str << '<c:spPr>'
|
|
98
|
+
str << '<a:ln>'
|
|
99
|
+
str << '<a:noFill/>'
|
|
100
|
+
str << '</a:ln>'
|
|
101
|
+
str << '</c:spPr>'
|
|
102
|
+
end
|
|
103
|
+
str << '</c:majorGridlines>'
|
|
104
|
+
str << '<c:numFmt formatCode="' << @format_code << '" sourceLinked="1"/>'
|
|
105
|
+
str << '<c:majorTickMark val="none"/>'
|
|
106
|
+
str << '<c:minorTickMark val="none"/>'
|
|
107
|
+
str << '<c:tickLblPos val="' << @tickLblPos.to_s << '"/>'
|
|
108
|
+
str << '<c:crossAx val="' << @crossAx.to_s << '"/>'
|
|
109
|
+
str << '<c:crosses val="' << @crosses.to_s << '"/>'
|
|
110
|
+
end
|
|
111
|
+
|
|
93
112
|
end
|
|
94
113
|
end
|
|
@@ -41,7 +41,7 @@ module Axlsx
|
|
|
41
41
|
|
|
42
42
|
# validation regex for gap amount percent
|
|
43
43
|
GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
# Creates a new bar chart object
|
|
46
46
|
# @param [GraphicFrame] frame The workbook that owns this chart.
|
|
47
47
|
# @option options [Cell, String] title
|
|
@@ -67,14 +67,14 @@ module Axlsx
|
|
|
67
67
|
@valAxId = rand(8 ** 8)
|
|
68
68
|
@catAxis = CatAxis.new(@catAxId, @valAxId)
|
|
69
69
|
@valAxis = ValAxis.new(@valAxId, @catAxId, :tickLblPos => :low)
|
|
70
|
-
super(frame, options)
|
|
70
|
+
super(frame, options)
|
|
71
71
|
@series_type = BarSeries
|
|
72
72
|
@view3D = View3D.new({:rAngAx=>1}.merge(options))
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
# The direction of the bars in the chart
|
|
76
76
|
# must be one of [:bar, :col]
|
|
77
|
-
def barDir=(v)
|
|
77
|
+
def barDir=(v)
|
|
78
78
|
RestrictionValidator.validate "Bar3DChart.barDir", [:bar, :col], v
|
|
79
79
|
@barDir = v
|
|
80
80
|
end
|
|
@@ -100,38 +100,39 @@ module Axlsx
|
|
|
100
100
|
|
|
101
101
|
# The shabe of the bars or columns
|
|
102
102
|
# must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]
|
|
103
|
-
def shape=(v)
|
|
103
|
+
def shape=(v)
|
|
104
104
|
RestrictionValidator.validate "Bar3DChart.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
|
|
105
105
|
@shape = v
|
|
106
106
|
end
|
|
107
|
-
|
|
108
|
-
# Serializes the
|
|
107
|
+
|
|
108
|
+
# Serializes the object
|
|
109
|
+
# @param [String] str
|
|
109
110
|
# @return [String]
|
|
110
|
-
def
|
|
111
|
-
super() do |
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
@catAxis.
|
|
133
|
-
@valAxis.
|
|
111
|
+
def to_xml_string(str = '')
|
|
112
|
+
super(str) do |str_inner|
|
|
113
|
+
str_inner << '<c:bar3DChart>'
|
|
114
|
+
str_inner << '<c:barDir val="' << barDir.to_s << '"/>'
|
|
115
|
+
str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
|
|
116
|
+
str_inner << '<c:varyColors val="1"/>'
|
|
117
|
+
@series.each { |ser| ser.to_xml_string(str_inner) }
|
|
118
|
+
str_inner << '<c:dLbls>'
|
|
119
|
+
str_inner << '<c:showLegendKey val="0"/>'
|
|
120
|
+
str_inner << '<c:showVal val="0"/>'
|
|
121
|
+
str_inner << '<c:showCatName val="0"/>'
|
|
122
|
+
str_inner << '<c:showSerName val="0"/>'
|
|
123
|
+
str_inner << '<c:showPercent val="0"/>'
|
|
124
|
+
str_inner << '<c:showBubbleSize val="0"/>'
|
|
125
|
+
str_inner << '</c:dLbls>'
|
|
126
|
+
str_inner << '<c:gapWidth val="' << @gapWidth.to_s << '"/>' unless @gapWidth.nil?
|
|
127
|
+
str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
|
|
128
|
+
str_inner << '<c:shape val="' << @shape.to_s << '"/>' unless @shape.nil?
|
|
129
|
+
str_inner << '<c:axId val="' << @catAxId.to_s << '"/>'
|
|
130
|
+
str_inner << '<c:axId val="' << @valAxId.to_s << '"/>'
|
|
131
|
+
str_inner << '<c:axId val="0"/>'
|
|
132
|
+
str_inner << '</c:bar3DChart>'
|
|
133
|
+
@catAxis.to_xml_string str_inner
|
|
134
|
+
@valAxis.to_xml_string str_inner
|
|
134
135
|
end
|
|
135
|
-
end
|
|
136
|
-
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
137
138
|
end
|
|
@@ -6,8 +6,8 @@ module Axlsx
|
|
|
6
6
|
# @see Chart#add_series
|
|
7
7
|
class BarSeries < Series
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
# The data for this series.
|
|
9
|
+
|
|
10
|
+
# The data for this series.
|
|
11
11
|
# @return [Array, SimpleTypedList]
|
|
12
12
|
attr_reader :data
|
|
13
13
|
|
|
@@ -31,28 +31,27 @@ module Axlsx
|
|
|
31
31
|
super(chart, options)
|
|
32
32
|
self.labels = CatAxisData.new(options[:labels]) unless options[:labels].nil?
|
|
33
33
|
self.data = ValAxisData.new(options[:data]) unless options[:data].nil?
|
|
34
|
-
end
|
|
34
|
+
end
|
|
35
35
|
|
|
36
36
|
# The shabe of the bars or columns
|
|
37
37
|
# must be one of [:percentStacked, :clustered, :standard, :stacked]
|
|
38
|
-
def shape=(v)
|
|
38
|
+
def shape=(v)
|
|
39
39
|
RestrictionValidator.validate "BarSeries.shape", [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax], v
|
|
40
40
|
@shape = v
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
# Serializes the
|
|
44
|
-
# @param [
|
|
43
|
+
# Serializes the object
|
|
44
|
+
# @param [String] str
|
|
45
45
|
# @return [String]
|
|
46
|
-
def
|
|
47
|
-
super(
|
|
48
|
-
@labels.
|
|
49
|
-
@data.
|
|
50
|
-
|
|
51
|
-
end
|
|
46
|
+
def to_xml_string(str = '')
|
|
47
|
+
super(str) do |str_inner|
|
|
48
|
+
@labels.to_xml_string(str_inner) unless @labels.nil?
|
|
49
|
+
@data.to_xml_string(str_inner) unless @data.nil?
|
|
50
|
+
str_inner << '<shape val="' << @shape.to_s << '"/>'
|
|
51
|
+
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
private
|
|
54
|
+
private
|
|
56
55
|
|
|
57
56
|
# assigns the data for this series
|
|
58
57
|
def data=(v) DataTypeValidator.validate "Series.data", [SimpleTypedList], v; @data = v; end
|
|
@@ -10,7 +10,7 @@ module Axlsx
|
|
|
10
10
|
# specifies how the perpendicular axis is crossed
|
|
11
11
|
# must be one of [:ctr, :l, :r]
|
|
12
12
|
# @return [Symbol]
|
|
13
|
-
attr_reader :lblAlgn
|
|
13
|
+
attr_reader :lblAlgn
|
|
14
14
|
|
|
15
15
|
# The offset of the labels
|
|
16
16
|
# must be between a string between 0 and 1000
|
|
@@ -20,7 +20,7 @@ module Axlsx
|
|
|
20
20
|
# regex for validating label offset
|
|
21
21
|
LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)%/
|
|
22
22
|
|
|
23
|
-
# Creates a new CatAxis object
|
|
23
|
+
# Creates a new CatAxis object
|
|
24
24
|
# @param [Integer] axId the id of this axis. Inherited
|
|
25
25
|
# @param [Integer] crossAx the id of the perpendicular axis. Inherited
|
|
26
26
|
# @option options [Symbol] axPos. Inherited
|
|
@@ -28,13 +28,13 @@ module Axlsx
|
|
|
28
28
|
# @option options [Symbol] crosses. Inherited
|
|
29
29
|
# @option options [Boolean] auto
|
|
30
30
|
# @option options [Symbol] lblAlgn
|
|
31
|
-
# @option options [Integer] lblOffset
|
|
31
|
+
# @option options [Integer] lblOffset
|
|
32
32
|
def initialize(axId, crossAx, options={})
|
|
33
33
|
self.auto = 1
|
|
34
34
|
self.lblAlgn = :ctr
|
|
35
35
|
self.lblOffset = "100%"
|
|
36
36
|
super(axId, crossAx, options)
|
|
37
|
-
end
|
|
37
|
+
end
|
|
38
38
|
|
|
39
39
|
# 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.
|
|
40
40
|
def auto=(v) Axlsx::validate_boolean(v); @auto = v; end
|
|
@@ -47,18 +47,19 @@ module Axlsx
|
|
|
47
47
|
# must be between a string between 0 and 1000
|
|
48
48
|
def lblOffset=(v) RegexValidator.validate "#{self.class}.lblOffset", LBL_OFFSET_REGEX, v; @lblOffset = v; end
|
|
49
49
|
|
|
50
|
-
# Serializes the
|
|
51
|
-
# @param [
|
|
50
|
+
# Serializes the object
|
|
51
|
+
# @param [String] str
|
|
52
52
|
# @return [String]
|
|
53
|
-
def
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
def to_xml_string(str = '')
|
|
54
|
+
str << '<c:catAx>'
|
|
55
|
+
super(str)
|
|
56
|
+
str << '<c:auto val="' << @auto.to_s << '"/>'
|
|
57
|
+
str << '<c:lblAlgn val="' << @lblAlgn.to_s << '"/>'
|
|
58
|
+
str << '<c:lblOffset val="' << @lblOffset.to_s << '"/>'
|
|
59
|
+
str << '</c:catAx>'
|
|
60
60
|
end
|
|
61
|
+
|
|
61
62
|
end
|
|
62
|
-
|
|
63
|
+
|
|
63
64
|
|
|
64
65
|
end
|
|
@@ -11,26 +11,24 @@ module Axlsx
|
|
|
11
11
|
data.each { |i| @list << i } if data.is_a?(SimpleTypedList)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
# Serializes the
|
|
15
|
-
# @param [
|
|
14
|
+
# Serializes the object
|
|
15
|
+
# @param [String] str
|
|
16
16
|
# @return [String]
|
|
17
|
-
def
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
}
|
|
17
|
+
def to_xml_string(str = '')
|
|
18
|
+
str << '<c:cat>'
|
|
19
|
+
str << '<c:strRef>'
|
|
20
|
+
str << '<c:f>' << Axlsx::cell_range(@list) << '</c:f>'
|
|
21
|
+
str << '<c:strCache>'
|
|
22
|
+
str << '<c:ptCount val="' << size.to_s << '"/>'
|
|
23
|
+
each_with_index do |item, index|
|
|
24
|
+
v = item.is_a?(Cell) ? item.value.to_s : item
|
|
25
|
+
str << '<c:pt idx="' << index.to_s << '"><c:v>' << v << '</c:v></c:pt>'
|
|
26
|
+
end
|
|
27
|
+
str << '</c:strCache>'
|
|
28
|
+
str << '</c:strRef>'
|
|
29
|
+
str << '</c:cat>'
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
end
|
|
35
|
-
|
|
33
|
+
|
|
36
34
|
end
|
data/lib/axlsx/drawing/chart.rb
CHANGED
|
@@ -28,7 +28,7 @@ module Axlsx
|
|
|
28
28
|
# @return [Title]
|
|
29
29
|
attr_reader :title
|
|
30
30
|
|
|
31
|
-
# The style for the chart.
|
|
31
|
+
# The style for the chart.
|
|
32
32
|
# see ECMA Part 1 §21.2.2.196
|
|
33
33
|
# @return [Integer]
|
|
34
34
|
attr_reader :style
|
|
@@ -36,13 +36,14 @@ module Axlsx
|
|
|
36
36
|
# Show the legend in the chart
|
|
37
37
|
# @return [Boolean]
|
|
38
38
|
attr_reader :show_legend
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
# Creates a new chart object
|
|
41
41
|
# @param [GraphicalFrame] frame The frame that holds this chart.
|
|
42
42
|
# @option options [Cell, String] title
|
|
43
43
|
# @option options [Boolean] show_legend
|
|
44
44
|
def initialize(frame, options={})
|
|
45
45
|
@style = 2
|
|
46
|
+
@view3D = nil
|
|
46
47
|
@graphic_frame=frame
|
|
47
48
|
@graphic_frame.anchor.drawing.worksheet.workbook.charts << self
|
|
48
49
|
@series = SimpleTypedList.new Series
|
|
@@ -72,7 +73,7 @@ module Axlsx
|
|
|
72
73
|
# The title object for the chart.
|
|
73
74
|
# @param [String, Cell] v
|
|
74
75
|
# @return [Title]
|
|
75
|
-
def title=(v)
|
|
76
|
+
def title=(v)
|
|
76
77
|
DataTypeValidator.validate "#{self.class}.title", [String, Cell], v
|
|
77
78
|
if v.is_a?(String)
|
|
78
79
|
@title.text = v
|
|
@@ -80,14 +81,14 @@ module Axlsx
|
|
|
80
81
|
@title.cell = v
|
|
81
82
|
end
|
|
82
83
|
end
|
|
83
|
-
|
|
84
|
+
|
|
84
85
|
# Show the legend in the chart
|
|
85
86
|
# @param [Boolean] v
|
|
86
87
|
# @return [Boolean]
|
|
87
88
|
def show_legend=(v) Axlsx::validate_boolean(v); @show_legend = v; end
|
|
88
89
|
|
|
89
90
|
|
|
90
|
-
# The style for the chart.
|
|
91
|
+
# The style for the chart.
|
|
91
92
|
# see ECMA Part 1 §21.2.2.196
|
|
92
93
|
# @param [Integer] v must be between 1 and 48
|
|
93
94
|
def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, lambda { |arg| arg >= 1 && arg <= 48 }; @style = v; end
|
|
@@ -112,40 +113,38 @@ module Axlsx
|
|
|
112
113
|
@series.last
|
|
113
114
|
end
|
|
114
115
|
|
|
115
|
-
#
|
|
116
|
-
#
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
xml.plotVisOnly :val => 1
|
|
142
|
-
xml.dispBlanksAs :val => :zero
|
|
143
|
-
xml.showDLblsOverMax :val => 1
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
}
|
|
116
|
+
# Serializes the object
|
|
117
|
+
# @param [String] str
|
|
118
|
+
# @return [String]
|
|
119
|
+
def to_xml_string(str = '')
|
|
120
|
+
str << '<?xml version="1.0" encoding="UTF-8"?>'
|
|
121
|
+
str << '<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '">'
|
|
122
|
+
str << '<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>'
|
|
123
|
+
str << '<c:style val="' << style.to_s << '"/>'
|
|
124
|
+
str << '<c:chart>'
|
|
125
|
+
@title.to_xml_string str
|
|
126
|
+
# do these need the c: namespace as well???
|
|
127
|
+
str << '<c:autoTitleDeleted val="0"/>'
|
|
128
|
+
@view3D.to_xml_string(str) if @view3D
|
|
129
|
+
str << '<c:floor><c:thickness val="0"/></c:floor>'
|
|
130
|
+
str << '<c:sideWall><c:thickness val="0"/></c:sideWall>'
|
|
131
|
+
str << '<c:backWall><c:thickness val="0"/></c:backWall>'
|
|
132
|
+
str << '<c:plotArea>'
|
|
133
|
+
str << '<c:layout/>'
|
|
134
|
+
yield str if block_given?
|
|
135
|
+
str << '</c:plotArea>'
|
|
136
|
+
if @show_legend
|
|
137
|
+
str << '<c:legend>'
|
|
138
|
+
str << '<c:legendPos val="r"/>'
|
|
139
|
+
str << '<c:layout/>'
|
|
140
|
+
str << '<c:overlay val="0"/>'
|
|
141
|
+
str << '</c:legend>'
|
|
147
142
|
end
|
|
148
|
-
|
|
143
|
+
str << '<c:plotVisOnly val="1"/>'
|
|
144
|
+
str << '<c:dispBlanksAs val="zero"/>'
|
|
145
|
+
str << '<c:showDLblsOverMax val="1"/>'
|
|
146
|
+
str << '</c:chart>'
|
|
147
|
+
str << '</c:chartSpace>'
|
|
149
148
|
end
|
|
150
149
|
|
|
151
150
|
# This is a short cut method to set the start anchor position
|