From 173f1c49fb449aebc5ddf30a9387006ee54e5260 Mon Sep 17 00:00:00 2001 From: Moses Hohman Date: Sun, 23 Jun 2013 01:06:26 -0500 Subject: Fixes Issue #202 Axes are borked in Bar3DChart --- lib/axlsx/drawing/axes.rb | 4 +++- test/drawing/tc_axes.rb | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/drawing/tc_axes.rb 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 << '' } + # 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 << '' } 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 = '' + str << '' + @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 -- cgit v1.2.3