1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef CHART2_REGRESSIONCURVEHELPER_HXX
20 #define CHART2_REGRESSIONCURVEHELPER_HXX
22 #include <com/sun/star/chart2/XRegressionCurve.hpp>
23 #include <com/sun/star/chart2/XRegressionCurveCalculator.hpp>
24 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
25 #include <com/sun/star/chart2/data/XDataSource.hpp>
26 #include <com/sun/star/chart2/XDataSeries.hpp>
27 #include <com/sun/star/chart2/XDiagram.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <com/sun/star/frame/XModel.hpp>
30 #include "charttoolsdllapi.hxx"
37 class OOO_DLLPUBLIC_CHARTTOOLS RegressionCurveHelper
40 /// returns a model mean-value line
41 SAL_DLLPRIVATE
static ::com::sun::star::uno::Reference
<
42 ::com::sun::star::chart2::XRegressionCurve
>
44 const ::com::sun::star::uno::Reference
<
45 ::com::sun::star::uno::XComponentContext
> & xContext
);
47 /// returns a model regression curve
48 SAL_DLLPRIVATE
static ::com::sun::star::uno::Reference
<
49 ::com::sun::star::chart2::XRegressionCurve
>
50 createRegressionCurveByServiceName(
51 const ::com::sun::star::uno::Reference
<
52 ::com::sun::star::uno::XComponentContext
> & xContext
,
53 OUString aServiceName
);
55 // ------------------------------------------------------------
57 static bool hasMeanValueLine(
58 const ::com::sun::star::uno::Reference
<
59 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
61 static bool isMeanValueLine(
62 const ::com::sun::star::uno::Reference
<
63 ::com::sun::star::chart2::XRegressionCurve
> & xRegCurve
);
65 static ::com::sun::star::uno::Reference
<
66 ::com::sun::star::chart2::XRegressionCurve
>
68 const ::com::sun::star::uno::Reference
<
69 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
71 /** creates a mean-value line and adds it to the container.
74 If set, this property-set will be used to apply a line color
76 static void addMeanValueLine(
77 ::com::sun::star::uno::Reference
<
78 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
,
79 const ::com::sun::star::uno::Reference
<
80 ::com::sun::star::uno::XComponentContext
> & xContext
,
81 const ::com::sun::star::uno::Reference
<
82 ::com::sun::star::beans::XPropertySet
> & xSeriesProp
);
84 static void removeMeanValueLine(
85 ::com::sun::star::uno::Reference
<
86 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
91 REGRESSION_TYPE_LINEAR
,
94 REGRESSION_TYPE_POWER
,
95 REGRESSION_TYPE_MEAN_VALUE
,
96 REGRESSION_TYPE_UNKNOWN
99 /** Returns the first regression curve found that is not of type
102 static ::com::sun::star::uno::Reference
<
103 ::com::sun::star::chart2::XRegressionCurve
>
104 getFirstCurveNotMeanValueLine(
105 const ::com::sun::star::uno::Reference
<
106 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
108 /** Returns the type of the first regression curve found that is not of type
111 static tRegressionType
getFirstRegressTypeNotMeanValueLine(
112 const ::com::sun::star::uno::Reference
<
113 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
115 static tRegressionType
getRegressionType(
116 const ::com::sun::star::uno::Reference
<
117 ::com::sun::star::chart2::XRegressionCurve
> & xCurve
);
119 /** @param xPropertySource is taken as source to copy all properties from if
121 @param xEquationProperties is set at the new regression curve as
122 equation properties if not null
124 static void addRegressionCurve( tRegressionType eType
,
125 ::com::sun::star::uno::Reference
<
126 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
,
127 const ::com::sun::star::uno::Reference
<
128 ::com::sun::star::uno::XComponentContext
> & xContext
,
129 const ::com::sun::star::uno::Reference
<
130 ::com::sun::star::beans::XPropertySet
>& xPropertySource
=
131 ::com::sun::star::uno::Reference
<
132 ::com::sun::star::beans::XPropertySet
>(),
133 const ::com::sun::star::uno::Reference
<
134 ::com::sun::star::beans::XPropertySet
>& xEquationProperties
=
135 ::com::sun::star::uno::Reference
<
136 ::com::sun::star::beans::XPropertySet
>()
139 static bool removeAllExceptMeanValueLine(
140 ::com::sun::star::uno::Reference
<
141 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
143 static void removeEquations(
144 ::com::sun::star::uno::Reference
<
145 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
);
147 /** adds the given regression curve if there was none before. If there are
148 regression curves, the first one is replaced by the one given by the
149 type. All remaining curves are remnoved.
151 <p>This function ignores mean-value lines.</p>
153 static void replaceOrAddCurveAndReduceToOne(
154 tRegressionType eType
,
155 ::com::sun::star::uno::Reference
<
156 ::com::sun::star::chart2::XRegressionCurveContainer
> & xRegCnt
,
157 const ::com::sun::star::uno::Reference
<
158 ::com::sun::star::uno::XComponentContext
> & xContext
);
160 // ------------------------------------------------------------
162 /// returns a calculator object for regression curves (used by the view)
163 static ::com::sun::star::uno::Reference
<
164 ::com::sun::star::chart2::XRegressionCurveCalculator
>
165 createRegressionCurveCalculatorByServiceName(
166 OUString aServiceName
);
168 /** recalculates the regression parameters according to the data given in
171 A sequence having the role "values-x" will be used as x-values for the
172 calculation if found. Otherwise a sequence (1, 2, 3, ...) of category
173 indexes will be used for the recalculateRegression() method of the
176 The first sequence having the role "values-y" will be used as y-values
177 for the recalculateRegression() method of the regression curve.
179 @param bUseXValuesIfAvailable
180 If false, the sequence (1, 2, 3, ...) will always be used, even if
181 there is a data-sequence with role "values-x"
183 SAL_DLLPRIVATE
static void initializeCurveCalculator(
184 const ::com::sun::star::uno::Reference
<
185 ::com::sun::star::chart2::XRegressionCurveCalculator
> & xOutCurveCalculator
,
186 const ::com::sun::star::uno::Reference
<
187 ::com::sun::star::chart2::data::XDataSource
> & xSource
,
188 bool bUseXValuesIfAvailable
= true );
190 /** Same method as above, but uses the given XModel to determine the
191 parameter bUseXValuesIfAvailable in the above function. It is also
192 necessary that the data::XDataSource is an XDataSeries, thus this parameter
195 static void initializeCurveCalculator(
196 const ::com::sun::star::uno::Reference
<
197 ::com::sun::star::chart2::XRegressionCurveCalculator
> & xOutCurveCalculator
,
198 const ::com::sun::star::uno::Reference
<
199 ::com::sun::star::chart2::XDataSeries
> & xSeries
,
200 const ::com::sun::star::uno::Reference
<
201 ::com::sun::star::frame::XModel
> & xModel
);
203 static OUString
getUINameForRegressionCurve( const ::com::sun::star::uno::Reference
<
204 ::com::sun::star::chart2::XRegressionCurve
>& xCurve
);
206 static ::std::vector
< ::com::sun::star::uno::Reference
<
207 ::com::sun::star::chart2::XRegressionCurve
> > getAllRegressionCurvesNotMeanValueLine(
208 const ::com::sun::star::uno::Reference
<
209 ::com::sun::star::chart2::XDiagram
> & xDiagram
);
211 static void resetEquationPosition( const ::com::sun::star::uno::Reference
<
212 ::com::sun::star::chart2::XRegressionCurve
> & xCurve
);
214 /// @return the index of the given curve in the given container. -1 if not contained
215 static sal_Int32
getRegressionCurveIndex(
216 const ::com::sun::star::uno::Reference
<
217 ::com::sun::star::chart2::XRegressionCurveContainer
> & xContainer
,
218 const ::com::sun::star::uno::Reference
<
219 ::com::sun::star::chart2::XRegressionCurve
> & xCurve
);
221 static bool hasEquation(
222 const ::com::sun::star::uno::Reference
<
223 ::com::sun::star::chart2::XRegressionCurve
> & xCurve
);
227 RegressionCurveHelper();
232 // CHART2_REGRESSIONCURVEHELPER_HXX
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */