summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMoses Hohman <[email protected]>2013-06-23 02:02:01 -0500
committerMoses Hohman <[email protected]>2013-06-23 11:20:01 -0500
commit24a491b2627ff10644637e1080fdbc31442e9664 (patch)
tree386c45e422317db18022b66e037744e4f028f1cb
parent21fce3b99e639abe757716750a2a7f9970e572ab (diff)
downloadcaxlsx-24a491b2627ff10644637e1080fdbc31442e9664.tar.gz
caxlsx-24a491b2627ff10644637e1080fdbc31442e9664.zip
provide a better default for dispBlanksAs and allow it to be configured
-rw-r--r--lib/axlsx/drawing/chart.rb18
-rw-r--r--lib/axlsx/util/validators.rb7
-rw-r--r--test/drawing/tc_chart.rb14
3 files changed, 38 insertions, 1 deletions
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb
index 79019a0a..1da3a253 100644
--- a/lib/axlsx/drawing/chart.rb
+++ b/lib/axlsx/drawing/chart.rb
@@ -20,6 +20,7 @@ module Axlsx
@graphic_frame.anchor.drawing.worksheet.workbook.charts << self
@series = SimpleTypedList.new Series
@show_legend = true
+ @display_blanks_as = :gap
@series_type = Series
@title = Title.new
parse_options options
@@ -70,6 +71,15 @@ module Axlsx
# @return [Boolean]
attr_reader :show_legend
+ # How to display blank values
+ # Options are
+ # * gap: Display nothing
+ # * span: Not sure what this does
+ # * zero: Display as if the value were zero, not blank
+ # @return [Symbol]
+ # Default :gap (although this really should vary by chart type and grouping)
+ attr_reader :display_blanks_as
+
# returns a relationship object for the chart
# @return [Axlsx::Relationship]
def relationship
@@ -105,6 +115,12 @@ module Axlsx
# @return [Boolean]
def show_legend=(v) Axlsx::validate_boolean(v); @show_legend = v; end
+ # How to display blank values
+ # @see display_blanks_as
+ # @param [Symbol] v
+ # @return [Symbol]
+ def display_blanks_as=(v) Axlsx::validate_display_blanks_as(v); @display_blanks_as = v; end
+
# The style for the chart.
# see ECMA Part 1 ยง21.2.2.196
# @param [Integer] v must be between 1 and 48
@@ -157,7 +173,7 @@ module Axlsx
str << '</c:legend>'
end
str << '<c:plotVisOnly val="1"/>'
- str << '<c:dispBlanksAs val="zero"/>'
+ str << '<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>'
str << '<c:showDLblsOverMax val="1"/>'
str << '</c:chart>'
str << '<c:printSettings>'
diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb
index 739a4de2..a161f0d9 100644
--- a/lib/axlsx/util/validators.rb
+++ b/lib/axlsx/util/validators.rb
@@ -290,4 +290,11 @@ module Axlsx
def self.validate_split_state_type(v)
RestrictionValidator.validate :split_state_type, [:frozen, :frozen_split, :split], v
end
+
+ # Requires that the value is a valid "display blanks as" type.
+ # valid types must be one of gap, span, zero
+ # @param [Any] v The value validated
+ def self.validate_display_blanks_as(v)
+ RestrictionValidator.validate :display_blanks_as, [:gap, :span, :zero], v
+ end
end
diff --git a/test/drawing/tc_chart.rb b/test/drawing/tc_chart.rb
index 03e4fd6f..751d2ae4 100644
--- a/test/drawing/tc_chart.rb
+++ b/test/drawing/tc_chart.rb
@@ -45,6 +45,14 @@ class TestChart < Test::Unit::TestCase
assert_equal(false, @chart.vary_colors)
end
+ def test_display_blanks_as
+ assert_equal(:gap, @chart.display_blanks_as, "default is not :gap")
+ assert_raise(ArgumentError, "did not validate possible values") { @chart.display_blanks_as = :hole }
+ assert_nothing_raised { @chart.display_blanks_as = :zero }
+ assert_nothing_raised { @chart.display_blanks_as = :span }
+ assert_equal(:span, @chart.display_blanks_as)
+ end
+
def test_start_at
@chart.start_at 15, 25
assert_equal(@chart.graphic_frame.anchor.from.col, 15)
@@ -94,4 +102,10 @@ class TestChart < Test::Unit::TestCase
assert(errors.empty?, "error free validation")
end
+ def test_to_xml_string_for_display_blanks_as
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
+ @chart.display_blanks_as = :span
+ doc = Nokogiri::XML(@chart.to_xml_string)
+ assert_equal("span", doc.xpath("//c:dispBlanksAs").attr("val").value, "did not use the display_blanks_as configuration")
+ end
end