diff options
author | Balazs Varga <balazs.varga991@gmail.com> | 2020-04-16 22:08:15 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-04-24 15:28:17 +0200 |
commit | 75156c6fd73dc202df541306e1636727d51d6fc3 (patch) | |
tree | 5b179fde360bc3c2d7d55ed2f67d99289496acfc /oox | |
parent | ccf40c0efcc371e3d5818df20af18bc10c3601bd (diff) |
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@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/chart/axisconverter.cxx | 10 | ||||
-rw-r--r-- | oox/source/export/chartexport.cxx | 62 |
2 files changed, 62 insertions, 10 deletions
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; |