1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RegressionCurveHelper.hxx,v $
10 * $Revision: 1.11.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef CHART2_REGRESSIONCURVEHELPER_HXX
31 #define CHART2_REGRESSIONCURVEHELPER_HXX
33 #include <com/sun/star/chart2/XRegressionCurve.hpp>
34 #include <com/sun/star/chart2/XRegressionCurveCalculator.hpp>
35 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
36 #include <com/sun/star/chart2/data/XDataSource.hpp>
37 #include <com/sun/star/chart2/XDataSeries.hpp>
38 #include <com/sun/star/chart2/XDiagram.hpp>
39 #include <com/sun/star/uno/XComponentContext.hpp>
40 #include <com/sun/star/frame/XModel.hpp>
41 #include "charttoolsdllapi.hxx"
48 class OOO_DLLPUBLIC_CHARTTOOLS RegressionCurveHelper
51 /// returns a model mean-value line
52 SAL_DLLPRIVATE
static ::com::sun::star::uno::Reference
<
53 ::com::sun::star::chart2::XRegressionCurve
>
55 const ::com::sun::star::uno::Reference
<
56 ::com::sun::star::uno::XComponentContext
> & xContext
);
58 /// returns a model regression curve
59 SAL_DLLPRIVATE
static ::com::sun::star::uno::Reference
<
60 ::com::sun::star::chart2::XRegressionCurve
>
61 createRegressionCurveByServiceName(
62 const ::com::sun::star::uno::Reference
<
63 ::com::sun::star::uno::XComponentContext
> & xContext
,
64 ::rtl::OUString aServiceName
);
66 // ------------------------------------------------------------
68 static bool hasMeanValueLine(
69 const ::com::sun::star::uno::Reference
<
70 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
72 static bool isMeanValueLine(
73 const ::com::sun::star::uno::Reference
<
74 ::com::sun::star::chart2::XRegressionCurve
> & xRegCurve
);
76 static ::com::sun::star::uno::Reference
<
77 ::com::sun::star::chart2::XRegressionCurve
>
79 const ::com::sun::star::uno::Reference
<
80 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
82 /** creates a mean-value line and adds it to the container.
85 If set, this property-set will be used to apply a line color
87 static void addMeanValueLine(
88 ::com::sun::star::uno::Reference
<
89 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
,
90 const ::com::sun::star::uno::Reference
<
91 ::com::sun::star::uno::XComponentContext
> & xContext
,
92 const ::com::sun::star::uno::Reference
<
93 ::com::sun::star::beans::XPropertySet
> & xSeriesProp
);
95 static void removeMeanValueLine(
96 ::com::sun::star::uno::Reference
<
97 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
101 REGRESSION_TYPE_NONE
,
102 REGRESSION_TYPE_LINEAR
,
105 REGRESSION_TYPE_POWER
,
106 REGRESSION_TYPE_MEAN_VALUE
,
107 REGRESSION_TYPE_UNKNOWN
110 /** Returns the first regression curve found that is not of type
113 static ::com::sun::star::uno::Reference
<
114 ::com::sun::star::chart2::XRegressionCurve
>
115 getFirstCurveNotMeanValueLine(
116 const ::com::sun::star::uno::Reference
<
117 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
119 /** Returns the type of the first regression curve found that is not of type
122 static tRegressionType
getFirstRegressTypeNotMeanValueLine(
123 const ::com::sun::star::uno::Reference
<
124 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
126 static tRegressionType
getRegressionType(
127 const ::com::sun::star::uno::Reference
<
128 ::com::sun::star::chart2::XRegressionCurve
> & xCurve
);
130 /** @param xPropertySource is taken as source to copy all properties from if
132 @param xEquationProperties is set at the new regression curve as
133 equation properties if not null
135 static void addRegressionCurve( tRegressionType eType
,
136 ::com::sun::star::uno::Reference
<
137 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
,
138 const ::com::sun::star::uno::Reference
<
139 ::com::sun::star::uno::XComponentContext
> & xContext
,
140 const ::com::sun::star::uno::Reference
<
141 ::com::sun::star::beans::XPropertySet
>& xPropertySource
=
142 ::com::sun::star::uno::Reference
<
143 ::com::sun::star::beans::XPropertySet
>(),
144 const ::com::sun::star::uno::Reference
<
145 ::com::sun::star::beans::XPropertySet
>& xEquationProperties
=
146 ::com::sun::star::uno::Reference
<
147 ::com::sun::star::beans::XPropertySet
>()
150 static bool removeAllExceptMeanValueLine(
151 ::com::sun::star::uno::Reference
<
152 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
154 static void removeEquations(
155 ::com::sun::star::uno::Reference
<
156 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
158 /** adds the given regression curve if there was none before. If there are
159 regression curves, the first one is replaced by the one given by the
160 type. All remaining curves are remnoved.
162 <p>This fuction ignores mean-value lines.</p>
164 static void replaceOrAddCurveAndReduceToOne(
165 tRegressionType eType
,
166 ::com::sun::star::uno::Reference
<
167 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
,
168 const ::com::sun::star::uno::Reference
<
169 ::com::sun::star::uno::XComponentContext
> & xContext
);
171 // ------------------------------------------------------------
173 /// returns a calculator object for regression curves (used by the view)
174 static ::com::sun::star::uno::Reference
<
175 ::com::sun::star::chart2::XRegressionCurveCalculator
>
176 createRegressionCurveCalculatorByServiceName(
177 ::rtl::OUString aServiceName
);
179 /** recalculates the regression parameters according to the data given in
182 A sequence having the role "values-x" will be used as x-values for the
183 calculation if found. Otherwise a sequence (1, 2, 3, ...) of category
184 indexes will be used for the recalculateRegression() method of the
187 The first sequence having the role "values-y" will be used as y-values
188 for the recalculateRegression() method of the regression curve.
190 @param bUseXValuesIfAvailable
191 If false, the sequence (1, 2, 3, ...) will always be used, even if
192 there is a data-sequence with role "values-x"
194 SAL_DLLPRIVATE
static void initializeCurveCalculator(
195 const ::com::sun::star::uno::Reference
<
196 ::com::sun::star::chart2::XRegressionCurveCalculator
> & xOutCurveCalculator
,
197 const ::com::sun::star::uno::Reference
<
198 ::com::sun::star::chart2::data::XDataSource
> & xSource
,
199 bool bUseXValuesIfAvailable
= true );
201 /** Same method as above, but uses the given XModel to determine the
202 parameter bUseXValuesIfAvailable in the above function. It is also
203 necessary that the data::XDataSource is an XDataSeries, thus this parameter
206 static void initializeCurveCalculator(
207 const ::com::sun::star::uno::Reference
<
208 ::com::sun::star::chart2::XRegressionCurveCalculator
> & xOutCurveCalculator
,
209 const ::com::sun::star::uno::Reference
<
210 ::com::sun::star::chart2::XDataSeries
> & xSeries
,
211 const ::com::sun::star::uno::Reference
<
212 ::com::sun::star::frame::XModel
> & xModel
);
214 static ::rtl::OUString
getUINameForRegressionCurve( const ::com::sun::star::uno::Reference
<
215 ::com::sun::star::chart2::XRegressionCurve
>& xCurve
);
217 static ::std::vector
< ::com::sun::star::uno::Reference
<
218 ::com::sun::star::chart2::XRegressionCurve
> > getAllRegressionCurvesNotMeanValueLine(
219 const ::com::sun::star::uno::Reference
<
220 ::com::sun::star::chart2::XDiagram
> & xDiagram
);
222 static void resetEquationPosition( const ::com::sun::star::uno::Reference
<
223 ::com::sun::star::chart2::XRegressionCurve
> & xCurve
);
225 /// @return the index of the given curve in the given container. -1 if not contained
226 static sal_Int32
getRegressionCurveIndex(
227 const ::com::sun::star::uno::Reference
<
228 ::com::sun::star::chart2::XRegressionCurveContainer
> & xContainer
,
229 const ::com::sun::star::uno::Reference
<
230 ::com::sun::star::chart2::XRegressionCurve
> & xCurve
);
232 static bool hasEquation(
233 const ::com::sun::star::uno::Reference
<
234 ::com::sun::star::chart2::XRegressionCurve
> & xCurve
);
238 RegressionCurveHelper();
243 // CHART2_REGRESSIONCURVEHELPER_HXX