diff options
author | Balazs Varga <balazs.varga991@gmail.com> | 2020-11-04 11:18:56 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-11-06 11:30:57 +0100 |
commit | e8a9d0050675034aa5d4670330ea47ef32306973 (patch) | |
tree | e52aace294c32e5172b6d243cd7cae6a3915a5d8 /oox | |
parent | 7ccbeade150f450568f44ad6283d4a4dc3b379bf (diff) |
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 <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/export/chartexport.cxx | 75 |
1 files changed, 75 insertions, 0 deletions
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)); } |