[Libreoffice-commits] core.git: chart2/source
Laurent Balland-Poirier
laurent.balland-poirier at laposte.net
Tue Oct 6 23:42:32 PDT 2015
chart2/source/tools/PotentialRegressionCurveCalculator.cxx | 16 +++++++------
1 file changed, 9 insertions(+), 7 deletions(-)
New commits:
commit 9ed8ec510cfa6b386628b6e2674040079f363d83
Author: Laurent Balland-Poirier <laurent.balland-poirier at laposte.net>
Date: Wed Sep 30 17:46:37 2015 +0200
Improve Power trend line equation
Skip intercept value if it is near 1
Change-Id: Ie52b2ac06c53c2e85b3c465be28081f6dc0ad2cb
Reviewed-on: https://gerrit.libreoffice.org/19038
Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
Tested-by: Noel Grandin <noelgrandin at gmail.com>
diff --git a/chart2/source/tools/PotentialRegressionCurveCalculator.cxx b/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
index c8a4b26..1a9c2be 100644
--- a/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
@@ -54,13 +54,13 @@ void SAL_CALL PotentialRegressionCurveCalculator::recalculateRegression(
m_fSign = 1.0;
size_t nMax = aValues.first.size();
- if( nMax == 0 )
+ if( nMax <= 1 ) // at least 2 points
{
aValues = RegressionCalculationHelper::cleanup(
aXValues, aYValues,
RegressionCalculationHelper::isValidAndXPositiveAndYNegative());
nMax = aValues.first.size();
- if( nMax == 0 )
+ if( nMax <= 1 )
{
::rtl::math::setNan( & m_fSlope );
::rtl::math::setNan( & m_fIntercept );
@@ -148,7 +148,7 @@ OUString PotentialRegressionCurveCalculator::ImplGetRepresentation(
if( m_fIntercept == 0.0 )
{
- aBuf.append( '0');
+ aBuf.append( '0' );
}
else if( m_fSlope == 0.0 )
{
@@ -156,16 +156,18 @@ OUString PotentialRegressionCurveCalculator::ImplGetRepresentation(
}
else
{
- if( ! rtl::math::approxEqual( m_fIntercept, 1.0 ) )
+ if( ! rtl::math::approxEqual( fabs(m_fIntercept), 1.0 ) )
{
aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fIntercept ));
aBuf.append( ' ');
}
- if( m_fSlope != 0.0 )
+ else // skip intercept if its value is 1 (or near 1)
{
- aBuf.append( "x^" );
- aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fSlope ));
+ if ( m_fIntercept < 0.0 )
+ aBuf.append( "- " );
}
+ aBuf.append( "x^" );
+ aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fSlope ));
}
return aBuf.makeStringAndClear();
More information about the Libreoffice-commits
mailing list