chart2/qa/extras/chart2export.cxx | 15 ++++++ chart2/qa/extras/data/xlsx/tdf137917.xlsx |binary oox/source/export/chartexport.cxx | 75 ++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+)
New commits: commit e8a9d0050675034aa5d4670330ea47ef32306973 Author: Balazs Varga <balazs.varga...@gmail.com> AuthorDate: Wed Nov 4 11:18:56 2020 +0100 Commit: László Németh <nem...@numbertext.org> CommitDate: Fri Nov 6 11:30:57 2020 +0100 tdf#137917 Chart OOXML: fix export of TimeIncrement of Date axis Export of Major, Minor interval and baseTimeUnit of date axis as required by the OOXML standard. Change-Id: I09820ad99777874e76176dcd8b64cbe864eaefdc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105284 Tested-by: Jenkins Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index d86fa14ef84c..73f9166d176c 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -181,6 +181,7 @@ public: void testTdf123647(); void testTdf136267(); void testDataLabelPlacementPieChart(); + void testTdf137917(); CPPUNIT_TEST_SUITE(Chart2ExportTest); CPPUNIT_TEST(testErrorBarXLSX); @@ -324,6 +325,7 @@ public: CPPUNIT_TEST(testTdf123647); CPPUNIT_TEST(testTdf136267); CPPUNIT_TEST(testDataLabelPlacementPieChart); + CPPUNIT_TEST(testTdf137917); CPPUNIT_TEST_SUITE_END(); @@ -2969,6 +2971,19 @@ void Chart2ExportTest::testDataLabelPlacementPieChart() } +void Chart2ExportTest::testTdf137917() +{ + load("/chart2/qa/extras/data/xlsx/", "tdf137917.xlsx"); + xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML"); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:baseTimeUnit", "val", "days"); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:majorUnit", "val", "1"); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:majorTimeUnit", "val", "months"); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:minorUnit", "val", "7"); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:dateAx/c:minorTimeUnit", "val", "days"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/chart2/qa/extras/data/xlsx/tdf137917.xlsx b/chart2/qa/extras/data/xlsx/tdf137917.xlsx new file mode 100644 index 000000000000..4d08a23acd8a Binary files /dev/null and b/chart2/qa/extras/data/xlsx/tdf137917.xlsx differ diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 19c5b7abf5f4..f13cbca60d8c 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -48,6 +48,9 @@ #include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/chart/MissingValueTreatment.hpp> #include <com/sun/star/chart/XDiagramPositioning.hpp> +#include <com/sun/star/chart/TimeIncrement.hpp> +#include <com/sun/star/chart/TimeInterval.hpp> +#include <com/sun/star/chart/TimeUnit.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> #include <com/sun/star/chart2/RelativeSize.hpp> @@ -286,6 +289,51 @@ static sal_Int32 lcl_getCategoryAxisType( const Reference< chart2::XDiagram >& x return nAxisType; } +static OUString lclGetTimeUnitToken( sal_Int32 nTimeUnit ) +{ + switch( nTimeUnit ) + { + case cssc::TimeUnit::DAY: return "days"; + case cssc::TimeUnit::MONTH: return "months"; + case cssc::TimeUnit::YEAR: return "years"; + default: OSL_ENSURE(false, "lclGetTimeUnitToken - unexpected time unit"); + } + return "days"; +} + +static cssc::TimeIncrement lcl_getDateTimeIncrement( const Reference< chart2::XDiagram >& xDiagram, sal_Int32 nAxisIndex ) +{ + cssc::TimeIncrement aTimeIncrement; + 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( 0 < xCooSys->getDimension() && nAxisIndex <= xCooSys->getMaximumAxisIndexByDimension(0) ) + { + Reference< chart2::XAxis > xAxis = xCooSys->getAxisByDimension(0, nAxisIndex); + OSL_ASSERT(xAxis.is()); + if( xAxis.is() ) + { + chart2::ScaleData aScaleData = xAxis->getScaleData(); + aTimeIncrement = aScaleData.TimeIncrement; + break; + } + } + } + } + catch (const uno::Exception&) + { + DBG_UNHANDLED_EXCEPTION("oox"); + } + + return aTimeIncrement; +} + static bool lcl_isSeriesAttachedToFirstAxis( const Reference< chart2::XDataSeries > & xDataSeries ) { @@ -3184,6 +3232,33 @@ void ChartExport::_exportAxis( // FIXME: seems not support? lblOffset pFS->singleElement(FSNS(XML_c, XML_lblOffset), XML_val, OString::number(100)); + // export baseTimeUnit, majorTimeUnit, minorTimeUnit of Date axis + if( nAxisType == XML_dateAx ) + { + sal_Int32 nAxisIndex = -1; + if( rAxisIdPair.nAxisType == AXIS_PRIMARY_X ) + nAxisIndex = 0; + else if( rAxisIdPair.nAxisType == AXIS_SECONDARY_X ) + nAxisIndex = 1; + + cssc::TimeIncrement aTimeIncrement = lcl_getDateTimeIncrement( mxNewDiagram, nAxisIndex ); + sal_Int32 nTimeResolution = css::chart::TimeUnit::DAY; + if( aTimeIncrement.TimeResolution >>= nTimeResolution ) + pFS->singleElement(FSNS(XML_c, XML_baseTimeUnit), XML_val, lclGetTimeUnitToken(nTimeResolution)); + + cssc::TimeInterval aInterval; + if( aTimeIncrement.MajorTimeInterval >>= aInterval ) + { + pFS->singleElement(FSNS(XML_c, XML_majorUnit), XML_val, OString::number(aInterval.Number)); + pFS->singleElement(FSNS(XML_c, XML_majorTimeUnit), XML_val, lclGetTimeUnitToken(aInterval.TimeUnit)); + } + if( aTimeIncrement.MinorTimeInterval >>= aInterval ) + { + pFS->singleElement(FSNS(XML_c, XML_minorUnit), XML_val, OString::number(aInterval.Number)); + pFS->singleElement(FSNS(XML_c, XML_minorTimeUnit), XML_val, lclGetTimeUnitToken(aInterval.TimeUnit)); + } + } + // FIXME: seems not support? noMultiLvlLbl pFS->singleElement(FSNS(XML_c, XML_noMultiLvlLbl), XML_val, OString::number(0)); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits