diff options
author | Balazs Varga <balazs.varga991@gmail.com> | 2020-02-12 13:47:50 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-02-20 11:18:40 +0100 |
commit | 769433ad93040bc81f06672c8a2c01e2b76fece3 (patch) | |
tree | f2f12845bc7486d4d7af0d0303dc201ebd6db4a6 /chart2 | |
parent | c6f5e12ee3f91234b064222272d756670f3bb207 (diff) |
tdf#90749 chart: add leader lines to custom data label positions
also export them as CustomXML extension for MSO interoperability.
Note: pie chart is not yet supported.
See commit 4223ff2be69f03e571464b0b09ad0d278918631b
( tdf#48436 Chart: add CustomLabelPosition UNO API property)
Change-Id: Ia8142408414d4ad8f689d789386db50038ed13f6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88531
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/qa/extras/chart2export.cxx | 14 | ||||
-rw-r--r-- | chart2/qa/extras/data/xlsx/testTdf90749.xlsx | bin | 0 -> 14505 bytes | |||
-rw-r--r-- | chart2/source/view/charttypes/VSeriesPlotter.cxx | 36 |
3 files changed, 49 insertions, 1 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index b9d5873052ba..88c7d154d170 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -136,6 +136,7 @@ public: void testCustomDataLabel(); void testCustomPositionofDataLabel(); void testCustomDataLabelMultipleSeries(); + void testLeaderLines(); void testNumberFormatExportPPTX(); void testLabelSeparatorExportDOCX(); void testChartTitlePropertiesColorFillPPTX(); @@ -254,6 +255,7 @@ public: CPPUNIT_TEST(testCustomDataLabel); CPPUNIT_TEST(testCustomPositionofDataLabel); CPPUNIT_TEST(testCustomDataLabelMultipleSeries); + CPPUNIT_TEST(testLeaderLines); CPPUNIT_TEST(testNumberFormatExportPPTX); CPPUNIT_TEST(testLabelSeparatorExportDOCX); CPPUNIT_TEST(testChartTitlePropertiesColorFillPPTX); @@ -349,7 +351,8 @@ void Chart2ExportTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) { "office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0" }, { "table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0" }, { "text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0" }, - { "xlink", "http://www.w3c.org/1999/xlink" } + { "xlink", "http://www.w3c.org/1999/xlink" }, + { "c15", "http://schemas.microsoft.com/office/drawing/2012/chart" } }; for(size_t i = 0; i < SAL_N_ELEMENTS(aNamespaces); ++i) { @@ -2246,6 +2249,15 @@ void Chart2ExportTest::testCustomDataLabelMultipleSeries() } +void Chart2ExportTest::testLeaderLines() +{ + load("/chart2/qa/extras/data/xlsx/", "testTdf90749.xlsx"); + xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML"); + CPPUNIT_ASSERT(pXmlDoc); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser[1]/c:dLbls/c:extLst/c:ext/c15:showLeaderLines", "val", "1"); + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser[2]/c:dLbls/c:extLst/c:ext/c15:showLeaderLines", "val", "1"); +} + void Chart2ExportTest::testNumberFormatExportPPTX() { load("/chart2/qa/extras/data/pptx/", "tdf115859.pptx"); diff --git a/chart2/qa/extras/data/xlsx/testTdf90749.xlsx b/chart2/qa/extras/data/xlsx/testTdf90749.xlsx Binary files differnew file mode 100644 index 000000000000..ca3bc806c03c --- /dev/null +++ b/chart2/qa/extras/data/xlsx/testTdf90749.xlsx diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index b6382943b418..2c46743696f6 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -19,6 +19,7 @@ #include <memory> #include <VSeriesPlotter.hxx> +#include <BaseGFXHelper.hxx> #include <VLineProperties.hxx> #include <ShapeFactory.hxx> @@ -86,6 +87,7 @@ namespace chart { using namespace ::com::sun::star; +using namespace ::com::sun::star::chart; using namespace ::com::sun::star::chart2; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; @@ -721,7 +723,41 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re { awt::Point aRelPos = rDataSeries.getLabelPosition(aTextShapePos, nPointIndex); if( aRelPos.X != -1 ) + { xTextShape->setPosition(aRelPos); + if( !m_xChartTypeModel->getChartType().equalsIgnoreAsciiCase(CHART2_SERVICE_NAME_CHARTTYPE_PIE) ) + { + sal_Int32 nX1 = rScreenPosition2D.X; + sal_Int32 nY1 = rScreenPosition2D.Y; + sal_Int32 nX2 = nX1; + sal_Int32 nY2 = nY1; + ::basegfx::B2IRectangle aRect(BaseGFXHelper::makeRectangle(aRelPos, xTextShape->getSize())); + if (nX1 < aRelPos.X) + nX2 = aRelPos.X; + else if (nX1 > aRect.getMaxX()) + nX2 = aRect.getMaxX(); + + if (nY1 < aRect.getMinY()) + nY2 = aRect.getMinY(); + else if (nY1 > aRect.getMaxY()) + nY2 = aRect.getMaxY(); + + //when the line is very short compared to the page size don't create one + ::basegfx::B2DVector aLength(nX1 - nX2, nY1 - nY2); + double fPageDiagonaleLength = sqrt(double(m_aPageReferenceSize.Width)*double(m_aPageReferenceSize.Width) + double(m_aPageReferenceSize.Height)*double(m_aPageReferenceSize.Height)); + if ((aLength.getLength() / fPageDiagonaleLength) >= 0.01) + { + drawing::PointSequenceSequence aPoints(1); + aPoints[0].realloc(2); + aPoints[0][0].X = nX1; + aPoints[0][0].Y = nY1; + aPoints[0][1].X = nX2; + aPoints[0][1].Y = nY2; + + m_pShapeFactory->createLine2D(xTarget, aPoints, new VLineProperties); + } + } + } } // in case legend symbol has to be displayed, text shape position is |