chart2/qa/extras/chart2export.cxx | 22 +++++++++ chart2/qa/extras/data/xlsx/barOfPieChart.xlsx |binary chart2/qa/extras/data/xlsx/pieOfPieChart.xlsx |binary chart2/source/view/charttypes/PieChart.cxx | 63 +++++++++++++++++++------- chart2/source/view/charttypes/PieChart.hxx | 2 5 files changed, 71 insertions(+), 16 deletions(-)
New commits: commit 96e9c3a7fd2ce877d6d4d87c5333334790f7d85a Author: Kurt Nordback <kurt.nordb...@protonmail.com> AuthorDate: Wed Dec 13 16:16:11 2023 -0700 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Feb 19 20:34:18 2024 +0100 tdf#50934: Fix compiler complaints and activate OOXML I/O tests Add tests for input and output of very basic pie-of-pie and bar-of-pie charts in OOXML. Change-Id: I6441d99941ea2aca9bf58ede40dbe8f3d38a3291 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160742 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index 81ed060e7acb..b46bc776d587 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -529,6 +529,28 @@ CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDoughnutChart) assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart"_ostr); } +CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testPieOfPieChart) +{ + loadFromFile(u"xlsx/pieOfPieChart.xlsx"); + save("Calc Office Open XML"); + xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml"); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart"_ostr); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart/c:ofPieType[1]"_ostr, "val"_ostr, "pie"); +} + +CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testBarOfPieChart) +{ + loadFromFile(u"xlsx/barOfPieChart.xlsx"); + save("Calc Office Open XML"); + xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart1.xml"); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart"_ostr); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:ofPieChart/c:ofPieType[1]"_ostr, "val"_ostr, "bar"); +} + CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDisplayUnits) { loadFromFile(u"docx/DisplayUnits.docx"); diff --git a/chart2/qa/extras/data/xlsx/barOfPieChart.xlsx b/chart2/qa/extras/data/xlsx/barOfPieChart.xlsx new file mode 100644 index 000000000000..227ab832a4ac Binary files /dev/null and b/chart2/qa/extras/data/xlsx/barOfPieChart.xlsx differ diff --git a/chart2/qa/extras/data/xlsx/pieOfPieChart.xlsx b/chart2/qa/extras/data/xlsx/pieOfPieChart.xlsx index efb1c05ca864..b3a1c3588427 100644 Binary files a/chart2/qa/extras/data/xlsx/pieOfPieChart.xlsx and b/chart2/qa/extras/data/xlsx/pieOfPieChart.xlsx differ diff --git a/chart2/source/view/charttypes/PieChart.cxx b/chart2/source/view/charttypes/PieChart.cxx index b70fde756c74..ff8cf62f133a 100644 --- a/chart2/source/view/charttypes/PieChart.cxx +++ b/chart2/source/view/charttypes/PieChart.cxx @@ -918,7 +918,7 @@ void PieChart::createShapes() // Default to regular pie if too few points for of-pie ::css::chart2::PieChartSubType eSubType = - nPointCount >= OfPieDataSrc::minPoints() ? + nPointCount >= OfPieDataSrc::minPoints ? m_eSubType : PieChartSubType_NONE; @@ -1068,7 +1068,38 @@ void PieChart::createShapes() }//next x slot } -void PieChart::createOneRing([[maybe_unused]]enum SubPieType eType, +static sal_Int32 propIndex( + sal_Int32 nPointIndex, + enum SubPieType eType, + const PieDataSrcBase *pDataSrc, + VDataSeries* pSeries) +{ + + switch (eType) { + case SubPieType::LEFT: + if (nPointIndex == pDataSrc->getNPoints(pSeries, + SubPieType::LEFT) - 1) { + return pSeries->getTotalPointCount(); + } else { + return nPointIndex; + } + break; + case SubPieType::RIGHT: + return pDataSrc->getNPoints(pSeries, SubPieType::LEFT) + + nPointIndex - 1; + break; + case SubPieType::NONE: + return nPointIndex; + break; + default: // shouldn't happen + assert(false); + return 0; // suppress compile warning + } +} + + +void PieChart::createOneRing( + enum SubPieType eType, double fSlotX, ShapeParam& aParam, const rtl::Reference<SvxShapeGroupAnyD>& xSeriesTarget, @@ -1187,11 +1218,9 @@ void PieChart::createOneRing([[maybe_unused]]enum SubPieType eType, bConcentricExplosion); // Handle coloring of the composite wedge - const sal_Int32 nPropIdx = ( - eType == SubPieType::LEFT && - nPointIndex == pDataSrc->getNPoints(pSeries, SubPieType::LEFT) - 1 ? - pSeries->getTotalPointCount() : - nPointIndex); + sal_Int32 nPropIdx = propIndex(nPointIndex, eType, pDataSrc, + pSeries); + ///point color: if (!pSeries->hasPointOwnColor(nPropIdx) && m_xColorScheme.is()) { @@ -1210,12 +1239,13 @@ void PieChart::createOneRing([[maybe_unused]]enum SubPieType eType, } ///create label - createTextLabelShape(xTextTarget, *pSeries, nPointIndex, aParam); + createTextLabelShape(xTextTarget, *pSeries, nPropIdx, aParam); if(!bDoExplode) { ShapeFactory::setShapeName( xPointShape - , ObjectIdentifier::createPointCID( pSeries->getPointCID_Stub(), nPointIndex ) ); + , ObjectIdentifier::createPointCID( + pSeries->getPointCID_Stub(), nPropIdx ) ); } else try { @@ -1242,7 +1272,8 @@ void PieChart::createOneRing([[maybe_unused]]enum SubPieType eType, ) ); ShapeFactory::setShapeName( xPointShape - , ObjectIdentifier::createPointCID( aPointCIDStub, nPointIndex ) ); + , ObjectIdentifier::createPointCID( aPointCIDStub, + nPropIdx ) ); } catch( const uno::Exception& ) { @@ -1301,17 +1332,19 @@ void PieChart::createOneBar( xPointProperties, aParam, fBarBottom, fBarTop); + sal_Int32 nPropIdx = propIndex(nPointIndex, eType, pDataSrc, pSeries); + ///point color: - if (!pSeries->hasPointOwnColor(nPointIndex) && m_xColorScheme.is()) + if (!pSeries->hasPointOwnColor(nPropIdx) && m_xColorScheme.is()) { xPointShape->setPropertyValue("FillColor", - uno::Any(m_xColorScheme->getColorByIndex( nPointIndex ))); + uno::Any(m_xColorScheme->getColorByIndex( nPropIdx ))); } if(bHasFillColorMapping) { - double nPropVal = pSeries->getValueByProperty(nPointIndex, "FillColor"); + double nPropVal = pSeries->getValueByProperty(nPropIdx, "FillColor"); if(!std::isnan(nPropVal)) { xPointShape->setPropertyValue("FillColor", uno::Any(static_cast<sal_Int32>( nPropVal))); @@ -1319,11 +1352,11 @@ void PieChart::createOneBar( } ///create label - createTextLabelShape(xTextTarget, *pSeries, nPointIndex, aParam); + createTextLabelShape(xTextTarget, *pSeries, nPropIdx, aParam); ShapeFactory::setShapeName( xPointShape, ObjectIdentifier::createPointCID( pSeries->getPointCID_Stub(), - nPointIndex ) ); + nPropIdx ) ); }//next category } diff --git a/chart2/source/view/charttypes/PieChart.hxx b/chart2/source/view/charttypes/PieChart.hxx index abcf1cc2db9b..bf11f6c69055 100644 --- a/chart2/source/view/charttypes/PieChart.hxx +++ b/chart2/source/view/charttypes/PieChart.hxx @@ -102,7 +102,7 @@ class OfPieDataSrc : public PieDataSrcBase { public: // Minimum sensible number of data points - static sal_Int32 minPoints() { return 4; } + static constexpr sal_Int32 minPoints = 4; sal_Int32 getNPoints(const VDataSeries* pSeries, enum SubPieType eType) const;