diff options
| author | Moses Hohman <[email protected]> | 2013-06-27 15:36:34 -0500 |
|---|---|---|
| committer | Moses Hohman <[email protected]> | 2013-06-27 15:38:53 -0500 |
| commit | c254678321c3ae620aa8a50161331d3f3c218f78 (patch) | |
| tree | 8f6bbdff5b44918186afbeaf122bd560b60cf5a6 | |
| parent | 9e2b64a27b2f13694fb1f53d1e50cc5120714521 (diff) | |
| download | caxlsx-c254678321c3ae620aa8a50161331d3f3c218f78.tar.gz caxlsx-c254678321c3ae620aa8a50161331d3f3c218f78.zip | |
Fixes Issue #202 Axes are borked in Bar3DChart by requiring axis order in the constructor
| -rw-r--r-- | lib/axlsx/drawing/axes.rb | 6 | ||||
| -rw-r--r-- | lib/axlsx/drawing/bar_3D_chart.rb | 4 | ||||
| -rw-r--r-- | test/drawing/tc_axes.rb | 14 | ||||
| -rw-r--r-- | test/drawing/tc_bar_3D_chart.rb | 6 |
4 files changed, 15 insertions, 15 deletions
diff --git a/lib/axlsx/drawing/axes.rb b/lib/axlsx/drawing/axes.rb index fc440b1a..bc40e532 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 index caa242ad..e3c26936 100644 --- a/test/drawing/tc_axes.rb +++ b/test/drawing/tc_axes.rb @@ -1,16 +1,8 @@ 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") + 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 |
