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

Balazs Varga (via logerrit) logerrit at kemper.freedesktop.org
Fri Apr 24 13:28:52 UTC 2020


 chart2/qa/extras/chart2export.cxx            |   20 ++++++++
 chart2/qa/extras/data/ods/tdf132076.ods      |binary
 chart2/qa/extras/data/xlsx/tdf132076.xlsx    |binary
 oox/source/drawingml/chart/axisconverter.cxx |   10 ++--
 oox/source/export/chartexport.cxx            |   62 ++++++++++++++++++++++++---
 5 files changed, 82 insertions(+), 10 deletions(-)

New commits:
commit 75156c6fd73dc202df541306e1636727d51d6fc3
Author:     Balazs Varga <balazs.varga991 at gmail.com>
AuthorDate: Thu Apr 16 22:08:15 2020 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Fri Apr 24 15:28:17 2020 +0200

    tdf#132076 Chart OOXML: fix lost date format of X axis
    
    labels. Set the number format of category or date axes
    too and use date axis type for date axes at import.
    Export the real axis type of the X axis.
    
    Change-Id: I45f5c69f0aadc4ec1db0b8873b5e374e2728d39c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92396
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 378e2361d034..b44d712dbd50 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -165,6 +165,7 @@ public:
     void testTdf75330();
     void testTdf127792();
     void testTdf131979();
+    void testTdf132076();
 
     CPPUNIT_TEST_SUITE(Chart2ExportTest);
     CPPUNIT_TEST(testErrorBarXLSX);
@@ -293,6 +294,7 @@ public:
     CPPUNIT_TEST(testTdf75330);
     CPPUNIT_TEST(testTdf127792);
     CPPUNIT_TEST(testTdf131979);
+    CPPUNIT_TEST(testTdf132076);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -2711,6 +2713,24 @@ void Chart2ExportTest::testTdf131979()
     }
 }
 
+void Chart2ExportTest::testTdf132076()
+{
+    {
+        load("/chart2/qa/extras/data/ods/", "tdf132076.ods");
+        xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
+        CPPUNIT_ASSERT(pXmlDoc);
+        assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:numFmt", "formatCode", "dd");
+        assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:numFmt", "sourceLinked", "0");
+    }
+    {
+        load("/chart2/qa/extras/data/xlsx/", "tdf132076.xlsx");
+        xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
+        CPPUNIT_ASSERT(pXmlDoc);
+        assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:numFmt", "formatCode", "dd");
+        assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:numFmt", "sourceLinked", "0");
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/data/ods/tdf132076.ods b/chart2/qa/extras/data/ods/tdf132076.ods
new file mode 100644
index 000000000000..348dd0d71f25
Binary files /dev/null and b/chart2/qa/extras/data/ods/tdf132076.ods differ
diff --git a/chart2/qa/extras/data/xlsx/tdf132076.xlsx b/chart2/qa/extras/data/xlsx/tdf132076.xlsx
new file mode 100644
index 000000000000..799ef9c8555a
Binary files /dev/null and b/chart2/qa/extras/data/xlsx/tdf132076.xlsx differ
diff --git a/oox/source/drawingml/chart/axisconverter.cxx b/oox/source/drawingml/chart/axisconverter.cxx
index 9e62b61d73bc..d73632476550 100644
--- a/oox/source/drawingml/chart/axisconverter.cxx
+++ b/oox/source/drawingml/chart/axisconverter.cxx
@@ -205,10 +205,8 @@ void AxisConverter::convertFromModel(
                     OSL_ENSURE( (mrModel.mnTypeId == C_TOKEN( catAx )) || (mrModel.mnTypeId == C_TOKEN( dateAx )),
                         "AxisConverter::convertFromModel - unexpected axis model type (must: c:catAx or c:dateAx)" );
                     bool bDateAxis = mrModel.mnTypeId == C_TOKEN( dateAx );
-                    /*  Chart2 requires axis type CATEGORY for automatic
-                        category/date axis (even if it is a date axis
-                        currently). */
-                    aScaleData.AxisType = (bDateAxis && !mrModel.mbAuto) ? cssc2::AxisType::DATE : cssc2::AxisType::CATEGORY;
+                    // tdf#132076: set axis type to date, if it is a date axis!
+                    aScaleData.AxisType = bDateAxis ? cssc2::AxisType::DATE : cssc2::AxisType::CATEGORY;
                     aScaleData.AutoDateAxis = mrModel.mbAuto;
                     aScaleData.Categories = rTypeGroups.front()->createCategorySequence();
                     /* set default ShiftedCategoryPosition values for some charttype,
@@ -341,8 +339,10 @@ void AxisConverter::convertFromModel(
         xAxis->setScaleData( aScaleData );
 
         // number format ------------------------------------------------------
-        if( !mrModel.mbDeleted && ((aScaleData.AxisType == cssc2::AxisType::REALNUMBER) || (aScaleData.AxisType == cssc2::AxisType::PERCENT)) )
+        if( !mrModel.mbDeleted && aScaleData.AxisType != cssc2::AxisType::SERIES )
+        {
             getFormatter().convertNumberFormat(aAxisProp, mrModel.maNumberFormat, true);
+        }
 
         // position of crossing axis ------------------------------------------
 
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 16c4788b32b7..556e8a8a5958 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -67,6 +67,7 @@
 #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
 #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
 #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
+#include <com/sun/star/chart2/AxisType.hpp>
 
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/container/XNameAccess.hpp>
@@ -260,6 +261,39 @@ static bool lcl_isCategoryAxisShifted(const Reference< chart2::XChartDocument >&
     return isCategoryPositionShifted;
 }
 
+static sal_Int32 lcl_getCategoryAxisType( const Reference< chart2::XDiagram >& xDiagram, sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
+{
+    sal_Int32 nAxisType = -1;
+    try
+    {
+        Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
+            xDiagram, uno::UNO_QUERY_THROW);
+        const Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
+            xCooSysCnt->getCoordinateSystems());
+        for( const auto& xCooSys : aCooSysSeq )
+        {
+            OSL_ASSERT(xCooSys.is());
+            if( nDimensionIndex < xCooSys->getDimension() && nAxisIndex <= xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex) )
+            {
+                Reference< chart2::XAxis > xAxis = xCooSys->getAxisByDimension(nDimensionIndex, nAxisIndex);
+                OSL_ASSERT(xAxis.is());
+                if( xAxis.is() )
+                {
+                    chart2::ScaleData aScaleData = xAxis->getScaleData();
+                    nAxisType = aScaleData.AxisType;
+                    break;
+                }
+            }
+        }
+    }
+    catch (const uno::Exception&)
+    {
+        DBG_UNHANDLED_EXCEPTION("oox");
+    }
+
+    return nAxisType;
+}
+
 static bool lcl_isSeriesAttachedToFirstAxis(
     const Reference< chart2::XDataSeries > & xDataSeries )
 {
@@ -2644,7 +2678,7 @@ void ChartExport::exportAxes( )
 
 namespace {
 
-sal_Int32 getXAxisType(sal_Int32 eChartType)
+sal_Int32 getXAxisTypeByChartType(sal_Int32 eChartType)
 {
     if( (eChartType == chart::TYPEID_SCATTER)
             || (eChartType == chart::TYPEID_BUBBLE) )
@@ -2655,6 +2689,18 @@ sal_Int32 getXAxisType(sal_Int32 eChartType)
     return XML_catAx;
 }
 
+sal_Int32 getRealXAxisType(sal_Int32 nAxisType)
+{
+    if( nAxisType == chart2::AxisType::CATEGORY )
+        return XML_catAx;
+    else if( nAxisType == chart2::AxisType::DATE )
+        return XML_dateAx;
+    else if( nAxisType == chart2::AxisType::SERIES )
+        return XML_serAx;
+
+    return XML_valAx;
+}
+
 }
 
 void ChartExport::exportAxis(const AxisIdPair& rAxisIdPair)
@@ -2709,8 +2755,11 @@ void ChartExport::exportAxis(const AxisIdPair& rAxisIdPair)
             if( bHasXAxisMinorGrid )
                 xMinorGrid = xAxisXSupp->getXHelpGrid();
 
-            sal_Int32 eChartType = getChartType();
-            nAxisType = getXAxisType(eChartType);
+            nAxisType = lcl_getCategoryAxisType(mxNewDiagram, 0, 0);
+            if( nAxisType != -1 )
+                nAxisType = getRealXAxisType(nAxisType);
+            else
+                nAxisType = getXAxisTypeByChartType( getChartType() );
             // FIXME: axPos, need to check axis direction
             sAxPos = "b";
             break;
@@ -2767,8 +2816,11 @@ void ChartExport::exportAxis(const AxisIdPair& rAxisIdPair)
                 xAxisTitle = xAxisSupp->getSecondXAxisTitle();
             }
 
-            sal_Int32 eChartType = getChartType();
-            nAxisType = getXAxisType(eChartType);
+            nAxisType = lcl_getCategoryAxisType(mxNewDiagram, 0, 1);
+            if( nAxisType != -1 )
+                nAxisType = getRealXAxisType(nAxisType);
+            else
+                nAxisType = getXAxisTypeByChartType( getChartType() );
             // FIXME: axPos, need to check axis direction
             sAxPos = "t";
             break;


More information about the Libreoffice-commits mailing list