caxlsx 2.0.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +41 -33
- data/Rakefile +9 -11
- data/examples/auto_filter.rb +10 -1
- data/examples/conditional_formatting/example_conditional_formatting.rb +18 -3
- data/examples/data_validation.rb +57 -40
- data/examples/example.rb +115 -7
- data/examples/merge_cells.rb +17 -0
- data/examples/no_grid_with_borders.rb +18 -0
- data/examples/pivot_test.rb +63 -0
- data/examples/split.rb +16 -0
- data/lib/axlsx.rb +34 -15
- data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
- data/lib/axlsx/content_type/content_type.rb +1 -1
- data/lib/axlsx/doc_props/app.rb +1 -1
- data/lib/axlsx/doc_props/core.rb +5 -5
- data/lib/axlsx/drawing/area_chart.rb +99 -0
- data/lib/axlsx/drawing/area_series.rb +110 -0
- data/lib/axlsx/drawing/axes.rb +1 -1
- data/lib/axlsx/drawing/axis.rb +12 -9
- data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
- data/lib/axlsx/drawing/bar_chart.rb +143 -0
- data/lib/axlsx/drawing/bar_series.rb +9 -9
- data/lib/axlsx/drawing/bubble_chart.rb +59 -0
- data/lib/axlsx/drawing/bubble_series.rb +63 -0
- data/lib/axlsx/drawing/cat_axis.rb +5 -5
- data/lib/axlsx/drawing/chart.rb +52 -8
- data/lib/axlsx/drawing/d_lbls.rb +3 -3
- data/lib/axlsx/drawing/drawing.rb +6 -1
- data/lib/axlsx/drawing/graphic_frame.rb +3 -3
- data/lib/axlsx/drawing/hyperlink.rb +1 -3
- data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
- data/lib/axlsx/drawing/line_chart.rb +10 -10
- data/lib/axlsx/drawing/line_series.rb +32 -3
- data/lib/axlsx/drawing/marker.rb +1 -1
- data/lib/axlsx/drawing/num_data.rb +4 -4
- data/lib/axlsx/drawing/num_data_source.rb +6 -6
- data/lib/axlsx/drawing/num_val.rb +3 -1
- data/lib/axlsx/drawing/one_cell_anchor.rb +3 -2
- data/lib/axlsx/drawing/pic.rb +25 -19
- data/lib/axlsx/drawing/picture_locking.rb +1 -3
- data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
- data/lib/axlsx/drawing/pie_series.rb +6 -6
- data/lib/axlsx/drawing/scaling.rb +6 -6
- data/lib/axlsx/drawing/scatter_chart.rb +10 -10
- data/lib/axlsx/drawing/scatter_series.rb +40 -7
- data/lib/axlsx/drawing/ser_axis.rb +2 -2
- data/lib/axlsx/drawing/series.rb +3 -3
- data/lib/axlsx/drawing/series_title.rb +2 -2
- data/lib/axlsx/drawing/str_data.rb +3 -3
- data/lib/axlsx/drawing/str_val.rb +3 -1
- data/lib/axlsx/drawing/title.rb +22 -4
- data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
- data/lib/axlsx/drawing/val_axis.rb +1 -1
- data/lib/axlsx/drawing/view_3D.rb +2 -2
- data/lib/axlsx/drawing/vml_drawing.rb +1 -1
- data/lib/axlsx/package.rb +33 -31
- data/lib/axlsx/rels/relationship.rb +1 -1
- data/lib/axlsx/rels/relationships.rb +7 -4
- data/lib/axlsx/stylesheet/border_pr.rb +2 -2
- data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
- data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
- data/lib/axlsx/stylesheet/cell_style.rb +1 -3
- data/lib/axlsx/stylesheet/color.rb +1 -3
- data/lib/axlsx/stylesheet/font.rb +1 -1
- data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
- data/lib/axlsx/stylesheet/num_fmt.rb +10 -3
- data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
- data/lib/axlsx/stylesheet/styles.rb +7 -7
- data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
- data/lib/axlsx/util/accessors.rb +6 -6
- data/lib/axlsx/util/constants.rb +107 -99
- data/lib/axlsx/util/mime_type_utils.rb +11 -0
- data/lib/axlsx/util/options_parser.rb +2 -1
- data/lib/axlsx/util/parser.rb +4 -4
- data/lib/axlsx/util/serialized_attributes.rb +16 -6
- data/lib/axlsx/util/simple_typed_list.rb +28 -52
- data/lib/axlsx/util/storage.rb +4 -4
- data/lib/axlsx/util/validators.rb +29 -17
- data/lib/axlsx/version.rb +1 -1
- data/lib/axlsx/workbook/defined_name.rb +11 -12
- data/lib/axlsx/workbook/defined_names.rb +2 -2
- data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
- data/lib/axlsx/workbook/workbook.rb +36 -11
- data/lib/axlsx/workbook/workbook_view.rb +80 -0
- data/lib/axlsx/workbook/workbook_views.rb +22 -0
- data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
- data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
- data/lib/axlsx/workbook/worksheet/break.rb +1 -3
- data/lib/axlsx/workbook/worksheet/cell.rb +136 -74
- data/lib/axlsx/workbook/worksheet/cell_serializer.rb +63 -43
- data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
- data/lib/axlsx/workbook/worksheet/cfvos.rb +4 -1
- data/lib/axlsx/workbook/worksheet/col.rb +7 -10
- data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
- data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
- data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
- data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
- data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
- data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
- data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
- data/lib/axlsx/workbook/worksheet/data_validation.rb +6 -4
- data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
- data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
- data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
- data/lib/axlsx/workbook/worksheet/merged_cells.rb +4 -2
- data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
- data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
- data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
- data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
- data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
- data/lib/axlsx/workbook/worksheet/pivot_table.rb +44 -28
- data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
- data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
- data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
- data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -2
- data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -0
- data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -0
- data/lib/axlsx/workbook/worksheet/row.rb +40 -51
- data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
- data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
- data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
- data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
- data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
- data/lib/axlsx/workbook/worksheet/table.rb +6 -6
- data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
- data/lib/axlsx/workbook/worksheet/tables.rb +4 -1
- data/lib/axlsx/workbook/worksheet/worksheet.rb +64 -78
- data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
- data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
- data/test/drawing/tc_area_chart.rb +39 -0
- data/test/drawing/tc_area_series.rb +71 -0
- data/test/drawing/tc_axis.rb +27 -0
- data/test/drawing/tc_bar_chart.rb +71 -0
- data/test/drawing/tc_bubble_chart.rb +44 -0
- data/test/drawing/tc_bubble_series.rb +21 -0
- data/test/drawing/tc_chart.rb +23 -10
- data/test/drawing/tc_data_source.rb +6 -0
- data/test/drawing/tc_drawing.rb +2 -2
- data/test/drawing/tc_line_chart.rb +5 -5
- data/test/drawing/tc_line_series.rb +47 -6
- data/test/drawing/tc_pic.rb +11 -15
- data/test/drawing/tc_scatter_series.rb +36 -1
- data/test/drawing/tc_str_val.rb +9 -0
- data/test/drawing/tc_title.rb +5 -0
- data/test/stylesheet/tc_styles.rb +2 -2
- data/test/tc_axlsx.rb +31 -0
- data/test/tc_helper.rb +2 -0
- data/test/tc_package.rb +19 -1
- data/test/util/tc_mime_type_utils.rb +13 -0
- data/test/util/tc_simple_typed_list.rb +2 -3
- data/test/util/tc_validators.rb +34 -10
- data/test/workbook/tc_defined_name.rb +12 -4
- data/test/workbook/tc_shared_strings_table.rb +16 -1
- data/test/workbook/tc_workbook.rb +38 -3
- data/test/workbook/tc_workbook_view.rb +50 -0
- data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
- data/test/workbook/worksheet/tc_break.rb +1 -1
- data/test/workbook/worksheet/tc_cell.rb +76 -8
- data/test/workbook/worksheet/tc_col.rb +2 -2
- data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
- data/test/workbook/worksheet/tc_data_bar.rb +1 -1
- data/test/workbook/worksheet/tc_data_validation.rb +11 -11
- data/test/workbook/worksheet/tc_header_footer.rb +2 -2
- data/test/workbook/worksheet/tc_icon_set.rb +1 -1
- data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
- data/test/workbook/worksheet/tc_page_setup.rb +3 -3
- data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
- data/test/workbook/worksheet/tc_print_options.rb +1 -1
- data/test/workbook/worksheet/tc_rich_text.rb +44 -0
- data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
- data/test/workbook/worksheet/tc_row.rb +7 -2
- data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
- data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
- data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
- data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
- data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
- data/test/workbook/worksheet/tc_table.rb +2 -3
- data/test/workbook/worksheet/tc_worksheet.rb +99 -45
- metadata +89 -16
@@ -1,5 +1,5 @@
|
|
1
1
|
module Axlsx
|
2
|
-
|
2
|
+
|
3
3
|
# This is a utility class for serialing the drawing node in a
|
4
4
|
# worksheet. Drawing objects have their own serialization that exports
|
5
5
|
# a drawing document. This is only for the single node in the
|
@@ -17,7 +17,7 @@ module Axlsx
|
|
17
17
|
attr_reader :worksheet
|
18
18
|
|
19
19
|
attr_reader :drawing
|
20
|
-
|
20
|
+
|
21
21
|
# adds a chart to the drawing object
|
22
22
|
# @param [Class] chart_type The type of chart to add
|
23
23
|
# @param [Hash] options Options to pass on to the drawing and chart
|
@@ -26,17 +26,17 @@ module Axlsx
|
|
26
26
|
@drawing ||= Drawing.new worksheet
|
27
27
|
drawing.add_chart(chart_type, options)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# adds an image to the drawing object
|
31
|
-
# @param [Hash] options Options to pass on to the drawing and image
|
31
|
+
# @param [Hash] options Options to pass on to the drawing and image
|
32
32
|
# @see Worksheet#add_image
|
33
33
|
def add_image(options)
|
34
|
-
@drawing ||= Drawing.new
|
34
|
+
@drawing ||= Drawing.new(worksheet)
|
35
35
|
drawing.add_image(options)
|
36
|
-
end
|
37
|
-
|
36
|
+
end
|
37
|
+
|
38
38
|
# helper method to tell us if the drawing has something in it or not
|
39
|
-
# @return [Boolean]
|
39
|
+
# @return [Boolean]
|
40
40
|
def has_drawing?
|
41
41
|
@drawing.is_a? Drawing
|
42
42
|
end
|
@@ -45,13 +45,13 @@ module Axlsx
|
|
45
45
|
# @return [Relationship]
|
46
46
|
def relationship
|
47
47
|
return unless has_drawing?
|
48
|
-
Relationship.new(self, DRAWING_R, "../#{drawing.pn}")
|
48
|
+
Relationship.new(self, DRAWING_R, "../#{drawing.pn}")
|
49
49
|
end
|
50
50
|
|
51
51
|
# Serialize the drawing for the worksheet
|
52
52
|
# @param [String] str
|
53
53
|
def to_xml_string(str = '')
|
54
|
-
return unless has_drawing?
|
54
|
+
return unless has_drawing?
|
55
55
|
str << "<drawing r:id='#{relationship.Id}'/>"
|
56
56
|
end
|
57
57
|
end
|
@@ -15,8 +15,8 @@ module Axlsx
|
|
15
15
|
# @see WorksheetHyperlink#initialize
|
16
16
|
# @return [WorksheetHyperlink]
|
17
17
|
def add(options)
|
18
|
-
|
19
|
-
|
18
|
+
self << WorksheetHyperlink.new(@worksheet, options)
|
19
|
+
last
|
20
20
|
end
|
21
21
|
|
22
22
|
# The relationships required by this collection's hyperlinks
|
@@ -31,7 +31,7 @@ module Axlsx
|
|
31
31
|
def to_xml_string(str='')
|
32
32
|
return if empty?
|
33
33
|
str << '<hyperlinks>'
|
34
|
-
|
34
|
+
each { |hyperlink| hyperlink.to_xml_string(str) }
|
35
35
|
str << '</hyperlinks>'
|
36
36
|
end
|
37
37
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestAreaChart < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@p = Axlsx::Package.new
|
7
|
+
ws = @p.workbook.add_worksheet
|
8
|
+
@row = ws.add_row ["one", 1, Time.now]
|
9
|
+
@chart = ws.add_chart Axlsx::AreaChart, :title => "fishery"
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_initialization
|
16
|
+
assert_equal(@chart.grouping, :standard, "grouping defualt incorrect")
|
17
|
+
assert_equal(@chart.series_type, Axlsx::AreaSeries, "series type incorrect")
|
18
|
+
assert(@chart.cat_axis.is_a?(Axlsx::CatAxis), "category axis not created")
|
19
|
+
assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_grouping
|
23
|
+
assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
|
24
|
+
assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked }
|
25
|
+
assert(@chart.grouping == :stacked)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_to_xml
|
29
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
|
30
|
+
doc = Nokogiri::XML(@chart.to_xml_string)
|
31
|
+
errors = []
|
32
|
+
schema.validate(doc).each do |error|
|
33
|
+
errors.push error
|
34
|
+
puts error.message
|
35
|
+
end
|
36
|
+
assert(errors.empty?, "error free validation")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestAreaSeries < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
p = Axlsx::Package.new
|
7
|
+
@ws = p.workbook.add_worksheet :name=>"hmmm"
|
8
|
+
chart = @ws.add_chart Axlsx::AreaChart, :title => "fishery"
|
9
|
+
@series = chart.add_series(
|
10
|
+
:data => [0,1,2],
|
11
|
+
:labels => ["zero", "one", "two"],
|
12
|
+
:title => "bob",
|
13
|
+
:color => "#FF0000",
|
14
|
+
:show_marker => true,
|
15
|
+
:smooth => true
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_initialize
|
20
|
+
assert_equal(@series.title.text, "bob", "series title has been applied")
|
21
|
+
assert_equal(@series.labels.class, Axlsx::AxDataSource)
|
22
|
+
assert_equal(@series.data.class, Axlsx::NumDataSource)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_show_marker
|
26
|
+
assert_equal(true, @series.show_marker)
|
27
|
+
@series.show_marker = false
|
28
|
+
assert_equal(false, @series.show_marker)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_smooth
|
32
|
+
assert_equal(true, @series.smooth)
|
33
|
+
@series.smooth = false
|
34
|
+
assert_equal(false, @series.smooth)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_marker_symbol
|
38
|
+
assert_equal(:default, @series.marker_symbol)
|
39
|
+
@series.marker_symbol = :circle
|
40
|
+
assert_equal(:circle, @series.marker_symbol)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_to_xml_string
|
44
|
+
doc = Nokogiri::XML(wrap_with_namespaces(@series))
|
45
|
+
assert(doc.xpath("//srgbClr[@val='#{@series.color}']"))
|
46
|
+
assert_equal(xpath_with_namespaces(doc, "//c:marker").size, 0)
|
47
|
+
assert(doc.xpath("//smooth"))
|
48
|
+
|
49
|
+
@series.marker_symbol = :diamond
|
50
|
+
doc = Nokogiri::XML(wrap_with_namespaces(@series))
|
51
|
+
assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='diamond']").size, 1)
|
52
|
+
|
53
|
+
@series.show_marker = false
|
54
|
+
doc = Nokogiri::XML(wrap_with_namespaces(@series))
|
55
|
+
assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='none']").size, 1)
|
56
|
+
end
|
57
|
+
|
58
|
+
def wrap_with_namespaces(series)
|
59
|
+
'<c:chartSpace xmlns:c="' <<
|
60
|
+
Axlsx::XML_NS_C <<
|
61
|
+
'" xmlns:a="' <<
|
62
|
+
Axlsx::XML_NS_A <<
|
63
|
+
'">' <<
|
64
|
+
series.to_xml_string <<
|
65
|
+
'</c:chartSpace>'
|
66
|
+
end
|
67
|
+
|
68
|
+
def xpath_with_namespaces(doc, xpath)
|
69
|
+
doc.xpath(xpath, "a" => Axlsx::XML_NS_A, "c" => Axlsx::XML_NS_C)
|
70
|
+
end
|
71
|
+
end
|
data/test/drawing/tc_axis.rb
CHANGED
@@ -61,6 +61,33 @@ class TestAxis < Test::Unit::TestCase
|
|
61
61
|
assert_nothing_raised("accepts valid format code") { @axis.format_code = "00.##" }
|
62
62
|
end
|
63
63
|
|
64
|
+
def create_chart_with_formatting(format_string=nil)
|
65
|
+
p = Axlsx::Package.new
|
66
|
+
p.workbook.add_worksheet(:name => "Formatting Test") do |sheet|
|
67
|
+
sheet.add_row(['test', 20])
|
68
|
+
sheet.add_chart(Axlsx::Bar3DChart, :start_at => [0,5], :end_at => [10, 20], :title => "Test Formatting") do |chart|
|
69
|
+
chart.add_series :data => sheet["B1:B1"], :labels => sheet["A1:A1"]
|
70
|
+
chart.val_axis.format_code = format_string if format_string
|
71
|
+
doc = Nokogiri::XML(chart.to_xml_string)
|
72
|
+
yield doc
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_format_code_resets_source_linked
|
78
|
+
create_chart_with_formatting("#,##0.00") do |doc|
|
79
|
+
assert_equal(doc.xpath("//c:valAx/c:numFmt[@formatCode='#,##0.00']").size, 1)
|
80
|
+
assert_equal(doc.xpath("//c:valAx/c:numFmt[@sourceLinked='0']").size, 1)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_no_format_code_keeps_source_linked
|
85
|
+
create_chart_with_formatting do |doc|
|
86
|
+
assert_equal(doc.xpath("//c:valAx/c:numFmt[@formatCode='General']").size, 1)
|
87
|
+
assert_equal(doc.xpath("//c:valAx/c:numFmt[@sourceLinked='1']").size, 1)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
64
91
|
def test_crosses
|
65
92
|
assert_raise(ArgumentError, "requires valid crosses") { @axis.crosses = 1 }
|
66
93
|
assert_nothing_raised("accepts valid crosses") { @axis.crosses = :min }
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestBarChart < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@p = Axlsx::Package.new
|
7
|
+
ws = @p.workbook.add_worksheet
|
8
|
+
@row = ws.add_row ["one", 1, Time.now]
|
9
|
+
@chart = ws.add_chart Axlsx::BarChart, :title => "fishery"
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_initialization
|
16
|
+
assert_equal(@chart.grouping, :clustered, "grouping defualt incorrect")
|
17
|
+
assert_equal(@chart.series_type, Axlsx::BarSeries, "series type incorrect")
|
18
|
+
assert_equal(@chart.bar_dir, :bar, " bar direction incorrect")
|
19
|
+
assert(@chart.cat_axis.is_a?(Axlsx::CatAxis), "category axis not created")
|
20
|
+
assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_bar_direction
|
24
|
+
assert_raise(ArgumentError, "require valid bar direction") { @chart.bar_dir = :left }
|
25
|
+
assert_nothing_raised("allow valid bar direction") { @chart.bar_dir = :col }
|
26
|
+
assert(@chart.bar_dir == :col)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_grouping
|
30
|
+
assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
|
31
|
+
assert_nothing_raised("allow valid grouping") { @chart.grouping = :standard }
|
32
|
+
assert(@chart.grouping == :standard)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def test_gapWidth
|
37
|
+
assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = 200 }
|
38
|
+
assert_nothing_raised("allow valid gapWidth") { @chart.gap_width = "200%" }
|
39
|
+
assert(@chart.gap_width == "200%")
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_gapDepth
|
43
|
+
assert_raise(ArgumentError, "require valid gap_depth") { @chart.gap_depth = 200 }
|
44
|
+
assert_nothing_raised("allow valid gap_depth") { @chart.gap_depth = "200%" }
|
45
|
+
assert(@chart.gap_depth == "200%")
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_shape
|
49
|
+
assert_raise(ArgumentError, "require valid shape") { @chart.shape = :star }
|
50
|
+
assert_nothing_raised("allow valid shape") { @chart.shape = :cone }
|
51
|
+
assert(@chart.shape == :cone)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_to_xml_string
|
55
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
|
56
|
+
doc = Nokogiri::XML(@chart.to_xml_string)
|
57
|
+
errors = []
|
58
|
+
schema.validate(doc).each do |error|
|
59
|
+
errors.push error
|
60
|
+
puts error.message
|
61
|
+
end
|
62
|
+
assert(errors.empty?, "error free validation")
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_to_xml_string_has_axes_in_correct_order
|
66
|
+
str = @chart.to_xml_string
|
67
|
+
cat_axis_position = str.index(@chart.axes[:cat_axis].id.to_s)
|
68
|
+
val_axis_position = str.index(@chart.axes[:val_axis].id.to_s)
|
69
|
+
assert(cat_axis_position < val_axis_position, "cat_axis must occur earlier than val_axis in the XML")
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestBubbleChart < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@p = Axlsx::Package.new
|
6
|
+
@chart = nil
|
7
|
+
@p.workbook.add_worksheet do |sheet|
|
8
|
+
sheet.add_row ["First", 1, 5, 7, 9]
|
9
|
+
sheet.add_row ["", 1, 25, 49, 81]
|
10
|
+
sheet.add_row ["", 1, 42, 60, 75]
|
11
|
+
sheet.add_row ["Second", 5, 2, 14, 9]
|
12
|
+
sheet.add_row ["", 5, 10, 15, 20]
|
13
|
+
sheet.add_row ["", 5, 28, 92, 13]
|
14
|
+
sheet.add_chart(Axlsx::BubbleChart, :title => "example: Bubble Chart") do |chart|
|
15
|
+
chart.start_at 0, 4
|
16
|
+
chart.end_at 10, 19
|
17
|
+
chart.add_series :xData => sheet["B1:E1"], :yData => sheet["B2:E2"], :bubbleSize => sheet["B3:E3"], :title => sheet["A1"]
|
18
|
+
chart.add_series :xData => sheet["B4:E4"], :yData => sheet["B5:E5"], :bubbleSize => sheet["B6:E6"], :title => sheet["A3"]
|
19
|
+
@chart = chart
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_initialization
|
28
|
+
assert_equal(@chart.series_type, Axlsx::BubbleSeries, "series type incorrect")
|
29
|
+
assert(@chart.xValAxis.is_a?(Axlsx::ValAxis), "independant value axis not created")
|
30
|
+
assert(@chart.yValAxis.is_a?(Axlsx::ValAxis), "dependant value axis not created")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_to_xml_string
|
34
|
+
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
|
35
|
+
doc = Nokogiri::XML(@chart.to_xml_string)
|
36
|
+
errors = []
|
37
|
+
schema.validate(doc).each do |error|
|
38
|
+
errors.push error
|
39
|
+
puts error.message
|
40
|
+
end
|
41
|
+
assert(errors.empty?, "error free validation")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'tc_helper.rb'
|
2
|
+
|
3
|
+
class TestBubbleSeries < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
p = Axlsx::Package.new
|
7
|
+
@ws = p.workbook.add_worksheet :name=>"hmmm"
|
8
|
+
@chart = @ws.add_chart Axlsx::BubbleChart, :title => "Bubble Chart"
|
9
|
+
@series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :bubbleSize=>[1,5,7], :title=>"GDP", :color => 'FF0000'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_initialize
|
13
|
+
assert_equal(@series.title.text, "GDP", "series title has been applied")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_to_xml_string
|
17
|
+
doc = Nokogiri::XML(@chart.to_xml_string)
|
18
|
+
assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size,2)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/test/drawing/tc_chart.rb
CHANGED
@@ -6,7 +6,7 @@ class TestChart < Test::Unit::TestCase
|
|
6
6
|
@p = Axlsx::Package.new
|
7
7
|
ws = @p.workbook.add_worksheet
|
8
8
|
@row = ws.add_row ["one", 1, Time.now]
|
9
|
-
@chart = ws.add_chart Axlsx::Bar3DChart, :title => "fishery"
|
9
|
+
@chart = ws.add_chart Axlsx::Bar3DChart, :title => "fishery", :bg_color => "000000"
|
10
10
|
end
|
11
11
|
|
12
12
|
def teardown
|
@@ -27,17 +27,30 @@ class TestChart < Test::Unit::TestCase
|
|
27
27
|
assert_equal(@chart.title.cell, @row.cells.first)
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_style
|
31
|
+
assert_raise(ArgumentError) { @chart.style = 49 }
|
32
|
+
assert_nothing_raised { @chart.style = 2 }
|
33
|
+
assert_equal(@chart.style, 2)
|
34
|
+
end
|
35
|
+
|
30
36
|
def test_to_from_marker_access
|
31
37
|
assert(@chart.to.is_a?(Axlsx::Marker))
|
32
38
|
assert(@chart.from.is_a?(Axlsx::Marker))
|
33
39
|
end
|
34
40
|
|
35
|
-
def
|
36
|
-
assert_raise(ArgumentError) { @chart.
|
37
|
-
assert_nothing_raised { @chart.
|
38
|
-
assert_equal(@chart.
|
41
|
+
def test_bg_color
|
42
|
+
assert_raise(ArgumentError) { @chart.bg_color = 2 }
|
43
|
+
assert_nothing_raised { @chart.bg_color = "FFFFFF" }
|
44
|
+
assert_equal(@chart.bg_color, "FFFFFF")
|
45
|
+
|
39
46
|
end
|
40
|
-
|
47
|
+
|
48
|
+
def test_title_size
|
49
|
+
assert_raise(ArgumentError) { @chart.title_size = 2 }
|
50
|
+
assert_nothing_raised { @chart.title_size = "100" }
|
51
|
+
assert_equal(@chart.title.text_size, "100")
|
52
|
+
end
|
53
|
+
|
41
54
|
def test_vary_colors
|
42
55
|
assert_equal(true, @chart.vary_colors)
|
43
56
|
assert_raise(ArgumentError) { @chart.vary_colors = 7 }
|
@@ -63,7 +76,7 @@ class TestChart < Test::Unit::TestCase
|
|
63
76
|
@chart.start_at [5,6]
|
64
77
|
assert_equal(@chart.graphic_frame.anchor.from.col, 5)
|
65
78
|
assert_equal(@chart.graphic_frame.anchor.from.row, 6)
|
66
|
-
|
79
|
+
|
67
80
|
end
|
68
81
|
|
69
82
|
def test_end_at
|
@@ -76,7 +89,7 @@ class TestChart < Test::Unit::TestCase
|
|
76
89
|
@chart.end_at [10,11]
|
77
90
|
assert_equal(@chart.graphic_frame.anchor.to.col, 10)
|
78
91
|
assert_equal(@chart.graphic_frame.anchor.to.row, 11)
|
79
|
-
|
92
|
+
|
80
93
|
end
|
81
94
|
|
82
95
|
def test_add_series
|
@@ -88,13 +101,13 @@ class TestChart < Test::Unit::TestCase
|
|
88
101
|
def test_pn
|
89
102
|
assert_equal(@chart.pn, "charts/chart1.xml")
|
90
103
|
end
|
91
|
-
|
104
|
+
|
92
105
|
def test_d_lbls
|
93
106
|
assert_equal(nil, @chart.instance_values[:d_lbls])
|
94
107
|
@chart.d_lbls.d_lbl_pos = :t
|
95
108
|
assert(@chart.d_lbls.is_a?(Axlsx::DLbls), 'DLbls instantiated on access')
|
96
109
|
end
|
97
|
-
|
110
|
+
|
98
111
|
def test_to_xml_string
|
99
112
|
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
|
100
113
|
doc = Nokogiri::XML(@chart.to_xml_string)
|
@@ -6,6 +6,12 @@
|
|
6
6
|
@data_source = Axlsx::NumDataSource.new :data => ["1", "2", "3"]
|
7
7
|
end
|
8
8
|
|
9
|
+
def test_tag_name
|
10
|
+
assert_raise(ArgumentError) { @data_source.tag_name = :zVal }
|
11
|
+
assert_nothing_raised { @data_source.tag_name = :yVal }
|
12
|
+
assert_nothing_raised { @data_source.tag_name = :bubbleSize }
|
13
|
+
end
|
14
|
+
|
9
15
|
def test_to_xml_string_strLit
|
10
16
|
str = '<?xml version="1.0" encoding="UTF-8"?>'
|
11
17
|
str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '">'
|