chart2/qa/extras/chart2import.cxx                                           |  
 92 ++++++++++
 chart2/qa/extras/chart2import2.cxx                                          |  
 14 -
 chart2/qa/extras/charttest.hxx                                              |  
 38 ++++
 chart2/qa/extras/data/pptx/PieChartWithAutomaticLayout_SizeAndPosition.pptx 
|binary
 chart2/source/view/main/ChartView.cxx                                       |  
 18 +
 sc/qa/uitest/chart/chartDataLabels.py                                       |  
  8 
 sw/qa/extras/layout/layout2.cxx                                             |  
  4 
 7 files changed, 158 insertions(+), 16 deletions(-)

New commits:
commit 959fbfc000d2e3167b2b57b6d11bea231993b4f0
Author:     Gülşah Köse <gulsah.k...@collabora.com>
AuthorDate: Wed Nov 23 17:05:28 2022 +0300
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Tue Jan 17 07:19:32 2023 +0000

    tdf#91265 Use same plot area distance as used in MSO
    
    Changes the postion calculation for pie charts, where the margin
    min distance is now constant for pie charts, but unchanged for
    other chart types.
    
    This changes the positions of various pie charts used in tests,
    which have been changed to the new value after the cases have been
    checked.
    
    Added a new test with all 3 use cases (chart area width equals
    height, width is greater than height, width is less than height).
    
    Change-Id: I51f98f336a7c64a3e6762144fc7dc8d9df80f696
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143179
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/chart2/qa/extras/chart2import.cxx 
b/chart2/qa/extras/chart2import.cxx
index a9c301a94b93..b02f52c68411 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -138,6 +138,7 @@ public:
     void testFixedSizeBarChartVeryLongLabel();
     void testAutomaticSizeBarChartVeryLongLabel();
     void testTotalsRowIgnored();
+    void testPieChartPlotAreaMarginWithAutomaticLayout();
 
     CPPUNIT_TEST_SUITE(Chart2ImportTest);
     CPPUNIT_TEST(Fdo60083);
@@ -225,6 +226,7 @@ public:
     CPPUNIT_TEST(testFixedSizeBarChartVeryLongLabel);
     CPPUNIT_TEST(testAutomaticSizeBarChartVeryLongLabel);
     CPPUNIT_TEST(testTotalsRowIgnored);
+    CPPUNIT_TEST(testPieChartPlotAreaMarginWithAutomaticLayout);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -2303,6 +2305,96 @@ void Chart2ImportTest::testTotalsRowIgnored()
     }
 }
 
+void Chart2ImportTest::testPieChartPlotAreaMarginWithAutomaticLayout()
+{
+    // tdf#91265
+    // Checks the margin and calculation of the plot area for the pie chart 
inside the chart area.
+
+    loadFromURL(u"pptx/PieChartWithAutomaticLayout_SizeAndPosition.pptx");
+
+    OUString aCheckShapeName = "CID/D=0:CS=0:CT=0:Series=0";
+    // Chart Wuse case Width == Height
+    {
+        // Load chart Chart_2_2 - 2cm x 2cm -
+        auto xDocument = getChartDocFromDrawImpressNamed(0, u"Chart_2_2");
+        CPPUNIT_ASSERT(xDocument.is());
+
+        uno::Reference<chart2::XChartDocument>xChartDocument(xDocument, 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xChartDocument.is());
+
+        // Get the shape of the diagram / chart
+        uno::Reference<drawing::XDrawPageSupplier> 
xDrawPageSupplier(xChartDocument, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xDrawPageSupplier.is());
+        uno::Reference<drawing::XDrawPage> xDrawPage = 
xDrawPageSupplier->getDrawPage();
+        uno::Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xShapes.is());
+
+        uno::Reference<drawing::XShape> xChartDiagramShape = 
getShapeByName(xShapes, aCheckShapeName);
+        CPPUNIT_ASSERT(xChartDiagramShape.is());
+
+        // Size
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(1300, 
xChartDiagramShape->getSize().Width, 5);  // calculated chart area size - 2 * 
margin
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(1300, 
xChartDiagramShape->getSize().Height, 5); // calculated chart area size - 2 * 
margin
+        // Position
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(350, xChartDiagramShape->getPosition().X, 
5); // margin
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(350, xChartDiagramShape->getPosition().Y, 
5); // margin
+    }
+
+    // Chart use case - Width < Height
+    {
+        // Load chart Chart_3_4 - 3cm x 4cm
+        auto xDocument = getChartDocFromDrawImpressNamed(0, u"Chart_3_4");
+        CPPUNIT_ASSERT(xDocument.is());
+
+        uno::Reference<chart2::XChartDocument>xChartDocument(xDocument, 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xChartDocument.is());
+
+        // Get the shape of the diagram / chart
+        uno::Reference<drawing::XDrawPageSupplier> 
xDrawPageSupplier(xChartDocument, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xDrawPageSupplier.is());
+        uno::Reference<drawing::XDrawPage> xDrawPage = 
xDrawPageSupplier->getDrawPage();
+        uno::Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xShapes.is());
+
+        uno::Reference<drawing::XShape> xChartDiagramShape = 
getShapeByName(xShapes, aCheckShapeName);
+        CPPUNIT_ASSERT(xChartDiagramShape.is());
+
+        // Size
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(2300, 
xChartDiagramShape->getSize().Width, 5);  // calculated chart area size - 2 * 
margin
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(2300, 
xChartDiagramShape->getSize().Height, 5); // calculated chart area size - 2 * 
margin
+        // Position
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(350, xChartDiagramShape->getPosition().X, 
5); // margin
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(850, xChartDiagramShape->getPosition().Y, 
5); // margin + calculated centering
+    }
+
+    // Chart use case - Width > Height
+    {
+        // Load chart Chart_3_2 - 3cm x 2cm
+        auto xDocument = getChartDocFromDrawImpressNamed(0, u"Chart_3_2");
+        CPPUNIT_ASSERT(xDocument.is());
+
+        uno::Reference<chart2::XChartDocument>xChartDocument(xDocument, 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xChartDocument.is());
+
+        // Get the shape of the diagram / chart
+        uno::Reference<drawing::XDrawPageSupplier> 
xDrawPageSupplier(xChartDocument, uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xDrawPageSupplier.is());
+        uno::Reference<drawing::XDrawPage> xDrawPage = 
xDrawPageSupplier->getDrawPage();
+        uno::Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), 
uno::UNO_QUERY);
+        CPPUNIT_ASSERT(xShapes.is());
+
+        uno::Reference<drawing::XShape> xChartDiagramShape = 
getShapeByName(xShapes, aCheckShapeName);
+        CPPUNIT_ASSERT(xChartDiagramShape.is());
+
+        // Size
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(1300, 
xChartDiagramShape->getSize().Width, 5);  // calculated chart area size - 2 * 
margin
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(1300, 
xChartDiagramShape->getSize().Height, 5); // calculated chart area size - 2 * 
margin
+        // Position
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(850, xChartDiagramShape->getPosition().X, 
5); // margin + calculated centering
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(350, xChartDiagramShape->getPosition().Y, 
5); // margin
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/chart2import2.cxx 
b/chart2/qa/extras/chart2import2.cxx
index 2afbb9c33830..69658f9bc88b 100644
--- a/chart2/qa/extras/chart2import2.cxx
+++ b/chart2/qa/extras/chart2import2.cxx
@@ -421,8 +421,8 @@ void Chart2ImportTest2::testTdf123504()
     CPPUNIT_ASSERT_GREATER(sal_Int32(3000), aSlicePosition.X);
     CPPUNIT_ASSERT_GREATER(sal_Int32(150), aSlicePosition.Y);
     awt::Size aSliceSize = xSlice->getSize();
-    CPPUNIT_ASSERT_GREATER(sal_Int32(8500), aSliceSize.Height);
-    CPPUNIT_ASSERT_GREATER(sal_Int32(8500), aSliceSize.Width);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(8300.0, aSliceSize.Height, 10);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(8300.0, aSliceSize.Width, 10);
 }
 
 void Chart2ImportTest2::testTdf122765()
@@ -599,8 +599,8 @@ void Chart2ImportTest2::testTdf133376()
     CPPUNIT_ASSERT(xDataPointLabel.is());
     // Check the position of the 3rd data point label, which is out from the 
pie slice
     awt::Point aLabelPosition = xDataPointLabel->getPosition();
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(1082, aLabelPosition.X, 30);
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(5462, aLabelPosition.Y, 30);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1208, aLabelPosition.X, 30);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(5370, aLabelPosition.Y, 30);
 }
 
 void Chart2ImportTest2::testTdf134225()
@@ -630,8 +630,8 @@ void Chart2ImportTest2::testTdf134225()
     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(1669, sal_Int32(aLabelPosition2.X - 
aLabelPosition1.X), 30);
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(2166, sal_Int32(aLabelPosition2.Y - 
aLabelPosition1.Y), 30);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1493, sal_Int32(aLabelPosition2.X - 
aLabelPosition1.X), 30);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(2015, sal_Int32(aLabelPosition2.Y - 
aLabelPosition1.Y), 30);
 #endif
 }
 
@@ -679,7 +679,7 @@ void Chart2ImportTest2::testTdf136105()
         // Check the position of the 1st data point label, which is out from 
the pie slice
         awt::Point aLabelPosition = xDataPointLabel->getPosition();
         CPPUNIT_ASSERT_DOUBLES_EQUAL(7978, aLabelPosition.X, 500);
-        CPPUNIT_ASSERT_DOUBLES_EQUAL(1048, aLabelPosition.Y, 500);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(1550, aLabelPosition.Y, 500);
     }
 }
 
diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx
index 1d78972974e9..ade5011b2b4b 100644
--- a/chart2/qa/extras/charttest.hxx
+++ b/chart2/qa/extras/charttest.hxx
@@ -122,6 +122,8 @@ public:
     uno::Reference< chart::XChartDocument > getChartDocFromImpress( 
std::u16string_view pDir, const char* pName );
 
     uno::Reference<chart::XChartDocument> getChartDocFromDrawImpress( 
sal_Int32 nPage, sal_Int32 nShape );
+    uno::Reference<chart::XChartDocument> getChartDocFromDrawImpressNamed( 
sal_Int32 nPage, std::u16string_view rName);
+
 
     uno::Reference<chart::XChartDocument> getChartDocFromWriter( sal_Int32 
nShape );
     Sequence< OUString > getFormattedDateCategories( const 
Reference<chart2::XChartDocument>& xChartDoc );
@@ -475,6 +477,42 @@ uno::Reference<chart::XChartDocument> 
ChartTest::getChartDocFromDrawImpress(
     return xChartDoc;
 }
 
+uno::Reference<chart::XChartDocument> 
ChartTest::getChartDocFromDrawImpressNamed(sal_Int32 nPage, std::u16string_view 
rName)
+{
+    uno::Reference<chart::XChartDocument> xChart;
+
+    uno::Reference<drawing::XDrawPagesSupplier> xPages(mxComponent, 
uno::UNO_QUERY);
+    if (!xPages.is())
+        return xChart;
+
+    uno::Reference<drawing::XDrawPage> 
xPage(xPages->getDrawPages()->getByIndex(nPage), uno::UNO_QUERY);
+    if (!xPage.is())
+        return xChart;
+
+    for (sal_Int32 i=0; i < xPage->getCount(); ++i)
+    {
+        uno::Reference<container::XNamed> xNamedShape(xPage->getByIndex(i), 
uno::UNO_QUERY);
+        if (!xNamedShape.is())
+            continue;
+
+        if (xNamedShape->getName() != rName)
+            continue;
+
+        uno::Reference<beans::XPropertySet> xShapeProps(xNamedShape, 
uno::UNO_QUERY);
+        if (!xShapeProps.is())
+            continue;
+
+        uno::Reference<frame::XModel> xDocModel;
+        xShapeProps->getPropertyValue("Model") >>= xDocModel;
+        if (!xDocModel.is())
+            continue;
+
+        return uno::Reference<chart::XChartDocument>(xDocModel, 
uno::UNO_QUERY);
+    }
+
+    return xChart;
+}
+
 uno::Reference<chart::XChartDocument> ChartTest::getChartDocFromWriter( 
sal_Int32 nShape )
 {
     // DO NOT use XDrawPageSupplier since SwVirtFlyDrawObj are not created
diff --git 
a/chart2/qa/extras/data/pptx/PieChartWithAutomaticLayout_SizeAndPosition.pptx 
b/chart2/qa/extras/data/pptx/PieChartWithAutomaticLayout_SizeAndPosition.pptx
new file mode 100644
index 000000000000..3f95e932b1c5
Binary files /dev/null and 
b/chart2/qa/extras/data/pptx/PieChartWithAutomaticLayout_SizeAndPosition.pptx 
differ
diff --git a/chart2/source/view/main/ChartView.cxx 
b/chart2/source/view/main/ChartView.cxx
index 2de5611c5ed0..37d237e7ee7a 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -925,15 +925,27 @@ namespace
 {
 
 constexpr double constPageLayoutDistancePercentage = 0.02;
+constexpr sal_Int32 constPageLayoutFixedDistance = 350;
 
 bool getAvailablePosAndSizeForDiagram(
-    CreateShapeParam2D& rParam, const awt::Size & rPageSize, const 
uno::Reference< beans::XPropertySet >& xProp)
+    CreateShapeParam2D& rParam, const awt::Size & rPageSize, 
rtl::Reference<Diagram> const& xDiagram)
 {
+    uno::Reference<beans::XPropertySet> const& xProp(xDiagram);
     rParam.mbUseFixedInnerSize = false;
 
     //@todo: we need a size dependent on the axis labels
-    sal_Int32 nYDistance = static_cast<sal_Int32>(rPageSize.Height * 
constPageLayoutDistancePercentage);
-    sal_Int32 nXDistance = static_cast<sal_Int32>(rPageSize.Width * 
constPageLayoutDistancePercentage);
+    rtl::Reference<ChartType> 
xChartType(DiagramHelper::getChartTypeByIndex(xDiagram, 0));
+
+    sal_Int32 nXDistance = sal_Int32(rPageSize.Width * 
constPageLayoutDistancePercentage);
+    sal_Int32 nYDistance = sal_Int32(rPageSize.Height * 
constPageLayoutDistancePercentage);
+
+    // Only pie chart uses fixed size margins
+    if (xChartType.is() && xChartType->getChartType() == 
CHART2_SERVICE_NAME_CHARTTYPE_PIE)
+    {
+        nXDistance = constPageLayoutFixedDistance;
+        nYDistance = constPageLayoutFixedDistance;
+    }
+
     rParam.maRemainingSpace.X += nXDistance;
     rParam.maRemainingSpace.Width -= 2*nXDistance;
     rParam.maRemainingSpace.Y += nYDistance;
diff --git a/sc/qa/uitest/chart/chartDataLabels.py 
b/sc/qa/uitest/chart/chartDataLabels.py
index 132f7ae2c656..a6e00e599c47 100644
--- a/sc/qa/uitest/chart/chartDataLabels.py
+++ b/sc/qa/uitest/chart/chartDataLabels.py
@@ -272,8 +272,8 @@ class chartDataLabels(UITestCase):
 
         with self.ui_test.execute_dialog_through_action(xDataLabel, "COMMAND", 
mkPropertyValues({"COMMAND": "TransformDialog"})) as xDialog:
 
-            self.assertEqual("0.5", 
get_state_as_dict(xDialog.getChild("MTR_FLD_POS_X"))['Value'])
-            self.assertEqual("2.89", 
get_state_as_dict(xDialog.getChild("MTR_FLD_POS_Y"))['Value'])
+            self.assertEqual("0.74", 
get_state_as_dict(xDialog.getChild("MTR_FLD_POS_X"))['Value'])
+            self.assertEqual("2.82", 
get_state_as_dict(xDialog.getChild("MTR_FLD_POS_Y"))['Value'])
 
             # Use OK button in order to test tdf#137165
 
@@ -283,8 +283,8 @@ class chartDataLabels(UITestCase):
         with self.ui_test.execute_dialog_through_action(xDataLabel, "COMMAND", 
mkPropertyValues({"COMMAND": "TransformDialog"})) as xDialog:
 
             # Check the position has changed after moving the label using the 
arrows keys
-            self.assertEqual("0.4", 
get_state_as_dict(xDialog.getChild("MTR_FLD_POS_X"))['Value'])
-            self.assertEqual("2.79", 
get_state_as_dict(xDialog.getChild("MTR_FLD_POS_Y"))['Value'])
+            self.assertEqual("0.64", 
get_state_as_dict(xDialog.getChild("MTR_FLD_POS_X"))['Value'])
+            self.assertEqual("2.72", 
get_state_as_dict(xDialog.getChild("MTR_FLD_POS_Y"))['Value'])
 
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx
index 434bf6376ebc..0fa9f9978857 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -1626,7 +1626,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf129054)
               
"/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/push[4]/polyline[1]/point[31]",
               "y")
               .toInt32();
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(4810, nYTop - nYBottom, 5);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(4615, nYTop - nYBottom, 5);
 }
 
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf129173)
@@ -1679,7 +1679,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf137116)
     // - Actual  : -225
     // - Delta   : 100
     // i.e. the second data label appeared inside the pie slice.
-    CPPUNIT_ASSERT_DOUBLES_EQUAL(1229, nX2 - nX4, 100);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1117, nX2 - nX4, 100);
 }
 
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf137154)

Reply via email to