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 /** adds the given regression curve if there was none before. If there are
155 regression curves, the first one is replaced by the one given by the
156 type. All remaining curves are remnoved.
158 <p>This fuction ignores mean-value lines.</p>
160 static void replaceOrAddCurveAndReduceToOne(
161 tRegressionType eType
,
162 ::com::sun::star::uno::Reference
<
163 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
,
164 const ::com::sun::star::uno::Reference
<
165 ::com::sun::star::uno::XComponentContext
> & xContext
);
167 // ------------------------------------------------------------
169 /// returns a calculator object for regression curves (used by the view)
170 static ::com::sun::star::uno::Reference
<
171 ::com::sun::star::chart2::XRegressionCurveCalculator
>
172 createRegressionCurveCalculatorByServiceName(
173 ::rtl::OUString aServiceName
);
175 /** recalculates the regression parameters according to the data given in
178 A sequence having the role "values-x" will be used as x-values for the
179 calculation if found. Otherwise a sequence (1, 2, 3, ...) of category
180 indexes will be used for the recalculateRegression() method of the
183 The first sequence having the role "values-y" will be used as y-values
184 for the recalculateRegression() method of the regression curve.
186 @param bUseXValuesIfAvailable
187 If false, the sequence (1, 2, 3, ...) will always be used, even if
188 there is a data-sequence with role "values-x"
190 SAL_DLLPRIVATE
static void initializeCurveCalculator(
191 const ::com::sun::star::uno::Reference
<
192 ::com::sun::star::chart2::XRegressionCurveCalculator
> & xOutCurveCalculator
,
193 const ::com::sun::star::uno::Reference
<
194 ::com::sun::star::chart2::data::XDataSource
> & xSource
,
195 bool bUseXValuesIfAvailable
= true );
197 /** Same method as above, but uses the given XModel to determine the
198 parameter bUseXValuesIfAvailable in the above function. It is also
199 necessary that the data::XDataSource is an XDataSeries, thus this parameter
202 static void initializeCurveCalculator(
203 const ::com::sun::star::uno::Reference
<
204 ::com::sun::star::chart2::XRegressionCurveCalculator
> & xOutCurveCalculator
,
205 const ::com::sun::star::uno::Reference
<
206 ::com::sun::star::chart2::XDataSeries
> & xSeries
,
207 const ::com::sun::star::uno::Reference
<
208 ::com::sun::star::frame::XModel
> & xModel
);
210 static ::rtl::OUString
getUINameForRegressionCurve( const ::com::sun::star::uno::Reference
<
211 ::com::sun::star::chart2::XRegressionCurve
>& xCurve
);
213 static ::std::vector
< ::com::sun::star::uno::Reference
<
214 ::com::sun::star::chart2::XRegressionCurve
> > getAllRegressionCurvesNotMeanValueLine(
215 const ::com::sun::star::uno::Reference
<
216 ::com::sun::star::chart2::XDiagram
> & xDiagram
);
218 static void resetEquationPosition( const ::com::sun::star::uno::Reference
<
219 ::com::sun::star::chart2::XRegressionCurve
> & xCurve
);
221 /// @return the index of the given curve in the given container. -1 if not contained
222 static sal_Int32
getRegressionCurveIndex(
223 const ::com::sun::star::uno::Reference
<
224 ::com::sun::star::chart2::XRegressionCurveContainer
> & xContainer
,
225 const ::com::sun::star::uno::Reference
<
226 ::com::sun::star::chart2::XRegressionCurve
> & xCurve
);
230 RegressionCurveHelper();
235 // CHART2_REGRESSIONCURVEHELPER_HXX