29#include <rtl/math.hxx>
30#include <rtl/ustrbuf.hxx>
38 : m_fLogSlope(
std::numeric_limits<double>::quiet_NaN())
39 , m_fLogIntercept(
std::numeric_limits<double>::quiet_NaN())
58 size_t nMax = aValues.first.size();
64 nMax = aValues.first.size();
67 m_fLogSlope = std::numeric_limits<double>::quiet_NaN();
75 double fAverageX = 0.0, fAverageY = 0.0;
77 std::vector<double> yVector;
78 yVector.resize(nMax, 0.0);
81 for(
i = 0;
i < nMax; ++
i )
86 yValue -= fLogIntercept;
90 fAverageX += aValues.first[
i];
96 const double fN =
static_cast< double >( nMax );
100 double fQx = 0.0, fQy = 0.0, fQxy = 0.0;
101 for(
i = 0;
i < nMax; ++
i )
103 double fDeltaX = aValues.first[
i] - fAverageX;
104 double fDeltaY = yVector[
i] - fAverageY;
106 fQx += fDeltaX * fDeltaX;
107 fQy += fDeltaY * fDeltaY;
108 fQxy += fDeltaX * fDeltaY;
124 return std::numeric_limits<double>::quiet_NaN();
128 double min,
double max, ::sal_Int32 nPointCount,
131 sal_Bool bMaySkipPointsInCalculation )
133 if( bMaySkipPointsInCalculation &&
149 sal_Int32 nNumberFormatKey, sal_Int32* pFormulaMaxWidth )
const
152 bool bHasSlope = !rtl::math::approxEqual( exp(
m_fLogSlope), 1.0 );
153 bool bHasLogSlope = !rtl::math::approxEqual( fabs(
m_fLogSlope), 1.0 );
154 bool bHasIntercept = !rtl::math::approxEqual( fIntercept, 1.0 ) && fIntercept != 0.0;
157 sal_Int32 nLineLength =
aBuf.getLength();
158 sal_Int32 nValueLength=0;
159 if ( pFormulaMaxWidth && *pFormulaMaxWidth > 0 )
161 sal_Int32 nCharMin = nLineLength + 10 +
mXName.getLength();
166 if ( ( bHasIntercept || fIntercept == 0.0 || ( !bHasSlope &&
m_fLogIntercept != 0.0 ) ) &&
168 nValueLength = ( *pFormulaMaxWidth - nCharMin ) / 2;
170 nValueLength = *pFormulaMaxWidth - nCharMin;
171 if ( nValueLength <= 0 )
175 OUStringBuffer aTmpBuf(
"");
177 sal_Int32* pValueLength = nValueLength ? &nValueLength :
nullptr;
179 aTmpBuf.append( OUStringChar(
aMinusSign) +
" " );
182 OUString aValueString =
getFormattedString( xNumFormatter, nNumberFormatKey, fIntercept, pValueLength );
183 if ( aValueString !=
"1" )
185 aTmpBuf.append( aValueString +
" " );
190 aTmpBuf.append(
"exp( " );
191 if ( !bHasIntercept )
193 if ( fIntercept == 0.0 ||
197 if ( aValueString !=
"0" )
199 aTmpBuf.append( aValueString ).append( (
m_fLogSlope < 0.0) ? std::u16string_view(
u" ") : std::u16string_view(
u" + ") );
204 aTmpBuf.append( OUStringChar(
aMinusSign) +
" " );
208 if ( aValueString !=
"1" )
210 aTmpBuf.append( aValueString +
" " );
213 aTmpBuf.append(
mXName +
" )");
216 return aBuf.makeStringAndClear();
const sal_Unicode aMinusSign
virtual ~ExponentialRegressionCurveCalculator() override
virtual double SAL_CALL getCurveValue(double x) override
virtual OUString ImplGetRepresentation(const css::uno::Reference< css::util::XNumberFormatter > &xNumFormatter, sal_Int32 nNumberFormatKey, sal_Int32 *pFormulaLength=nullptr) const override
virtual css::uno::Sequence< css::geometry::RealPoint2D > SAL_CALL getCurveValues(double min, double max, sal_Int32 nPointCount, const css::uno::Reference< css::chart2::XScaling > &xScalingX, const css::uno::Reference< css::chart2::XScaling > &xScalingY, sal_Bool bMaySkipPointsInCalculation) override
virtual void SAL_CALL recalculateRegression(const css::uno::Sequence< double > &aXValues, const css::uno::Sequence< double > &aYValues) override
ExponentialRegressionCurveCalculator()
static bool isLogarithmicScaling(const css::uno::Reference< css::chart2::XScaling > &xScaling)
static void addStringToEquation(OUStringBuffer &aStrEquation, sal_Int32 &nLineLength, OUStringBuffer const &aAddString, const sal_Int32 *pMaxLength)
static OUString getFormattedString(const css::uno::Reference< css::util::XNumberFormatter > &xNumFormatter, sal_Int32 nNumberFormatKey, double fNumber, const sal_Int32 *pStringLength)
static bool isLinearScaling(const css::uno::Reference< css::chart2::XScaling > &xScaling)
virtual css::uno::Sequence< css::geometry::RealPoint2D > SAL_CALL getCurveValues(double min, double max, sal_Int32 nPointCount, const css::uno::Reference< css::chart2::XScaling > &xScalingX, const css::uno::Reference< css::chart2::XScaling > &xScalingY, sal_Bool bMaySkipPointsInCalculation) override
double m_fCorrelationCoefficient
std::pair< std::vector< double >, std::vector< double > > tDoubleVectorPair
tDoubleVectorPair cleanup(const css::uno::Sequence< double > &rXValues, const css::uno::Sequence< double > &rYValues, Pred aPred)
takes the given x- and y-values and copies them into the resulting pair, which contains x-values in t...
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)