[Libreoffice-commits] core.git: chart2/qa chart2/source oox/source

Tünde Tóth (via logerrit) logerrit at kemper.freedesktop.org
Fri Oct 9 07:24:53 UTC 2020


 chart2/qa/extras/chart2import.cxx              |   23 ++++++++++++++++++++++-
 chart2/qa/extras/data/xlsx/tdf134978.xlsx      |binary
 chart2/source/tools/ChartTypeHelper.cxx        |    3 ++-
 chart2/source/view/charttypes/PieChart.cxx     |    7 +++++--
 oox/source/drawingml/chart/seriesconverter.cxx |    6 +++++-
 oox/source/export/chartexport.cxx              |    1 +
 6 files changed, 35 insertions(+), 5 deletions(-)

New commits:
commit 20da1a5dd37c7edac620566c992d5a53b23a5f12
Author:     Tünde Tóth <toth.tunde at nisz.hu>
AuthorDate: Thu Sep 17 16:49:02 2020 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Fri Oct 9 09:24:18 2020 +0200

    tdf#134978 Chart OOXML Import: fix pie chart label custom position
    
    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 <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>

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<beans::XPropertySet> 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<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
+    CPPUNIT_ASSERT(xChartDoc.is());
+    uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
+    CPPUNIT_ASSERT(xDataSeries.is());
+
+    uno::Reference<beans::XPropertySet> 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())
             {
diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx
index 007c76cf8e1f..416e6c32e638 100644
--- a/oox/source/drawingml/chart/seriesconverter.cxx
+++ b/oox/source/drawingml/chart/seriesconverter.cxx
@@ -283,10 +283,14 @@ void DataLabelConverter::convertFromModel( const Reference< XDataSeries >& rxDat
         const TypeGroupInfo& rTypeInfo = rTypeGroup.getTypeInfo();
         bool bIsPie = rTypeInfo.meTypeCategory == TYPECATEGORY_PIE;
 
-        if( mrModel.mxLayout && !mrModel.mxLayout->mbAutoLayout && !bIsPie )
+        if( mrModel.mxLayout && !mrModel.mxLayout->mbAutoLayout )
         {
             RelativePosition aPos(mrModel.mxLayout->mfX, mrModel.mxLayout->mfY, css::drawing::Alignment_TOP_LEFT);
             aPropSet.setProperty(PROP_CustomLabelPosition, aPos);
+            sal_Int32 nPlacement = -1;
+            if (bIsPie && aPropSet.getProperty(nPlacement, PROP_LabelPlacement)
+                && nPlacement == css::chart::DataLabelPlacement::AVOID_OVERLAP)
+                aPropSet.setProperty(PROP_LabelPlacement, css::chart::DataLabelPlacement::CUSTOM);
         }
 
         if (mrModel.mxShapeProp)
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 0e3cff0d4a95..5b52d312c091 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -3297,6 +3297,7 @@ const char* toOOXMLPlacement( sal_Int32 nPlacement )
         case css::chart::DataLabelPlacement::BOTTOM:        return "b";
         case css::chart::DataLabelPlacement::LEFT:          return "l";
         case css::chart::DataLabelPlacement::RIGHT:         return "r";
+        case css::chart::DataLabelPlacement::CUSTOM:
         case css::chart::DataLabelPlacement::AVOID_OVERLAP: return "bestFit";
         default:
             ;


More information about the Libreoffice-commits mailing list