[Libreoffice-commits] core.git: chart2/qa chart2/source

Balazs Varga (via logerrit) logerrit at kemper.freedesktop.org
Fri Aug 30 11:19:05 UTC 2019


 chart2/qa/extras/chart2import.cxx            |   18 ++++++++++++++++++
 chart2/qa/extras/data/docx/tdf124083.docx    |binary
 chart2/source/tools/InternalDataProvider.cxx |   11 +++++++++--
 3 files changed, 27 insertions(+), 2 deletions(-)

New commits:
commit 4afd65776457be3391f3e1340da614dffc8f227b
Author:     Balazs Varga <balazs.varga991 at gmail.com>
AuthorDate: Tue Aug 27 10:55:30 2019 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Fri Aug 30 13:18:14 2019 +0200

    tdf#124083 OOXML import: fix broken charts with missing value X
    
    Importing NaN value X, ie. where only "ptCount" was defined without
    explicit data, messed up the charts replacing all X values with sequence
    1, 2, 3..., showing data points in wrong X positions, also showing the
    invalid "NaN" data points. Now internal data table contains the original
    X values, including NaNs, fixing broken charts.
    
    Change-Id: Ic3c69e15095d9b29643f5daef8f58c58b4a442db
    Reviewed-on: https://gerrit.libreoffice.org/78177
    Reviewed-by: László Németh <nemeth at numbertext.org>
    Tested-by: László Németh <nemeth at numbertext.org>

diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index 116a0a93519f..53f4a2d30e19 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -134,6 +134,7 @@ public:
     void testExternalStrRefsXLSX();
     void testSourceNumberFormatComplexCategoriesXLS();
     void testMultilevelCategoryAxis();
+    void testXaxisValues();
     void testTdf123504();
     void testTdf122765();
 
@@ -222,6 +223,7 @@ public:
     CPPUNIT_TEST(testExternalStrRefsXLSX);
     CPPUNIT_TEST(testSourceNumberFormatComplexCategoriesXLS);
     CPPUNIT_TEST(testMultilevelCategoryAxis);
+    CPPUNIT_TEST(testXaxisValues);
     CPPUNIT_TEST(testTdf123504);
     CPPUNIT_TEST(testTdf122765);
 
@@ -2023,6 +2025,22 @@ void Chart2ImportTest::testMultilevelCategoryAxis()
     CPPUNIT_ASSERT_EQUAL(OUString("Categoria 4"), aCategories[3][1]);
 }
 
+void Chart2ImportTest::testXaxisValues()
+{
+    load("/chart2/qa/extras/data/docx/", "tdf124083.docx");
+    uno::Reference< chart2::XChartDocument > xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xChartDoc.is());
+
+    const uno::Reference< chart2::data::XDataSequence > xDataSeq = getDataSequenceFromDocByRole(xChartDoc, "values-x");
+    Sequence<uno::Any> xSequence = xDataSeq->getData();
+    // test X values
+    CPPUNIT_ASSERT_EQUAL(uno::Any(0.04), xSequence[0]);
+    CPPUNIT_ASSERT(rtl::math::isNan(*static_cast<const double*>(xSequence[1].getValue())));
+    CPPUNIT_ASSERT_EQUAL(uno::Any(0.16), xSequence[2]);
+    CPPUNIT_ASSERT_EQUAL(uno::Any(0.11), xSequence[3]);
+    CPPUNIT_ASSERT(rtl::math::isNan(*static_cast<const double*>(xSequence[4].getValue())));
+}
+
 void Chart2ImportTest::testTdf123504()
 {
     load("/chart2/qa/extras/data/ods/", "pie_chart_100_and_0.ods");
diff --git a/chart2/qa/extras/data/docx/tdf124083.docx b/chart2/qa/extras/data/docx/tdf124083.docx
new file mode 100644
index 000000000000..b8030ca9a807
Binary files /dev/null and b/chart2/qa/extras/data/docx/tdf124083.docx differ
diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx
index 0fa8a4bff815..eec8280425b4 100644
--- a/chart2/source/tools/InternalDataProvider.cxx
+++ b/chart2/source/tools/InternalDataProvider.cxx
@@ -526,7 +526,6 @@ InternalDataProvider::createDataSequenceFromArray( const OUString& rArrayStr, co
             if (bInQuote)
             {
                 // Opening quote.
-                bAllNumeric = false;
                 pElem = nullptr;
             }
             else
@@ -534,6 +533,9 @@ InternalDataProvider::createDataSequenceFromArray( const OUString& rArrayStr, co
                 // Closing quote.
                 if (pElem)
                     aElem = OUString(pElem, p-pElem);
+                // Non empty string
+                if (!aElem.isEmpty())
+                    bAllNumeric = false;
                 aRawElems.push_back(aElem);
                 pElem = nullptr;
                 aElem.clear();
@@ -591,7 +593,12 @@ InternalDataProvider::createDataSequenceFromArray( const OUString& rArrayStr, co
         if (bAllNumeric)
         {
             for (const OUString & aRawElem : aRawElems)
-                aValues.push_back(aRawElem.toDouble());
+            {
+                if (!aRawElem.isEmpty())
+                    aValues.push_back(aRawElem.toDouble());
+                else
+                    aValues.push_back(NAN);
+            }
         }
         else
         {


More information about the Libreoffice-commits mailing list