From a960e6be4032e7f5638359503c81cdfa31a1f7b5 Mon Sep 17 00:00:00 2001 From: Moses Hohman Date: Thu, 27 Jun 2013 15:36:34 -0500 Subject: Fixes Issue #202 Axes are borked in Bar3DChart by requiring axis order in the constructor --- lib/axlsx/drawing/axes.rb | 6 ++++-- lib/axlsx/drawing/bar_3D_chart.rb | 4 ++-- test/drawing/tc_axes.rb | 8 ++++++++ test/drawing/tc_bar_3D_chart.rb | 6 ++++++ 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/drawing/tc_axes.rb diff --git a/lib/axlsx/drawing/axes.rb b/lib/axlsx/drawing/axes.rb index c3a8dd85..40364d10 100644 --- a/lib/axlsx/drawing/axes.rb +++ b/lib/axlsx/drawing/axes.rb @@ -5,9 +5,11 @@ module Axlsx class Axes # @param [Hash] options options used to generate axis each key - # should be an axis name like :val_axix and its value should be the - # class of the axis type to construct. + # should be an axis name like :val_axis and its value should be the + # class of the axis type to construct. The :cat_axis, if there is one, + # must come first (we assume a Ruby 1.9+ Hash or an OrderedHash). def initialize(options={}) + raise(ArgumentError, "CatAxis must come first") if options.keys.include?(:cat_axis) && options.keys.first != :cat_axis options.each do |name, axis_class| add_axis(name, axis_class) end diff --git a/lib/axlsx/drawing/bar_3D_chart.rb b/lib/axlsx/drawing/bar_3D_chart.rb index 3315ad80..755f334c 100644 --- a/lib/axlsx/drawing/bar_3D_chart.rb +++ b/lib/axlsx/drawing/bar_3D_chart.rb @@ -142,10 +142,10 @@ module Axlsx end # A hash of axes used by this chart. Bar charts have a value and - # category axes specified via axex[:val_axes] and axes[:cat_axis] + # category axes specified via axes[:val_axes] and axes[:cat_axis] # @return [Axes] def axes - @axes ||= Axes.new(:val_axis => ValAxis, :cat_axis => CatAxis) + @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis) end end end diff --git a/test/drawing/tc_axes.rb b/test/drawing/tc_axes.rb new file mode 100644 index 00000000..e3c26936 --- /dev/null +++ b/test/drawing/tc_axes.rb @@ -0,0 +1,8 @@ +require 'tc_helper.rb' + +class TestAxes < Test::Unit::TestCase + def test_constructor_requires_cat_axis_first + assert_raise(ArgumentError) { Axlsx::Axes.new(:val_axis => Axlsx::ValAxis, :cat_axis => Axlsx::CatAxis) } + assert_nothing_raised { Axlsx::Axes.new(:cat_axis => Axlsx::CatAxis, :val_axis => Axlsx::ValAxis) } + end +end \ No newline at end of file diff --git a/test/drawing/tc_bar_3D_chart.rb b/test/drawing/tc_bar_3D_chart.rb index 3e1ff342..0cae7af6 100644 --- a/test/drawing/tc_bar_3D_chart.rb +++ b/test/drawing/tc_bar_3D_chart.rb @@ -62,4 +62,10 @@ class TestBar3DChart < Test::Unit::TestCase assert(errors.empty?, "error free validation") end + def test_to_xml_string_has_axes_in_correct_order + str = @chart.to_xml_string + cat_axis_position = str.index(@chart.axes[:cat_axis].id.to_s) + val_axis_position = str.index(@chart.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 -- cgit v1.2.3