From 9ed8ec510cfa6b386628b6e2674040079f363d83 Mon Sep 17 00:00:00 2001 From: Laurent Balland-Poirier Date: Wed, 30 Sep 2015 17:46:37 +0200 Subject: 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 Tested-by: Noel Grandin --- .../source/tools/PotentialRegressionCurveCalculator.cxx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/chart2/source/tools/PotentialRegressionCurveCalculator.cxx b/chart2/source/tools/PotentialRegressionCurveCalculator.cxx index c8a4b267057d..1a9c2be98a14 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(); -- cgit