diff options
-rw-r--r-- | chart2/qa/extras/chart2import2.cxx | 48 | ||||
-rw-r--r-- | chart2/qa/extras/data/ods/tdf146066.ods | bin | 0 -> 15079 bytes | |||
-rw-r--r-- | chart2/source/view/axes/VCoordinateSystem.cxx | 22 |
3 files changed, 69 insertions, 1 deletions
diff --git a/chart2/qa/extras/chart2import2.cxx b/chart2/qa/extras/chart2import2.cxx index f84254c30c2a..17b762824f43 100644 --- a/chart2/qa/extras/chart2import2.cxx +++ b/chart2/qa/extras/chart2import2.cxx @@ -58,6 +58,7 @@ public: void testTdfCustomShapePos(); void testTdf121281(); void testTdf139658(); + void testTdf146066(); CPPUNIT_TEST_SUITE(Chart2ImportTest2); @@ -97,6 +98,7 @@ public: CPPUNIT_TEST(testTdfCustomShapePos); CPPUNIT_TEST(testTdf121281); CPPUNIT_TEST(testTdf139658); + CPPUNIT_TEST(testTdf146066); CPPUNIT_TEST_SUITE_END(); }; @@ -857,6 +859,52 @@ void Chart2ImportTest2::testTdf139658() CPPUNIT_ASSERT_EQUAL(OUString("category\"3"), aCategories[2]); } +void Chart2ImportTest2::testTdf146066() +{ + load(u"/chart2/qa/extras/data/ods/", "tdf146066.ods"); + Reference<chart::XChartDocument> xChartDoc(getChartDocFromSheet(0, mxComponent), + UNO_QUERY_THROW); + 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()); + + uno::Reference<drawing::XShape> xYAxisShape = getShapeByName( + xShapes, "CID/D=0:CS=0:Axis=1,0", // Y Axis + // 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>(8), 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("5"), xLabel1->getString()); + uno::Reference<text::XTextRange> xLabel2(xIndexAccess->getByIndex(2), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("10"), xLabel2->getString()); + uno::Reference<text::XTextRange> xLabel3(xIndexAccess->getByIndex(3), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("15"), xLabel3->getString()); + uno::Reference<text::XTextRange> xLabel4(xIndexAccess->getByIndex(4), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("20"), xLabel4->getString()); + uno::Reference<text::XTextRange> xLabel5(xIndexAccess->getByIndex(5), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("25"), xLabel5->getString()); + uno::Reference<text::XTextRange> xLabel6(xIndexAccess->getByIndex(6), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("30"), xLabel6->getString()); + uno::Reference<text::XTextRange> xLabel7(xIndexAccess->getByIndex(7), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("35"), xLabel7->getString()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest2); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/chart2/qa/extras/data/ods/tdf146066.ods b/chart2/qa/extras/data/ods/tdf146066.ods Binary files differnew file mode 100644 index 000000000000..03abe9ae68ca --- /dev/null +++ b/chart2/qa/extras/data/ods/tdf146066.ods diff --git a/chart2/source/view/axes/VCoordinateSystem.cxx b/chart2/source/view/axes/VCoordinateSystem.cxx index f98f66502857..222383c8c7be 100644 --- a/chart2/source/view/axes/VCoordinateSystem.cxx +++ b/chart2/source/view/axes/VCoordinateSystem.cxx @@ -18,6 +18,7 @@ */ #include <BaseGFXHelper.hxx> +#include <DateHelper.hxx> #include <VCoordinateSystem.hxx> #include "VCartesianCoordinateSystem.hxx" #include "VPolarCoordinateSystem.hxx" @@ -35,6 +36,7 @@ #include <com/sun/star/chart2/AxisType.hpp> #include <com/sun/star/chart2/XCoordinateSystem.hpp> #include <comphelper/sequence.hxx> +#include <rtl/math.hxx> #include <tools/diagnose_ex.h> #include <algorithm> @@ -365,8 +367,26 @@ void VCoordinateSystem::prepareAutomaticAxisScaling( ScaleAutomatism& rScaleAuto { // y dimension ExplicitScaleData aScale = getExplicitScale( 0, 0 ); + double fMaximum = aScale.Maximum; + if (!aScale.m_bShiftedCategoryPosition && aScale.AxisType == AxisType::DATE) + { + // tdf#146066 Increase maximum date value by one month/year, + // because the automatic scaling of the Y axis was incorrect when the last Y value was the highest value. + Date aMaxDate(aScale.NullDate); + aMaxDate.AddDays(::rtl::math::approxFloor(fMaximum)); + switch (aScale.TimeResolution) + { + case css::chart::TimeUnit::MONTH: + aMaxDate = DateHelper::GetDateSomeMonthsAway(aMaxDate, 1); + break; + case css::chart::TimeUnit::YEAR: + aMaxDate = DateHelper::GetDateSomeYearsAway(aMaxDate, 1); + break; + } + fMaximum = aMaxDate - aScale.NullDate; + } fMin = m_aMergedMinMaxSupplier.getMinimumYInRange(aScale.Minimum,aScale.Maximum, nAxisIndex); - fMax = m_aMergedMinMaxSupplier.getMaximumYInRange(aScale.Minimum,aScale.Maximum, nAxisIndex); + fMax = m_aMergedMinMaxSupplier.getMaximumYInRange(aScale.Minimum, fMaximum, nAxisIndex); } else if( nDimIndex == 2 ) { |