From 20da1a5dd37c7edac620566c992d5a53b23a5f12 Mon Sep 17 00:00:00 2001 From: Tünde Tóth Date: Thu, 17 Sep 2020 16:49:02 +0200 Subject: tdf#134978 Chart OOXML Import: fix pie chart label custom position MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up of commit dff7a46fb46d1fa2a3ad674ee493ae2d59150fe3 (tdf#130032 Chart OOXML Import: fix data label custom position). Change-Id: Iaaf4ae654ac0c1b4896a53be6034e6c027412df0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102981 Tested-by: Jenkins Tested-by: László Németh Reviewed-by: László Németh --- chart2/qa/extras/chart2import.cxx | 23 ++++++++++++++++++++++- chart2/qa/extras/data/xlsx/tdf134978.xlsx | Bin 0 -> 13746 bytes chart2/source/tools/ChartTypeHelper.cxx | 3 ++- chart2/source/view/charttypes/PieChart.cxx | 7 +++++-- 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 chart2/qa/extras/data/xlsx/tdf134978.xlsx (limited to 'chart2') diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index dadc782c0af6..d901f879ea18 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -158,6 +158,7 @@ public: void testTdf125444PercentageCustomLabel(); void testDataPointLabelCustomPos(); void testTdf130032(); + void testTdf134978(); void testTdf119138MissingAutoTitleDeleted(); void testStockChartShiftedCategoryPosition(); void testTdf133376(); @@ -272,6 +273,7 @@ public: CPPUNIT_TEST(testTdf125444PercentageCustomLabel); CPPUNIT_TEST(testDataPointLabelCustomPos); CPPUNIT_TEST(testTdf130032); + CPPUNIT_TEST(testTdf134978); CPPUNIT_TEST(testTdf119138MissingAutoTitleDeleted); CPPUNIT_TEST(testStockChartShiftedCategoryPosition); CPPUNIT_TEST(testTdf133376); @@ -1783,7 +1785,7 @@ void Chart2ImportTest::testTdf109858() CPPUNIT_ASSERT( aAny.hasValue() ); sal_Int32 nLabelPlacement = 0; CPPUNIT_ASSERT( aAny >>= nLabelPlacement ); - CPPUNIT_ASSERT_EQUAL_MESSAGE( "Data point label should be placed bestFit", chart::DataLabelPlacement::AVOID_OVERLAP, nLabelPlacement ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Data point label should be placed bestfit", chart::DataLabelPlacement::CUSTOM, nLabelPlacement ); // test data series label position Reference xSeriesPropSet(xChart1Doc->getDiagram()->getDataRowProperties(0), uno::UNO_SET_THROW); @@ -2511,6 +2513,25 @@ void Chart2ImportTest::testTdf130032() CPPUNIT_ASSERT_EQUAL(chart::DataLabelPlacement::RIGHT, aPlacement); } +void Chart2ImportTest::testTdf134978() +{ + // test CustomLabelPosition on Pie chart + load("/chart2/qa/extras/data/xlsx/", "tdf134978.xlsx"); + uno::Reference xChartDoc = getChartDocFromSheet(0, mxComponent); + CPPUNIT_ASSERT(xChartDoc.is()); + uno::Reference xDataSeries(getDataSeriesFromDoc(xChartDoc, 0)); + CPPUNIT_ASSERT(xDataSeries.is()); + + uno::Reference xPropertySet(xDataSeries->getDataPointByIndex(2), + uno::UNO_SET_THROW); + CPPUNIT_ASSERT(xPropertySet.is()); + + chart2::RelativePosition aCustomLabelPosition; + xPropertySet->getPropertyValue("CustomLabelPosition") >>= aCustomLabelPosition; + CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.040273622047244093, aCustomLabelPosition.Primary, 1e-7); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.25635352872557599, aCustomLabelPosition.Secondary, 1e-7); +} + void Chart2ImportTest::testTdf119138MissingAutoTitleDeleted() { load("/chart2/qa/extras/data/xlsx/", "tdf119138-missing-autotitledeleted.xlsx"); diff --git a/chart2/qa/extras/data/xlsx/tdf134978.xlsx b/chart2/qa/extras/data/xlsx/tdf134978.xlsx new file mode 100644 index 000000000000..ad5522a9144d Binary files /dev/null and b/chart2/qa/extras/data/xlsx/tdf134978.xlsx differ diff --git a/chart2/source/tools/ChartTypeHelper.cxx b/chart2/source/tools/ChartTypeHelper.cxx index 236d066f77d3..a4b8059ffb19 100644 --- a/chart2/source/tools/ChartTypeHelper.cxx +++ b/chart2/source/tools/ChartTypeHelper.cxx @@ -252,12 +252,13 @@ uno::Sequence < sal_Int32 > ChartTypeHelper::getSupportedLabelPlacements( const if(!bDonut) { - aRet.realloc(4); + aRet.realloc(5); sal_Int32* pSeq = aRet.getArray(); *pSeq++ = css::chart::DataLabelPlacement::AVOID_OVERLAP; *pSeq++ = css::chart::DataLabelPlacement::OUTSIDE; *pSeq++ = css::chart::DataLabelPlacement::INSIDE; *pSeq++ = css::chart::DataLabelPlacement::CENTER; + *pSeq++ = css::chart::DataLabelPlacement::CUSTOM; } else { diff --git a/chart2/source/view/charttypes/PieChart.cxx b/chart2/source/view/charttypes/PieChart.cxx index 6042b0d0dbe4..55eb67037b9a 100644 --- a/chart2/source/view/charttypes/PieChart.cxx +++ b/chart2/source/view/charttypes/PieChart.cxx @@ -293,7 +293,8 @@ void PieChart::createTextLabelShape( double nVal = rSeries.getYValue(nPointIndex); //AVOID_OVERLAP is in fact "Best fit" in the UI. - bool bMovementAllowed = ( nLabelPlacement == css::chart::DataLabelPlacement::AVOID_OVERLAP ); + bool bMovementAllowed = nLabelPlacement == css::chart::DataLabelPlacement::AVOID_OVERLAP + || nLabelPlacement == css::chart::DataLabelPlacement::CUSTOM; if( bMovementAllowed ) nLabelPlacement = css::chart::DataLabelPlacement::CENTER; @@ -389,7 +390,9 @@ void PieChart::createTextLabelShape( * First off the routine try to place the label inside the related pie slice, * if this is not possible the label is placed outside. */ - if (!performLabelBestFitInnerPlacement(rParam, aPieLabelInfo)) + if (rSeries.getLabelPlacement(nPointIndex, m_xChartTypeModel, m_pPosHelper->isSwapXAndY()) + == css::chart::DataLabelPlacement::CUSTOM + || !performLabelBestFitInnerPlacement(rParam, aPieLabelInfo)) { if (m_aAvailableOuterRect.getWidth()) { -- cgit