23#include <rtl/math.hxx>
25#include <com/sun/star/lang/XServiceName.hpp>
26#include <com/sun/star/util/NumberFormatter.hpp>
33using ::com::sun::star::uno::Reference;
34using ::com::sun::star::uno::Sequence;
40 : m_fCorrelationCoefficient(
std::numeric_limits<double>::quiet_NaN())
42 , mForceIntercept(false)
43 , mInterceptValue(
std::numeric_limits<double>::quiet_NaN())
61 return xServiceName.is() && xServiceName->getServiceName() ==
"com.sun.star.chart2.LinearScaling";
68 return xServiceName.is() && xServiceName->getServiceName() ==
"com.sun.star.chart2.LogarithmicScaling";
74 double aInterceptValue,
76 sal_Int32 nMovingType )
79 throw lang::IllegalArgumentException(
"aPeriod may not be < 0",
static_cast<cppu::OWeakObject*
>(
this), 3);
89 sal_Int32 nNumberFormatKey,
90 double fNumber,
const sal_Int32* pStringLength )
92 if ( pStringLength && *pStringLength <= 0 )
96 if( xNumFormatter.is() )
98 bool bStandard = ::cppu::any2bool( ::comphelper::getNumberFormatProperty( xNumFormatter, nNumberFormatKey,
"StandardFormat" ) );
99 if( pStringLength && bStandard )
101 const sal_Int32 nMinDigit = 6;
102 sal_Int32 nSignificantDigit = ( *pStringLength <= nMinDigit ? nMinDigit : *pStringLength );
103 aResult = ::rtl::math::doubleToUString( fNumber, rtl_math_StringFormat_G1, nSignificantDigit,
'.',
true );
105 sal_Int32 nExtraChar = aResult.getLength() - *pStringLength;
106 if ( nExtraChar > 0 && *pStringLength > nMinDigit )
108 nSignificantDigit = *pStringLength - nExtraChar;
109 if ( nSignificantDigit < nMinDigit )
110 nSignificantDigit = nMinDigit;
111 aResult = ::rtl::math::doubleToUString( fNumber, rtl_math_StringFormat_G1, nSignificantDigit,
'.',
true );
113 fNumber = ::rtl::math::stringToDouble( aResult,
'.',
',' );
115 aResult = xNumFormatter->convertNumberToString( nNumberFormatKey, fNumber );
119 sal_Int32 nStringLength = 4;
121 nStringLength = *pStringLength;
122 aResult = ::rtl::math::doubleToUString( fNumber, rtl_math_StringFormat_G1, nStringLength,
'.',
true );
128 double min,
double max, ::sal_Int32 nPointCount,
133 if( nPointCount < 2 )
134 throw lang::IllegalArgumentException(
"too few points",
static_cast<cppu::OWeakObject*
>(
this), 2);
137 bool bDoXScaling( xScalingX.is());
140 xInverseScaling.set( xScalingX->getInverseScaling());
141 bDoXScaling = bDoXScaling && xInverseScaling.is();
144 auto pResult = aResult.getArray();
147 double fFact = (
max -
min) /
double(nPointCount-1);
151 fMin = xScalingX->doScaling(
min );
152 fFact = (xScalingX->doScaling(
max ) - fMin) /
double(nPointCount-1);
155 for(sal_Int32 nP=0; nP<nPointCount; nP++)
157 double x = fMin + nP * fFact;
159 x = xInverseScaling->doScaling(
x );
179 sal_Int32 nNumberFormatKey, sal_Int32 nFormulaLength )
182 if( !xNumFmtSupplier.is())
186 xNumFormatter->attachNumberFormatsSupplier( xNumFmtSupplier );
188 if ( nFormulaLength > 0 )
194 OUStringBuffer& aStrEquation, sal_Int32& nLineLength, OUStringBuffer
const & aAddString,
const sal_Int32* pMaxWidth)
196 if ( pMaxWidth && ( nLineLength + aAddString.getLength() > *pMaxWidth ) )
198 aStrEquation.append(
"\n " );
201 aStrEquation.append( aAddString );
202 nLineLength += aAddString.getLength();
207 if ( aXName.isEmpty() )
211 if ( aYName.isEmpty() )
212 mYName = OUString (
"f(x)");
virtual void SAL_CALL setXYNames(const OUString &aXName, const OUString &aYName) override
static bool isLogarithmicScaling(const css::uno::Reference< css::chart2::XScaling > &xScaling)
virtual OUString ImplGetRepresentation(const css::uno::Reference< css::util::XNumberFormatter > &xNumFormatter, sal_Int32 nNumberFormatKey, sal_Int32 *pFormulaLength=nullptr) const =0
RegressionCurveCalculator()
static void addStringToEquation(OUStringBuffer &aStrEquation, sal_Int32 &nLineLength, OUStringBuffer const &aAddString, const sal_Int32 *pMaxLength)
virtual ~RegressionCurveCalculator() override
virtual void SAL_CALL setRegressionProperties(sal_Int32 aDegree, sal_Bool aForceIntercept, double aInterceptValue, sal_Int32 aPeriod, sal_Int32 nMovingType) override
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
virtual double SAL_CALL getCurveValue(double x) override=0
virtual OUString SAL_CALL getRepresentation() override
virtual double SAL_CALL getCorrelationCoefficient() override
virtual OUString SAL_CALL getFormattedRepresentation(const css::uno::Reference< css::util::XNumberFormatsSupplier > &xNumFmtSupplier, sal_Int32 nNumberFormatKey, sal_Int32 nFormulaLength) override
double m_fCorrelationCoefficient
Reference< XComponentContext > getProcessComponentContext()
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)