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 <MovingAverageRegressionCurveCalculator.hxx>
21 #include <RegressionCalculationHelper.hxx>
23 #include <strings.hrc>
25 #include <rtl/math.hxx>
27 using namespace ::com::sun::star
;
32 MovingAverageRegressionCurveCalculator::MovingAverageRegressionCurveCalculator()
35 MovingAverageRegressionCurveCalculator::~MovingAverageRegressionCurveCalculator()
38 // ____ XRegressionCurveCalculator ____
39 void SAL_CALL
MovingAverageRegressionCurveCalculator::recalculateRegression(
40 const uno::Sequence
< double >& aXValues
,
41 const uno::Sequence
< double >& aYValues
)
43 ::rtl::math::setNan( & m_fCorrelationCoefficient
);
45 RegressionCalculationHelper::tDoubleVectorPair
aValues(
46 RegressionCalculationHelper::cleanup(
48 RegressionCalculationHelper::isValid()));
50 const size_t aSize
= aValues
.first
.size();
55 for( size_t i
= mPeriod
- 1; i
< aSize
; ++i
)
60 for (sal_Int32 j
= 0; j
< mPeriod
; j
++)
62 yAvg
+= aValues
.second
[i
- j
];
66 double x
= aValues
.first
[i
];
67 aYList
.push_back(yAvg
);
72 double SAL_CALL
MovingAverageRegressionCurveCalculator::getCurveValue( double /*x*/ )
75 rtl::math::setNan(&fResult
);
79 uno::Sequence
< geometry::RealPoint2D
> SAL_CALL
MovingAverageRegressionCurveCalculator::getCurveValues(
80 double /*min*/, double /*max*/, sal_Int32
/*nPointCount*/,
81 const uno::Reference
< chart2::XScaling
>& /*xScalingX*/,
82 const uno::Reference
< chart2::XScaling
>& /*xScalingY*/,
83 sal_Bool
/*bMaySkipPointsInCalculation*/ )
85 uno::Sequence
< geometry::RealPoint2D
> aResult( aYList
.size() );
87 for( size_t i
= 0; i
< aYList
.size(); ++i
)
89 aResult
[i
].X
= aXList
[i
];
90 aResult
[i
].Y
= aYList
[i
];
95 OUString
MovingAverageRegressionCurveCalculator::ImplGetRepresentation(
96 const uno::Reference
< util::XNumberFormatter
>& /*xNumFormatter*/,
97 sal_Int32
/*nNumberFormatKey*/, sal_Int32
* /*pFormulaLength = nullptr */ ) const
99 return SchResId( STR_OBJECT_MOVING_AVERAGE_WITH_PARAMETERS
);
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */