diff options
author | Balazs Varga <balazs.varga991@gmail.com> | 2020-06-23 15:02:59 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-07-09 10:48:55 +0200 |
commit | 57fedb272cfcad3436142dbe9eac2870e3c3e3d2 (patch) | |
tree | 121aaa818cc01439fcc7314f45118f950066f5af | |
parent | 966ad3db0a7330f29d2056e46d245b9320b3202a (diff) |
tdf#134225 Chart view: fix moved date label
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 <nemeth@numbertext.org>
-rw-r--r-- | chart2/qa/extras/chart2import.cxx | 26 | ||||
-rw-r--r-- | chart2/qa/extras/data/xlsx/tdf134225.xlsx | bin | 0 -> 13956 bytes | |||
-rw-r--r-- | chart2/source/view/charttypes/PieChart.cxx | 14 |
3 files changed, 27 insertions, 13 deletions
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<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent), + UNO_QUERY_THROW); + + Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, UNO_QUERY_THROW); + Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW); + Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), UNO_QUERY_THROW); + Reference<drawing::XShape> 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<drawing::XShape> 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 Binary files differnew file mode 100644 index 000000000000..ae7bdc66e302 --- /dev/null +++ b/chart2/qa/extras/data/xlsx/tdf134225.xlsx 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 |