From 57fedb272cfcad3436142dbe9eac2870e3c3e3d2 Mon Sep 17 00:00:00 2001 From: Balazs Varga Date: Tue, 23 Jun 2020 15:02:59 +0200 Subject: tdf#134225 Chart view: fix moved date label MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit outside from pie chart. Do not need to check the sector size of a pie slice, before best fit algorithm, so we can use the CENTER position as a start position of BEST_FIT. Completion of c66cb6d6e4a843dc7c7d06e1c2c0723a6ff85fc5 (tdf#134029 Chart view: enable to move data label) Change-Id: Ie1a53784e7df2887282155113bf8bb607cdb09e9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96945 Tested-by: Jenkins Reviewed-by: László Németh --- chart2/qa/extras/chart2import.cxx | 26 ++++++++++++++++++++++++++ chart2/qa/extras/data/xlsx/tdf134225.xlsx | Bin 0 -> 13956 bytes chart2/source/view/charttypes/PieChart.cxx | 14 +------------- 3 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 chart2/qa/extras/data/xlsx/tdf134225.xlsx (limited to 'chart2') diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index 6e78a08d67d1..9d7b43274a6f 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -161,6 +161,7 @@ public: void testTdf119138MissingAutoTitleDeleted(); void testStockChartShiftedCategoryPosition(); void testTdf133376(); + void testTdf134225(); void testTdf91250(); CPPUNIT_TEST_SUITE(Chart2ImportTest); @@ -271,6 +272,7 @@ public: CPPUNIT_TEST(testTdf119138MissingAutoTitleDeleted); CPPUNIT_TEST(testStockChartShiftedCategoryPosition); CPPUNIT_TEST(testTdf133376); + CPPUNIT_TEST(testTdf134225); CPPUNIT_TEST(testTdf91250); CPPUNIT_TEST_SUITE_END(); @@ -2525,6 +2527,30 @@ void Chart2ImportTest::testTdf133376() CPPUNIT_ASSERT_DOUBLES_EQUAL(5269, aLabelPosition.Y, 30); } +void Chart2ImportTest::testTdf134225() +{ + load("/chart2/qa/extras/data/xlsx/", "tdf134225.xlsx"); + Reference xChartDoc(getChartDocFromSheet(0, mxComponent), + UNO_QUERY_THROW); + + Reference xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW); + Reference xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW); + Reference xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW); + Reference xDataPointLabel1(getShapeByName(xShapes, + "CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=0"), UNO_SET_THROW); + CPPUNIT_ASSERT(xDataPointLabel1.is()); + awt::Point aLabelPosition1 = xDataPointLabel1->getPosition(); + + Reference xDataPointLabel2(getShapeByName(xShapes, + "CID/MultiClick/CID/D=0:CS=0:CT=0:Series=0:DataLabels=:DataLabel=1"), UNO_SET_THROW); + CPPUNIT_ASSERT(xDataPointLabel2.is()); + awt::Point aLabelPosition2 = xDataPointLabel2->getPosition(); + + // Check the distance between the position of the 1st data point label and the second one + CPPUNIT_ASSERT_DOUBLES_EQUAL(1800, sal_Int32(aLabelPosition2.X - aLabelPosition1.X), 30); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2123, sal_Int32(aLabelPosition2.Y - aLabelPosition1.Y), 30); +} + void Chart2ImportTest::testTdf91250() { load("/chart2/qa/extras/data/docx/", "tdf91250.docx"); diff --git a/chart2/qa/extras/data/xlsx/tdf134225.xlsx b/chart2/qa/extras/data/xlsx/tdf134225.xlsx new file mode 100644 index 000000000000..ae7bdc66e302 Binary files /dev/null and b/chart2/qa/extras/data/xlsx/tdf134225.xlsx differ diff --git a/chart2/source/view/charttypes/PieChart.cxx b/chart2/source/view/charttypes/PieChart.cxx index 9032b40977f1..5ab60729cf93 100644 --- a/chart2/source/view/charttypes/PieChart.cxx +++ b/chart2/source/view/charttypes/PieChart.cxx @@ -294,19 +294,7 @@ void PieChart::createTextLabelShape( //AVOID_OVERLAP is in fact "Best fit" in the UI. bool bMovementAllowed = ( nLabelPlacement == css::chart::DataLabelPlacement::AVOID_OVERLAP ); if( bMovementAllowed ) - { - // Use center for "Best fit" for now. In the future we - // may want to implement a real best fit algorithm. - // But center is good enough, and close to what Excel - // does. - - // Place the label outside if the sector is too small - // The threshold is set to 2%, but can be improved by making it a function of - // label width and radius too ? - double fFrac = fabs( nVal / rParam.mfLogicYSum ); - nLabelPlacement = ( fFrac <= 0.02 ) ? css::chart::DataLabelPlacement::OUTSIDE : - css::chart::DataLabelPlacement::CENTER; - } + nLabelPlacement = css::chart::DataLabelPlacement::CENTER; ///for `OUTSIDE` (`INSIDE`) label placements an offset of 150 (-150), in the ///radius direction, is added to the final screen position of the label -- cgit