[Libreoffice-commits] core.git: chart2/source

Laurent Balland-Poirier laurent.balland-poirier at laposte.net
Mon Jun 22 02:58:12 PDT 2015


 chart2/source/inc/PotentialRegressionCurveCalculator.hxx   |    3 +
 chart2/source/inc/RegressionCalculationHelper.hxx          |   13 ++++++
 chart2/source/tools/PotentialRegressionCurveCalculator.cxx |   25 ++++++++-----
 3 files changed, 32 insertions(+), 9 deletions(-)

New commits:
commit 35fd66e8648c6d82396486a9469dcb061c832b91
Author: Laurent Balland-Poirier <laurent.balland-poirier at laposte.net>
Date:   Thu Apr 16 22:32:07 2015 +0200

    tdf#70673 Power trendline: enable negative Y values
    
    With a negative intercept, Y values can be negative
    
    Change-Id: I9c23cc89b74498f7e7c7bcee00057627768f48aa
    Reviewed-on: https://gerrit.libreoffice.org/15357
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Philippe Jung <phil.jung at free.fr>

diff --git a/chart2/source/inc/PotentialRegressionCurveCalculator.hxx b/chart2/source/inc/PotentialRegressionCurveCalculator.hxx
index dba739e..d9ad473 100644
--- a/chart2/source/inc/PotentialRegressionCurveCalculator.hxx
+++ b/chart2/source/inc/PotentialRegressionCurveCalculator.hxx
@@ -57,9 +57,10 @@ private:
         throw (css::lang::IllegalArgumentException,
                css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
 
-    // formula is: f(x) = x ^ m_fSlope * m_fIntercept
+    // formula is: f(x) = x ^ m_fSlope * m_fSign * m_fIntercept
     double m_fSlope;
     double m_fIntercept;
+    double m_fSign;
 };
 
 } //  namespace chart
diff --git a/chart2/source/inc/RegressionCalculationHelper.hxx b/chart2/source/inc/RegressionCalculationHelper.hxx
index 2e0e3a4..7f0a693 100644
--- a/chart2/source/inc/RegressionCalculationHelper.hxx
+++ b/chart2/source/inc/RegressionCalculationHelper.hxx
@@ -127,6 +127,19 @@ public:
     }
 };
 
+class isValidAndXPositiveAndYNegative : public ::std::binary_function< double, double, bool >
+{
+public:
+    inline bool operator()( double x, double y )
+    { return ! ( ::rtl::math::isNan( x ) ||
+                 ::rtl::math::isNan( y ) ||
+                 ::rtl::math::isInf( x ) ||
+                 ::rtl::math::isInf( y ) ||
+                 x <= 0.0 ||
+                 y >= 0.0 );
+    }
+};
+
 } //  namespace RegressionCalculationHelper
 } //  namespace chart
 
diff --git a/chart2/source/tools/PotentialRegressionCurveCalculator.cxx b/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
index 7495c91..0e4f4cd 100644
--- a/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/PotentialRegressionCurveCalculator.cxx
@@ -50,14 +50,23 @@ void SAL_CALL PotentialRegressionCurveCalculator::recalculateRegression(
         RegressionCalculationHelper::cleanup(
             aXValues, aYValues,
             RegressionCalculationHelper::isValidAndBothPositive()));
+    m_fSign = 1.0;
 
-    const size_t nMax = aValues.first.size();
+    size_t nMax = aValues.first.size();
     if( nMax == 0 )
     {
-        ::rtl::math::setNan( & m_fSlope );
-        ::rtl::math::setNan( & m_fIntercept );
-        ::rtl::math::setNan( & m_fCorrelationCoeffitient );
-        return;
+        aValues = RegressionCalculationHelper::cleanup(
+                    aXValues, aYValues,
+                    RegressionCalculationHelper::isValidAndXPositiveAndYNegative());
+         nMax = aValues.first.size();
+         if( nMax == 0 )
+         {
+            ::rtl::math::setNan( & m_fSlope );
+            ::rtl::math::setNan( & m_fIntercept );
+            ::rtl::math::setNan( & m_fCorrelationCoeffitient );
+            return;
+         }
+         m_fSign = -1.0;
     }
 
     double fAverageX = 0.0, fAverageY = 0.0;
@@ -65,7 +74,7 @@ void SAL_CALL PotentialRegressionCurveCalculator::recalculateRegression(
     for( i = 0; i < nMax; ++i )
     {
         fAverageX += log( aValues.first[i] );
-        fAverageY += log( aValues.second[i] );
+        fAverageY += log( m_fSign * aValues.second[i] );
     }
 
     const double fN = static_cast< double >( nMax );
@@ -76,7 +85,7 @@ void SAL_CALL PotentialRegressionCurveCalculator::recalculateRegression(
     for( i = 0; i < nMax; ++i )
     {
         double fDeltaX = log( aValues.first[i] ) - fAverageX;
-        double fDeltaY = log( aValues.second[i] ) - fAverageY;
+        double fDeltaY = log( m_fSign * aValues.second[i] ) - fAverageY;
 
         fQx  += fDeltaX * fDeltaX;
         fQy  += fDeltaY * fDeltaY;
@@ -87,7 +96,7 @@ void SAL_CALL PotentialRegressionCurveCalculator::recalculateRegression(
     m_fIntercept = fAverageY - m_fSlope * fAverageX;
     m_fCorrelationCoeffitient = fQxy / sqrt( fQx * fQy );
 
-    m_fIntercept = exp( m_fIntercept );
+    m_fIntercept = m_fSign * exp( m_fIntercept );
 }
 
 double SAL_CALL PotentialRegressionCurveCalculator::getCurveValue( double x )


More information about the Libreoffice-commits mailing list