Kaydet (Commit) ad363fd4 authored tarafından Balazs Varga's avatar Balazs Varga Kaydeden (comit) László Németh

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/70059Reviewed-by: 's avatarLászló Németh <nemeth@numbertext.org>
Tested-by: 's avatarLászló Németh <nemeth@numbertext.org>
üst 7b74a1f4
......@@ -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");
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment