diff options
author | Tünde Tóth <tundeth@gmail.com> | 2020-01-16 12:10:24 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-01-28 09:51:07 +0100 |
commit | f8966bb398cf0623be841c618b123866801a063c (patch) | |
tree | 2077ea488f825151cd921eda640d1b70849adf65 | |
parent | b5bde198a8e5054277787d3c6b5feddb4c5b93fd (diff) |
tdf#130031 Chart OOXML import: fix area chart data label position
Default data label positioning of area charts in Excel is vertically
centered between the X axes and the data point. In LibreOffice
the data labels positioning was above the data point.
Change-Id: Icff3e2554dee7b5ee264bc6f9579a84852da6f7b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86927
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | chart2/source/tools/ChartTypeHelper.cxx | 3 | ||||
-rw-r--r-- | chart2/source/view/charttypes/AreaChart.cxx | 14 | ||||
-rw-r--r-- | sw/qa/extras/layout/data/tdf130031.docx | bin | 0 -> 27382 bytes | |||
-rw-r--r-- | sw/qa/extras/layout/layout.cxx | 14 |
4 files changed, 26 insertions, 5 deletions
diff --git a/chart2/source/tools/ChartTypeHelper.cxx b/chart2/source/tools/ChartTypeHelper.cxx index ebd2af04ab45..b7b3e889e1a1 100644 --- a/chart2/source/tools/ChartTypeHelper.cxx +++ b/chart2/source/tools/ChartTypeHelper.cxx @@ -314,9 +314,10 @@ uno::Sequence < sal_Int32 > ChartTypeHelper::getSupportedLabelPlacements( const } else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_AREA) ) { - aRet.realloc(1); + aRet.realloc(2); sal_Int32* pSeq = aRet.getArray(); *pSeq++ = css::chart::DataLabelPlacement::TOP; + *pSeq++ = css::chart::DataLabelPlacement::CENTER; } else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) ) { diff --git a/chart2/source/view/charttypes/AreaChart.cxx b/chart2/source/view/charttypes/AreaChart.cxx index 6d67d0b6a94c..158d3f21bca6 100644 --- a/chart2/source/view/charttypes/AreaChart.cxx +++ b/chart2/source/view/charttypes/AreaChart.cxx @@ -750,6 +750,7 @@ void AreaChart::createShapes() if( rLogicYForNextSeriesMap.find(nAttachedAxisIndex) == rLogicYForNextSeriesMap.end() ) rLogicYForNextSeriesMap[nAttachedAxisIndex] = 0.0; + double fPreviousYValue = rLogicYForNextSeriesMap[nAttachedAxisIndex]; fLogicY += rLogicYForNextSeriesMap[nAttachedAxisIndex]; rLogicYForNextSeriesMap[nAttachedAxisIndex] = fLogicY; @@ -897,13 +898,19 @@ void AreaChart::createShapes() if( pSeries->getDataPointLabelIfLabel(nIndex) ) { LabelAlignment eAlignment = LABEL_ALIGN_TOP; + sal_Int32 nLabelPlacement = pSeries->getLabelPlacement( + nIndex, m_xChartTypeModel, rPosHelper.isSwapXAndY()); + + if (m_bArea && nLabelPlacement == css::chart::DataLabelPlacement::CENTER) + { + fLogicY -= (fLogicY - fPreviousYValue) / 2.0; + aScenePosition = rPosHelper.transformLogicToScene(fLogicX, fLogicY, fLogicZ, false); + } + drawing::Position3D aScenePosition3D( aScenePosition.PositionX , aScenePosition.PositionY , aScenePosition.PositionZ+getTransformedDepth() ); - sal_Int32 nLabelPlacement = pSeries->getLabelPlacement( - nIndex, m_xChartTypeModel, rPosHelper.isSwapXAndY()); - switch(nLabelPlacement) { case css::chart::DataLabelPlacement::TOP: @@ -924,7 +931,6 @@ void AreaChart::createShapes() break; case css::chart::DataLabelPlacement::CENTER: eAlignment = LABEL_ALIGN_CENTER; - //todo implement this different for area charts break; default: OSL_FAIL("this label alignment is not implemented yet"); diff --git a/sw/qa/extras/layout/data/tdf130031.docx b/sw/qa/extras/layout/data/tdf130031.docx Binary files differnew file mode 100644 index 000000000000..4ac420a83c8e --- /dev/null +++ b/sw/qa/extras/layout/data/tdf130031.docx diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx index 862f4a30eb41..567fdea446f0 100644 --- a/sw/qa/extras/layout/layout.cxx +++ b/sw/qa/extras/layout/layout.cxx @@ -2504,6 +2504,20 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf129173) pXmlDoc, "/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/textarray[22]/text", "56"); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf130031) +{ + SwDoc* pDoc = createDoc("tdf130031.docx"); + SwDocShell* pShell = pDoc->GetDocShell(); + + // Dump the rendering of the first page as an XML file. + std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile(); + MetafileXmlDump dumper; + xmlDocPtr pXmlDoc = dumpAndParse(dumper, *xMetaFile); + CPPUNIT_ASSERT(pXmlDoc); + sal_Int32 nY = getXPath(pXmlDoc, "//textarray[11]", "y").toInt32(); + CPPUNIT_ASSERT_DOUBLES_EQUAL(4339, nY, 50); +} + CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf116925) { SwDoc* pDoc = createDoc("tdf116925.docx"); |