chart2/source/view/charttypes/PieChart.cxx |   49 ++++++++++++++++++++---------
 chart2/source/view/charttypes/PieChart.hxx |   14 +++++---
 2 files changed, 45 insertions(+), 18 deletions(-)

New commits:
commit 853736f0d523c4f5459e15e7e109e81340f8c25e
Author:     Kurt Nordback <kurt.nordb...@protonmail.com>
AuthorDate: Wed Nov 15 16:49:41 2023 -0700
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Feb 17 07:06:56 2024 +0100

    tdf#50934: Fix of-pie subchart colors
    
    Change-Id: I43e0118786853b0258741e5181f7e622c6f747ec
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160727
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/chart2/source/view/charttypes/PieChart.cxx 
b/chart2/source/view/charttypes/PieChart.cxx
index aee48da35084..ed20a65fc0ca 100644
--- a/chart2/source/view/charttypes/PieChart.cxx
+++ b/chart2/source/view/charttypes/PieChart.cxx
@@ -964,11 +964,12 @@ void PieChart::createOneRing([[maybe_unused]]enum 
SubPieType eType,
     if( m_aPosHelper.isMathematicalOrientationRadius() && m_bUseRings )
         nExplodeableSlot = m_aZSlots.front().size()-1;
 
-    sal_Int32 nRingPtCnt = pDataSrc->getNPoints(pSeries, eType);
+    sal_Int32 nBegin = pDataSrc->getBeginIndex(pSeries, eType);
+    sal_Int32 nEnd = pDataSrc->getEndIndex(pSeries, eType);
 
     // Find sum of entries for this ring or sub-pie
     double ringSum = 0;
-    for (sal_Int32 nPointIndex = 0; nPointIndex < nRingPtCnt; nPointIndex++ ) {
+    for (sal_Int32 nPointIndex = nBegin; nPointIndex < nEnd; nPointIndex++ ) {
         double fY = pDataSrc->getData(pSeries, nPointIndex, eType);
         if (!std::isnan(fY) ) ringSum += fY;
     }
@@ -980,7 +981,7 @@ void PieChart::createOneRing([[maybe_unused]]enum 
SubPieType eType,
             // Left of-pie has the "composite" wedge (the one expanded in the 
right
             // subgraph) facing to the right in the chart, to allow the 
expansion
             // lines to meet it
-            double compositeVal = pDataSrc->getData(pSeries, nRingPtCnt - 1, 
eType);
+            double compositeVal = pDataSrc->getData(pSeries, nEnd - 1, eType);
             return compositeVal * 360 / (ringSum * 2);
         } else {
             /// The angle degree offset is set by the same property of the
@@ -994,7 +995,7 @@ void PieChart::createOneRing([[maybe_unused]]enum 
SubPieType eType,
 
     double fLogicYForNextPoint = 0.0;
     ///iterate through all points to create shapes
-    for(sal_Int32 nPointIndex = 0; nPointIndex < nRingPtCnt; nPointIndex++ )
+    for(sal_Int32 nPointIndex = nBegin; nPointIndex < nEnd; nPointIndex++ )
     {
         double fLogicInnerRadius, fLogicOuterRadius;
 
@@ -1060,8 +1061,7 @@ void PieChart::createOneRing([[maybe_unused]]enum 
SubPieType eType,
             const bool bConcentricExplosion = m_bUseRings && 
(m_aZSlots.front().size() > 1);
             rtl::Reference<SvxShape> xPointShape =
                 createDataPoint(eType, xSeriesGroupShape_Shapes,
-                        xPointProperties, aParam, nRingPtCnt,
-                        bConcentricExplosion);
+                        xPointProperties, aParam, nEnd, bConcentricExplosion);
 
             ///point color:
             if (!pSeries->hasPointOwnColor(nPointIndex) && m_xColorScheme.is())
@@ -1134,11 +1134,12 @@ void PieChart::createOneBar(
 {
     bool bHasFillColorMapping = pSeries->hasPropertyMapping("FillColor");
 
-    sal_Int32 nBarPtCnt = pDataSrc->getNPoints(pSeries, eType);
+    sal_Int32 nBegin = pDataSrc->getBeginIndex(pSeries, eType);
+    sal_Int32 nEnd = pDataSrc->getEndIndex(pSeries, eType);
 
     // Find sum of entries for this bar chart
     double barSum = 0;
-    for (sal_Int32 nPointIndex = 0; nPointIndex < nBarPtCnt; nPointIndex++ ) {
+    for (sal_Int32 nPointIndex = nBegin; nPointIndex < nEnd; nPointIndex++ ) {
         double fY = pDataSrc->getData(pSeries, nPointIndex, eType);
         if (!std::isnan(fY) ) barSum += fY;
     }
@@ -1146,7 +1147,7 @@ void PieChart::createOneBar(
     double fBarBottom = 0.0;
     double fBarTop = -0.5;  // make the bar go from -0.5 to 0.5
     ///iterate through all points to create shapes
-    for(sal_Int32 nPointIndex = 0; nPointIndex < nBarPtCnt; nPointIndex++ )
+    for(sal_Int32 nPointIndex = nBegin; nPointIndex < nEnd; nPointIndex++ )
     {
         aParam.mfDepth  = getTransformedDepth() * (n3DRelativeHeight / 100.0);
 
@@ -2005,7 +2006,14 @@ double PieDataSrc::getData(const VDataSeries* pSeries, 
sal_Int32 nPtIdx,
     return fabs(pSeries->getYValue( nPtIdx ));
 }
 
-sal_Int32 PieDataSrc::getNPoints(const VDataSeries* pSeries,
+sal_Int32 PieDataSrc::getBeginIndex([[maybe_unused]]const VDataSeries* pSeries,
+            [[maybe_unused]] enum SubPieType eType) const
+{
+    assert(eType == SubPieType::NONE);
+    return 0;
+}
+
+sal_Int32 PieDataSrc::getEndIndex(const VDataSeries* pSeries,
             [[maybe_unused]] enum SubPieType eType) const
 {
     assert(eType == SubPieType::NONE);
@@ -2030,14 +2038,25 @@ uno::Reference< beans::XPropertySet > 
PieDataSrc::getProps(
 // behaviors should be supported later.
 // TODO
 
-sal_Int32 OfPieDataSrc::getNPoints(const VDataSeries* pSeries,
+sal_Int32 OfPieDataSrc::getBeginIndex(const VDataSeries* pSeries,
+            enum SubPieType eType) const
+{
+    if (eType == SubPieType::LEFT) {
+        return 0;
+    } else {
+        assert(eType == SubPieType::RIGHT);
+        return pSeries->getTotalPointCount() - 3;
+    }
+}
+
+sal_Int32 OfPieDataSrc::getEndIndex(const VDataSeries* pSeries,
             enum SubPieType eType) const
 {
     if (eType == SubPieType::LEFT) {
         return pSeries->getTotalPointCount() - 2;
     } else {
         assert(eType == SubPieType::RIGHT);
-        return 3;
+        return pSeries->getTotalPointCount();
     }
 }
 
@@ -2056,8 +2075,10 @@ double OfPieDataSrc::getData(const VDataSeries* pSeries, 
sal_Int32 nPtIdx,
                 fabs(pSeries->getYValue(n+2));
         }
     } else {
+        // nPtIdx should be in [n, n+2]
         assert(eType == SubPieType::RIGHT);
-        return fabs(pSeries->getYValue(nPtIdx + n));
+        assert(nPtIdx >= n && nPtIdx <= n+2);
+        return fabs(pSeries->getYValue(nPtIdx));
     }
 }
 
@@ -2078,7 +2099,7 @@ uno::Reference< beans::XPropertySet > 
OfPieDataSrc::getProps(
         }
     } else {
         assert(eType == SubPieType::RIGHT);
-        return pSeries->getPropertiesOfPoint(nPtIdx + n);
+        return pSeries->getPropertiesOfPoint(nPtIdx);
     }
 }
 
diff --git a/chart2/source/view/charttypes/PieChart.hxx 
b/chart2/source/view/charttypes/PieChart.hxx
index 731c4e62020d..1630874c2745 100644
--- a/chart2/source/view/charttypes/PieChart.hxx
+++ b/chart2/source/view/charttypes/PieChart.hxx
@@ -60,8 +60,10 @@ public:
     PieDataSrcBase() = default;
     virtual ~PieDataSrcBase() = default;
 
-    // Get number of points in the given pie subtype
-    virtual sal_Int32 getNPoints(const VDataSeries* pSeries,
+    // Beginning and ending indices for given pie subtype
+    virtual sal_Int32 getBeginIndex(const VDataSeries* pSeries,
+                enum SubPieType eType) const = 0;
+    virtual sal_Int32 getEndIndex(const VDataSeries* pSeries,
                 enum SubPieType eType) const = 0;
 
     // Get the value for the given pie wedge, for the given subtype
@@ -80,7 +82,9 @@ public:
 class PieDataSrc : public PieDataSrcBase
 {
 public:
-    sal_Int32 getNPoints(const VDataSeries* pSeries,
+    sal_Int32 getBeginIndex(const VDataSeries* pSeries,
+                enum SubPieType eType) const;
+    sal_Int32 getEndIndex(const VDataSeries* pSeries,
                 enum SubPieType eType) const;
 
     double getData(const VDataSeries* pSeries, sal_Int32 nPtIdx,
@@ -100,7 +104,9 @@ public:
     // Minimum sensible number of data points
     static sal_Int32 minPoints() { return 4; }
 
-    sal_Int32 getNPoints(const VDataSeries* pSeries,
+    sal_Int32 getBeginIndex(const VDataSeries* pSeries,
+                enum SubPieType eType) const;
+    sal_Int32 getEndIndex(const VDataSeries* pSeries,
                 enum SubPieType eType) const;
 
     double getData(const VDataSeries* pSeries, sal_Int32 nPtIdx,

Reply via email to