axlsx 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +13 -0
- data/lib/axlsx.rb +38 -0
- data/lib/axlsx/content_type/content_type.rb +23 -0
- data/lib/axlsx/content_type/default.rb +32 -0
- data/lib/axlsx/content_type/override.rb +30 -0
- data/lib/axlsx/doc_props/app.rb +148 -0
- data/lib/axlsx/doc_props/core.rb +34 -0
- data/lib/axlsx/drawing/axis.rb +78 -0
- data/lib/axlsx/drawing/bar_3D_chart.rb +138 -0
- data/lib/axlsx/drawing/bar_series.rb +91 -0
- data/lib/axlsx/drawing/cat_axis.rb +58 -0
- data/lib/axlsx/drawing/chart.rb +120 -0
- data/lib/axlsx/drawing/drawing.rb +121 -0
- data/lib/axlsx/drawing/graphic_frame.rb +55 -0
- data/lib/axlsx/drawing/marker.rb +57 -0
- data/lib/axlsx/drawing/pie_3D_chart.rb +59 -0
- data/lib/axlsx/drawing/pie_series.rb +88 -0
- data/lib/axlsx/drawing/scaling.rb +53 -0
- data/lib/axlsx/drawing/series.rb +70 -0
- data/lib/axlsx/drawing/title.rb +69 -0
- data/lib/axlsx/drawing/two_cell_anchor.rb +88 -0
- data/lib/axlsx/drawing/val_axis.rb +34 -0
- data/lib/axlsx/drawing/view_3D.rb +72 -0
- data/lib/axlsx/package.rb +181 -0
- data/lib/axlsx/rels/relationship.rb +43 -0
- data/lib/axlsx/rels/relationships.rb +25 -0
- data/lib/axlsx/stylesheet/border.rb +52 -0
- data/lib/axlsx/stylesheet/border_pr.rb +65 -0
- data/lib/axlsx/stylesheet/cell_alignment.rb +96 -0
- data/lib/axlsx/stylesheet/cell_protection.rb +33 -0
- data/lib/axlsx/stylesheet/cell_style.rb +60 -0
- data/lib/axlsx/stylesheet/color.rb +57 -0
- data/lib/axlsx/stylesheet/fill.rb +31 -0
- data/lib/axlsx/stylesheet/font.rb +128 -0
- data/lib/axlsx/stylesheet/gradient_fill.rb +70 -0
- data/lib/axlsx/stylesheet/gradient_stop.rb +31 -0
- data/lib/axlsx/stylesheet/num_fmt.rb +61 -0
- data/lib/axlsx/stylesheet/pattern_fill.rb +64 -0
- data/lib/axlsx/stylesheet/styles.rb +296 -0
- data/lib/axlsx/stylesheet/table_style.rb +44 -0
- data/lib/axlsx/stylesheet/table_style_element.rb +66 -0
- data/lib/axlsx/stylesheet/table_styles.rb +39 -0
- data/lib/axlsx/stylesheet/xf.rb +117 -0
- data/lib/axlsx/util/constants.rb +189 -0
- data/lib/axlsx/util/simple_typed_list.rb +150 -0
- data/lib/axlsx/util/validators.rb +132 -0
- data/lib/axlsx/workbook/workbook.rb +130 -0
- data/lib/axlsx/workbook/worksheet/cell.rb +184 -0
- data/lib/axlsx/workbook/worksheet/row.rb +92 -0
- data/lib/axlsx/workbook/worksheet/worksheet.rb +194 -0
- data/lib/schema/dc.xsd +118 -0
- data/lib/schema/dcmitype.xsd +50 -0
- data/lib/schema/dcterms.xsd +331 -0
- data/lib/schema/dml-chart.xsd +1499 -0
- data/lib/schema/dml-chartDrawing.xsd +146 -0
- data/lib/schema/dml-compatibility.xsd +14 -0
- data/lib/schema/dml-diagram.xsd +1091 -0
- data/lib/schema/dml-lockedCanvas.xsd +11 -0
- data/lib/schema/dml-main.xsd +3048 -0
- data/lib/schema/dml-picture.xsd +23 -0
- data/lib/schema/dml-spreadsheetDrawing.xsd +185 -0
- data/lib/schema/dml-wordprocessingDrawing.xsd +185 -0
- data/lib/schema/opc-contentTypes.xsd +42 -0
- data/lib/schema/opc-coreProperties.xsd +50 -0
- data/lib/schema/opc-digSig.xsd +49 -0
- data/lib/schema/opc-relationships.xsd +33 -0
- data/lib/schema/pml.xsd +1676 -0
- data/lib/schema/shared-additionalCharacteristics.xsd +28 -0
- data/lib/schema/shared-bibliography.xsd +144 -0
- data/lib/schema/shared-commonSimpleTypes.xsd +166 -0
- data/lib/schema/shared-customXmlDataProperties.xsd +25 -0
- data/lib/schema/shared-customXmlSchemaProperties.xsd +18 -0
- data/lib/schema/shared-documentPropertiesCustom.xsd +59 -0
- data/lib/schema/shared-documentPropertiesExtended.xsd +56 -0
- data/lib/schema/shared-documentPropertiesVariantTypes.xsd +195 -0
- data/lib/schema/shared-math.xsd +582 -0
- data/lib/schema/shared-relationshipReference.xsd +25 -0
- data/lib/schema/sml.xsd +4430 -0
- data/lib/schema/vml-main.xsd +569 -0
- data/lib/schema/vml-officeDrawing.xsd +509 -0
- data/lib/schema/vml-presentationDrawing.xsd +12 -0
- data/lib/schema/vml-spreadsheetDrawing.xsd +108 -0
- data/lib/schema/vml-wordprocessingDrawing.xsd +96 -0
- data/lib/schema/wml.xsd +3644 -0
- data/lib/schema/xml.xsd +117 -0
- data/test/content_type/tc_content_type.rb +81 -0
- data/test/content_type/tc_content_type.rb~ +81 -0
- data/test/content_type/tc_default.rb +40 -0
- data/test/content_type/tc_default.rb~ +40 -0
- data/test/content_type/tc_override.rb +40 -0
- data/test/content_type/tc_override.rb~ +40 -0
- data/test/doc_props/tc_app.rb +19 -0
- data/test/doc_props/tc_app.rb~ +19 -0
- data/test/doc_props/tc_core.rb +34 -0
- data/test/drawing/tc_axis.rb +39 -0
- data/test/drawing/tc_axis.rb~ +0 -0
- data/test/drawing/tc_bar_3D_chart.rb +66 -0
- data/test/drawing/tc_bar_3D_chart.rb~ +4 -0
- data/test/drawing/tc_bar_series.rb +34 -0
- data/test/drawing/tc_bar_series.rb~ +31 -0
- data/test/drawing/tc_cat_axis.rb +32 -0
- data/test/drawing/tc_cat_axis.rb~ +39 -0
- data/test/drawing/tc_chart.rb +59 -0
- data/test/drawing/tc_chart.rb~ +58 -0
- data/test/drawing/tc_drawing.rb +71 -0
- data/test/drawing/tc_graphic_frame.rb +26 -0
- data/test/drawing/tc_graphic_frame.rb~ +21 -0
- data/test/drawing/tc_marker.rb +45 -0
- data/test/drawing/tc_marker.rb~ +26 -0
- data/test/drawing/tc_pie_3D_chart.rb +33 -0
- data/test/drawing/tc_pie_3D_chart.rb~ +58 -0
- data/test/drawing/tc_pie_series.rb +35 -0
- data/test/drawing/tc_pie_series.rb~ +26 -0
- data/test/drawing/tc_scaling.rb +37 -0
- data/test/drawing/tc_scaling.rb~ +45 -0
- data/test/drawing/tc_series.rb +24 -0
- data/test/drawing/tc_series.rb~ +31 -0
- data/test/drawing/tc_title.rb +34 -0
- data/test/drawing/tc_title.rb~ +37 -0
- data/test/drawing/tc_two_cell_anchor.rb +37 -0
- data/test/drawing/tc_two_cell_anchor.rb~ +35 -0
- data/test/drawing/tc_val_axis.rb +20 -0
- data/test/drawing/tc_val_axis.rb~ +32 -0
- data/test/drawing/tc_view_3D.rb +46 -0
- data/test/drawing/tc_view_3D.rb~ +37 -0
- data/test/rels/tc_relationship.rb +16 -0
- data/test/rels/tc_relationship.rb~ +39 -0
- data/test/rels/tc_relationships.rb +32 -0
- data/test/rels/tc_relationships.rb~ +37 -0
- data/test/stylesheet/tc_border.rb +38 -0
- data/test/stylesheet/tc_border.rb~ +31 -0
- data/test/stylesheet/tc_border_pr.rb +33 -0
- data/test/stylesheet/tc_border_pr.rb~ +31 -0
- data/test/stylesheet/tc_cell_alignment.rb +77 -0
- data/test/stylesheet/tc_cell_alignment.rb~ +38 -0
- data/test/stylesheet/tc_cell_protection.rb +30 -0
- data/test/stylesheet/tc_cell_protection.rb~ +77 -0
- data/test/stylesheet/tc_cell_style.rb +58 -0
- data/test/stylesheet/tc_cell_style.rb~ +30 -0
- data/test/stylesheet/tc_color.rb +38 -0
- data/test/stylesheet/tc_color.rb~ +38 -0
- data/test/stylesheet/tc_fill.rb +19 -0
- data/test/stylesheet/tc_fill.rb~ +19 -0
- data/test/stylesheet/tc_font.rb +114 -0
- data/test/stylesheet/tc_font.rb~ +19 -0
- data/test/stylesheet/tc_gradient_fill.rb +65 -0
- data/test/stylesheet/tc_gradient_fill.rb~ +114 -0
- data/test/stylesheet/tc_gradient_stop.rb +32 -0
- data/test/stylesheet/tc_gradient_stop.rb~ +65 -0
- data/test/stylesheet/tc_num_fmt.rb +31 -0
- data/test/stylesheet/tc_num_fmt.rb~ +32 -0
- data/test/stylesheet/tc_pattern_fill.rb +38 -0
- data/test/stylesheet/tc_pattern_fill.rb~ +31 -0
- data/test/stylesheet/tc_styles.rb +64 -0
- data/test/stylesheet/tc_table_style.rb +37 -0
- data/test/stylesheet/tc_table_style.rb~ +38 -0
- data/test/stylesheet/tc_table_style_element.rb +37 -0
- data/test/stylesheet/tc_table_style_element.rb~ +37 -0
- data/test/stylesheet/tc_table_styles.rb +30 -0
- data/test/stylesheet/tc_table_styles.rb~ +37 -0
- data/test/stylesheet/tc_xf.rb +121 -0
- data/test/stylesheet/tc_xf.rb~ +30 -0
- data/test/tc_app.rb~ +19 -0
- data/test/tc_border_pr.rb~ +21 -0
- data/test/tc_package.rb +70 -0
- data/test/tc_package.rb~ +64 -0
- data/test/tc_pie_3D_chart.rb~ +66 -0
- data/test/tc_relationships.rb~ +37 -0
- data/test/tc_series.rb~ +31 -0
- data/test/tc_styles.rb~ +64 -0
- data/test/tc_validators.rb~ +77 -0
- data/test/tc_worksheet.rb~ +85 -0
- data/test/util/tc_simple_typed_list.rb +66 -0
- data/test/util/tc_validators.rb +76 -0
- data/test/workbook/tc_workbook.rb +53 -0
- data/test/workbook/worksheet/tc_cell.rb +78 -0
- data/test/workbook/worksheet/tc_row.rb +30 -0
- data/test/workbook/worksheet/tc_worksheet.rb +85 -0
- metadata +378 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# The Marker class defines a point in the worksheet that drawing anchors attach to.
|
3
|
+
# @note The recommended way to manage markers is Worksheet#add_chart Markers are created for a two cell anchor based on the :start and :end options.
|
4
|
+
# @see Worksheet#add_chart
|
5
|
+
class Marker
|
6
|
+
|
7
|
+
# The column this marker anchors to
|
8
|
+
# @return [Integer]
|
9
|
+
attr_accessor :col
|
10
|
+
|
11
|
+
# The offset distance from this marker's column
|
12
|
+
# @return [Integer]
|
13
|
+
attr_accessor :colOff
|
14
|
+
|
15
|
+
# The row this marker anchors to
|
16
|
+
# @return [Integer]
|
17
|
+
attr_accessor :row
|
18
|
+
|
19
|
+
# The offset distance from this marker's row
|
20
|
+
# @return [Integer]
|
21
|
+
attr_accessor :rowOff
|
22
|
+
|
23
|
+
# Creates a new Marker object
|
24
|
+
# @option options [Integer] col
|
25
|
+
# @option options [Integer] colOff
|
26
|
+
# @option options [Integer] row
|
27
|
+
# @option options [Integer] rowOff
|
28
|
+
def initialize(options={})
|
29
|
+
@col, @colOff, @row, @rowOff = 0, 0, 0, 0
|
30
|
+
options.each do |o|
|
31
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def col=(v) Axlsx::validate_unsigned_int v; @col = v end
|
36
|
+
def colOff=(v) Axlsx::validate_int v; @colOff = v end
|
37
|
+
def row=(v) Axlsx::validate_unsigned_int v; @row = v end
|
38
|
+
def rowOff=(v) Axlsx::validate_int v; @rowOff = v end
|
39
|
+
|
40
|
+
# shortcut to set the column, row position for this marker
|
41
|
+
# @param col the column for the marker
|
42
|
+
# @param row the row of the marker
|
43
|
+
def coord(col, row)
|
44
|
+
self.col = col
|
45
|
+
self.row = row
|
46
|
+
end
|
47
|
+
# Serializes the marker
|
48
|
+
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
49
|
+
# @return [String]
|
50
|
+
def to_xml(xml)
|
51
|
+
[:col, :colOff, :row, :rowOff].each do |k|
|
52
|
+
xml.send("xdr:#{k.to_s}", self.send(k))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Axlsx
|
2
|
+
|
3
|
+
|
4
|
+
# The Pie3DChart is a three dimentional piechart (who would have guessed?) that you can add to your worksheet.
|
5
|
+
# @example Creating a chart
|
6
|
+
# # This example creates two charts in a single sheet.
|
7
|
+
# # The first uses data directly fed to the sheet, while the second references cells withing the worksheet for data.
|
8
|
+
#
|
9
|
+
# require "rubygems" # if that is your preferred way to manage gems!
|
10
|
+
# require "axlsx"
|
11
|
+
#
|
12
|
+
# p = Axlsx::Package.new
|
13
|
+
# ws = p.workbook.add_worksheet
|
14
|
+
# ws.add_row :values => ["This is a chart with no data in the sheet"]
|
15
|
+
#
|
16
|
+
# chart = ws.add_chart(Axlsx::Pie3DChart, :start_at=> [0,1], :end_at=>[0,6], :title=>"Most Popular Pets")
|
17
|
+
# chart.add_series :data => [1, 9, 10], :labels => ["Slimy Reptiles", "Fuzzy Bunnies", "Rottweiler"]
|
18
|
+
#
|
19
|
+
# ws.add_row :values => ["This chart uses the data below"]
|
20
|
+
# title_row = ws.add_row :values => ["Least Popular Pets"]
|
21
|
+
# label_row = ws.add_row :values => ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"]
|
22
|
+
# data_row = ws.add_row :values => ["Votes", 6, 4, 1]
|
23
|
+
#
|
24
|
+
# chart = ws.add_chart(Axlsx::Pie3DChart, :start_at => [0,11], :end_at =>[0,16], :title => title_row.cells.last)
|
25
|
+
# chart.add_series :data => data_row.cells[(1..-1)], :labels => label_row.cells
|
26
|
+
#
|
27
|
+
# f = File.open('example_pie_3d_chart.xlsx', 'w')
|
28
|
+
# p.serialize(f)
|
29
|
+
#
|
30
|
+
# @see Worksheet#add_chart
|
31
|
+
# @see Worksheet#add_row
|
32
|
+
# @see Chart#add_series
|
33
|
+
# @see Series
|
34
|
+
# @see Package#serialize
|
35
|
+
class Pie3DChart < Chart
|
36
|
+
|
37
|
+
|
38
|
+
# Creates a new pie chart object
|
39
|
+
# @param [Workbook] workbook The workbook that owns this chart.
|
40
|
+
# @option options [Cell, String] title
|
41
|
+
def initialize(workbook, options={})
|
42
|
+
super(workbook, options)
|
43
|
+
# this charts series type
|
44
|
+
@series_type = PieSeries
|
45
|
+
@view3D = View3D.new(:rotX => 30, :perspective => 30)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Serializes the pie chart
|
49
|
+
# @return [String]
|
50
|
+
def to_xml
|
51
|
+
super() do |xml|
|
52
|
+
xml.send('c:pie3DChart') {
|
53
|
+
xml.send('c:varyColors', :val=>1)
|
54
|
+
@series.each { |ser| ser.to_xml(xml) }
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# A PieSeries defines the title, data and labels for pie charts
|
3
|
+
# @note The recommended way to manage series is to use Chart#add_series
|
4
|
+
# @see Worksheet#add_chart
|
5
|
+
# @see Chart#add_series
|
6
|
+
class PieSeries < Series
|
7
|
+
|
8
|
+
# The data for this series.
|
9
|
+
# @return [Array, SimpleTypedList]
|
10
|
+
attr_reader :data
|
11
|
+
|
12
|
+
|
13
|
+
# The labels for this series.
|
14
|
+
# @return [Array, SimpleTypedList]
|
15
|
+
attr_reader :labels
|
16
|
+
|
17
|
+
|
18
|
+
# The explosion for this series
|
19
|
+
# @return [Array, SimpleTypedList]
|
20
|
+
attr_accessor :explosion
|
21
|
+
|
22
|
+
# Creates a new series
|
23
|
+
# @option options [Array, SimpleTypedList] data
|
24
|
+
# @option options [Array, SimpleTypedList] labels
|
25
|
+
# @option options [String] title
|
26
|
+
# @option options [Integer] explosion
|
27
|
+
# @param [Chart] chart
|
28
|
+
def initialize(chart, options={})
|
29
|
+
super(chart, options)
|
30
|
+
self.data = options[:data] || []
|
31
|
+
self.labels = options[:labels] || []
|
32
|
+
end
|
33
|
+
|
34
|
+
def explosion=(v) Axlsx::validate_unsigned_int(v); @explosion = v; end
|
35
|
+
# Serializes the series
|
36
|
+
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
37
|
+
# @return [String]
|
38
|
+
def to_xml(xml)
|
39
|
+
super(xml) do |xml|
|
40
|
+
xml.send('c:explosion', :val=>@explosion) unless @explosion.nil?
|
41
|
+
if !labels.empty?
|
42
|
+
xml.send('c:cat') {
|
43
|
+
xml.send('c:strRef') {
|
44
|
+
xml.send('c:f', Axlsx::cell_range(labels))
|
45
|
+
xml.send('c:strCache') {
|
46
|
+
xml.send('c:ptCount', :val=>labels.size)
|
47
|
+
labels.each_with_index do |cell, index|
|
48
|
+
v = cell.is_a?(Cell) ? cell.value : cell
|
49
|
+
xml.send('c:pt', :idx=>index) {
|
50
|
+
xml.send('c:v', v)
|
51
|
+
}
|
52
|
+
end
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
end
|
57
|
+
xml.send('c:val') {
|
58
|
+
xml.send('c:numRef') {
|
59
|
+
xml.send('c:f', Axlsx::cell_range(data))
|
60
|
+
xml.send('c:numCache') {
|
61
|
+
xml.send('c:formatCode', 'General')
|
62
|
+
xml.send('c:ptCount', :val=>data.size)
|
63
|
+
data.each_with_index do |cell, index|
|
64
|
+
v = cell.is_a?(Cell) ? cell.value : cell
|
65
|
+
xml.send('c:pt', :idx=>index) {
|
66
|
+
xml.send('c:v', v)
|
67
|
+
}
|
68
|
+
end
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
|
80
|
+
# assigns the data for this series
|
81
|
+
def data=(v) DataTypeValidator.validate "Series.data", [Array, SimpleTypedList], v; @data = v; end
|
82
|
+
|
83
|
+
# assigns the labels for this series
|
84
|
+
def labels=(v) DataTypeValidator.validate "Series.labels", [Array, SimpleTypedList], v; @labels = v; end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# The Scaling class defines axis scaling
|
3
|
+
class Scaling
|
4
|
+
|
5
|
+
# logarithmic base for a logarithmic axis.
|
6
|
+
# must be between 2 and 1000
|
7
|
+
# @return [Integer]
|
8
|
+
attr_accessor :logBase
|
9
|
+
|
10
|
+
# the orientation of the axis
|
11
|
+
# must be one of [:minMax, :maxMin]
|
12
|
+
# @return [Symbol]
|
13
|
+
attr_accessor :orientation
|
14
|
+
|
15
|
+
# the maximum scaling
|
16
|
+
# @return [Float]
|
17
|
+
attr_accessor :max
|
18
|
+
|
19
|
+
# the minimu scaling
|
20
|
+
# @return [Float]
|
21
|
+
attr_accessor :min
|
22
|
+
|
23
|
+
# creates a new Scaling object
|
24
|
+
# @option options [Integer, Fixnum] logBase
|
25
|
+
# @option options [Symbol] orientation
|
26
|
+
# @option options [Float] max
|
27
|
+
# @option options [Float] min
|
28
|
+
def initialize(options={})
|
29
|
+
@orientation = :minMax
|
30
|
+
options.each do |o|
|
31
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer, Fixnum], v, lambda { |v| v >= 2 && v <= 1000}; @logBase = v; end
|
36
|
+
def orientation=(v) RestrictionValidator.validate "Scaling.orientation", [:minMax, :maxMin], v; @orientation = v; end
|
37
|
+
def max=(v) DataTypeValidator.validate "Scaling.max", Float, v; @max = v; end
|
38
|
+
def min=(v) DataTypeValidator.validate "Scaling.min", Float, v; @min = v; end
|
39
|
+
|
40
|
+
# Serializes the axId
|
41
|
+
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
42
|
+
# @return [String]
|
43
|
+
def to_xml(xml)
|
44
|
+
xml.send('c:scaling') {
|
45
|
+
xml.send('c:logBase', :val=> @logBase) unless @logBase.nil?
|
46
|
+
xml.send('c:orientation', :val=> @orientation) unless @orientation.nil?
|
47
|
+
xml.send('c:min', :val => @min) unless @min.nil?
|
48
|
+
xml.send('c:max', :val => @max) unless @max.nil?
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# A Series defines the title, data and labels for chart data.
|
3
|
+
# @note The recommended way to manage series is to use Chart#add_series
|
4
|
+
# @see Worksheet#add_chart
|
5
|
+
# @see Chart#add_series
|
6
|
+
class Series
|
7
|
+
|
8
|
+
# The chart that owns this series
|
9
|
+
# @return [Chart]
|
10
|
+
attr_reader :chart
|
11
|
+
|
12
|
+
# The index of this series in the chart's series.
|
13
|
+
# @return [Integer]
|
14
|
+
attr_reader :index
|
15
|
+
|
16
|
+
# The order of this series in the chart's series.
|
17
|
+
# @return [Integer]
|
18
|
+
attr_accessor :order
|
19
|
+
|
20
|
+
# The title of the series
|
21
|
+
# @return [String]
|
22
|
+
attr_accessor :title
|
23
|
+
|
24
|
+
# Creates a new series
|
25
|
+
# @param [Chart] chart
|
26
|
+
# @option options [Integer] order
|
27
|
+
# @option options [String] title
|
28
|
+
def initialize(chart, options={})
|
29
|
+
self.chart = chart
|
30
|
+
@chart.series << self
|
31
|
+
options.each do |o|
|
32
|
+
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# retrieves the series index in the chart's series collection
|
37
|
+
def index
|
38
|
+
@chart.series.index(self)
|
39
|
+
end
|
40
|
+
|
41
|
+
def order=(v) Axlsx::validate_unsigned_int(v); @order = v; end
|
42
|
+
|
43
|
+
def order
|
44
|
+
@order || index
|
45
|
+
end
|
46
|
+
|
47
|
+
def title=(v) Axlsx::validate_string(v); @title = v; end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# assigns the chart for this series
|
52
|
+
def chart=(v) DataTypeValidator.validate "Series.chart", Chart, v; @chart = v; end
|
53
|
+
|
54
|
+
# Serializes the series
|
55
|
+
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
56
|
+
# @return [String]
|
57
|
+
def to_xml(xml)
|
58
|
+
xml.send('c:ser') {
|
59
|
+
xml.send('c:idx', :val=>index)
|
60
|
+
xml.send('c:order', :val=>order || index)
|
61
|
+
xml.send('c:tx') {
|
62
|
+
xml.send('c:v', self.title)
|
63
|
+
}
|
64
|
+
yield xml if block_given?
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# A Title stores information about the title of a chart
|
3
|
+
class Title
|
4
|
+
|
5
|
+
# The text to be shown. Setting this property directly with a string will remove the cell reference.
|
6
|
+
# @return [String]
|
7
|
+
attr_accessor :text
|
8
|
+
|
9
|
+
# The cell that holds the text for the title. Setting this property will automatically update the text attribute.
|
10
|
+
# @return [Cell]
|
11
|
+
attr_accessor :cell
|
12
|
+
|
13
|
+
# Creates a new Title object
|
14
|
+
# @param [String, Cell] title The cell or string to be used for the chart's title
|
15
|
+
def initialize(title="")
|
16
|
+
self.cell = title if title.is_a?(Cell)
|
17
|
+
self.text = title.to_s unless title.is_a?(Cell)
|
18
|
+
end
|
19
|
+
|
20
|
+
def text=(v)
|
21
|
+
DataTypeValidator.validate 'Title.text', String, v
|
22
|
+
@text = v
|
23
|
+
@cell = nil
|
24
|
+
v
|
25
|
+
end
|
26
|
+
|
27
|
+
def cell=(v)
|
28
|
+
DataTypeValidator.validate 'Title.text', Cell, v
|
29
|
+
@cell = v
|
30
|
+
@text = v.value.to_s
|
31
|
+
v
|
32
|
+
end
|
33
|
+
|
34
|
+
# Not implemented at this time.
|
35
|
+
#def tx=(v) DataTypeValidator.validate 'Title.tx', Tx, v; @tx=v; end
|
36
|
+
#def layout=(v) DataTypeValidator.validate 'Title.layout', Layout, v; @layout = v; end
|
37
|
+
#def overlay=(v) Axlsx::validate_boolean v; @overlay=v; end
|
38
|
+
#def spPr=(v) DataTypeValidator.validate 'Title.spPr', SpPr, v; @spPr = v; end
|
39
|
+
|
40
|
+
# Serializes the chart title
|
41
|
+
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
42
|
+
# @return [String]
|
43
|
+
def to_xml(xml)
|
44
|
+
xml.send('c:title') {
|
45
|
+
xml.send('c:tx') {
|
46
|
+
xml.send('c:strRef') {
|
47
|
+
xml.send('c:f', range)
|
48
|
+
xml.send('c:strCache') {
|
49
|
+
xml.send('c:ptCount', :val=>1)
|
50
|
+
xml.send('c:pt', :idx=>0) {
|
51
|
+
xml.send('c:v', @text)
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# returns the excel style abslute reference for the title when title is a Cell object
|
62
|
+
# @return [String]
|
63
|
+
def range
|
64
|
+
return "" unless @data.is_a?(Cell)
|
65
|
+
"#{@data.row.worksheet.name}!#{data.row.r_abs}"
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Axlsx
|
2
|
+
# This class details the anchor points for drawings.
|
3
|
+
# @note The recommended way to manage drawings and charts is Worksheet#add_chart. Anchors are specified by the :start_at and :end_at options to that method.
|
4
|
+
# @see Worksheet#add_chart
|
5
|
+
class TwoCellAnchor
|
6
|
+
|
7
|
+
# A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively
|
8
|
+
# @return [Marker]
|
9
|
+
attr_reader :from
|
10
|
+
# A marker that returns the to cell anchor. The default to column and row are 5 and 10 respectively
|
11
|
+
# @return [Marker]
|
12
|
+
attr_reader :to
|
13
|
+
|
14
|
+
# The frame for your chart
|
15
|
+
# @return [GraphicFrame]
|
16
|
+
attr_reader :graphic_frame
|
17
|
+
|
18
|
+
# The drawing that holds this anchor
|
19
|
+
# @return [Drawing]
|
20
|
+
attr_reader :drawing
|
21
|
+
|
22
|
+
# The index of this anchor in the drawing
|
23
|
+
# @return [Integer]
|
24
|
+
attr_reader :index
|
25
|
+
|
26
|
+
# Creates a new TwoCellAnchor object
|
27
|
+
# @param [Drawing] drawing
|
28
|
+
# @param [Chart] chart
|
29
|
+
# @option options [Array] start_at
|
30
|
+
# @option options [Array] end_at
|
31
|
+
def initialize(drawing, chart_type, options)
|
32
|
+
@drawing = drawing
|
33
|
+
drawing.anchors << self
|
34
|
+
|
35
|
+
@from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
|
36
|
+
@graphic_frame = GraphicFrame.new(self, chart_type, options)
|
37
|
+
|
38
|
+
self.start_at(options[:start_at][0], options[:start_at][1]) if options[:start_at].is_a?(Array)
|
39
|
+
self.end_at(options[:end_at][0], options[:end_at][1]) if options[:end_at].is_a?(Array)
|
40
|
+
# passing a reference to our start and end markers for convenience
|
41
|
+
# this lets us access the markers directly from the chart.
|
42
|
+
@graphic_frame.chart.send(:start_at=, @from)
|
43
|
+
@graphic_frame.chart.send(:end_at=, @to)
|
44
|
+
end
|
45
|
+
|
46
|
+
def index
|
47
|
+
@drawing.anchors.index(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# This is a short cut method to set the start anchor position
|
52
|
+
# @param [Integer] x The column
|
53
|
+
# @param [Integer] y The row
|
54
|
+
# @return [Marker]
|
55
|
+
def start_at(x, y)
|
56
|
+
@from.col = x
|
57
|
+
@from.row = y
|
58
|
+
@from
|
59
|
+
end
|
60
|
+
|
61
|
+
# This is a short cut method to set the end anchor position
|
62
|
+
# @param [Integer] x The column
|
63
|
+
# @param [Integer] y The row
|
64
|
+
# @return [Marker]
|
65
|
+
def end_at(x, y)
|
66
|
+
@to.col = x
|
67
|
+
@to.row = y
|
68
|
+
@to
|
69
|
+
end
|
70
|
+
|
71
|
+
# Serializes the two cell anchor
|
72
|
+
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
|
73
|
+
# @return [String]
|
74
|
+
def to_xml(xml)
|
75
|
+
#build it for now, break it down later!
|
76
|
+
xml.send('xdr:twoCellAnchor') {
|
77
|
+
xml.send('xdr:from') {
|
78
|
+
from.to_xml(xml)
|
79
|
+
}
|
80
|
+
xml.send('xdr:to') {
|
81
|
+
to.to_xml(xml)
|
82
|
+
}
|
83
|
+
@graphic_frame.to_xml(xml)
|
84
|
+
xml.send('xdr:clientData')
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|