[Libreoffice-commits] core.git: Branch 'distro/nisz/libreoffice-7-0' - chart2/qa oox/source
Balazs Varga (via logerrit)
logerrit at kemper.freedesktop.org
Fri Feb 26 08:01:52 UTC 2021
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 1dbadbdb7ba9e99a0ad88125889188a84ebc9edc
Author: Balazs Varga <balazs.varga991 at gmail.com>
AuthorDate: Wed Nov 4 11:18:56 2020 +0100
Commit: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
CommitDate: Fri Feb 26 09:00:56 2021 +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 <nemeth at numbertext.org>
Reviewed-by: László Németh <nemeth at numbertext.org>
(cherry picked from commit e8a9d0050675034aa5d4670330ea47ef32306973)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111576
Tested-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
Reviewed-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index a7fbc4a4b21a..1456b5cf33d9 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -176,6 +176,7 @@ public:
void testTdf136267();
void testTdf134255();
void testTdf134977();
+ void testTdf137917();
CPPUNIT_TEST_SUITE(Chart2ExportTest);
CPPUNIT_TEST(testErrorBarXLSX);
@@ -315,6 +316,7 @@ public:
CPPUNIT_TEST(testTdf136267);
CPPUNIT_TEST(testTdf134255);
CPPUNIT_TEST(testTdf134977);
+ CPPUNIT_TEST(testTdf137917);
CPPUNIT_TEST_SUITE_END();
@@ -2884,6 +2886,19 @@ void Chart2ExportTest::testTdf134977()
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dLbls/c:dLbl/c:tx/c:rich/a:p/a:r/a:rPr", "sz", "900");
}
+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 a42f1dc0553b..712807192431 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>
@@ -285,6 +288,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 )
{
@@ -3086,6 +3134,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));
}
More information about the Libreoffice-commits
mailing list