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