chart2/qa/extras/chart2export2.cxx |   30 ++++++++++++++++++++++++++++++
 oox/source/export/chartexport.cxx  |   14 +++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)

New commits:
commit dfffe516199b595e78a23178bc6e508a28ee48e6
Author:     Attila Szűcs <attila.sz...@collabora.com>
AuthorDate: Thu Jun 13 21:31:25 2024 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Jun 18 09:49:31 2024 +0200

    tdf#161571 chart: OOXML export of piechart label positions
    
    Custom Positions of lables was not exported in case
    of piechart.
    
    As far as i know, Best Fit Placement in PieChart may can
    cause issues, because MS, and LO may calculate it differently,
    so i left that case unchanged, to avoid possible regressions.
    
    Change-Id: I84e94f30390eb323c7311ae1d97ca3c63da0bc6a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168972
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/chart2/qa/extras/chart2export2.cxx 
b/chart2/qa/extras/chart2export2.cxx
index 440c526cb5fc..67907d3643cf 100644
--- a/chart2/qa/extras/chart2export2.cxx
+++ b/chart2/qa/extras/chart2export2.cxx
@@ -455,6 +455,36 @@ CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, 
testCustomPositionofDataLabel)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, 
testTdf161571PiechartCustomPosDataLabels)
+{
+    // FIXME: validation error in OOXML export
+    skipValidation();
+
+    loadFromFile(u"xlsx/tdf161607PieChartLeaderLinesColorWidth.xlsx");
+    save(u"Calc Office Open XML"_ustr);
+    xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr);
+    CPPUNIT_ASSERT(pXmlDoc);
+
+    // test custom position of data label (xlsx)
+    assertXPath(
+        pXmlDoc,
+        
"/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/c:dLbl[2]/c:idx"_ostr,
+        "val"_ostr, u"1"_ustr);
+    OUString aXVal = getXPath(pXmlDoc,
+                              
"/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/"
+                              "c:dLbl[2]/c:layout/c:manualLayout/c:x"_ostr,
+                              "val"_ostr);
+    double nX = aXVal.toDouble();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.13500189609404625, nX, 1e-7);
+
+    OUString aYVal = getXPath(pXmlDoc,
+                              
"/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/"
+                              "c:dLbl[2]/c:layout/c:manualLayout/c:y"_ostr,
+                              "val"_ostr);
+    double nY = aYVal.toDouble();
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.15994818221025045, nY, 1e-7);
+}
+
 CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCustomDataLabelMultipleSeries)
 {
     loadFromFile(u"pptx/tdf115107-2.pptx");
diff --git a/oox/source/export/chartexport.cxx 
b/oox/source/export/chartexport.cxx
index c63c8497daf1..78d3d4cbcebf 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -4052,8 +4052,20 @@ void ChartExport::exportDataLabels(
         pFS->startElement(FSNS(XML_c, XML_dLbl));
         pFS->singleElement(FSNS(XML_c, XML_idx), XML_val, 
OString::number(nIdx));
 
+        // As far as i know there can be issues with the Positions,
+        // if a piechart label use AVOID_OVERLAP placement (== BestFit)
+        // because LO and MS may calculate the bestFit positions differently.
+        bool bWritePosition = true;
+        if (eChartType == chart::TYPEID_PIE)
+        {
+            sal_Int32 nLabelPlacement = aParam.meDefault;
+            xLabelPropSet->getPropertyValue(u"LabelPlacement"_ustr) >>= 
nLabelPlacement;
+            if (nLabelPlacement == 
css::chart::DataLabelPlacement::AVOID_OVERLAP)
+                bWritePosition = false;
+        }
+
         // export custom position of data label
-        if( eChartType != chart::TYPEID_PIE )
+        if (bWritePosition)
         {
             chart2::RelativePosition aCustomLabelPosition;
             if( xLabelPropSet->getPropertyValue(u"CustomLabelPosition"_ustr) 
>>= aCustomLabelPosition )

Reply via email to