summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2013-06-30 23:14:06 +0200
committerTomaž Vajngerl <quikee@gmail.com>2013-07-03 21:46:46 +0200
commit28293399e263a64299cfadafdfaf2817bc505713 (patch)
treea37a929020e5ff00150b634fc03328207f04c058 /chart2
parent7302c4f649827f70b116be266be76ae6f864b11f (diff)
Linear curve is polyinomial curve with degree = 1
Change-Id: I3785afc7b18ab3f742e4ecc0e299baafc2bd6614
Diffstat (limited to 'chart2')
-rw-r--r--chart2/source/inc/LinearRegressionCurveCalculator.hxx41
-rw-r--r--chart2/source/inc/PolynomialRegressionCurveCalculator.hxx10
-rw-r--r--chart2/source/tools/LinearRegressionCurveCalculator.cxx114
3 files changed, 32 insertions, 133 deletions
diff --git a/chart2/source/inc/LinearRegressionCurveCalculator.hxx b/chart2/source/inc/LinearRegressionCurveCalculator.hxx
index c2cc8807671b..79c6d5da0dce 100644
--- a/chart2/source/inc/LinearRegressionCurveCalculator.hxx
+++ b/chart2/source/inc/LinearRegressionCurveCalculator.hxx
@@ -20,44 +20,33 @@
#define CHART2_LINEARREGRESSIONCURVECALCULATOR_HXX
#include "RegressionCurveCalculator.hxx"
+#include "PolynomialRegressionCurveCalculator.hxx"
namespace chart
{
-class LinearRegressionCurveCalculator :
- public RegressionCurveCalculator
+class LinearRegressionCurveCalculator : public PolynomialRegressionCurveCalculator
{
public:
LinearRegressionCurveCalculator();
virtual ~LinearRegressionCurveCalculator();
-protected:
- virtual OUString ImplGetRepresentation(
- const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& xNumFormatter,
- ::sal_Int32 nNumberFormatKey ) const;
-
private:
- // ____ XRegressionCurveCalculator ____
- virtual void SAL_CALL recalculateRegression(
- const ::com::sun::star::uno::Sequence< double >& aXValues,
- const ::com::sun::star::uno::Sequence< double >& aYValues )
- throw (::com::sun::star::uno::RuntimeException);
- virtual double SAL_CALL getCurveValue( double x )
- throw (::com::sun::star::lang::IllegalArgumentException,
- ::com::sun::star::uno::RuntimeException);
- virtual ::com::sun::star::uno::Sequence< ::com::sun::star::geometry::RealPoint2D > SAL_CALL getCurveValues(
+ virtual void SAL_CALL setRegressionProperties(
+ sal_Int32 aDegree,
+ sal_Bool aForceIntercept,
+ double aInterceptValue,
+ sal_Int32 aPeriod);
+
+ virtual com::sun::star::uno::Sequence< com::sun::star::geometry::RealPoint2D > SAL_CALL getCurveValues(
double min,
double max,
- ::sal_Int32 nPointCount,
- const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XScaling >& xScalingX,
- const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XScaling >& xScalingY,
- ::sal_Bool bMaySkipPointsInCalculation )
- throw (::com::sun::star::lang::IllegalArgumentException,
- ::com::sun::star::uno::RuntimeException);
-
- // formula is: f(x) = m_fSlope * x + m_fIntercept
- double m_fSlope;
- double m_fIntercept;
+ sal_Int32 nPointCount,
+ const com::sun::star::uno::Reference< com::sun::star::chart2::XScaling >& xScalingX,
+ const com::sun::star::uno::Reference< com::sun::star::chart2::XScaling >& xScalingY,
+ sal_Bool bMaySkipPointsInCalculation )
+ throw (com::sun::star::lang::IllegalArgumentException,
+ com::sun::star::uno::RuntimeException);
};
} // namespace chart
diff --git a/chart2/source/inc/PolynomialRegressionCurveCalculator.hxx b/chart2/source/inc/PolynomialRegressionCurveCalculator.hxx
index 803abb69f91b..e3b43a26095f 100644
--- a/chart2/source/inc/PolynomialRegressionCurveCalculator.hxx
+++ b/chart2/source/inc/PolynomialRegressionCurveCalculator.hxx
@@ -36,6 +36,10 @@ protected:
const com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatter >& xNumFormatter,
sal_Int32 nNumberFormatKey ) const;
+ virtual double SAL_CALL getCurveValue( double x )
+ throw (com::sun::star::lang::IllegalArgumentException,
+ com::sun::star::uno::RuntimeException);
+
private:
// ____ XRegressionCurveCalculator ____
virtual void SAL_CALL recalculateRegression(
@@ -43,11 +47,7 @@ private:
const com::sun::star::uno::Sequence< double >& aYValues )
throw (com::sun::star::uno::RuntimeException);
- virtual double SAL_CALL getCurveValue( double x )
- throw (com::sun::star::lang::IllegalArgumentException,
- com::sun::star::uno::RuntimeException);
-
- virtual ::com::sun::star::uno::Sequence< com::sun::star::geometry::RealPoint2D > SAL_CALL getCurveValues(
+ virtual com::sun::star::uno::Sequence< com::sun::star::geometry::RealPoint2D > SAL_CALL getCurveValues(
double min,
double max,
sal_Int32 nPointCount,
diff --git a/chart2/source/tools/LinearRegressionCurveCalculator.cxx b/chart2/source/tools/LinearRegressionCurveCalculator.cxx
index 5b388ee4139e..07c19a4124a6 100644
--- a/chart2/source/tools/LinearRegressionCurveCalculator.cxx
+++ b/chart2/source/tools/LinearRegressionCurveCalculator.cxx
@@ -31,69 +31,23 @@ namespace chart
{
LinearRegressionCurveCalculator::LinearRegressionCurveCalculator() :
- m_fSlope( 0.0 ),
- m_fIntercept( 0.0 )
-{
- ::rtl::math::setNan( & m_fSlope );
- ::rtl::math::setNan( & m_fIntercept );
-}
+ PolynomialRegressionCurveCalculator()
+{}
LinearRegressionCurveCalculator::~LinearRegressionCurveCalculator()
{}
-// ____ XRegressionCurveCalculator ____
-void SAL_CALL LinearRegressionCurveCalculator::recalculateRegression(
- const uno::Sequence< double >& aXValues,
- const uno::Sequence< double >& aYValues )
- throw (uno::RuntimeException)
+void LinearRegressionCurveCalculator::setRegressionProperties(
+ sal_Int32 /*aDegree*/,
+ sal_Bool aForceIntercept,
+ double aInterceptValue,
+ sal_Int32 aPeriod)
{
- RegressionCalculationHelper::tDoubleVectorPair aValues(
- RegressionCalculationHelper::cleanup(
- aXValues, aYValues,
- RegressionCalculationHelper::isValid()));
-
- const 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;
- }
-
- const double fN = static_cast< double >( nMax );
- double fSumX = 0.0, fSumY = 0.0, fSumXSq = 0.0, fSumYSq = 0.0, fSumXY = 0.0;
- for( size_t i = 0; i < nMax; ++i )
- {
- fSumX += aValues.first[i];
- fSumY += aValues.second[i];
- fSumXSq += aValues.first[i] * aValues.first[i];
- fSumYSq += aValues.second[i] * aValues.second[i];
- fSumXY += aValues.first[i] * aValues.second[i];
- }
-
- m_fSlope = (fN * fSumXY - fSumX * fSumY) / ( fN * fSumXSq - fSumX * fSumX );
- m_fIntercept = (fSumY - m_fSlope * fSumX) / fN;
-
- m_fCorrelationCoeffitient = ( fN * fSumXY - fSumX * fSumY ) /
- sqrt( ( fN * fSumXSq - fSumX * fSumX ) *
- ( fN * fSumYSq - fSumY * fSumY ) );
-}
-
-double SAL_CALL LinearRegressionCurveCalculator::getCurveValue( double x )
- throw (lang::IllegalArgumentException,
- uno::RuntimeException)
-{
- double fResult;
- ::rtl::math::setNan( & fResult );
-
- if( ! ( ::rtl::math::isNan( m_fSlope ) ||
- ::rtl::math::isNan( m_fIntercept )))
- {
- fResult = m_fSlope * x + m_fIntercept;
- }
-
- return fResult;
+ PolynomialRegressionCurveCalculator::setRegressionProperties(
+ 1,
+ aForceIntercept,
+ aInterceptValue,
+ aPeriod);
}
uno::Sequence< geometry::RealPoint2D > SAL_CALL LinearRegressionCurveCalculator::getCurveValues(
@@ -120,50 +74,6 @@ uno::Sequence< geometry::RealPoint2D > SAL_CALL LinearRegressionCurveCalculator:
return RegressionCurveCalculator::getCurveValues( min, max, nPointCount, xScalingX, xScalingY, bMaySkipPointsInCalculation );
}
-OUString LinearRegressionCurveCalculator::ImplGetRepresentation(
- const uno::Reference< util::XNumberFormatter >& xNumFormatter,
- ::sal_Int32 nNumberFormatKey ) const
-{
- OUStringBuffer aBuf( "f(x) = ");
-
- bool bHaveSlope = false;
-
- if( m_fSlope != 0.0 )
- {
- if( ::rtl::math::approxEqual( fabs( m_fSlope ), 1.0 ))
- {
- if( m_fSlope < 0 )
- aBuf.append( UC_MINUS_SIGN );
- }
- else
- aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fSlope ));
- aBuf.append( sal_Unicode( 'x' ));
- bHaveSlope = true;
- }
-
- if( bHaveSlope )
- {
- if( m_fIntercept < 0.0 )
- {
- aBuf.append( UC_SPACE );
- aBuf.append( UC_MINUS_SIGN );
- aBuf.append( UC_SPACE );
- aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, fabs( m_fIntercept )));
- }
- else if( m_fIntercept > 0.0 )
- {
- aBuf.appendAscii( RTL_CONSTASCII_STRINGPARAM( " + " ));
- aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fIntercept ));
- }
- }
- else
- {
- aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, m_fIntercept ));
- }
-
- return aBuf.makeStringAndClear();
-}
-
} // namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */