1*de7b3f82SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*de7b3f82SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*de7b3f82SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*de7b3f82SAndrew Rist * distributed with this work for additional information 6*de7b3f82SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*de7b3f82SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*de7b3f82SAndrew Rist * "License"); you may not use this file except in compliance 9*de7b3f82SAndrew Rist * with the License. You may obtain a copy of the License at 10*de7b3f82SAndrew Rist * 11*de7b3f82SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*de7b3f82SAndrew Rist * 13*de7b3f82SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*de7b3f82SAndrew Rist * software distributed under the License is distributed on an 15*de7b3f82SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*de7b3f82SAndrew Rist * KIND, either express or implied. See the License for the 17*de7b3f82SAndrew Rist * specific language governing permissions and limitations 18*de7b3f82SAndrew Rist * under the License. 19*de7b3f82SAndrew Rist * 20*de7b3f82SAndrew Rist *************************************************************/ 21*de7b3f82SAndrew Rist 22*de7b3f82SAndrew Rist 23cdf0e10cSrcweir #ifndef CHART2_REGRESSIONCURVEHELPER_HXX 24cdf0e10cSrcweir #define CHART2_REGRESSIONCURVEHELPER_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <com/sun/star/chart2/XRegressionCurve.hpp> 27cdf0e10cSrcweir #include <com/sun/star/chart2/XRegressionCurveCalculator.hpp> 28cdf0e10cSrcweir #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> 29cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataSource.hpp> 30cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeries.hpp> 31cdf0e10cSrcweir #include <com/sun/star/chart2/XDiagram.hpp> 32cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 33cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 34cdf0e10cSrcweir #include "charttoolsdllapi.hxx" 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <vector> 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace chart 39cdf0e10cSrcweir { 40cdf0e10cSrcweir 41cdf0e10cSrcweir class OOO_DLLPUBLIC_CHARTTOOLS RegressionCurveHelper 42cdf0e10cSrcweir { 43cdf0e10cSrcweir public: 44cdf0e10cSrcweir /// returns a model mean-value line 45cdf0e10cSrcweir SAL_DLLPRIVATE static ::com::sun::star::uno::Reference< 46cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurve > 47cdf0e10cSrcweir createMeanValueLine( 48cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 49cdf0e10cSrcweir ::com::sun::star::uno::XComponentContext > & xContext ); 50cdf0e10cSrcweir 51cdf0e10cSrcweir /// returns a model regression curve 52cdf0e10cSrcweir SAL_DLLPRIVATE static ::com::sun::star::uno::Reference< 53cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurve > 54cdf0e10cSrcweir createRegressionCurveByServiceName( 55cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 56cdf0e10cSrcweir ::com::sun::star::uno::XComponentContext > & xContext, 57cdf0e10cSrcweir ::rtl::OUString aServiceName ); 58cdf0e10cSrcweir 59cdf0e10cSrcweir // ------------------------------------------------------------ 60cdf0e10cSrcweir 61cdf0e10cSrcweir static bool hasMeanValueLine( 62cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 63cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 64cdf0e10cSrcweir 65cdf0e10cSrcweir static bool isMeanValueLine( 66cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 67cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurve > & xRegCurve ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir static ::com::sun::star::uno::Reference< 70cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurve > 71cdf0e10cSrcweir getMeanValueLine( 72cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 73cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir /** creates a mean-value line and adds it to the container. 76cdf0e10cSrcweir 77cdf0e10cSrcweir @param xSeriesProp 78cdf0e10cSrcweir If set, this property-set will be used to apply a line color 79cdf0e10cSrcweir */ 80cdf0e10cSrcweir static void addMeanValueLine( 81cdf0e10cSrcweir ::com::sun::star::uno::Reference< 82cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt, 83cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 84cdf0e10cSrcweir ::com::sun::star::uno::XComponentContext > & xContext, 85cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 86cdf0e10cSrcweir ::com::sun::star::beans::XPropertySet > & xSeriesProp ); 87cdf0e10cSrcweir 88cdf0e10cSrcweir static void removeMeanValueLine( 89cdf0e10cSrcweir ::com::sun::star::uno::Reference< 90cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir enum tRegressionType 93cdf0e10cSrcweir { 94cdf0e10cSrcweir REGRESSION_TYPE_NONE, 95cdf0e10cSrcweir REGRESSION_TYPE_LINEAR, 96cdf0e10cSrcweir REGRESSION_TYPE_LOG, 97cdf0e10cSrcweir REGRESSION_TYPE_EXP, 98cdf0e10cSrcweir REGRESSION_TYPE_POWER, 99cdf0e10cSrcweir REGRESSION_TYPE_MEAN_VALUE, 100cdf0e10cSrcweir REGRESSION_TYPE_UNKNOWN 101cdf0e10cSrcweir }; 102cdf0e10cSrcweir 103cdf0e10cSrcweir /** Returns the first regression curve found that is not of type 104cdf0e10cSrcweir mean-value line 105cdf0e10cSrcweir */ 106cdf0e10cSrcweir static ::com::sun::star::uno::Reference< 107cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurve > 108cdf0e10cSrcweir getFirstCurveNotMeanValueLine( 109cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 110cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir /** Returns the type of the first regression curve found that is not of type 113cdf0e10cSrcweir mean-value line 114cdf0e10cSrcweir */ 115cdf0e10cSrcweir static tRegressionType getFirstRegressTypeNotMeanValueLine( 116cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 117cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir static tRegressionType getRegressionType( 120cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 121cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurve > & xCurve ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir /** @param xPropertySource is taken as source to copy all properties from if 124cdf0e10cSrcweir not null 125cdf0e10cSrcweir @param xEquationProperties is set at the new regression curve as 126cdf0e10cSrcweir equation properties if not null 127cdf0e10cSrcweir */ 128cdf0e10cSrcweir static void addRegressionCurve( tRegressionType eType, 129cdf0e10cSrcweir ::com::sun::star::uno::Reference< 130cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt, 131cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 132cdf0e10cSrcweir ::com::sun::star::uno::XComponentContext > & xContext, 133cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 134cdf0e10cSrcweir ::com::sun::star::beans::XPropertySet >& xPropertySource = 135cdf0e10cSrcweir ::com::sun::star::uno::Reference< 136cdf0e10cSrcweir ::com::sun::star::beans::XPropertySet >(), 137cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 138cdf0e10cSrcweir ::com::sun::star::beans::XPropertySet >& xEquationProperties = 139cdf0e10cSrcweir ::com::sun::star::uno::Reference< 140cdf0e10cSrcweir ::com::sun::star::beans::XPropertySet >() 141cdf0e10cSrcweir ); 142cdf0e10cSrcweir 143cdf0e10cSrcweir static bool removeAllExceptMeanValueLine( 144cdf0e10cSrcweir ::com::sun::star::uno::Reference< 145cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 146cdf0e10cSrcweir 147cdf0e10cSrcweir static void removeEquations( 148cdf0e10cSrcweir ::com::sun::star::uno::Reference< 149cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir /** adds the given regression curve if there was none before. If there are 152cdf0e10cSrcweir regression curves, the first one is replaced by the one given by the 153cdf0e10cSrcweir type. All remaining curves are remnoved. 154cdf0e10cSrcweir 155cdf0e10cSrcweir <p>This fuction ignores mean-value lines.</p> 156cdf0e10cSrcweir */ 157cdf0e10cSrcweir static void replaceOrAddCurveAndReduceToOne( 158cdf0e10cSrcweir tRegressionType eType, 159cdf0e10cSrcweir ::com::sun::star::uno::Reference< 160cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt, 161cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 162cdf0e10cSrcweir ::com::sun::star::uno::XComponentContext > & xContext ); 163cdf0e10cSrcweir 164cdf0e10cSrcweir // ------------------------------------------------------------ 165cdf0e10cSrcweir 166cdf0e10cSrcweir /// returns a calculator object for regression curves (used by the view) 167cdf0e10cSrcweir static ::com::sun::star::uno::Reference< 168cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveCalculator > 169cdf0e10cSrcweir createRegressionCurveCalculatorByServiceName( 170cdf0e10cSrcweir ::rtl::OUString aServiceName ); 171cdf0e10cSrcweir 172cdf0e10cSrcweir /** recalculates the regression parameters according to the data given in 173cdf0e10cSrcweir the data source. 174cdf0e10cSrcweir 175cdf0e10cSrcweir A sequence having the role "values-x" will be used as x-values for the 176cdf0e10cSrcweir calculation if found. Otherwise a sequence (1, 2, 3, ...) of category 177cdf0e10cSrcweir indexes will be used for the recalculateRegression() method of the 178cdf0e10cSrcweir regression curve. 179cdf0e10cSrcweir 180cdf0e10cSrcweir The first sequence having the role "values-y" will be used as y-values 181cdf0e10cSrcweir for the recalculateRegression() method of the regression curve. 182cdf0e10cSrcweir 183cdf0e10cSrcweir @param bUseXValuesIfAvailable 184cdf0e10cSrcweir If false, the sequence (1, 2, 3, ...) will always be used, even if 185cdf0e10cSrcweir there is a data-sequence with role "values-x" 186cdf0e10cSrcweir */ 187cdf0e10cSrcweir SAL_DLLPRIVATE static void initializeCurveCalculator( 188cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 189cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveCalculator > & xOutCurveCalculator, 190cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 191cdf0e10cSrcweir ::com::sun::star::chart2::data::XDataSource > & xSource, 192cdf0e10cSrcweir bool bUseXValuesIfAvailable = true ); 193cdf0e10cSrcweir 194cdf0e10cSrcweir /** Same method as above, but uses the given XModel to determine the 195cdf0e10cSrcweir parameter bUseXValuesIfAvailable in the above function. It is also 196cdf0e10cSrcweir necessary that the data::XDataSource is an XDataSeries, thus this parameter 197cdf0e10cSrcweir also changed. 198cdf0e10cSrcweir */ 199cdf0e10cSrcweir static void initializeCurveCalculator( 200cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 201cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveCalculator > & xOutCurveCalculator, 202cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 203cdf0e10cSrcweir ::com::sun::star::chart2::XDataSeries > & xSeries, 204cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 205cdf0e10cSrcweir ::com::sun::star::frame::XModel > & xModel ); 206cdf0e10cSrcweir 207cdf0e10cSrcweir static ::rtl::OUString getUINameForRegressionCurve( const ::com::sun::star::uno::Reference< 208cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurve >& xCurve ); 209cdf0e10cSrcweir 210cdf0e10cSrcweir static ::std::vector< ::com::sun::star::uno::Reference< 211cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurve > > getAllRegressionCurvesNotMeanValueLine( 212cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 213cdf0e10cSrcweir ::com::sun::star::chart2::XDiagram > & xDiagram ); 214cdf0e10cSrcweir 215cdf0e10cSrcweir static void resetEquationPosition( const ::com::sun::star::uno::Reference< 216cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurve > & xCurve ); 217cdf0e10cSrcweir 218cdf0e10cSrcweir /// @return the index of the given curve in the given container. -1 if not contained 219cdf0e10cSrcweir static sal_Int32 getRegressionCurveIndex( 220cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 221cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurveContainer > & xContainer, 222cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 223cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurve > & xCurve ); 224cdf0e10cSrcweir 225cdf0e10cSrcweir static bool hasEquation( 226cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 227cdf0e10cSrcweir ::com::sun::star::chart2::XRegressionCurve > & xCurve ); 228cdf0e10cSrcweir 229cdf0e10cSrcweir private: 230cdf0e10cSrcweir // not implemented 231cdf0e10cSrcweir RegressionCurveHelper(); 232cdf0e10cSrcweir }; 233cdf0e10cSrcweir 234cdf0e10cSrcweir } // namespace chart 235cdf0e10cSrcweir 236cdf0e10cSrcweir // CHART2_REGRESSIONCURVEHELPER_HXX 237cdf0e10cSrcweir #endif 238