1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "MeanValueRegressionCurveCalculator.hxx"
33 #include <rtl/math.hxx>
34 #include <rtl/ustrbuf.hxx>
36 using namespace ::com::sun::star
;
38 using ::rtl::OUString
;
39 using ::rtl::OUStringBuffer
;
44 MeanValueRegressionCurveCalculator::MeanValueRegressionCurveCalculator() :
47 ::rtl::math::setNan( & m_fMeanValue
);
50 MeanValueRegressionCurveCalculator::~MeanValueRegressionCurveCalculator()
53 // ____ XRegressionCurveCalculator ____
54 void SAL_CALL
MeanValueRegressionCurveCalculator::recalculateRegression(
55 const uno::Sequence
< double >& /*aXValues*/,
56 const uno::Sequence
< double >& aYValues
)
57 throw (uno::RuntimeException
)
59 const sal_Int32 nDataLength
= aYValues
.getLength();
60 sal_Int32 nMax
= nDataLength
;
62 const double * pY
= aYValues
.getConstArray();
64 for( sal_Int32 i
= 0; i
< nDataLength
; ++i
)
66 if( ::rtl::math::isNan( pY
[i
] ) ||
67 ::rtl::math::isInf( pY
[i
] ))
73 m_fCorrelationCoeffitient
= 0.0;
77 ::rtl::math::setNan( & m_fMeanValue
);
81 m_fMeanValue
= fSumY
/ static_cast< double >( nMax
);
83 // correlation coefficient: standard deviation
86 double fErrorSum
= 0.0;
87 for( sal_Int32 i
= 0; i
< nDataLength
; ++i
)
89 if( !::rtl::math::isNan( pY
[i
] ) &&
90 !::rtl::math::isInf( pY
[i
] ))
92 double v
= m_fMeanValue
- pY
[i
];
96 OSL_ASSERT( fErrorSum
>= 0.0 );
97 m_fCorrelationCoeffitient
= sqrt( fErrorSum
/ (nMax
- 1 ));
102 double SAL_CALL
MeanValueRegressionCurveCalculator::getCurveValue( double /*x*/ )
103 throw (lang::IllegalArgumentException
,
104 uno::RuntimeException
)
110 uno::Sequence
< geometry::RealPoint2D
> SAL_CALL
MeanValueRegressionCurveCalculator::getCurveValues(
111 double min
, double max
, ::sal_Int32 nPointCount
,
112 const uno::Reference
< chart2::XScaling
>& xScalingX
,
113 const uno::Reference
< chart2::XScaling
>& xScalingY
,
114 ::sal_Bool bMaySkipPointsInCalculation
)
115 throw (lang::IllegalArgumentException
,
116 uno::RuntimeException
)
118 if( bMaySkipPointsInCalculation
)
121 uno::Sequence
< geometry::RealPoint2D
> aResult( 2 );
123 aResult
[0].Y
= m_fMeanValue
;
125 aResult
[1].Y
= m_fMeanValue
;
129 return RegressionCurveCalculator::getCurveValues( min
, max
, nPointCount
, xScalingX
, xScalingY
, bMaySkipPointsInCalculation
);
132 OUString
MeanValueRegressionCurveCalculator::ImplGetRepresentation(
133 const uno::Reference
< util::XNumberFormatter
>& xNumFormatter
,
134 ::sal_Int32 nNumberFormatKey
) const
136 OUStringBuffer
aBuf( C2U( "f(x) = " ));
138 aBuf
.append( getFormattedString( xNumFormatter
, nNumberFormatKey
, m_fMeanValue
));
140 return aBuf
.makeStringAndClear();