summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorTünde Tóth <toth.tunde@nisz.hu>2022-01-06 15:05:10 +0100
committerLászló Németh <nemeth@numbertext.org>2022-02-01 09:41:38 +0100
commitdca425203c0205a6c570fa36f0dfdfa078960249 (patch)
treebd31a7bab7f705ed3ff2b0a3b47e4c9e9be9b9f6 /chart2
parent721cd0658ab9721c01be0097f71a66ff3bdad7ac (diff)
tdf#146066 chart: fix automatic axis scaling at dates
Automatic scaling of the Y axis was incorrect when the X axis was a date axis and the last Y value was the highest value. To fix this, increase maximum date value by one month/year. Regression from commit ed2c880a691a0b179bbc92a8ce4ee49eac004035 (tdf#133005 Chart: fix ODF import of date axis position). Change-Id: I0989ae8002e55f4ecfaf530ab845badb4409ecf1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128209 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org> (cherry picked from commit 81abc0d7657f194804681415a786627ab71475e3) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129085 Tested-by: Jenkins Reviewed-by: Tünde Tóth <toth.tunde@nisz.hu>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/qa/extras/chart2import2.cxx48
-rw-r--r--chart2/qa/extras/data/ods/tdf146066.odsbin0 -> 15079 bytes
-rw-r--r--chart2/source/view/axes/VCoordinateSystem.cxx22
3 files changed, 69 insertions, 1 deletions
diff --git a/chart2/qa/extras/chart2import2.cxx b/chart2/qa/extras/chart2import2.cxx
index 0693a1e64184..95ee2428b47d 100644
--- a/chart2/qa/extras/chart2import2.cxx
+++ b/chart2/qa/extras/chart2import2.cxx
@@ -75,6 +75,7 @@ public:
void testTdfCustomShapePos();
void testTdf121281();
void testTdf139658();
+ void testTdf146066();
CPPUNIT_TEST_SUITE(Chart2ImportTest2);
@@ -114,6 +115,7 @@ public:
CPPUNIT_TEST(testTdfCustomShapePos);
CPPUNIT_TEST(testTdf121281);
CPPUNIT_TEST(testTdf139658);
+ CPPUNIT_TEST(testTdf146066);
CPPUNIT_TEST_SUITE_END();
};
@@ -874,6 +876,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
new file mode 100644
index 000000000000..03abe9ae68ca
--- /dev/null
+++ b/chart2/qa/extras/data/ods/tdf146066.ods
Binary files differ
diff --git a/chart2/source/view/axes/VCoordinateSystem.cxx b/chart2/source/view/axes/VCoordinateSystem.cxx
index f546af789ddd..9b330a0b4171 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"
@@ -33,6 +34,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>
@@ -366,8 +368,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 )
{