chart2/qa/extras/chart2export.cxx | 18 ++++++++++++++++++ chart2/qa/extras/data/ods/secondary_axis.ods |binary oox/source/export/chartexport.cxx | 15 +++++++++++++++ 3 files changed, 33 insertions(+)
New commits: commit ad363fd42e439b43c57b6541988234fbaf1ddb30 Author: Balazs Varga <balazs.varga...@gmail.com> AuthorDate: Mon Apr 1 13:57:33 2019 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Tue Apr 2 08:34:08 2019 +0200 tdf#124463 XLSX export: fix splitDataSeriesByAxis splitDataSeriesByAxis couldn't split series correctly into two sequences, because it put all series into the first created sequence, except the first series of the newer sequence. Other improvement: first sequence of the return vector always contains the series attached to the primary axis. Change-Id: I6e107aa990f9a1a1db49cae2a4f3c9d8a35fb54c Reviewed-on: https://gerrit.libreoffice.org/70059 Reviewed-by: László Németh <nem...@numbertext.org> Tested-by: László Németh <nem...@numbertext.org> diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index f4d8f5e981a9..3d537cf2ab90 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -112,6 +112,7 @@ public: void testPlotVisOnlyXLSX(); void testBarChartVaryColorsXLSX(); void testMultipleAxisXLSX(); + void testSecondaryAxisXLSX(); void testAxisTitleRotationXLSX(); void testAxisCrossBetweenXSLX(); void testPieChartDataPointExplosionXLSX(); @@ -204,6 +205,7 @@ public: CPPUNIT_TEST(testPlotVisOnlyXLSX); CPPUNIT_TEST(testBarChartVaryColorsXLSX); CPPUNIT_TEST(testMultipleAxisXLSX); + CPPUNIT_TEST(testSecondaryAxisXLSX); CPPUNIT_TEST(testAxisTitleRotationXLSX); CPPUNIT_TEST(testAxisCrossBetweenXSLX); CPPUNIT_TEST(testPieChartDataPointExplosionXLSX); @@ -1742,6 +1744,22 @@ void Chart2ExportTest::testMultipleAxisXLSX() assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:valAx/c:axPos[@val='r']", 1); } +void Chart2ExportTest::testSecondaryAxisXLSX() +{ + load("/chart2/qa/extras/data/ods/", "secondary_axis.ods"); + xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML"); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart", 2); + // test there is just those series in the first <lineChart> tag which are attached to the primary axis + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart[1]/c:ser", 2); + assertXPathContent(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart[1]/c:ser[1]/c:tx/c:strRef/c:strCache/c:pt/c:v", "b"); + assertXPathContent(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart[1]/c:ser[2]/c:tx/c:strRef/c:strCache/c:pt/c:v", "c"); + // test there is just those series in the second <lineChart> tag which are attached to the secondary axis + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart[2]/c:ser", 1); + assertXPathContent(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart[2]/c:ser[1]/c:tx/c:strRef/c:strCache/c:pt/c:v", "a"); +} + void Chart2ExportTest::testAxisTitleRotationXLSX() { load("/chart2/qa/extras/data/xlsx/", "axis_title_rotation.xlsx"); diff --git a/chart2/qa/extras/data/ods/secondary_axis.ods b/chart2/qa/extras/data/ods/secondary_axis.ods new file mode 100755 index 000000000000..3f8f269c0f00 Binary files /dev/null and b/chart2/qa/extras/data/ods/secondary_axis.ods differ diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 47c30b1ba569..062636c91d62 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -1592,6 +1592,7 @@ std::vector<Sequence<Reference<chart2::XDataSeries> > > splitDataSeriesByAxis(co Reference< chart2::XDataSeriesContainer > xDSCnt( xChartType, uno::UNO_QUERY ); if(xDSCnt.is()) { + sal_Int32 nAxisIndexOfFirstSeries = -1; Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries()); for (sal_Int32 nIndex = 0, nEnd = aSeriesSeq.getLength(); nIndex < nEnd; ++nIndex) { @@ -1604,6 +1605,10 @@ std::vector<Sequence<Reference<chart2::XDataSeries> > > splitDataSeriesByAxis(co uno::Any aAny = xPropSet->getPropertyValue("AttachedAxisIndex"); aAny >>= nAxisIndex; size_t nVectorPos = 0; + if (nAxisIndexOfFirstSeries == -1) + { + nAxisIndexOfFirstSeries = nAxisIndex; + } auto it = aMapAxisToIndex.find(nAxisIndex); if (it == aMapAxisToIndex.end()) @@ -1612,12 +1617,22 @@ std::vector<Sequence<Reference<chart2::XDataSeries> > > splitDataSeriesByAxis(co nVectorPos = aSplitSeries.size() - 1; aMapAxisToIndex.insert(std::pair<sal_Int32, size_t>(nAxisIndex, nVectorPos)); } + else + { + nVectorPos = it->second; + } uno::Sequence<Reference<chart2::XDataSeries> >& rAxisSeriesSeq = aSplitSeries[nVectorPos]; sal_Int32 nLength = rAxisSeriesSeq.getLength(); rAxisSeriesSeq.realloc(nLength + 1); rAxisSeriesSeq[nLength] = xSeries; } + // if the first series attached to secondary axis, then export those series first, which are attached to primary axis + // also the MS Office export every time in this order + if ( aSplitSeries.size() > 1 && nAxisIndexOfFirstSeries == 1 ) + { + std::swap( aSplitSeries[0], aSplitSeries[1] ); + } } return aSplitSeries; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits