43#include <com/sun/star/chart2/AxisType.hpp>
44#include <com/sun/star/chart2/XRegressionCurveCalculator.hpp>
45#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
46#include <com/sun/star/chart2/XDataSeries.hpp>
47#include <com/sun/star/chart2/data/XDataSource.hpp>
55using ::com::sun::star::uno::Reference;
56using ::com::sun::star::uno::Sequence;
57using ::com::sun::star::lang::XServiceName;
58using ::com::sun::star::beans::XPropertySet;
59using ::com::sun::star::uno::Exception;
65 OUString aServiceName;
68 case SvxChartRegress::Linear:
69 aServiceName =
"com.sun.star.chart2.LinearRegressionCurve";
71 case SvxChartRegress::Log:
72 aServiceName =
"com.sun.star.chart2.LogarithmicRegressionCurve";
74 case SvxChartRegress::Exp:
75 aServiceName =
"com.sun.star.chart2.ExponentialRegressionCurve";
77 case SvxChartRegress::Power:
78 aServiceName =
"com.sun.star.chart2.PotentialRegressionCurve";
80 case SvxChartRegress::Polynomial:
81 aServiceName =
"com.sun.star.chart2.PolynomialRegressionCurve";
83 case SvxChartRegress::MovingAverage:
84 aServiceName =
"com.sun.star.chart2.MovingAverageRegressionCurve";
87 OSL_FAIL(
"unknown regression curve type - use linear instead");
88 aServiceName =
"com.sun.star.chart2.LinearRegressionCurve";
105 std::u16string_view aServiceName )
110 if( aServiceName ==
u"com.sun.star.chart2.LinearRegressionCurve" )
114 else if( aServiceName ==
u"com.sun.star.chart2.LogarithmicRegressionCurve" )
118 else if( aServiceName ==
u"com.sun.star.chart2.ExponentialRegressionCurve" )
122 else if( aServiceName ==
u"com.sun.star.chart2.PotentialRegressionCurve" )
126 else if( aServiceName ==
u"com.sun.star.chart2.PolynomialRegressionCurve" )
130 else if( aServiceName ==
u"com.sun.star.chart2.MovingAverageRegressionCurve" )
139 std::u16string_view aServiceName )
144 if( aServiceName ==
u"com.sun.star.chart2.MeanValueRegressionCurve" )
148 if( aServiceName ==
u"com.sun.star.chart2.LinearRegressionCurve" )
152 else if( aServiceName ==
u"com.sun.star.chart2.LogarithmicRegressionCurve" )
156 else if( aServiceName ==
u"com.sun.star.chart2.ExponentialRegressionCurve" )
160 else if( aServiceName ==
u"com.sun.star.chart2.PotentialRegressionCurve" )
164 else if( aServiceName ==
u"com.sun.star.chart2.PolynomialRegressionCurve" )
168 else if( aServiceName ==
u"com.sun.star.chart2.MovingAverageRegressionCurve" )
179 bool bUseXValuesIfAvailable )
181 if( ! (xOutCurveCalculator.is() &&
186 bool bXValuesFound =
false, bYValuesFound =
false;
191 ! (bXValuesFound && bYValuesFound) && i<aDataSeqs.getLength();
199 if( xProp->getPropertyValue(
"Role" ) >>= aRole )
201 if( bUseXValuesIfAvailable && !bXValuesFound && aRole ==
"values-x" )
204 bXValuesFound =
true;
206 else if( !bYValuesFound && aRole ==
"values-y" )
209 bYValuesFound =
true;
213 catch(
const Exception & )
219 if( ! bXValuesFound &&
224 aXValues.realloc( aYValues.getLength());
225 auto pXValues = aXValues.getArray();
226 for( i=0;
i<aXValues.getLength(); ++
i )
228 bXValuesFound =
true;
231 if( bXValuesFound && bYValuesFound &&
232 aXValues.hasElements() &&
233 aYValues.hasElements() )
234 xOutCurveCalculator->recalculateRegression( aXValues, aYValues );
238 const Reference< XRegressionCurveCalculator > & xOutCurveCalculator,
247 (nAxisType == AxisType::REALNUMBER) );
251 const uno::Reference< XRegressionCurveContainer > & xRegCnt )
258 const uno::Sequence< uno::Reference< XRegressionCurve > > aCurves(
259 xRegCnt->getRegressionCurves());
260 for( uno::Reference< XRegressionCurve >
const & curve : aCurves )
266 catch(
const Exception & )
288 catch(
const Exception & )
297 const uno::Reference< chart2::XRegressionCurve > & xRegCurve )
299 uno::Reference< XServiceName > xServName( xRegCurve, uno::UNO_QUERY );
300 return xServName.is() &&
301 xServName->getServiceName() ==
302 "com.sun.star.chart2.MeanValueRegressionCurve";
308 return xRegCurve.is() &&
309 xRegCurve->getServiceName() ==
310 "com.sun.star.chart2.MeanValueRegressionCurve";
315 const uno::Reference< chart2::XRegressionCurveContainer > & xRegCnt )
321 const uno::Sequence< uno::Reference< XRegressionCurve > > aCurves(
322 xRegCnt->getRegressionCurves());
323 for( uno::Reference< XRegressionCurve >
const & curve : aCurves )
326 return dynamic_cast<RegressionCurveModel*
>(curve.get());
329 catch(
const Exception & )
352 catch(
const Exception & )
362 uno::Reference< XRegressionCurveContainer >
const & xRegCnt,
363 const uno::Reference< XPropertySet > & xSeriesProp )
371 xRegCnt->addRegressionCurve( xCurve );
373 if( xSeriesProp.is())
375 uno::Reference< XPropertySet > xProp( xCurve, uno::UNO_QUERY );
378 xProp->setPropertyValue(
"LineColor",
379 xSeriesProp->getPropertyValue(
"Color"));
386 const uno::Reference< XPropertySet > & xSeriesProp )
394 xRegCnt->addRegressionCurve( xCurve );
396 if( xSeriesProp.is())
398 xCurve->setPropertyValue(
"LineColor",
399 xSeriesProp->getPropertyValue(
"Color"));
404 Reference< XRegressionCurveContainer >
const & xRegCnt )
411 const Sequence< Reference< XRegressionCurve > > aCurves(
412 xRegCnt->getRegressionCurves());
413 for( Reference< XRegressionCurve >
const & curve : aCurves )
417 xRegCnt->removeRegressionCurve( curve );
426 catch(
const Exception & )
444 xRegCnt->removeRegressionCurve( curve );
453 catch(
const Exception & )
461 uno::Reference< XRegressionCurveContainer >
const & xRegressionCurveContainer,
462 const uno::Reference< beans::XPropertySet >& xPropertySource,
463 const uno::Reference< beans::XPropertySet >& xEquationProperties )
467 if( !xRegressionCurveContainer.is() )
470 if( eType == SvxChartRegress::NONE )
472 OSL_FAIL(
"don't create a regression curve of type none");
476 OUString aServiceName( lcl_getServiceNameForType( eType ));
477 if( !aServiceName.isEmpty())
482 if( xEquationProperties.is())
483 xCurve->setEquationProperties( xEquationProperties );
485 if( xPropertySource.is())
489 uno::Reference< XPropertySet > xSeriesProp( xRegressionCurveContainer, uno::UNO_QUERY );
490 if( xSeriesProp.is())
492 xCurve->setPropertyValue(
"LineColor",
493 xSeriesProp->getPropertyValue(
"Color"));
497 xRegressionCurveContainer->addRegressionCurve( xCurve );
505 const uno::Reference< beans::XPropertySet >& xPropertySource,
506 const uno::Reference< beans::XPropertySet >& xEquationProperties )
510 if( !xRegressionCurveContainer.is() )
513 if( eType == SvxChartRegress::NONE )
515 OSL_FAIL(
"don't create a regression curve of type none");
519 OUString aServiceName( lcl_getServiceNameForType( eType ));
520 if( !aServiceName.isEmpty())
525 if( xEquationProperties.is())
526 xCurve->setEquationProperties( xEquationProperties );
528 if( xPropertySource.is())
532 xCurve->setPropertyValue(
"LineColor",
533 xRegressionCurveContainer->getPropertyValue(
"Color"));
536 xRegressionCurveContainer->addRegressionCurve( xCurve );
550 bool bRemovedSomething =
false;
553 std::vector< rtl::Reference< RegressionCurveModel > > aCurvesToDelete;
558 aCurvesToDelete.push_back( curve );
562 for (
auto const& curveToDelete : aCurvesToDelete)
564 xRegCnt->removeRegressionCurve(curveToDelete);
565 bRemovedSomething =
true;
568 catch(
const uno::Exception & )
572 return bRemovedSomething;
587 uno::Reference< beans::XPropertySet > xEqProp( curve->getEquationProperties() ) ;
590 xEqProp->setPropertyValue(
"ShowEquation",
uno::Any(
false ));
591 xEqProp->setPropertyValue(
"XName",
uno::Any( OUString(
"x") ));
592 xEqProp->setPropertyValue(
"YName",
uno::Any( OUString(
"f(x) ") ));
593 xEqProp->setPropertyValue(
"ShowCorrelationCoefficient",
uno::Any(
false ));
598 catch(
const uno::Exception & )
606 uno::Reference< XRegressionCurveContainer >
const & xRegressionCurveContainer,
607 uno::Reference< XRegressionCurve >
const & xRegressionCurve )
609 xRegressionCurveContainer->removeRegressionCurve( xRegressionCurve );
612 xRegressionCurveContainer,
613 uno::Reference< beans::XPropertySet >( xRegressionCurve, uno::UNO_QUERY ),
614 xRegressionCurve->getEquationProperties());
618 const Reference< XRegressionCurveContainer > & xRegCnt )
625 const uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves(
626 xRegCnt->getRegressionCurves());
627 for( uno::Reference< chart2::XRegressionCurve >
const & curve : aCurves )
631 return dynamic_cast<RegressionCurveModel*
>(curve.get());
635 catch(
const Exception & )
659 catch(
const Exception & )
671 if( !xCurveContainer.is())
676 const std::vector< rtl::Reference< RegressionCurveModel > > aCurves(xCurveContainer->getRegressionCurves2());
683 catch(
const Exception & )
692 const Reference< XRegressionCurve > & xCurve )
698 Reference< lang::XServiceName > xServName( xCurve, uno::UNO_QUERY );
701 OUString aServiceName( xServName->getServiceName() );
703 if( aServiceName ==
"com.sun.star.chart2.LinearRegressionCurve" )
705 eResult = SvxChartRegress::Linear;
707 else if( aServiceName ==
"com.sun.star.chart2.LogarithmicRegressionCurve" )
709 eResult = SvxChartRegress::Log;
711 else if( aServiceName ==
"com.sun.star.chart2.ExponentialRegressionCurve" )
713 eResult = SvxChartRegress::Exp;
715 else if( aServiceName ==
"com.sun.star.chart2.PotentialRegressionCurve" )
717 eResult = SvxChartRegress::Power;
719 else if( aServiceName ==
"com.sun.star.chart2.MeanValueRegressionCurve" )
721 eResult = SvxChartRegress::MeanValue;
723 else if( aServiceName ==
"com.sun.star.chart2.PolynomialRegressionCurve" )
725 eResult = SvxChartRegress::Polynomial;
727 else if( aServiceName ==
"com.sun.star.chart2.MovingAverageRegressionCurve" )
729 eResult = SvxChartRegress::MovingAverage;
733 catch(
const Exception & )
742 const Reference< XRegressionCurveContainer > & xRegCnt )
748 const Sequence< Reference< XRegressionCurve > > aCurves(
749 xRegCnt->getRegressionCurves());
750 for( Reference< XRegressionCurve >
const & curve : aCurves )
753 if( eType != SvxChartRegress::MeanValue &&
754 eType != SvxChartRegress::Unknown )
768 if (aResult.isEmpty())
771 if (!aResult.isEmpty())
773 aResult +=
" (%SERIESNAME)";
782 if(!xRegressionCurve.is())
785 Reference< lang::XServiceName > xServiceName( xRegressionCurve, uno::UNO_QUERY );
786 if(!xServiceName.is())
789 OUString aServiceName(xServiceName->getServiceName());
791 if( aServiceName ==
"com.sun.star.chart2.MeanValueRegressionCurve" )
793 aResult =
SchResId(STR_REGRESSION_MEAN);
795 else if( aServiceName ==
"com.sun.star.chart2.LinearRegressionCurve" )
797 aResult =
SchResId(STR_REGRESSION_LINEAR);
799 else if( aServiceName ==
"com.sun.star.chart2.LogarithmicRegressionCurve" )
801 aResult =
SchResId(STR_REGRESSION_LOG);
803 else if( aServiceName ==
"com.sun.star.chart2.ExponentialRegressionCurve" )
805 aResult =
SchResId(STR_REGRESSION_EXP);
807 else if( aServiceName ==
"com.sun.star.chart2.PotentialRegressionCurve" )
809 aResult =
SchResId(STR_REGRESSION_POWER);
811 else if( aServiceName ==
"com.sun.star.chart2.PolynomialRegressionCurve" )
813 aResult =
SchResId(STR_REGRESSION_POLYNOMIAL);
815 else if( aServiceName ==
"com.sun.star.chart2.MovingAverageRegressionCurve" )
817 aResult =
SchResId(STR_REGRESSION_MOVING_AVERAGE);
826 if(!xRegressionCurve.is())
829 Reference<XPropertySet> xProperties( xRegressionCurve, uno::UNO_QUERY );
830 if(!xProperties.is())
833 xProperties->getPropertyValue(
"CurveName") >>= aResult;
841 if (aResult.isEmpty())
847 const Reference< chart2::XRegressionCurve > & xCurve )
854 static constexpr OUStringLiteral aPosPropertyName( u
"RelativePosition" );
855 Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
856 if( xEqProp->getPropertyValue( aPosPropertyName ).hasValue())
857 xEqProp->setPropertyValue( aPosPropertyName,
uno::Any());
859 catch(
const uno::Exception & )
871 const std::vector< rtl::Reference< RegressionCurveModel > > & aCurves(
872 xContainer->getRegressionCurves2());
874 for( std::size_t i = 0;
i < aCurves.size(); ++
i )
876 if( xCurve == aCurves[i] )
885 bool bHasEquation =
false;
888 uno::Reference< beans::XPropertySet > xEquationProp( xCurve->getEquationProperties());
889 if( xEquationProp.is())
891 bool bShowEquation =
false;
892 bool bShowCoefficient =
false;
893 xEquationProp->getPropertyValue(
"ShowEquation") >>= bShowEquation;
894 xEquationProp->getPropertyValue(
"ShowCorrelationCoefficient") >>= bShowCoefficient;
895 bHasEquation = bShowEquation || bShowCoefficient;
903 bool bMayHaveCorrelationCoefficient =
true;
906 uno::Reference< beans::XPropertySet > xEquationProp( xCurve->getEquationProperties() );
907 if( xEquationProp.is() )
909 xEquationProp->getPropertyValue(
"MayHaveCorrelationCoefficient") >>= bMayHaveCorrelationCoefficient;
912 return bMayHaveCorrelationCoefficient;
static rtl::Reference< ChartType > getChartTypeOfSeries(const rtl::Reference<::chart::ChartModel > &xModel, const rtl::Reference< ::chart::DataSeries > &xGivenDataSeries)
static sal_Int32 getAxisType(const rtl::Reference< ::chart::ChartType > &xChartType, sal_Int32 nDimensionIndex)
#define DBG_UNHANDLED_EXCEPTION(...)
std::deque< AttacherIndex_Impl > aIndex
OOO_DLLPUBLIC_CHARTTOOLS SvxChartRegress getFirstRegressTypeNotMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xCurveContainer)
Returns the type of the first regression curve found that is not of type mean-value line.
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveCalculator > createRegressionCurveCalculatorByServiceName(std::u16string_view aServiceName)
returns a calculator object for regression curves (used by the view)
OOO_DLLPUBLIC_CHARTTOOLS bool isMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurve > &xRegCurve)
OOO_DLLPUBLIC_CHARTTOOLS bool MayHaveCorrelationCoefficient(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS bool removeAllExceptMeanValueLine(rtl::Reference<::chart::DataSeries > const &xCurveContainer)
void initializeCurveCalculator(const css::uno::Reference< css::chart2::XRegressionCurveCalculator > &xOutCurveCalculator, const css::uno::Reference< css::chart2::data::XDataSource > &xSource, bool bUseXValuesIfAvailable)
recalculates the regression parameters according to the data given in the data source.
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > getFirstCurveNotMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xCurveContainer)
Returns the first regression curve found that is not of type mean-value line.
OOO_DLLPUBLIC_CHARTTOOLS OUString getUINameForRegressionCurve(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS bool hasMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xRegCnt)
OOO_DLLPUBLIC_CHARTTOOLS void resetEquationPosition(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS void removeEquations(rtl::Reference<::chart::DataSeries > const &xCurveContainer)
OOO_DLLPUBLIC_CHARTTOOLS OUString getRegressionCurveGenericName(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > getRegressionCurveAtIndex(const rtl::Reference<::chart::DataSeries > &xCurveContainer, sal_Int32 aIndex)
Returns the regression curve found at the index provided.
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > changeRegressionCurveType(SvxChartRegress eType, css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xRegressionCurveContainer, css::uno::Reference< css::chart2::XRegressionCurve > const &xRegressionCurve)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > getMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xRegCnt)
OOO_DLLPUBLIC_CHARTTOOLS void removeMeanValueLine(css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xRegCnt)
OOO_DLLPUBLIC_CHARTTOOLS bool hasEquation(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS sal_Int32 getRegressionCurveIndex(const rtl::Reference<::chart::DataSeries > &xContainer, const rtl::Reference<::chart::RegressionCurveModel > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS SvxChartRegress getRegressionType(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS OUString getRegressionCurveSpecificName(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > addRegressionCurve(SvxChartRegress eType, css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xCurveContainer, const css::uno::Reference< css::beans::XPropertySet > &xPropertySource=css::uno::Reference< css::beans::XPropertySet >(), const css::uno::Reference< css::beans::XPropertySet > &xEquationProperties=css::uno::Reference< css::beans::XPropertySet >())
rtl::Reference<::chart::RegressionCurveModel > createRegressionCurveByServiceName(std::u16string_view aServiceName)
returns a model regression curve
OOO_DLLPUBLIC_CHARTTOOLS OUString getRegressionCurveName(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
rtl::Reference<::chart::RegressionCurveModel > createMeanValueLine()
returns a model mean-value line
OOO_DLLPUBLIC_CHARTTOOLS void addMeanValueLine(css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xRegCnt, const css::uno::Reference< css::beans::XPropertySet > &xSeriesProp)
creates a mean-value line and adds it to the container.
OOO_DLLPUBLIC_CHARTTOOLS css::uno::Sequence< double > DataSequenceToDoubleSequence(const css::uno::Reference< css::chart2::data::XDataSequence > &xDataSequence)
chart2::XDataSequence -> uno::Sequence< double >
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
void copyProperties(const Reference< XPropertySet > &_rxSource, const Reference< XPropertySet > &_rxDest)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)