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 | 11 ++-- oox/source/export/chartexport.cxx | 62 ++++++++++++++++++++++++--- 5 files changed, 82 insertions(+), 11 deletions(-)
New commits: commit 7cd9fece534dd73be92a1acdcdf89ed17f3cbb8e Author: Balazs Varga <balazs.varga...@gmail.com> AuthorDate: Thu Apr 16 22:08:15 2020 +0200 Commit: Balazs Varga <balazs.varga...@gmail.com> CommitDate: Thu Jul 16 08:23:42 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. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92396 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit 75156c6fd73dc202df541306e1636727d51d6fc3) Change-Id: I45f5c69f0aadc4ec1db0b8873b5e374e2728d39c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98833 Tested-by: Gabor Kelemen <kelemen.gab...@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gab...@nisz.hu> diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index 6c693be3cce5..f1666188a00c 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -153,6 +153,7 @@ public: void testCustomLabelText(); void testTdf131979(); void testTdf126076(); + void testTdf132076(); CPPUNIT_TEST_SUITE(Chart2ExportTest); CPPUNIT_TEST(testErrorBarXLSX); @@ -269,6 +270,7 @@ public: CPPUNIT_TEST(testCustomLabelText); CPPUNIT_TEST(testTdf131979); CPPUNIT_TEST(testTdf126076); + CPPUNIT_TEST(testTdf132076); CPPUNIT_TEST_SUITE_END(); @@ -2481,6 +2483,24 @@ void Chart2ExportTest::testTdf126076() assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:marker", 0); } +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 86764b241e52..9c2b4fa9e993 100644 --- a/oox/source/drawingml/chart/axisconverter.cxx +++ b/oox/source/drawingml/chart/axisconverter.cxx @@ -207,10 +207,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, @@ -343,9 +341,10 @@ void AxisConverter::convertFromModel( xAxis->setScaleData( aScaleData ); // number format ------------------------------------------------------ - - if( (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 ab2628ec11dd..aa27692400b8 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -75,6 +75,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/drawing/XShape.hpp> @@ -269,6 +270,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 ) { @@ -2574,7 +2608,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) ) @@ -2585,6 +2619,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) @@ -2639,8 +2685,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; @@ -2697,8 +2746,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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits