diff options
| author | Stefan <[email protected]> | 2022-05-15 19:16:55 +0200 |
|---|---|---|
| committer | Stefan Daschek <[email protected]> | 2022-05-18 13:04:15 +0200 |
| commit | 3c8831827fc789cda2fe5333910710f4d75547d5 (patch) | |
| tree | c9039891c89d022caf87d25929edc3296a552bcd /test/drawing | |
| parent | 7a1ec08ad38c989ba7b9b30ef69d0143f71ba746 (diff) | |
| download | caxlsx-3c8831827fc789cda2fe5333910710f4d75547d5.tar.gz caxlsx-3c8831827fc789cda2fe5333910710f4d75547d5.zip | |
Completely hide chart titles if blank
Before this change, a chart with a blank title would show up in Excel with a default title like “Chart title” or “Diagrammtitel”.
It was not possible to completely hide a chart title: Setting it to an empty space would override Excel’s default, but the empty title did still occupy vertical space.
Per OOXML standard the `title` element is optional, so omitting it if the title is blank looks like the right thing to do and seems to work correctly in Excel.
Diffstat (limited to 'test/drawing')
| -rw-r--r-- | test/drawing/tc_chart.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/drawing/tc_chart.rb b/test/drawing/tc_chart.rb index 302d13cd..58622621 100644 --- a/test/drawing/tc_chart.rb +++ b/test/drawing/tc_chart.rb @@ -1,3 +1,5 @@ +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../" + require 'tc_helper.rb' class TestChart < Test::Unit::TestCase @@ -25,6 +27,8 @@ class TestChart < Test::Unit::TestCase @chart.title = @row.cells.first assert_equal(@chart.title.text, "one", "the title text was set via cell reference") assert_equal(@chart.title.cell, @row.cells.first) + @chart.title = "" + assert(@chart.title.empty?) end def test_style @@ -121,4 +125,14 @@ class TestChart < Test::Unit::TestCase 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 + + def test_to_xml_string_for_title + @chart.title = "foobar" + doc = Nokogiri::XML(@chart.to_xml_string) + assert_equal("foobar", doc.xpath("//c:title//c:tx//a:t").text) + + @chart.title = "" + doc = Nokogiri::XML(@chart.to_xml_string) + assert_equal(0, doc.xpath("//c:title").size) + end end |
