chart2/qa/extras/chart2export.cxx            |   18 ++++++++++++++++++
 chart2/qa/extras/data/docx/TableOnPage3.docx |binary
 chart2/source/tools/InternalDataProvider.cxx |    8 ++++++--
 3 files changed, 24 insertions(+), 2 deletions(-)

New commits:
commit cfd82e7a2cc2b45b738eb0efa0827196d2de61a4
Author:     Justin Luth <justin_l...@sil.org>
AuthorDate: Fri Mar 4 07:57:31 2022 +0200
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Wed Mar 16 10:28:42 2022 +0100

    tdf#128747 chart2: don't overwrite labels
    
    In almost every case, the values of a labeledDataSequence
    create a new column, and therefore the label is attached
    to the last column.
    
    However, in the case where there are no values at all,
    then this function is not called (for the value portion),
    resulting in no new column being created,
    and thus the label overwrote the previous series label.
    
    Empty-value columns are excluded in later code,
    so perhaps we shouldn't addDataSequenceToMap either,
    but I don't know the implications of that.
    
    Change-Id: Iad4ab54552b3c6b144feb2bc223ddae538316fa7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130946
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/chart2/qa/extras/chart2export.cxx 
b/chart2/qa/extras/chart2export.cxx
index bca7897025a0..c333ab9d651e 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -119,6 +119,7 @@ public:
     void testPlotVisOnlyXLSX();
     void testBarChartVaryColorsXLSX();
     void testTdf96161();
+    void testTableOnPage3();
     void testMultipleAxisXLSX();
     void testSecondaryAxisXLSX();
     void testBarChartSecondaryAxisXLSX();
@@ -213,6 +214,7 @@ public:
     CPPUNIT_TEST(testPlotVisOnlyXLSX);
     CPPUNIT_TEST(testBarChartVaryColorsXLSX);
     CPPUNIT_TEST(testTdf96161);
+    CPPUNIT_TEST(testTableOnPage3);
     CPPUNIT_TEST(testMultipleAxisXLSX);
     CPPUNIT_TEST(testSecondaryAxisXLSX);
     CPPUNIT_TEST(testBarChartSecondaryAxisXLSX);
@@ -1900,6 +1902,22 @@ void Chart2ExportTest::testTdf96161()
     assertXPath(pXmlDoc, 
"/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:varyColors", "val", "0");
 }
 
+void Chart2ExportTest::testTableOnPage3()
+{
+    load(u"/chart2/qa/extras/data/docx/", "TableOnPage3.docx");
+    reload("Office Open XML Text");
+
+    Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xChartDoc.is());
+    uno::Reference< chart::XChartDataArray > 
xDataArray(xChartDoc->getDataProvider(), UNO_QUERY_THROW);
+    Sequence<OUString> aColumnDesc = xDataArray->getColumnDescriptions();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("There must be 4 columns and descriptions", 
static_cast<sal_Int32>(4), aColumnDesc.getLength());
+    CPPUNIT_ASSERT_EQUAL(OUString("If oversubscription relative to allowance 
increases at the same average rate B15-B17"), aColumnDesc[0]);
+    CPPUNIT_ASSERT_EQUAL(OUString("Known requirements"), aColumnDesc[1]);
+    CPPUNIT_ASSERT_EQUAL(OUString("Allowance"), aColumnDesc[2]);
+    CPPUNIT_ASSERT_EQUAL(OUString("If oversubscription relative to allowance 
holds steady at average oversubscription level B15-B17"), aColumnDesc[3]);
+}
+
 void Chart2ExportTest::testMultipleAxisXLSX()
 {
     load(u"/chart2/qa/extras/data/ods/", "multiple_axis.ods");
diff --git a/chart2/qa/extras/data/docx/TableOnPage3.docx 
b/chart2/qa/extras/data/docx/TableOnPage3.docx
new file mode 100644
index 000000000000..79763bd35290
Binary files /dev/null and b/chart2/qa/extras/data/docx/TableOnPage3.docx differ
diff --git a/chart2/source/tools/InternalDataProvider.cxx 
b/chart2/source/tools/InternalDataProvider.cxx
index e1bf32b7ff10..6fe4ec94a8db 100644
--- a/chart2/source/tools/InternalDataProvider.cxx
+++ b/chart2/source/tools/InternalDataProvider.cxx
@@ -647,8 +647,12 @@ InternalDataProvider::createDataSequenceFromArray( const 
OUString& rArrayStr, st
         sal_Int32 nColSize = m_aInternalData.getColumnCount();
         if (!aRawElems.empty() && nColSize)
         {
-            std::vector<uno::Any> aLabels(1, uno::Any(aRawElems[0]));
-            m_aInternalData.setComplexColumnLabel(nColSize-1, 
std::move(aLabels));
+            // Do not overwrite an existing label (attempted by series with no 
data values)
+            if 
(!m_aInternalData.getComplexColumnLabel(nColSize-1)[0].hasValue())
+            {
+                std::vector<uno::Any> aLabels(1, uno::Any(aRawElems[0]));
+                m_aInternalData.setComplexColumnLabel(nColSize-1, 
std::move(aLabels));
+            }
 
             OUString aRangeRep = lcl_aLabelRangePrefix + 
OUString::number(nColSize-1);
             xSeq.set(new UncachedDataSequence(this, aRangeRep));

Reply via email to