diff options
-rw-r--r-- | chart2/qa/extras/chart2export.cxx | 18 | ||||
-rwxr-xr-x | chart2/qa/extras/data/ods/secondary_axis.ods | bin | 0 -> 16783 bytes | |||
-rw-r--r-- | oox/source/export/chartexport.cxx | 15 |
3 files changed, 33 insertions, 0 deletions
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 Binary files differnew file mode 100755 index 000000000000..3f8f269c0f00 --- /dev/null +++ b/chart2/qa/extras/data/ods/secondary_axis.ods 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; |