1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <MeanValueRegressionCurveCalculator.hxx>
22 #include <osl/diagnose.h>
23 #include <rtl/math.hxx>
25 using namespace ::com::sun::star
;
30 MeanValueRegressionCurveCalculator::MeanValueRegressionCurveCalculator() :
33 ::rtl::math::setNan( & m_fMeanValue
);
36 MeanValueRegressionCurveCalculator::~MeanValueRegressionCurveCalculator()
39 // ____ XRegressionCurveCalculator ____
40 void SAL_CALL
MeanValueRegressionCurveCalculator::recalculateRegression(
41 const uno::Sequence
< double >& /*aXValues*/,
42 const uno::Sequence
< double >& aYValues
)
44 const sal_Int32 nDataLength
= aYValues
.getLength();
45 sal_Int32 nMax
= nDataLength
;
47 const double * pY
= aYValues
.getConstArray();
49 for( sal_Int32 i
= 0; i
< nDataLength
; ++i
)
51 if( ::rtl::math::isNan( pY
[i
] ) ||
52 ::rtl::math::isInf( pY
[i
] ))
58 m_fCorrelationCoeffitient
= 0.0;
62 ::rtl::math::setNan( & m_fMeanValue
);
66 m_fMeanValue
= fSumY
/ static_cast< double >( nMax
);
68 // correlation coefficient: standard deviation
71 double fErrorSum
= 0.0;
72 for( sal_Int32 i
= 0; i
< nDataLength
; ++i
)
74 if( !::rtl::math::isNan( pY
[i
] ) &&
75 !::rtl::math::isInf( pY
[i
] ))
77 double v
= m_fMeanValue
- pY
[i
];
81 OSL_ASSERT( fErrorSum
>= 0.0 );
82 m_fCorrelationCoeffitient
= sqrt( fErrorSum
/ (nMax
- 1 ));
87 double SAL_CALL
MeanValueRegressionCurveCalculator::getCurveValue( double /*x*/ )
92 uno::Sequence
< geometry::RealPoint2D
> SAL_CALL
MeanValueRegressionCurveCalculator::getCurveValues(
93 double min
, double max
, ::sal_Int32 nPointCount
,
94 const uno::Reference
< chart2::XScaling
>& xScalingX
,
95 const uno::Reference
< chart2::XScaling
>& xScalingY
,
96 sal_Bool bMaySkipPointsInCalculation
)
98 if( bMaySkipPointsInCalculation
)
101 uno::Sequence
< geometry::RealPoint2D
> aResult( 2 );
103 aResult
[0].Y
= m_fMeanValue
;
105 aResult
[1].Y
= m_fMeanValue
;
109 return RegressionCurveCalculator::getCurveValues( min
, max
, nPointCount
, xScalingX
, xScalingY
, bMaySkipPointsInCalculation
);
112 OUString
MeanValueRegressionCurveCalculator::ImplGetRepresentation(
113 const uno::Reference
< util::XNumberFormatter
>& xNumFormatter
,
114 sal_Int32 nNumberFormatKey
, sal_Int32
* pFormulaLength
/* = nullptr */ ) const
116 OUString
aBuf(mYName
+ " = ");
117 if ( pFormulaLength
)
119 *pFormulaLength
-= aBuf
.getLength();
120 if ( *pFormulaLength
<= 0 )
123 return ( aBuf
+ getFormattedString( xNumFormatter
, nNumberFormatKey
, m_fMeanValue
, pFormulaLength
) );
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */