Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "StatisticsItemConverter.hxx"
21 : : #include "SchWhichPairs.hxx"
22 : : #include "macros.hxx"
23 : : #include "RegressionCurveHelper.hxx"
24 : : #include "ItemPropertyMap.hxx"
25 : : #include "ErrorBar.hxx"
26 : : #include "PropertyHelper.hxx"
27 : : #include "ChartModelHelper.hxx"
28 : : #include "ChartTypeHelper.hxx"
29 : : #include "StatisticsHelper.hxx"
30 : :
31 : : #include "GraphicPropertyItemConverter.hxx"
32 : :
33 : : #include <svl/stritem.hxx>
34 : : #include <svx/chrtitem.hxx>
35 : : #include <svl/intitem.hxx>
36 : : #include <rtl/math.hxx>
37 : :
38 : : #include <com/sun/star/chart2/DataPointLabel.hpp>
39 : : #include <com/sun/star/chart2/XInternalDataProvider.hpp>
40 : : #include <com/sun/star/chart/ErrorBarStyle.hpp>
41 : : #include <com/sun/star/lang/XServiceName.hpp>
42 : :
43 : : #include <functional>
44 : : #include <algorithm>
45 : : #include <vector>
46 : :
47 : : using namespace ::com::sun::star;
48 : :
49 : : namespace
50 : : {
51 : :
52 : 0 : uno::Reference< beans::XPropertySet > lcl_GetErrorBar(
53 : : const uno::Reference< beans::XPropertySet > & xProp, bool bYError )
54 : : {
55 : 0 : uno::Reference< beans::XPropertySet > xResult;
56 : :
57 [ # # ]: 0 : if( xProp.is())
58 : : try
59 : : {
60 [ # # ][ # # ]: 0 : ( xProp->getPropertyValue( bYError ? C2U( "ErrorBarY" ) : C2U("ErrorBarX") ) >>= xResult );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
61 : : }
62 [ # # ]: 0 : catch( const uno::Exception & ex )
63 : : {
64 : : ASSERT_EXCEPTION( ex );
65 : : }
66 : :
67 : 0 : return xResult;
68 : : }
69 : :
70 : 0 : ::chart::RegressionCurveHelper::tRegressionType lcl_convertRegressionType( SvxChartRegress eRegress )
71 : : {
72 : 0 : ::chart::RegressionCurveHelper::tRegressionType eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_NONE;
73 [ # # # # : 0 : switch( eRegress )
# # ]
74 : : {
75 : : case CHREGRESS_LINEAR:
76 : 0 : eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LINEAR;
77 : 0 : break;
78 : : case CHREGRESS_LOG:
79 : 0 : eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_LOG;
80 : 0 : break;
81 : : case CHREGRESS_EXP:
82 : 0 : eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_EXP;
83 : 0 : break;
84 : : case CHREGRESS_POWER:
85 : 0 : eType = ::chart::RegressionCurveHelper::REGRESSION_TYPE_POWER;
86 : 0 : break;
87 : : case CHREGRESS_NONE:
88 : 0 : break;
89 : : }
90 : 0 : return eType;
91 : : }
92 : :
93 : :
94 : 0 : uno::Reference< beans::XPropertySet > lcl_GetDefaultErrorBar()
95 : : {
96 : : // todo: use a valid context
97 : : return uno::Reference< beans::XPropertySet >(
98 [ # # ]: 0 : ::chart::createErrorBar( uno::Reference< uno::XComponentContext >()));
99 : : }
100 : :
101 : 0 : void lcl_getErrorValues( const uno::Reference< beans::XPropertySet > & xErrorBarProp,
102 : : double & rOutPosError, double & rOutNegError )
103 : : {
104 [ # # ]: 0 : if( ! xErrorBarProp.is())
105 : 0 : return;
106 : :
107 : : try
108 : : {
109 [ # # ][ # # ]: 0 : xErrorBarProp->getPropertyValue( C2U( "PositiveError" )) >>= rOutPosError;
[ # # ]
110 [ # # ][ # # ]: 0 : xErrorBarProp->getPropertyValue( C2U( "NegativeError" )) >>= rOutNegError;
[ # # ][ # # ]
111 : : }
112 : 0 : catch( const uno::Exception & ex )
113 : : {
114 : : ASSERT_EXCEPTION( ex );
115 : : }
116 : : }
117 : :
118 : 0 : void lcl_getErrorIndicatorValues(
119 : : const uno::Reference< beans::XPropertySet > & xErrorBarProp,
120 : : bool & rOutShowPosError, bool & rOutShowNegError )
121 : : {
122 [ # # ]: 0 : if( ! xErrorBarProp.is())
123 : 0 : return;
124 : :
125 : : try
126 : : {
127 [ # # ][ # # ]: 0 : xErrorBarProp->getPropertyValue( C2U( "ShowPositiveError" )) >>= rOutShowPosError;
[ # # ]
128 [ # # ][ # # ]: 0 : xErrorBarProp->getPropertyValue( C2U( "ShowNegativeError" )) >>= rOutShowNegError;
[ # # ][ # # ]
129 : : }
130 : 0 : catch( const uno::Exception & ex )
131 : : {
132 : : ASSERT_EXCEPTION( ex );
133 : : }
134 : : }
135 : :
136 : 0 : uno::Reference< beans::XPropertySet > lcl_getEquationProperties(
137 : : const uno::Reference< beans::XPropertySet > & xSeriesPropSet, const SfxItemSet * pItemSet )
138 : : {
139 : 0 : bool bEquationExists = true;
140 : :
141 : : // ensure that a trendline is on
142 [ # # ]: 0 : if( pItemSet )
143 : : {
144 : 0 : SvxChartRegress eRegress = CHREGRESS_NONE;
145 : 0 : const SfxPoolItem *pPoolItem = NULL;
146 [ # # ][ # # ]: 0 : if( pItemSet->GetItemState( SCHATTR_REGRESSION_TYPE, sal_True, &pPoolItem ) == SFX_ITEM_SET )
147 : : {
148 : 0 : eRegress = static_cast< const SvxChartRegressItem * >( pPoolItem )->GetValue();
149 : 0 : bEquationExists = ( eRegress != CHREGRESS_NONE );
150 : : }
151 : : }
152 : :
153 [ # # ]: 0 : if( bEquationExists )
154 : : {
155 [ # # ]: 0 : uno::Reference< chart2::XRegressionCurveContainer > xRegCnt( xSeriesPropSet, uno::UNO_QUERY );
156 : : uno::Reference< chart2::XRegressionCurve > xCurve(
157 [ # # ]: 0 : ::chart::RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCnt ));
158 [ # # ]: 0 : if( xCurve.is())
159 : : {
160 [ # # ][ # # ]: 0 : return xCurve->getEquationProperties();
161 [ # # ][ # # ]: 0 : }
162 : : }
163 : :
164 : 0 : return uno::Reference< beans::XPropertySet >();
165 : : }
166 : :
167 : : } // anonymous namespace
168 : :
169 : : namespace chart
170 : : {
171 : : namespace wrapper
172 : : {
173 : :
174 : 0 : StatisticsItemConverter::StatisticsItemConverter(
175 : : const uno::Reference< frame::XModel > & xModel,
176 : : const uno::Reference< beans::XPropertySet > & rPropertySet,
177 : : SfxItemPool& rItemPool ) :
178 : : ItemConverter( rPropertySet, rItemPool ),
179 : 0 : m_xModel( xModel )
180 : : {
181 : : OSL_ASSERT( static_cast< int >( RegressionCurveHelper::REGRESSION_TYPE_NONE ) ==
182 : : static_cast< int >( CHREGRESS_NONE ));
183 : : OSL_ASSERT( static_cast< int >( RegressionCurveHelper::REGRESSION_TYPE_LINEAR ) ==
184 : : static_cast< int >( CHREGRESS_LINEAR ));
185 : : OSL_ASSERT( static_cast< int >( RegressionCurveHelper::REGRESSION_TYPE_LOG ) ==
186 : : static_cast< int >( CHREGRESS_LOG ));
187 : : OSL_ASSERT( static_cast< int >( RegressionCurveHelper::REGRESSION_TYPE_EXP ) ==
188 : : static_cast< int >( CHREGRESS_EXP ));
189 : : OSL_ASSERT( static_cast< int >( RegressionCurveHelper::REGRESSION_TYPE_POWER ) ==
190 : : static_cast< int >( CHREGRESS_POWER ));
191 : 0 : }
192 : :
193 : 0 : StatisticsItemConverter::~StatisticsItemConverter()
194 [ # # ]: 0 : {}
195 : :
196 : 0 : const sal_uInt16 * StatisticsItemConverter::GetWhichPairs() const
197 : : {
198 : : // must span all used items!
199 : 0 : return nStatWhichPairs;
200 : : }
201 : :
202 : 0 : bool StatisticsItemConverter::GetItemProperty(
203 : : tWhichIdType /* nWhichId */,
204 : : tPropertyNameWithMemberId & /* rOutProperty */ ) const
205 : : {
206 : 0 : return false;
207 : : }
208 : :
209 : 0 : bool StatisticsItemConverter::ApplySpecialItem(
210 : : sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
211 : : throw( uno::Exception )
212 : : {
213 : 0 : bool bChanged = false;
214 : 0 : uno::Any aValue;
215 : :
216 [ # # # # : 0 : switch( nWhichId )
# # # # #
# # ]
217 : : {
218 : : case SCHATTR_STAT_AVERAGE:
219 : : {
220 : : uno::Reference< chart2::XRegressionCurveContainer > xRegCnt(
221 [ # # ][ # # ]: 0 : GetPropertySet(), uno::UNO_QUERY );
222 [ # # ]: 0 : bool bOldHasMeanValueLine = RegressionCurveHelper::hasMeanValueLine( xRegCnt );
223 : :
224 : : bool bNewHasMeanValueLine =
225 [ # # ]: 0 : static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
226 : :
227 [ # # ]: 0 : if( bOldHasMeanValueLine != bNewHasMeanValueLine )
228 : : {
229 [ # # ]: 0 : if( ! bNewHasMeanValueLine )
230 [ # # ]: 0 : RegressionCurveHelper::removeMeanValueLine( xRegCnt );
231 : : else
232 : : RegressionCurveHelper::addMeanValueLine(
233 [ # # ][ # # ]: 0 : xRegCnt, uno::Reference< uno::XComponentContext >(), GetPropertySet() );
234 : 0 : bChanged = true;
235 : 0 : }
236 : : }
237 : 0 : break;
238 : :
239 : : // Attention !!! This case must be passed before SCHATTR_STAT_PERCENT,
240 : : // SCHATTR_STAT_BIGERROR, SCHATTR_STAT_CONSTPLUS,
241 : : // SCHATTR_STAT_CONSTMINUS and SCHATTR_STAT_INDICATE
242 : : case SCHATTR_STAT_KIND_ERROR:
243 : : {
244 : : bool bYError =
245 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
246 : :
247 : : uno::Reference< beans::XPropertySet > xErrorBarProp(
248 [ # # ][ # # ]: 0 : lcl_GetErrorBar( GetPropertySet(), bYError ));
249 : :
250 : : SvxChartKindError eErrorKind =
251 : : static_cast< const SvxChartKindErrorItem & >(
252 [ # # ]: 0 : rItemSet.Get( nWhichId )).GetValue();
253 : :
254 [ # # ][ # # ]: 0 : if( !xErrorBarProp.is() && eErrorKind == CHERROR_NONE)
[ # # ]
255 : : {
256 : : //nothing to do
257 : : }
258 : : else
259 : : {
260 : 0 : sal_Int32 nStyle = ::com::sun::star::chart::ErrorBarStyle::NONE;
261 : :
262 [ # # # # : 0 : switch( eErrorKind )
# # # #
# ]
263 : : {
264 : : case CHERROR_NONE:
265 : 0 : nStyle = ::com::sun::star::chart::ErrorBarStyle::NONE; break;
266 : : case CHERROR_VARIANT:
267 : 0 : nStyle = ::com::sun::star::chart::ErrorBarStyle::VARIANCE; break;
268 : : case CHERROR_SIGMA:
269 : 0 : nStyle = ::com::sun::star::chart::ErrorBarStyle::STANDARD_DEVIATION; break;
270 : : case CHERROR_PERCENT:
271 : 0 : nStyle = ::com::sun::star::chart::ErrorBarStyle::RELATIVE; break;
272 : : case CHERROR_BIGERROR:
273 : 0 : nStyle = ::com::sun::star::chart::ErrorBarStyle::ERROR_MARGIN; break;
274 : : case CHERROR_CONST:
275 : 0 : nStyle = ::com::sun::star::chart::ErrorBarStyle::ABSOLUTE; break;
276 : : case CHERROR_STDERROR:
277 : 0 : nStyle = ::com::sun::star::chart::ErrorBarStyle::STANDARD_ERROR; break;
278 : : case CHERROR_RANGE:
279 : 0 : nStyle = ::com::sun::star::chart::ErrorBarStyle::FROM_DATA; break;
280 : : }
281 : :
282 [ # # ]: 0 : if( !xErrorBarProp.is() )
283 : : {
284 [ # # ][ # # ]: 0 : xErrorBarProp = lcl_GetDefaultErrorBar();
285 [ # # ][ # # ]: 0 : GetPropertySet()->setPropertyValue( bYError ? C2U( "ErrorBarY" ) : C2U("ErrorBarX"),
286 [ # # ][ # # ]: 0 : uno::makeAny( xErrorBarProp ));
[ # # ][ # # ]
[ # # ]
287 : : }
288 : :
289 [ # # ]: 0 : xErrorBarProp->setPropertyValue( C2U( "ErrorBarStyle" ),
290 [ # # ][ # # ]: 0 : uno::makeAny( nStyle ));
[ # # ]
291 : 0 : bChanged = true;
292 : 0 : }
293 : : }
294 : 0 : break;
295 : :
296 : : case SCHATTR_STAT_PERCENT:
297 : : case SCHATTR_STAT_BIGERROR:
298 : : {
299 : : OSL_FAIL( "Deprectaed item" );
300 : : bool bYError =
301 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
302 : :
303 : : uno::Reference< beans::XPropertySet > xErrorBarProp(
304 [ # # ][ # # ]: 0 : lcl_GetErrorBar( GetPropertySet(), bYError));
305 : 0 : bool bOldHasErrorBar = xErrorBarProp.is();
306 : :
307 : : double fValue =
308 : : static_cast< const SvxDoubleItem & >(
309 [ # # ]: 0 : rItemSet.Get( nWhichId )).GetValue();
310 : : double fPos, fNeg;
311 [ # # ]: 0 : lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
312 : :
313 [ # # # # ]: 0 : if( bOldHasErrorBar &&
[ # # ]
314 : 0 : ! ( ::rtl::math::approxEqual( fPos, fValue ) &&
315 [ # # ]: 0 : ::rtl::math::approxEqual( fNeg, fValue )))
316 : : {
317 [ # # ]: 0 : xErrorBarProp->setPropertyValue( C2U( "PositiveError" ),
318 [ # # ][ # # ]: 0 : uno::makeAny( fValue ));
[ # # ]
319 [ # # ]: 0 : xErrorBarProp->setPropertyValue( C2U( "NegativeError" ),
320 [ # # ][ # # ]: 0 : uno::makeAny( fValue ));
[ # # ]
321 : 0 : bChanged = true;
322 : 0 : }
323 : : }
324 : 0 : break;
325 : :
326 : : case SCHATTR_STAT_CONSTPLUS:
327 : : {
328 : : bool bYError =
329 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
330 : :
331 : : uno::Reference< beans::XPropertySet > xErrorBarProp(
332 [ # # ][ # # ]: 0 : lcl_GetErrorBar( GetPropertySet(),bYError));
333 : 0 : bool bOldHasErrorBar = xErrorBarProp.is();
334 : :
335 : : double fValue =
336 : : static_cast< const SvxDoubleItem & >(
337 [ # # ]: 0 : rItemSet.Get( nWhichId )).GetValue();
338 : : double fPos, fNeg;
339 [ # # ]: 0 : lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
340 : :
341 [ # # # # ]: 0 : if( bOldHasErrorBar &&
[ # # ]
342 : 0 : ! ::rtl::math::approxEqual( fPos, fValue ))
343 : : {
344 [ # # ][ # # ]: 0 : xErrorBarProp->setPropertyValue( C2U( "PositiveError" ), uno::makeAny( fValue ));
[ # # ][ # # ]
345 : 0 : bChanged = true;
346 : 0 : }
347 : : }
348 : 0 : break;
349 : :
350 : : case SCHATTR_STAT_CONSTMINUS:
351 : : {
352 : : bool bYError =
353 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
354 : : uno::Reference< beans::XPropertySet > xErrorBarProp(
355 [ # # ][ # # ]: 0 : lcl_GetErrorBar( GetPropertySet(),bYError));
356 : 0 : bool bOldHasErrorBar = xErrorBarProp.is();
357 : :
358 : : double fValue =
359 : : static_cast< const SvxDoubleItem & >(
360 [ # # ]: 0 : rItemSet.Get( nWhichId )).GetValue();
361 : : double fPos, fNeg;
362 [ # # ]: 0 : lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
363 : :
364 [ # # # # ]: 0 : if( bOldHasErrorBar &&
[ # # ]
365 : 0 : ! ::rtl::math::approxEqual( fNeg, fValue ))
366 : : {
367 [ # # ][ # # ]: 0 : xErrorBarProp->setPropertyValue( C2U( "NegativeError" ), uno::makeAny( fValue ));
[ # # ][ # # ]
368 : 0 : bChanged = true;
369 : 0 : }
370 : : }
371 : 0 : break;
372 : :
373 : : case SCHATTR_REGRESSION_TYPE:
374 : : {
375 : : SvxChartRegress eRegress =
376 : : static_cast< const SvxChartRegressItem & >(
377 [ # # ]: 0 : rItemSet.Get( nWhichId )).GetValue();
378 : :
379 : : uno::Reference< chart2::XRegressionCurveContainer > xRegCnt(
380 [ # # ][ # # ]: 0 : GetPropertySet(), uno::UNO_QUERY );
381 : :
382 [ # # ]: 0 : if( eRegress == CHREGRESS_NONE )
383 : : {
384 [ # # ]: 0 : bChanged = RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCnt );
385 : : }
386 : : else
387 : : {
388 : : SvxChartRegress eOldRegress(
389 : : static_cast< SvxChartRegress >(
390 : : static_cast< sal_Int32 >(
391 [ # # ]: 0 : RegressionCurveHelper::getFirstRegressTypeNotMeanValueLine( xRegCnt ))));
392 [ # # ]: 0 : if( eOldRegress != eRegress )
393 : : {
394 : : RegressionCurveHelper::replaceOrAddCurveAndReduceToOne(
395 : : lcl_convertRegressionType( eRegress ), xRegCnt,
396 [ # # ]: 0 : uno::Reference< uno::XComponentContext >());
397 : 0 : bChanged = true;
398 : : }
399 : 0 : }
400 : : }
401 : 0 : break;
402 : :
403 : : case SCHATTR_REGRESSION_SHOW_EQUATION:
404 : : {
405 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
406 [ # # ]: 0 : if( xEqProp.is())
407 : : {
408 : 0 : bool bShowEq = false;
409 [ # # ][ # # ]: 0 : xEqProp->getPropertyValue( C2U("ShowEquation")) >>= bShowEq;
[ # # ]
410 : : bool bNewShowEq =
411 [ # # ]: 0 : static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
412 [ # # ]: 0 : if( bShowEq != bNewShowEq )
413 : : {
414 [ # # ][ # # ]: 0 : xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( bNewShowEq ));
[ # # ][ # # ]
415 : 0 : bChanged = true;
416 : : }
417 : 0 : }
418 : : }
419 : 0 : break;
420 : :
421 : : case SCHATTR_REGRESSION_SHOW_COEFF:
422 : : {
423 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), &rItemSet ));
424 [ # # ]: 0 : if( xEqProp.is())
425 : : {
426 : 0 : bool bShowCoeff = false;
427 [ # # ][ # # ]: 0 : xEqProp->getPropertyValue( C2U("ShowCorrelationCoefficient")) >>= bShowCoeff;
[ # # ]
428 : : bool bNewShowCoeff =
429 [ # # ]: 0 : static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId )).GetValue();
430 [ # # ]: 0 : if( bShowCoeff != bNewShowCoeff )
431 : : {
432 [ # # ][ # # ]: 0 : xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( bNewShowCoeff ));
[ # # ][ # # ]
433 : 0 : bChanged = true;
434 : : }
435 : 0 : }
436 : : }
437 : 0 : break;
438 : :
439 : : case SCHATTR_STAT_INDICATE:
440 : : {
441 : : bool bYError =
442 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
443 : : uno::Reference< beans::XPropertySet > xErrorBarProp(
444 [ # # ][ # # ]: 0 : lcl_GetErrorBar( GetPropertySet(),bYError));
445 : 0 : bool bOldHasErrorBar = xErrorBarProp.is();
446 : :
447 : : SvxChartIndicate eIndicate =
448 : : static_cast< const SvxChartIndicateItem & >(
449 [ # # ]: 0 : rItemSet.Get( nWhichId )).GetValue();
450 : :
451 [ # # ][ # # ]: 0 : bool bNewIndPos = (eIndicate == CHINDICATE_BOTH || eIndicate == CHINDICATE_UP );
452 [ # # ][ # # ]: 0 : bool bNewIndNeg = (eIndicate == CHINDICATE_BOTH || eIndicate == CHINDICATE_DOWN );
453 : :
454 : : bool bShowPos, bShowNeg;
455 [ # # ]: 0 : lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
456 : :
457 [ # # ][ # # ]: 0 : if( bOldHasErrorBar &&
[ # # ]
458 : : ( bShowPos != bNewIndPos ||
459 : : bShowNeg != bNewIndNeg ))
460 : : {
461 [ # # ][ # # ]: 0 : xErrorBarProp->setPropertyValue( C2U( "ShowPositiveError" ), uno::makeAny( bNewIndPos ));
[ # # ][ # # ]
462 [ # # ][ # # ]: 0 : xErrorBarProp->setPropertyValue( C2U( "ShowNegativeError" ), uno::makeAny( bNewIndNeg ));
[ # # ][ # # ]
463 : 0 : bChanged = true;
464 : 0 : }
465 : : }
466 : 0 : break;
467 : :
468 : : case SCHATTR_STAT_RANGE_POS:
469 : : case SCHATTR_STAT_RANGE_NEG:
470 : : {
471 : : const bool bYError =
472 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
473 : : uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(), bYError),
474 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ]
475 [ # # ]: 0 : uno::Reference< chart2::XChartDocument > xChartDoc( m_xModel, uno::UNO_QUERY );
476 : 0 : uno::Reference< chart2::data::XDataProvider > xDataProvider;
477 : :
478 [ # # ]: 0 : if( xChartDoc.is())
479 [ # # ][ # # ]: 0 : xDataProvider.set( xChartDoc->getDataProvider());
[ # # ]
480 [ # # ][ # # ]: 0 : if( xErrorBarSource.is() && xDataProvider.is())
[ # # ]
481 : : {
482 [ # # ][ # # ]: 0 : ::rtl::OUString aNewRange( static_cast< const SfxStringItem & >( rItemSet.Get( nWhichId )).GetValue());
483 : 0 : bool bApplyNewRange = false;
484 : :
485 : 0 : bool bIsPositiveValue( nWhichId == SCHATTR_STAT_RANGE_POS );
486 [ # # ][ # # ]: 0 : if( xChartDoc->hasInternalDataProvider())
[ # # ]
487 : : {
488 [ # # ]: 0 : if( !aNewRange.isEmpty())
489 : : {
490 : : uno::Reference< chart2::data::XDataSequence > xSeq(
491 : : StatisticsHelper::getErrorDataSequenceFromDataSource(
492 [ # # ]: 0 : xErrorBarSource, bIsPositiveValue, bYError ));
493 [ # # ]: 0 : if( ! xSeq.is())
494 : : {
495 : : // no data range for error bars yet => create
496 [ # # ]: 0 : uno::Reference< chart2::XInternalDataProvider > xIntDataProvider( xDataProvider, uno::UNO_QUERY );
497 : : OSL_ASSERT( xIntDataProvider.is());
498 [ # # ]: 0 : if( xIntDataProvider.is())
499 : : {
500 [ # # ][ # # ]: 0 : xIntDataProvider->appendSequence();
501 [ # # ]: 0 : aNewRange = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("last"));
502 : 0 : bApplyNewRange = true;
503 : 0 : }
504 : 0 : }
505 : : }
506 : : }
507 : : else
508 : : {
509 : : uno::Reference< chart2::data::XDataSequence > xSeq(
510 : : StatisticsHelper::getErrorDataSequenceFromDataSource(
511 [ # # ]: 0 : xErrorBarSource, bIsPositiveValue, bYError ));
512 : : bApplyNewRange =
513 [ # # ][ # # ]: 0 : ! ( xSeq.is() && aNewRange.equals( xSeq->getSourceRangeRepresentation()));
[ # # ][ # # ]
[ # # ][ # # ]
514 : : }
515 : :
516 [ # # ]: 0 : if( bApplyNewRange )
517 : : StatisticsHelper::setErrorDataSequence(
518 [ # # ]: 0 : xErrorBarSource, xDataProvider, aNewRange, bIsPositiveValue, bYError );
519 : 0 : }
520 : : }
521 : 0 : break;
522 : : }
523 : :
524 : 0 : return bChanged;
525 : : }
526 : :
527 : 0 : void StatisticsItemConverter::FillSpecialItem(
528 : : sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
529 : : throw( uno::Exception )
530 : : {
531 [ # # # # : 0 : switch( nWhichId )
# # # # #
# # # ]
532 : : {
533 : : case SCHATTR_STAT_AVERAGE:
534 : : rOutItemSet.Put(
535 : : SfxBoolItem( nWhichId,
536 : : RegressionCurveHelper::hasMeanValueLine(
537 : : uno::Reference< chart2::XRegressionCurveContainer >(
538 [ # # ][ # # ]: 0 : GetPropertySet(), uno::UNO_QUERY ))));
[ # # ][ # # ]
[ # # ]
539 : 0 : break;
540 : :
541 : : case SCHATTR_STAT_KIND_ERROR:
542 : : {
543 : : bool bYError =
544 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
545 : 0 : SvxChartKindError eErrorKind = CHERROR_NONE;
546 : : uno::Reference< beans::XPropertySet > xErrorBarProp(
547 [ # # ][ # # ]: 0 : lcl_GetErrorBar( GetPropertySet(), bYError));
548 [ # # ]: 0 : if( xErrorBarProp.is() )
549 : : {
550 : 0 : sal_Int32 nStyle = 0;
551 [ # # ][ # # ]: 0 : if( xErrorBarProp->getPropertyValue( C2U( "ErrorBarStyle" )) >>= nStyle )
[ # # ][ # # ]
552 : : {
553 [ # # # # : 0 : switch( nStyle )
# # # #
# ]
554 : : {
555 : : case ::com::sun::star::chart::ErrorBarStyle::NONE:
556 : 0 : break;
557 : : case ::com::sun::star::chart::ErrorBarStyle::VARIANCE:
558 : 0 : eErrorKind = CHERROR_VARIANT; break;
559 : : case ::com::sun::star::chart::ErrorBarStyle::STANDARD_DEVIATION:
560 : 0 : eErrorKind = CHERROR_SIGMA; break;
561 : : case ::com::sun::star::chart::ErrorBarStyle::ABSOLUTE:
562 : 0 : eErrorKind = CHERROR_CONST; break;
563 : : case ::com::sun::star::chart::ErrorBarStyle::RELATIVE:
564 : 0 : eErrorKind = CHERROR_PERCENT; break;
565 : : case ::com::sun::star::chart::ErrorBarStyle::ERROR_MARGIN:
566 : 0 : eErrorKind = CHERROR_BIGERROR; break;
567 : : case ::com::sun::star::chart::ErrorBarStyle::STANDARD_ERROR:
568 : 0 : eErrorKind = CHERROR_STDERROR; break;
569 : : case ::com::sun::star::chart::ErrorBarStyle::FROM_DATA:
570 : 0 : eErrorKind = CHERROR_RANGE; break;
571 : : }
572 : : }
573 : : }
574 [ # # ][ # # ]: 0 : rOutItemSet.Put( SvxChartKindErrorItem( eErrorKind, SCHATTR_STAT_KIND_ERROR ));
[ # # ]
575 : : }
576 : 0 : break;
577 : :
578 : : case SCHATTR_STAT_PERCENT:
579 : : {
580 : : bool bYError =
581 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
582 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
583 [ # # ]: 0 : if( xErrorBarProp.is())
584 : : {
585 : : double fPos, fNeg;
586 [ # # ]: 0 : lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
587 [ # # ][ # # ]: 0 : rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, nWhichId ));
[ # # ]
588 : 0 : }
589 : : }
590 : 0 : break;
591 : :
592 : : case SCHATTR_STAT_BIGERROR:
593 : : {
594 : : bool bYError =
595 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
596 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
597 [ # # ]: 0 : if( xErrorBarProp.is())
598 : : {
599 : : double fPos, fNeg;
600 [ # # ]: 0 : lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
601 [ # # ][ # # ]: 0 : rOutItemSet.Put( SvxDoubleItem( ( fPos + fNeg ) / 2.0, nWhichId ));
[ # # ]
602 : 0 : }
603 : : }
604 : 0 : break;
605 : :
606 : : case SCHATTR_STAT_CONSTPLUS:
607 : : {
608 : : bool bYError =
609 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
610 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
611 [ # # ]: 0 : if( xErrorBarProp.is())
612 : : {
613 : : double fPos, fNeg;
614 [ # # ]: 0 : lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
615 [ # # ][ # # ]: 0 : rOutItemSet.Put( SvxDoubleItem( fPos, nWhichId ));
[ # # ]
616 : 0 : }
617 : : }
618 : 0 : break;
619 : :
620 : : case SCHATTR_STAT_CONSTMINUS:
621 : : {
622 : : bool bYError =
623 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
624 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
625 [ # # ]: 0 : if( xErrorBarProp.is())
626 : : {
627 : : double fPos, fNeg;
628 [ # # ]: 0 : lcl_getErrorValues( xErrorBarProp, fPos, fNeg );
629 [ # # ][ # # ]: 0 : rOutItemSet.Put( SvxDoubleItem( fNeg, nWhichId ));
[ # # ]
630 : 0 : }
631 : : }
632 : 0 : break;
633 : :
634 : : case SCHATTR_REGRESSION_TYPE:
635 : : {
636 : : SvxChartRegress eRegress = static_cast< SvxChartRegress >(
637 : : static_cast< sal_Int32 >(
638 : : RegressionCurveHelper::getFirstRegressTypeNotMeanValueLine(
639 : : uno::Reference< chart2::XRegressionCurveContainer >(
640 [ # # ][ # # ]: 0 : GetPropertySet(), uno::UNO_QUERY ) )));
641 [ # # ]: 0 : rOutItemSet.Put( SvxChartRegressItem( eRegress, SCHATTR_REGRESSION_TYPE ));
642 : : }
643 : 0 : break;
644 : :
645 : : case SCHATTR_REGRESSION_SHOW_EQUATION:
646 : : {
647 : 0 : bool bShowEq = false;
648 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), 0 ));
649 [ # # ]: 0 : if( xEqProp.is())
650 [ # # ][ # # ]: 0 : xEqProp->getPropertyValue( C2U("ShowEquation")) >>= bShowEq;
[ # # ]
651 [ # # ][ # # ]: 0 : rOutItemSet.Put( SfxBoolItem( nWhichId, bShowEq ));
[ # # ]
652 : : }
653 : 0 : break;
654 : :
655 : : case SCHATTR_REGRESSION_SHOW_COEFF:
656 : : {
657 : 0 : bool bShowCoeff = false;
658 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xEqProp( lcl_getEquationProperties( GetPropertySet(), 0 ));
659 [ # # ]: 0 : if( xEqProp.is())
660 [ # # ][ # # ]: 0 : xEqProp->getPropertyValue( C2U("ShowCorrelationCoefficient")) >>= bShowCoeff;
[ # # ]
661 [ # # ][ # # ]: 0 : rOutItemSet.Put( SfxBoolItem( nWhichId, bShowCoeff ));
[ # # ]
662 : : }
663 : 0 : break;
664 : :
665 : : case SCHATTR_STAT_INDICATE:
666 : : {
667 : : bool bYError =
668 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
669 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xErrorBarProp( lcl_GetErrorBar( GetPropertySet(),bYError));
670 : 0 : SvxChartIndicate eIndicate = CHINDICATE_BOTH;
671 [ # # ]: 0 : if( xErrorBarProp.is())
672 : : {
673 : : bool bShowPos, bShowNeg;
674 [ # # ]: 0 : lcl_getErrorIndicatorValues( xErrorBarProp, bShowPos, bShowNeg );
675 : :
676 [ # # ]: 0 : if( bShowPos )
677 : : {
678 [ # # ]: 0 : if( bShowNeg )
679 : 0 : eIndicate = CHINDICATE_BOTH;
680 : : else
681 : 0 : eIndicate = CHINDICATE_UP;
682 : : }
683 : : else
684 : : {
685 [ # # ]: 0 : if( bShowNeg )
686 : 0 : eIndicate = CHINDICATE_DOWN;
687 : : else
688 : 0 : eIndicate = CHINDICATE_NONE;
689 : : }
690 : : }
691 [ # # ][ # # ]: 0 : rOutItemSet.Put( SvxChartIndicateItem( eIndicate, SCHATTR_STAT_INDICATE ));
[ # # ]
692 : : }
693 : 0 : break;
694 : :
695 : : case SCHATTR_STAT_RANGE_POS:
696 : : case SCHATTR_STAT_RANGE_NEG:
697 : : {
698 : : bool bYError =
699 [ # # ]: 0 : static_cast<const SfxBoolItem&>(rOutItemSet.Get(SCHATTR_STAT_ERRORBAR_TYPE)).GetValue();
700 : : uno::Reference< chart2::data::XDataSource > xErrorBarSource( lcl_GetErrorBar( GetPropertySet(),bYError),
701 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ]
702 [ # # ]: 0 : if( xErrorBarSource.is())
703 : : {
704 : : uno::Reference< chart2::data::XDataSequence > xSeq(
705 : : StatisticsHelper::getErrorDataSequenceFromDataSource(
706 [ # # ]: 0 : xErrorBarSource, (nWhichId == SCHATTR_STAT_RANGE_POS), bYError ));
707 [ # # ]: 0 : if( xSeq.is())
708 [ # # ][ # # ]: 0 : rOutItemSet.Put( SfxStringItem( nWhichId, String( xSeq->getSourceRangeRepresentation())));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
709 : 0 : }
710 : : }
711 : 0 : break;
712 : : }
713 : 0 : }
714 : :
715 : : } // namespace wrapper
716 : : } // namespace chart
717 : :
718 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|