diff options
author | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2021-02-11 07:53:15 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2021-02-22 07:36:21 +0100 |
commit | 4141533a3fb984fbaefe87b15fceeda7f2082061 (patch) | |
tree | 46b7dc9e659033666cdef2275ec283dd2de8fd96 /chart2 | |
parent | c40ce0c542b46d45a00561a926953df2fe9a9762 (diff) |
[API CHANGE] tdf#133423 Implement chart:regression-moving-type
Change-Id: Icb967367fbf12e5a1566b7f18ebe5e3d8a3534f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110748
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>
Diffstat (limited to 'chart2')
17 files changed, 220 insertions, 51 deletions
diff --git a/chart2/qa/extras/chart2_trendcalculators.cxx b/chart2/qa/extras/chart2_trendcalculators.cxx index b8eb367524bb..1eeea5d12e23 100644 --- a/chart2/qa/extras/chart2_trendcalculators.cxx +++ b/chart2/qa/extras/chart2_trendcalculators.cxx @@ -110,7 +110,7 @@ void Chart2TrendCalculators::checkCalculator( void Chart2TrendCalculators::testPotentialRegression1() { loadCalculatorFromSheet( SHEET_POTENTIAL1 ); - m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0 ); + m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0, 0 ); Sequence< double > xValues( 7 ); Sequence< double > yValues( 7 ); for (int i=0; i<7; i++) @@ -126,7 +126,7 @@ void Chart2TrendCalculators::testPotentialRegression1() void Chart2TrendCalculators::testPotentialRegression2() { loadCalculatorFromSheet( SHEET_POTENTIAL2 ); - m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0 ); + m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0, 0 ); Sequence< double > xValues( 7 ); Sequence< double > yValues( 7 ); for (int i=0; i<7; i++) @@ -142,7 +142,7 @@ void Chart2TrendCalculators::testPotentialRegression2() void Chart2TrendCalculators::testLinearRegression1() { loadCalculatorFromSheet( SHEET_LINEAR1 ); - m_xRegressionCurveCalculator->setRegressionProperties( 1, false, 0, 0 ); + m_xRegressionCurveCalculator->setRegressionProperties( 1, false, 0, 0, 0 ); Sequence< double > xValues( 7 ); Sequence< double > yValues( 7 ); for (int i=0; i<7; i++) @@ -158,7 +158,7 @@ void Chart2TrendCalculators::testLinearRegression1() void Chart2TrendCalculators::testPolynomialRegression1() { loadCalculatorFromSheet( SHEET_POLYNOMIAL1 ); - m_xRegressionCurveCalculator->setRegressionProperties( 2, false, 0, 0 ); + m_xRegressionCurveCalculator->setRegressionProperties( 2, false, 0, 0, 0 ); Sequence< double > xValues( 7 ); Sequence< double > yValues( 7 ); for (int i=0; i<7; i++) @@ -174,7 +174,7 @@ void Chart2TrendCalculators::testPolynomialRegression1() void Chart2TrendCalculators::testExponentialRegression1() { loadCalculatorFromSheet( SHEET_EXPONENTIAL1 ); - m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0 ); + m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0, 0 ); Sequence< double > xValues( 7 ); Sequence< double > yValues( 7 ); for (int i=0; i<7; i++) @@ -189,7 +189,7 @@ void Chart2TrendCalculators::testExponentialRegression1() void Chart2TrendCalculators::testExponentialRegression2() { loadCalculatorFromSheet( SHEET_EXPONENTIAL2 ); - m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0 ); + m_xRegressionCurveCalculator->setRegressionProperties( 0, false, 0, 0, 0 ); Sequence< double > xValues( 7 ); Sequence< double > yValues( 7 ); for (int i=0; i<7; i++) diff --git a/chart2/source/controller/dialogs/ObjectNameProvider.cxx b/chart2/source/controller/dialogs/ObjectNameProvider.cxx index 56dca8dde908..5eae3853add8 100644 --- a/chart2/source/controller/dialogs/ObjectNameProvider.cxx +++ b/chart2/source/controller/dialogs/ObjectNameProvider.cxx @@ -41,6 +41,7 @@ #include <unotools/localedatawrapper.hxx> #include <com/sun/star/chart2/XTitle.hpp> +#include <com/sun/star/chart2/MovingAverageType.hpp> #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> #include <tools/diagnose_ex.h> @@ -567,6 +568,7 @@ OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Refe Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_SET_THROW ); sal_Int32 aDegree = 2; sal_Int32 aPeriod = 2; + sal_Int32 aMovingType = css::chart2::MovingAverageType::Prior; bool bForceIntercept = false; double aInterceptValue = 0.0; OUString aXName ("x"), aYName ("f(x)"); @@ -579,6 +581,7 @@ OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Refe { xProperties->getPropertyValue( "PolynomialDegree") >>= aDegree; xProperties->getPropertyValue( "MovingAveragePeriod") >>= aPeriod; + xProperties->getPropertyValue( "MovingAverageType") >>= aMovingType; xProperties->getPropertyValue( "ForceIntercept") >>= bForceIntercept; if (bForceIntercept) xProperties->getPropertyValue( "InterceptValue") >>= aInterceptValue; @@ -591,7 +594,7 @@ OUString ObjectNameProvider::getHelpText( const OUString& rObjectCID, const Refe aYName = "f(x)"; } } - xCalculator->setRegressionProperties(aDegree, bForceIntercept, aInterceptValue, 2); + xCalculator->setRegressionProperties(aDegree, bForceIntercept, aInterceptValue, 2, aMovingType); xCalculator->setXYNames ( aXName, aYName ); RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel ); diff --git a/chart2/source/controller/dialogs/res_Trendline.cxx b/chart2/source/controller/dialogs/res_Trendline.cxx index 11514a19a84a..6d994e13bc6d 100644 --- a/chart2/source/controller/dialogs/res_Trendline.cxx +++ b/chart2/source/controller/dialogs/res_Trendline.cxx @@ -21,12 +21,16 @@ #include <bitmaps.hlst> #include <chartview/ChartSfxItemIds.hxx> +#include <com/sun/star/chart2/MovingAverageType.hpp> + #include <svl/intitem.hxx> #include <svl/stritem.hxx> #include <svl/zforlist.hxx> #include <vcl/formatter.hxx> #include <vcl/weld.hxx> +using namespace css::chart2; + namespace chart { @@ -65,6 +69,7 @@ TrendlineResources::TrendlineResources(weld::Builder& rBuilder, const SfxItemSet , m_xEE_XName(rBuilder.weld_entry("entry_Xname")) , m_xEE_YName(rBuilder.weld_entry("entry_Yname")) , m_xCB_ShowCorrelationCoeff(rBuilder.weld_check_button("showCorrelationCoefficient")) + , m_xCB_RegressionMovingType(rBuilder.weld_combo_box("combo_moving_type")) { FillValueSets(); @@ -240,6 +245,21 @@ void TrendlineResources::Reset( const SfxItemSet& rInAttrs ) m_xCB_ShowCorrelationCoeff->set_active( static_cast< const SfxBoolItem * >( pPoolItem )->GetValue()); } + if( rInAttrs.GetItemState( SCHATTR_REGRESSION_MOVING_TYPE, true, &pPoolItem ) == SfxItemState::SET ) + { + sal_Int32 nMovingType = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue(); + if (nMovingType == MovingAverageType::Prior) + m_xCB_RegressionMovingType->set_active(0); + else if (nMovingType == MovingAverageType::Central) + m_xCB_RegressionMovingType->set_active(1); + else if (nMovingType == MovingAverageType::AveragedAbscissa) + m_xCB_RegressionMovingType->set_active(2); + } + else + { + m_xCB_RegressionMovingType->set_active(0); + } + if( !m_bTrendLineUnique ) return; @@ -273,6 +293,17 @@ void TrendlineResources::FillItemSet(SfxItemSet* rOutAttrs) const if( m_bTrendLineUnique ) rOutAttrs->Put( SvxChartRegressItem( m_eTrendLineType, SCHATTR_REGRESSION_TYPE )); + if (m_eTrendLineType == SvxChartRegress::MovingAverage) + { + sal_Int32 nType = MovingAverageType::Prior; + if (m_xCB_RegressionMovingType->get_active() == 1) + nType = MovingAverageType::Central; + else if (m_xCB_RegressionMovingType->get_active() == 2) + nType = MovingAverageType::AveragedAbscissa; + + rOutAttrs->Put(SfxInt32Item(SCHATTR_REGRESSION_MOVING_TYPE, nType)); + } + if( m_xCB_ShowEquation->get_state() != TRISTATE_INDET ) rOutAttrs->Put( SfxBoolItem( SCHATTR_REGRESSION_SHOW_EQUATION, m_xCB_ShowEquation->get_active() )); @@ -346,6 +377,7 @@ void TrendlineResources::UpdateControlStates() } m_xCB_ShowEquation->set_sensitive( !bMovingAverage ); m_xCB_ShowCorrelationCoeff->set_sensitive( !bMovingAverage ); + m_xCB_RegressionMovingType->set_sensitive(bMovingAverage); m_xEE_XName->set_sensitive( !bMovingAverage && m_xCB_ShowEquation->get_active() ); m_xEE_YName->set_sensitive( !bMovingAverage && m_xCB_ShowEquation->get_active() ); } diff --git a/chart2/source/controller/dialogs/res_Trendline.hxx b/chart2/source/controller/dialogs/res_Trendline.hxx index 29d916fe068f..2327b05c355d 100644 --- a/chart2/source/controller/dialogs/res_Trendline.hxx +++ b/chart2/source/controller/dialogs/res_Trendline.hxx @@ -24,6 +24,7 @@ namespace weld { class Builder; } namespace weld { class CheckButton; } +namespace weld { class ComboBox; } namespace weld { class Entry; } namespace weld { class FormattedSpinButton; } namespace weld { class Image; } @@ -83,6 +84,7 @@ private: std::unique_ptr<weld::Entry> m_xEE_XName; std::unique_ptr<weld::Entry> m_xEE_YName; std::unique_ptr<weld::CheckButton> m_xCB_ShowCorrelationCoeff; + std::unique_ptr<weld::ComboBox> m_xCB_RegressionMovingType; void UpdateControlStates(); DECL_LINK(SelectTrendLine, weld::ToggleButton&, void); diff --git a/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx b/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx index 8859158ac5b8..7fe5d2acad41 100644 --- a/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx +++ b/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx @@ -212,6 +212,13 @@ bool RegressionCurveItemConverter::ApplySpecialItem( } break; + case SCHATTR_REGRESSION_MOVING_TYPE: + { + uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); + bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAverageType"); + } + break; + case SCHATTR_REGRESSION_SHOW_EQUATION: { uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); @@ -304,6 +311,12 @@ void RegressionCurveItemConverter::FillSpecialItem(sal_uInt16 nWhichId, SfxItemS } break; + case SCHATTR_REGRESSION_MOVING_TYPE: + { + lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAverageType"); + } + break; + case SCHATTR_REGRESSION_SHOW_EQUATION: { lclConvertToItemSet<bool, SfxBoolItem>(rOutItemSet, nWhichId, xCurve->getEquationProperties(), "ShowEquation"); diff --git a/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx b/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx index c0691daf24cf..d9ec4ea1f534 100644 --- a/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx +++ b/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx @@ -447,6 +447,13 @@ bool StatisticsItemConverter::ApplySpecialItem( } break; + case SCHATTR_REGRESSION_MOVING_TYPE: + { + uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet )); + bChanged = lclConvertToPropertySet<sal_Int32, SfxInt32Item>(rItemSet, nWhichId, xProperties, "MovingAverageType"); + } + break; + case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD: { uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), &rItemSet )); @@ -729,6 +736,13 @@ void StatisticsItemConverter::FillSpecialItem( } break; + case SCHATTR_REGRESSION_MOVING_TYPE: + { + uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr )); + lclConvertToItemSet<sal_Int32, SfxInt32Item>(rOutItemSet, nWhichId, xProperties, "MovingAverageType"); + } + break; + case SCHATTR_REGRESSION_EXTRAPOLATE_FORWARD: { uno::Reference< beans::XPropertySet > xProperties( lcl_getCurveProperties( GetPropertySet(), nullptr )); diff --git a/chart2/source/inc/LinearRegressionCurveCalculator.hxx b/chart2/source/inc/LinearRegressionCurveCalculator.hxx index accc43c06294..57d85a24f884 100644 --- a/chart2/source/inc/LinearRegressionCurveCalculator.hxx +++ b/chart2/source/inc/LinearRegressionCurveCalculator.hxx @@ -34,7 +34,8 @@ private: sal_Int32 aDegree, sal_Bool aForceIntercept, double aInterceptValue, - sal_Int32 aPeriod) override; + sal_Int32 aPeriod, + sal_Int32 nMovingType) override; virtual css::uno::Sequence<css::geometry::RealPoint2D> SAL_CALL getCurveValues( double min, diff --git a/chart2/source/inc/MovingAverageRegressionCurveCalculator.hxx b/chart2/source/inc/MovingAverageRegressionCurveCalculator.hxx index 0b15ca5e817e..8ba5456c2939 100644 --- a/chart2/source/inc/MovingAverageRegressionCurveCalculator.hxx +++ b/chart2/source/inc/MovingAverageRegressionCurveCalculator.hxx @@ -19,6 +19,7 @@ #pragma once #include "RegressionCurveCalculator.hxx" +#include "RegressionCalculationHelper.hxx" #include <vector> namespace chart @@ -51,6 +52,9 @@ private: const css::uno::Reference<css::chart2::XScaling>& xScalingY, sal_Bool bMaySkipPointsInCalculation ) override; + void calculateValues(RegressionCalculationHelper::tDoubleVectorPair aValues, sal_Int32 nPeriod, + bool bUseXAvg); + std::vector<double> aYList; std::vector<double> aXList; }; diff --git a/chart2/source/inc/RegressionCurveCalculator.hxx b/chart2/source/inc/RegressionCurveCalculator.hxx index 1914c4effea9..6cf1f2914d5b 100644 --- a/chart2/source/inc/RegressionCurveCalculator.hxx +++ b/chart2/source/inc/RegressionCurveCalculator.hxx @@ -62,13 +62,15 @@ protected: double mInterceptValue; sal_Int32 mPeriod; OUString mXName, mYName; + sal_Int32 mnMovingType; // ____ XRegressionCurveCalculator ____ virtual void SAL_CALL setRegressionProperties( sal_Int32 aDegree, sal_Bool aForceIntercept, double aInterceptValue, - sal_Int32 aPeriod) override; + sal_Int32 aPeriod, + sal_Int32 nMovingType) override; virtual void SAL_CALL recalculateRegression( const css::uno::Sequence< double >& aXValues, diff --git a/chart2/source/inc/chartview/ChartSfxItemIds.hxx b/chart2/source/inc/chartview/ChartSfxItemIds.hxx index 7ed412ce4500..55fec55872f3 100644 --- a/chart2/source/inc/chartview/ChartSfxItemIds.hxx +++ b/chart2/source/inc/chartview/ChartSfxItemIds.hxx @@ -191,7 +191,8 @@ constexpr TypedWhichId<SvxDoubleItem> SCHATTR_REGRESSION_INTERCEPT_VALUE constexpr TypedWhichId<SfxStringItem> SCHATTR_REGRESSION_CURVE_NAME (SCHATTR_REGRESSION_START + 9); constexpr TypedWhichId<SfxStringItem> SCHATTR_REGRESSION_XNAME (SCHATTR_REGRESSION_START + 10); constexpr TypedWhichId<SfxStringItem> SCHATTR_REGRESSION_YNAME (SCHATTR_REGRESSION_START + 11); -constexpr sal_uInt16 SCHATTR_REGRESSION_END (SCHATTR_REGRESSION_YNAME); +constexpr TypedWhichId<SfxInt32Item> SCHATTR_REGRESSION_MOVING_TYPE (SCHATTR_REGRESSION_START + 12); +constexpr sal_uInt16 SCHATTR_REGRESSION_END (SCHATTR_REGRESSION_MOVING_TYPE); constexpr sal_uInt16 SCHATTR_END (SCHATTR_REGRESSION_END); diff --git a/chart2/source/tools/LinearRegressionCurveCalculator.cxx b/chart2/source/tools/LinearRegressionCurveCalculator.cxx index 9cf3492d8e8e..811381507cb6 100644 --- a/chart2/source/tools/LinearRegressionCurveCalculator.cxx +++ b/chart2/source/tools/LinearRegressionCurveCalculator.cxx @@ -35,13 +35,15 @@ void LinearRegressionCurveCalculator::setRegressionProperties( sal_Int32 /*aDegree*/, sal_Bool aForceIntercept, double aInterceptValue, - sal_Int32 aPeriod ) + sal_Int32 aPeriod, + sal_Int32 /*nMovingType*/) { PolynomialRegressionCurveCalculator::setRegressionProperties( 1, aForceIntercept, aInterceptValue, - aPeriod); + aPeriod, + 0); } uno::Sequence< geometry::RealPoint2D > SAL_CALL LinearRegressionCurveCalculator::getCurveValues( diff --git a/chart2/source/tools/MovingAverageRegressionCurveCalculator.cxx b/chart2/source/tools/MovingAverageRegressionCurveCalculator.cxx index 7774bec02a4f..bca154047935 100644 --- a/chart2/source/tools/MovingAverageRegressionCurveCalculator.cxx +++ b/chart2/source/tools/MovingAverageRegressionCurveCalculator.cxx @@ -24,7 +24,10 @@ #include <rtl/math.hxx> +#include <com/sun/star/chart2/MovingAverageType.hpp> + using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; namespace chart { @@ -47,25 +50,59 @@ void SAL_CALL MovingAverageRegressionCurveCalculator::recalculateRegression( aXValues, aYValues, RegressionCalculationHelper::isValid())); - const size_t aSize = aValues.first.size(); - aYList.clear(); aXList.clear(); - for( size_t i = mPeriod - 1; i < aSize; ++i ) + switch (mnMovingType) + { + case MovingAverageType::Central: + { + sal_Int32 nCentralPeriod = (mPeriod % 2 == 0) ? (mPeriod / 2) : ((mPeriod - 1) / 2); + calculateValues(aValues, nCentralPeriod, false); + break; + } + + case MovingAverageType::AveragedAbscissa: + { + calculateValues(aValues, mPeriod, true); + break; + } + case MovingAverageType::Prior: + default: + { + calculateValues(aValues, mPeriod, false); + break; + } + } +} + +void MovingAverageRegressionCurveCalculator::calculateValues( + RegressionCalculationHelper::tDoubleVectorPair aValues, sal_Int32 nPeriod, bool bUseXAvg) +{ + const size_t aSize = aValues.first.size(); + for (size_t i = nPeriod - 1; i < aSize; ++i) { - double yAvg; - yAvg = 0.0; + double xAvg = 0.0; + double yAvg = 0.0; - for (sal_Int32 j = 0; j < mPeriod; j++) + for (sal_Int32 j = 0; j < nPeriod; j++) { + xAvg += aValues.first[i - j]; yAvg += aValues.second[i - j]; } - yAvg /= mPeriod; + yAvg /= nPeriod; + xAvg /= nPeriod; - double x = aValues.first[i]; aYList.push_back(yAvg); - aXList.push_back(x); + if (bUseXAvg) + { + aXList.push_back(xAvg); + } + else + { + double x = aValues.first[i]; + aXList.push_back(x); + } } } diff --git a/chart2/source/tools/RegressionCurveCalculator.cxx b/chart2/source/tools/RegressionCurveCalculator.cxx index ba8a7423c01e..c27a47e502cd 100644 --- a/chart2/source/tools/RegressionCurveCalculator.cxx +++ b/chart2/source/tools/RegressionCurveCalculator.cxx @@ -72,12 +72,14 @@ void RegressionCurveCalculator::setRegressionProperties( sal_Int32 aDegree, sal_Bool aForceIntercept, double aInterceptValue, - sal_Int32 aPeriod ) + sal_Int32 aPeriod, + sal_Int32 nMovingType ) { mDegree = aDegree; mForceIntercept = aForceIntercept; mInterceptValue = aInterceptValue; mPeriod = aPeriod; + mnMovingType = nMovingType; } OUString RegressionCurveCalculator::getFormattedString( diff --git a/chart2/source/tools/RegressionCurveModel.cxx b/chart2/source/tools/RegressionCurveModel.cxx index 649e93e2702f..0fb7662830af 100644 --- a/chart2/source/tools/RegressionCurveModel.cxx +++ b/chart2/source/tools/RegressionCurveModel.cxx @@ -44,7 +44,8 @@ enum PROPERTY_EXTRAPOLATE_BACKWARD, PROPERTY_FORCE_INTERCEPT, PROPERTY_INTERCEPT_VALUE, - PROPERTY_CURVE_NAME + PROPERTY_CURVE_NAME, + PROPERTY_MOVING_AVERAGE_TYPE }; void lcl_AddPropertiesToVector( @@ -62,6 +63,12 @@ void lcl_AddPropertiesToVector( beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT ); + rOutProperties.emplace_back( "MovingAverageType", + PROPERTY_MOVING_AVERAGE_TYPE, + cppu::UnoType<sal_Int32>::get(), + beans::PropertyAttribute::BOUND | + beans::PropertyAttribute::MAYBEDEFAULT ); + rOutProperties.emplace_back( "ExtrapolateForward", PROPERTY_EXTRAPOLATE_FORWARD, cppu::UnoType<double>::get(), diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index c235148a2045..39a97c618a47 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -56,6 +56,7 @@ #include <com/sun/star/chart2/DataPointLabel.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/chart/TimeUnit.hpp> +#include <com/sun/star/chart2/MovingAverageType.hpp> #include <com/sun/star/chart2/XDataPointCustomLabelField.hpp> #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> #include <com/sun/star/container/XChild.hpp> @@ -1335,6 +1336,7 @@ void VSeriesPlotter::createRegressionCurvesShapes( VDataSeries const & rVDataSer sal_Int32 aDegree = 2; sal_Int32 aPeriod = 2; + sal_Int32 aMovingAverageType = css::chart2::MovingAverageType::Prior; double aExtrapolateForward = 0.0; double aExtrapolateBackward = 0.0; bool bForceIntercept = false; @@ -1344,6 +1346,7 @@ void VSeriesPlotter::createRegressionCurvesShapes( VDataSeries const & rVDataSer { xProperties->getPropertyValue( "PolynomialDegree") >>= aDegree; xProperties->getPropertyValue( "MovingAveragePeriod") >>= aPeriod; + xProperties->getPropertyValue( "MovingAverageType") >>= aMovingAverageType; xProperties->getPropertyValue( "ExtrapolateForward") >>= aExtrapolateForward; xProperties->getPropertyValue( "ExtrapolateBackward") >>= aExtrapolateBackward; xProperties->getPropertyValue( "ForceIntercept") >>= bForceIntercept; @@ -1370,8 +1373,9 @@ void VSeriesPlotter::createRegressionCurvesShapes( VDataSeries const & rVDataSer fPointScale = std::min(fPointScale, 1000.0); } - xCalculator->setRegressionProperties(aDegree, bForceIntercept, aInterceptValue, aPeriod); - xCalculator->recalculateRegression( rVDataSeries.getAllX(), rVDataSeries.getAllY() ); + xCalculator->setRegressionProperties(aDegree, bForceIntercept, aInterceptValue, aPeriod, + aMovingAverageType); + xCalculator->recalculateRegression(rVDataSeries.getAllX(), rVDataSeries.getAllY()); sal_Int32 nPointCount = 100 * fPointScale; if ( nPointCount < 2 ) diff --git a/chart2/source/view/main/ChartItemPool.cxx b/chart2/source/view/main/ChartItemPool.cxx index 7f67cdde45ca..8b5bade3ebc3 100644 --- a/chart2/source/view/main/ChartItemPool.cxx +++ b/chart2/source/view/main/ChartItemPool.cxx @@ -31,6 +31,7 @@ #include <vector> #include <com/sun/star/chart2/LegendPosition.hpp> +#include <com/sun/star/chart2/MovingAverageType.hpp> namespace chart { @@ -165,6 +166,7 @@ ChartItemPool::ChartItemPool(): rPoolDefaults[SCHATTR_REGRESSION_CURVE_NAME - SCHATTR_START] = new SfxStringItem(SCHATTR_REGRESSION_CURVE_NAME, OUString()); rPoolDefaults[SCHATTR_REGRESSION_XNAME - SCHATTR_START] = new SfxStringItem(SCHATTR_REGRESSION_XNAME, "x"); rPoolDefaults[SCHATTR_REGRESSION_YNAME - SCHATTR_START] = new SfxStringItem(SCHATTR_REGRESSION_YNAME, "f(x)"); + rPoolDefaults[SCHATTR_REGRESSION_MOVING_TYPE - SCHATTR_START] = new SfxInt32Item(SCHATTR_REGRESSION_MOVING_TYPE, css::chart2::MovingAverageType::Prior); /************************************************************************** * ItemInfos diff --git a/chart2/uiconfig/ui/tp_Trendline.ui b/chart2/uiconfig/ui/tp_Trendline.ui index ed7e4fecf934..486d67e57994 100644 --- a/chart2/uiconfig/ui/tp_Trendline.ui +++ b/chart2/uiconfig/ui/tp_Trendline.ui @@ -32,6 +32,23 @@ <property name="step_increment">1</property> <property name="page_increment">10</property> </object> + <object class="GtkListStore" id="liststore_moving_type"> + <columns> + <!-- column-name moving_type --> + <column type="gchararray"/> + </columns> + <data> + <row> + <col id="0" translatable="yes" context="tp_Trendline|liststore_moving_type">Prior</col> + </row> + <row> + <col id="0" translatable="yes" context="tp_Trendline|liststore_moving_type">Central</col> + </row> + <row> + <col id="0" translatable="yes" context="tp_Trendline|liststore_moving_type">Averaged Abscissa</col> + </row> + </data> + </object> <object class="GtkBox" id="TP_TRENDLINE"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -47,16 +64,15 @@ <property name="label_xalign">0</property> <property name="shadow_type">none</property> <child> - <!-- n-columns=1 n-rows=1 --> <object class="GtkGrid" id="grid1"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="halign">start</property> + <property name="margin_start">12</property> + <property name="margin_top">6</property> <property name="row_spacing">6</property> <property name="column_spacing">6</property> <property name="row_homogeneous">True</property> - <property name="margin-start">12</property> - <property name="margin-top">6</property> <child> <object class="GtkRadioButton" id="linear"> <property name="label" translatable="yes" context="tp_Trendline|linear">_Linear</property> @@ -183,7 +199,6 @@ </packing> </child> <child> - <!-- n-columns=1 n-rows=1 --> <object class="GtkGrid" id="grid2"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -211,8 +226,8 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="activates_default">True</property> + <property name="truncate_multiline">True</property> <property name="adjustment">adjustmentDegree</property> - <property name="truncate-multiline">True</property> <child internal-child="accessible"> <object class="AtkObject" id="degree-atkobject"> <property name="AtkObject::accessible-description" translatable="yes" context="tp_Trendline|extended_tip|degree">Degree of polynomial trend line.</property> @@ -231,7 +246,6 @@ </packing> </child> <child> - <!-- n-columns=1 n-rows=1 --> <object class="GtkGrid" id="grid3"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -259,8 +273,8 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="activates_default">True</property> + <property name="truncate_multiline">True</property> <property name="adjustment">adjustmentPeriod</property> - <property name="truncate-multiline">True</property> <child internal-child="accessible"> <object class="AtkObject" id="period-atkobject"> <property name="AtkObject::accessible-description" translatable="yes" context="tp_Trendline|extended_tip|period">Number of points to calculate average of moving average trend line.</property> @@ -282,7 +296,7 @@ <object class="GtkImage" id="imageLinear"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="icon-name">missing-image</property> + <property name="icon_name">missing-image</property> </object> <packing> <property name="left_attach">0</property> @@ -293,7 +307,7 @@ <object class="GtkImage" id="imageLogarithmic"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="icon-name">missing-image</property> + <property name="icon_name">missing-image</property> </object> <packing> <property name="left_attach">0</property> @@ -304,7 +318,7 @@ <object class="GtkImage" id="imageExponential"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="icon-name">missing-image</property> + <property name="icon_name">missing-image</property> </object> <packing> <property name="left_attach">0</property> @@ -315,7 +329,7 @@ <object class="GtkImage" id="imagePower"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="icon-name">missing-image</property> + <property name="icon_name">missing-image</property> </object> <packing> <property name="left_attach">0</property> @@ -326,7 +340,7 @@ <object class="GtkImage" id="imagePolynomial"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="icon-name">missing-image</property> + <property name="icon_name">missing-image</property> </object> <packing> <property name="left_attach">2</property> @@ -337,7 +351,7 @@ <object class="GtkImage" id="imageMovingAverage"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="icon-name">missing-image</property> + <property name="icon_name">missing-image</property> </object> <packing> <property name="left_attach">2</property> @@ -376,15 +390,14 @@ <property name="label_xalign">0</property> <property name="shadow_type">none</property> <child> - <!-- n-columns=1 n-rows=1 --> <object class="GtkGrid" id="grid5"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="margin_start">12</property> + <property name="margin_top">6</property> <property name="row_spacing">6</property> <property name="column_spacing">12</property> <property name="row_homogeneous">True</property> - <property name="margin-start">12</property> - <property name="margin-top">6</property> <child> <object class="GtkLabel" id="label7"> <property name="visible">True</property> @@ -428,9 +441,9 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="activates_default">True</property> + <property name="truncate_multiline">True</property> <property name="caps_lock_warning">False</property> <property name="adjustment">adjustmentForwardBackward</property> - <property name="truncate-multiline">True</property> <property name="digits">2</property> </object> <packing> @@ -443,8 +456,8 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="activates_default">True</property> + <property name="truncate_multiline">True</property> <property name="adjustment">adjustmentForwardBackward1</property> - <property name="truncate-multiline">True</property> <property name="digits">2</property> </object> <packing> @@ -538,7 +551,7 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="activates_default">True</property> - <property name="truncate-multiline">True</property> + <property name="truncate_multiline">True</property> <child internal-child="accessible"> <object class="AtkObject" id="entry_name-atkobject"> <property name="AtkObject::accessible-description" translatable="yes" context="tp_Trendline|extended_tip|entry_name">Name of trend line in legend.</property> @@ -556,6 +569,7 @@ <property name="can_focus">True</property> <property name="activates_default">True</property> <property name="text">0</property> + <property name="truncate_multiline">True</property> <property name="caps_lock_warning">False</property> <property name="input_purpose">number</property> <property name="adjustment">adjustmentForwardBackward2</property> @@ -563,7 +577,6 @@ <accessibility> <relation type="labelled-by" target="setIntercept"/> </accessibility> - <property name="truncate-multiline">True</property> <child internal-child="accessible"> <object class="AtkObject" id="interceptValue-atkobject"> <property name="AtkObject::accessible-description" translatable="yes" context="tp_Trendline|extended_tip|interceptValue">Value of intercept if it is forced.</property> @@ -591,7 +604,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">6</property> + <property name="top_attach">7</property> </packing> </child> <child> @@ -599,7 +612,7 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="activates_default">True</property> - <property name="truncate-multiline">True</property> + <property name="truncate_multiline">True</property> <child internal-child="accessible"> <object class="AtkObject" id="entry_Xname-atkobject"> <property name="AtkObject::accessible-description" translatable="yes" context="tp_Trendline|extended_tip|entry_Xname">Name of X variable in trend line equation.</property> @@ -608,7 +621,7 @@ </object> <packing> <property name="left_attach">1</property> - <property name="top_attach">6</property> + <property name="top_attach">7</property> </packing> </child> <child> @@ -627,7 +640,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">7</property> + <property name="top_attach">8</property> </packing> </child> <child> @@ -635,7 +648,7 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="activates_default">True</property> - <property name="truncate-multiline">True</property> + <property name="truncate_multiline">True</property> <child internal-child="accessible"> <object class="AtkObject" id="entry_Yname-atkobject"> <property name="AtkObject::accessible-description" translatable="yes" context="tp_Trendline|extended_tip|entry_Yname">Name of Y variable in trend line equation.</property> @@ -644,7 +657,37 @@ </object> <packing> <property name="left_attach">1</property> - <property name="top_attach">7</property> + <property name="top_attach">8</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label10"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes" context="tp_Trendline|label10">Moving _Type</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">combo_moving_type</property> + <property name="xalign">0</property> + <child internal-child="accessible"> + <object class="AtkObject" id="label10-atkobject"> + <property name="AtkObject::accessible-description" translatable="yes" context="tp_Trendline|extended_tip|label10">How the trend line is calculated.</property> + </object> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">6</property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="combo_moving_type"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="model">liststore_moving_type</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">6</property> </packing> </child> </object> |