chart2/source/view/charttypes/AreaChart.cxx | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
New commits: commit cd22ac3f63084a4290fa5cdad8300f7a69b2030e Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sun Apr 6 14:51:36 2025 +0200 Commit: Noel Grandin <noelgran...@gmail.com> CommitDate: Mon Apr 7 09:27:25 2025 +0200 tdf#151876 flatten data-structure a little so we need to do less pointer chasing to perform the work Change-Id: I16f160a009ca157b1712eab98dd7ad7b1414b5d2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183759 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/chart2/source/view/charttypes/AreaChart.cxx b/chart2/source/view/charttypes/AreaChart.cxx index 444fd5b39b07..7d78e1b38c2b 100644 --- a/chart2/source/view/charttypes/AreaChart.cxx +++ b/chart2/source/view/charttypes/AreaChart.cxx @@ -604,7 +604,8 @@ void AreaChart::createShapes() bool bDateCategory = (m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->isDateAxis()); - std::vector<std::map< sal_Int32, double > > aLogicYSumMapByX(nEndIndex);//one for each different nAttachedAxisIndex + // indexed by {nIndex, nAttachedAxisIndex} + std::map< std::pair<sal_Int32, sal_Int32>, double > aLogicYSumMapByX; for( auto const& rZSlot : m_aZSlots ) { //iterate through all x slots in this category to get 100percent sum @@ -623,7 +624,7 @@ void AreaChart::createShapes() { double fAdd = pSeries->getYValue( nIndex ); if( !std::isnan(fAdd) && !std::isinf(fAdd) ) - aLogicYSumMapByX[nIndex][nAttachedAxisIndex] += fabs( fAdd ); + aLogicYSumMapByX[ {nIndex, nAttachedAxisIndex} ] += fabs( fAdd ); } } } @@ -681,11 +682,12 @@ void AreaChart::createShapes() fLogicY = fabs( fLogicY ); double fLogicValueForLabeDisplay = fLogicY; - std::map< sal_Int32, double >& rLogicYSumMap = aLogicYSumMapByX[nIndex]; - if (rPosHelper.isPercentY() && rLogicYSumMap[nAttachedAxisIndex] != 0.0) - { - fLogicY = fabs( fLogicY )/rLogicYSumMap[nAttachedAxisIndex]; - } + double fLogicSumForX = 0.0; + auto it = aLogicYSumMapByX.find({nIndex, nAttachedAxisIndex}); + if (it != aLogicYSumMapByX.end()) + fLogicSumForX = it->second; + if (rPosHelper.isPercentY() && fLogicSumForX != 0.0) + fLogicY = fabs( fLogicY ) / fLogicSumForX; if( std::isnan(fLogicX) || std::isinf(fLogicX) || std::isnan(fLogicY) || std::isinf(fLogicY) @@ -910,7 +912,7 @@ void AreaChart::createShapes() createDataLabel( m_xTextTarget, *pSeries, nIndex , fLogicValueForLabeDisplay - , rLogicYSumMap[nAttachedAxisIndex], aScreenPosition2D, eAlignment, nOffset ); + , fLogicSumForX, aScreenPosition2D, eAlignment, nOffset ); } } } commit f2924ccd27919f850e94e5ab68dc8f908058a066 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sun Apr 6 14:40:45 2025 +0200 Commit: Noel Grandin <noelgran...@gmail.com> CommitDate: Mon Apr 7 09:27:17 2025 +0200 tdf#151876 no need to insert zero here when we use operator[], it will create an entry if necessary, and if it needs to do so, that entry will default to zero. Change-Id: I5b2646cd4a7bbe49e3e3dd281062a7f23aa6a399 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183758 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins diff --git a/chart2/source/view/charttypes/AreaChart.cxx b/chart2/source/view/charttypes/AreaChart.cxx index 453641ea675b..444fd5b39b07 100644 --- a/chart2/source/view/charttypes/AreaChart.cxx +++ b/chart2/source/view/charttypes/AreaChart.cxx @@ -621,12 +621,9 @@ void AreaChart::createShapes() sal_Int32 nAttachedAxisIndex = pSeries->getAttachedAxisIndex(); for( sal_Int32 nIndex = nStartIndex; nIndex < nEndIndex; nIndex++ ) { - std::map< sal_Int32, double >& rLogicYSumMap = aLogicYSumMapByX[nIndex]; - rLogicYSumMap.insert({nAttachedAxisIndex, 0.0}); - double fAdd = pSeries->getYValue( nIndex ); if( !std::isnan(fAdd) && !std::isinf(fAdd) ) - rLogicYSumMap[nAttachedAxisIndex] += fabs( fAdd ); + aLogicYSumMapByX[nIndex][nAttachedAxisIndex] += fabs( fAdd ); } } }