summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorGülşah Köse <gulsah.kose@collabora.com>2022-11-23 17:05:28 +0300
committerAron Budea <aron.budea@collabora.com>2023-06-14 08:06:15 +0200
commitc93d88a7d321483e9d040fad17394a738f8cde7c (patch)
treeb2ffb2d160c533167ba02872def7902d6f0dd95e /chart2
parente04080c1259cd91388e157b58e3c4b041aed163c (diff)
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 <quikee@gmail.com> (cherry picked from commit 959fbfc000d2e3167b2b57b6d11bea231993b4f0) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153017 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Aron Budea <aron.budea@collabora.com>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/qa/extras/chart2import.cxx92
-rw-r--r--chart2/qa/extras/chart2import2.cxx14
-rw-r--r--chart2/qa/extras/charttest.hxx38
-rw-r--r--chart2/qa/extras/data/pptx/PieChartWithAutomaticLayout_SizeAndPosition.pptxbin0 -> 165804 bytes
-rw-r--r--chart2/source/view/main/ChartView.cxx18
5 files changed, 152 insertions, 10 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index 243597a060ab..d9f443466d9f 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -139,6 +139,7 @@ public:
void testFixedSizeBarChartVeryLongLabel();
void testAutomaticSizeBarChartVeryLongLabel();
void testTotalsRowIgnored();
+ void testPieChartPlotAreaMarginWithAutomaticLayout();
CPPUNIT_TEST_SUITE(Chart2ImportTest);
CPPUNIT_TEST(Fdo60083);
@@ -226,6 +227,7 @@ public:
CPPUNIT_TEST(testFixedSizeBarChartVeryLongLabel);
CPPUNIT_TEST(testAutomaticSizeBarChartVeryLongLabel);
CPPUNIT_TEST(testTotalsRowIgnored);
+ CPPUNIT_TEST(testPieChartPlotAreaMarginWithAutomaticLayout);
CPPUNIT_TEST_SUITE_END();
};
@@ -2319,6 +2321,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
--- /dev/null
+++ b/chart2/qa/extras/data/pptx/PieChartWithAutomaticLayout_SizeAndPosition.pptx
Binary files differ
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 584dfdb5ea72..0cb29255f06d 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -924,15 +924,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;