summaryrefslogtreecommitdiff
path: root/chart2/source/tools
diff options
context:
space:
mode:
authorLaurent Balland-Poirier <laurent.balland-poirier@laposte.net>2015-09-30 17:46:37 +0200
committerNoel Grandin <noelgrandin@gmail.com>2015-10-07 06:42:06 +0000
commit9ed8ec510cfa6b386628b6e2674040079f363d83 (patch)
treef893c8e1765b9052fb1b80a4da50964315a977a5 /chart2/source/tools
parentce9d48e5f58ec26e817202414a08225db1c11206 (diff)
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@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'chart2/source/tools')
-rw-r--r--chart2/source/tools/PotentialRegressionCurveCalculator.cxx16
1 files 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();