summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMoses Hohman <[email protected]>2013-06-23 01:06:26 -0500
committerMoses Hohman <[email protected]>2013-06-23 01:06:26 -0500
commit173f1c49fb449aebc5ddf30a9387006ee54e5260 (patch)
tree15262ded1d8fe4a6d4ce814423e22ccf0c3fa6e5
parent21fce3b99e639abe757716750a2a7f9970e572ab (diff)
downloadcaxlsx-173f1c49fb449aebc5ddf30a9387006ee54e5260.tar.gz
caxlsx-173f1c49fb449aebc5ddf30a9387006ee54e5260.zip
Fixes Issue #202 Axes are borked in Bar3DChart
-rw-r--r--lib/axlsx/drawing/axes.rb4
-rw-r--r--test/drawing/tc_axes.rb16
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/axlsx/drawing/axes.rb b/lib/axlsx/drawing/axes.rb
index c3a8dd85..fc440b1a 100644
--- a/lib/axlsx/drawing/axes.rb
+++ b/lib/axlsx/drawing/axes.rb
@@ -28,7 +28,9 @@ module Axlsx
# serialized. Otherwise, each axis is serialized in full.
def to_xml_string(str = '', options = {})
if options[:ids]
- axes.inject(str) { |string, axis| string << '<c:axId val="' << axis[1].id.to_s << '"/>' }
+ # CatAxis must come first in the XML (for Microsoft Excel at least)
+ sorted = axes.sort_by { |name, axis| axis.kind_of?(CatAxis) ? 0 : 1 }
+ sorted.inject(str) { |string, axis| string << '<c:axId val="' << axis[1].id.to_s << '"/>' }
else
axes.each { |axis| axis[1].to_xml_string(str) }
end
diff --git a/test/drawing/tc_axes.rb b/test/drawing/tc_axes.rb
new file mode 100644
index 00000000..caa242ad
--- /dev/null
+++ b/test/drawing/tc_axes.rb
@@ -0,0 +1,16 @@
+require 'tc_helper.rb'
+
+class TestAxes < Test::Unit::TestCase
+ def setup
+ @axes = Axlsx::Axes.new(:val_axis => Axlsx::ValAxis, :cat_axis => Axlsx::CatAxis)
+ end
+
+ def test_to_xml_string_just_ids
+ str = '<?xml version="1.0" encoding="UTF-8"?>'
+ str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '" xmlns:a="' << Axlsx::XML_NS_A << '">'
+ @axes.to_xml_string(str, :ids => true)
+ cat_axis_position = str.index(@axes[:cat_axis].id.to_s)
+ val_axis_position = str.index(@axes[:val_axis].id.to_s)
+ assert(cat_axis_position < val_axis_position, "cat_axis must occur earlier than val_axis in the XML")
+ end
+end \ No newline at end of file