diff options
author | Balazs Varga <balazs.varga991@gmail.com> | 2019-05-30 13:30:26 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2019-06-03 16:11:06 +0200 |
commit | 7f373a4c88961348f35e4f990182628488878efe (patch) | |
tree | 7094560bf1e66918e92eded573fbee0849a666ca /chart2 | |
parent | 90ace7be71d41257e29a28fa2e7c0adf8f84050d (diff) |
tdf#48041 Chart: do not duplicate major value
axis labels and vertical axis lines. If the same
value labels follow each other, because of
the number format, only display them once.
Change-Id: I3c5577a0e86c475cb2fafb62d63f991cef7229d8
Reviewed-on: https://gerrit.libreoffice.org/73200
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/qa/extras/chart2import.cxx | 55 | ||||
-rw-r--r-- | chart2/qa/extras/data/pptx/tdf48041.pptx | bin | 0 -> 23937 bytes | |||
-rw-r--r-- | chart2/source/view/axes/VCartesianAxis.cxx | 32 |
3 files changed, 87 insertions, 0 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index 5c7255a0e632..a55107b36318 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -118,6 +118,8 @@ public: void testTdf116163(); + void testTdf48041(); + void testTdf121205(); void testTdf114179(); @@ -199,6 +201,8 @@ public: CPPUNIT_TEST(testTdf116163); + CPPUNIT_TEST(testTdf48041); + CPPUNIT_TEST(testTdf121205); CPPUNIT_TEST(testTdf114179); @@ -1746,6 +1750,57 @@ void Chart2ImportTest::testTdf116163() CPPUNIT_ASSERT_EQUAL(OUString("Dddd..."), xLabel3->getString()); } +void Chart2ImportTest::testTdf48041() +{ + load("/chart2/qa/extras/data/pptx/", "tdf48041.pptx"); + + Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + + Reference<chart2::XAxis> xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0); + CPPUNIT_ASSERT(xYAxis.is()); + + chart2::ScaleData aScaleData = xYAxis->getScaleData(); + CPPUNIT_ASSERT(aScaleData.Scaling.is()); + + // Check visible text + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xShapes.is()); + + const OUString sYAxisName = "CID/D=0:CS=0:Axis=1,0"; // Y Axis + uno::Reference<drawing::XShape> xYAxisShape = getShapeByName(xShapes, sYAxisName, + // Axis occurs twice in chart xshape representation so need to get the one related to labels + [](const uno::Reference<drawing::XShape>& rXShape) -> bool + { + uno::Reference<drawing::XShapes> xAxisShapes(rXShape, uno::UNO_QUERY); + CPPUNIT_ASSERT(xAxisShapes.is()); + uno::Reference<drawing::XShape> xChildShape(xAxisShapes->getByIndex(0), uno::UNO_QUERY); + uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor(xChildShape, uno::UNO_QUERY_THROW); + return (xShapeDescriptor->getShapeType() == "com.sun.star.drawing.TextShape"); + }); + CPPUNIT_ASSERT(xYAxisShape.is()); + + // Check label count + uno::Reference<container::XIndexAccess> xIndexAccess(xYAxisShape, UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6), xIndexAccess->getCount()); + + // Check text + uno::Reference<text::XTextRange> xLabel0(xIndexAccess->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("0"), xLabel0->getString()); + uno::Reference<text::XTextRange> xLabel1(xIndexAccess->getByIndex(1), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xLabel1->getString()); + uno::Reference<text::XTextRange> xLabel2(xIndexAccess->getByIndex(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("2"), xLabel2->getString()); + uno::Reference<text::XTextRange> xLabel3(xIndexAccess->getByIndex(3), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("3"), xLabel3->getString()); + uno::Reference<text::XTextRange> xLabel4(xIndexAccess->getByIndex(4), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("4"), xLabel4->getString()); + uno::Reference<text::XTextRange> xLabel5(xIndexAccess->getByIndex(5), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("5"), xLabel5->getString()); +} + void Chart2ImportTest::testTdf121205() { load("/chart2/qa/extras/data/pptx/", "tdf121205.pptx"); diff --git a/chart2/qa/extras/data/pptx/tdf48041.pptx b/chart2/qa/extras/data/pptx/tdf48041.pptx Binary files differnew file mode 100644 index 000000000000..b0872f84f2f6 --- /dev/null +++ b/chart2/qa/extras/data/pptx/tdf48041.pptx diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index 4fac1f83b72e..99eb1b085185 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -28,6 +28,7 @@ #include <AxisHelper.hxx> #include "Tickmarks_Equidistant.hxx" #include <ExplicitCategoriesProvider.hxx> +#include <com/sun/star/chart2/AxisType.hpp> #include <rtl/math.hxx> #include <tools/color.hxx> @@ -1551,11 +1552,35 @@ sal_Int32 VCartesianAxis::estimateMaximumAutoMainIncrementCount() sal_Int32 nTotalAvailable = nMaxHeight; sal_Int32 nSingleNeeded = m_nMaximumTextHeightSoFar; + sal_Int32 nMaxSameLabel = 0; //for horizontal axis: if( (m_nDimensionIndex == 0 && !m_aAxisProperties.m_bSwapXAndY) || (m_nDimensionIndex == 1 && m_aAxisProperties.m_bSwapXAndY) ) { + if (m_aAxisProperties.m_nAxisType != css::chart2::AxisType::DATE) + { + // tdf#48041: do not duplicate the value labels because of rounding + FixedNumberFormatter aFixedNumberFormatterTest(m_xNumberFormatsSupplier, m_aAxisLabelProperties.nNumberFormatKey); + OUString sPreviousValueLabel; + sal_Int32 nSameLabel = 0; + for (sal_Int32 nLabel = 0; nLabel < static_cast<sal_Int32>(m_aAllTickInfos[0].size()); ++nLabel) + { + Color nColor = COL_AUTO; + bool bHasColor = false; + OUString sValueLabel = aFixedNumberFormatterTest.getFormattedString(m_aAllTickInfos[0][nLabel].fScaledTickValue, nColor, bHasColor); + if (sValueLabel == sPreviousValueLabel) + { + nSameLabel++; + if (nSameLabel > nMaxSameLabel) + nMaxSameLabel = nSameLabel; + } + else + nSameLabel = 0; + sPreviousValueLabel = sValueLabel; + } + } + nTotalAvailable = nMaxWidth; nSingleNeeded = m_nMaximumTextWidthSoFar; } @@ -1563,6 +1588,13 @@ sal_Int32 VCartesianAxis::estimateMaximumAutoMainIncrementCount() if( nSingleNeeded>0 ) nRet = nTotalAvailable/nSingleNeeded; + if ( nMaxSameLabel > 0 ) + { + sal_Int32 nRetNoSameLabel = m_aAllTickInfos[0].size() / (nMaxSameLabel + 1); + if ( nRet > nRetNoSameLabel ) + nRet = nRetNoSameLabel; + } + return nRet; } |