summaryrefslogtreecommitdiff
path: root/chart2/source
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-01-31 16:07:06 +0100
commit81abc0d7657f194804681415a786627ab71475e3 (patch)
treef5ba9a9c882e871e7b406d709f2731edca70fa3e /chart2/source
parent36d75660ee5f3d2f9b433935e2c5d689767804fc (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>
Diffstat (limited to 'chart2/source')
-rw-r--r--chart2/source/view/axes/VCoordinateSystem.cxx22
1 files changed, 21 insertions, 1 deletions
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 )
{