merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / tools / RegressionCurveHelper.cxx
blobb553dbc2d217fae7606f4798472fa8a0f67994da
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "RegressionCurveHelper.hxx"
31 #include "MeanValueRegressionCurveCalculator.hxx"
32 #include "LinearRegressionCurveCalculator.hxx"
33 #include "LogarithmicRegressionCurveCalculator.hxx"
34 #include "ExponentialRegressionCurveCalculator.hxx"
35 #include "PotentialRegressionCurveCalculator.hxx"
36 #include "CommonConverters.hxx"
37 #include "RegressionCurveModel.hxx"
38 #include "ChartTypeHelper.hxx"
39 #include "ChartModelHelper.hxx"
40 #include "macros.hxx"
41 #include "PropertyHelper.hxx"
42 #include "ResId.hxx"
43 #include "Strings.hrc"
44 #include "DiagramHelper.hxx"
45 #include <com/sun/star/chart2/XChartDocument.hpp>
47 using namespace ::com::sun::star;
48 using namespace ::com::sun::star::chart2;
50 using ::com::sun::star::uno::Reference;
51 using ::com::sun::star::uno::Sequence;
52 using ::com::sun::star::uno::XComponentContext;
53 using ::com::sun::star::lang::XServiceName;
54 using ::com::sun::star::beans::XPropertySet;
55 using ::com::sun::star::uno::Exception;
56 using ::rtl::OUString;
58 namespace
60 OUString lcl_getServiceNameForType( ::chart::RegressionCurveHelper::tRegressionType eType )
62 OUString aServiceName;
63 switch( eType )
65 case ::chart::RegressionCurveHelper::REGRESSION_TYPE_LINEAR:
66 aServiceName = C2U( "com.sun.star.chart2.LinearRegressionCurve" );
67 break;
68 case ::chart::RegressionCurveHelper::REGRESSION_TYPE_LOG:
69 aServiceName = C2U( "com.sun.star.chart2.LogarithmicRegressionCurve" );
70 break;
71 case ::chart::RegressionCurveHelper::REGRESSION_TYPE_EXP:
72 aServiceName = C2U( "com.sun.star.chart2.ExponentialRegressionCurve" );
73 break;
74 case ::chart::RegressionCurveHelper::REGRESSION_TYPE_POWER:
75 aServiceName = C2U( "com.sun.star.chart2.PotentialRegressionCurve" );
76 break;
77 default:
78 OSL_ENSURE(false,"unknown regression curve type - use linear instead");
79 aServiceName = C2U( "com.sun.star.chart2.LinearRegressionCurve" );
80 break;
82 return aServiceName;
84 } // anonymous namespace
86 //.............................................................................
87 namespace chart
89 //.............................................................................
91 // static
92 Reference< XRegressionCurve > RegressionCurveHelper::createMeanValueLine(
93 const Reference< XComponentContext > & xContext )
95 return Reference< XRegressionCurve >(
96 new MeanValueRegressionCurve( xContext ));
99 // static
100 Reference< XRegressionCurve > RegressionCurveHelper::createRegressionCurveByServiceName(
101 const Reference< XComponentContext > & xContext,
102 ::rtl::OUString aServiceName )
104 Reference< XRegressionCurve > xResult;
106 // todo: use factory methods with service name
107 if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
108 "com.sun.star.chart2.LinearRegressionCurve" )))
110 xResult.set(
111 new LinearRegressionCurve( xContext ));
113 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
114 "com.sun.star.chart2.LogarithmicRegressionCurve" )))
116 xResult.set(
117 new LogarithmicRegressionCurve( xContext ));
119 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
120 "com.sun.star.chart2.ExponentialRegressionCurve" )))
122 xResult.set(
123 new ExponentialRegressionCurve( xContext ));
125 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
126 "com.sun.star.chart2.PotentialRegressionCurve" )))
128 xResult.set(
129 new PotentialRegressionCurve( xContext ));
132 return xResult;
135 // ------------------------------------------------------------
137 // static
138 Reference< XRegressionCurveCalculator > RegressionCurveHelper::createRegressionCurveCalculatorByServiceName(
139 ::rtl::OUString aServiceName )
141 Reference< XRegressionCurveCalculator > xResult;
143 // todo: use factory methods with service name
144 if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
145 "com.sun.star.chart2.MeanValueRegressionCurve" )))
147 xResult.set( new MeanValueRegressionCurveCalculator());
149 if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
150 "com.sun.star.chart2.LinearRegressionCurve" )))
152 xResult.set( new LinearRegressionCurveCalculator());
154 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
155 "com.sun.star.chart2.LogarithmicRegressionCurve" )))
157 xResult.set( new LogarithmicRegressionCurveCalculator());
159 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
160 "com.sun.star.chart2.ExponentialRegressionCurve" )))
162 xResult.set( new ExponentialRegressionCurveCalculator());
164 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(
165 "com.sun.star.chart2.PotentialRegressionCurve" )))
167 xResult.set( new PotentialRegressionCurveCalculator());
170 return xResult;
173 // static
174 void RegressionCurveHelper::initializeCurveCalculator(
175 const Reference< XRegressionCurveCalculator > & xOutCurveCalculator,
176 const Reference< data::XDataSource > & xSource,
177 bool bUseXValuesIfAvailable /* = true */ )
179 if( ! (xOutCurveCalculator.is() &&
180 xSource.is() ))
181 return;
183 Sequence< double > aXValues, aYValues;
184 bool bXValuesFound = false, bYValuesFound = false;
186 Sequence< Reference< data::XLabeledDataSequence > > aDataSeqs( xSource->getDataSequences());
187 sal_Int32 i = 0;
188 for( i=0;
189 ! (bXValuesFound && bYValuesFound) && i<aDataSeqs.getLength();
190 ++i )
194 Reference< data::XDataSequence > xSeq( aDataSeqs[i]->getValues());
195 Reference< XPropertySet > xProp( xSeq, uno::UNO_QUERY_THROW );
196 ::rtl::OUString aRole;
197 if( xProp->getPropertyValue(
198 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Role" ))) >>= aRole )
200 if( bUseXValuesIfAvailable &&
201 ! bXValuesFound &&
202 aRole.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "values-x" )))
204 aXValues = DataSequenceToDoubleSequence( xSeq );
205 bXValuesFound = true;
207 else if( ! bYValuesFound &&
208 aRole.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "values-y" )))
210 aYValues = DataSequenceToDoubleSequence( xSeq );
211 bYValuesFound = true;
215 catch( Exception & ex )
217 ASSERT_EXCEPTION( ex );
221 if( ! bXValuesFound &&
222 bYValuesFound )
224 // initialize with 1, 2, ...
225 //first category (index 0) matches with real number 1.0
226 aXValues.realloc( aYValues.getLength());
227 for( i=0; i<aXValues.getLength(); ++i )
228 aXValues[i] = i+1;
229 bXValuesFound = true;
232 if( bXValuesFound && bYValuesFound &&
233 aXValues.getLength() > 0 &&
234 aYValues.getLength() > 0 )
235 xOutCurveCalculator->recalculateRegression( aXValues, aYValues );
238 // static
239 void RegressionCurveHelper::initializeCurveCalculator(
240 const Reference< XRegressionCurveCalculator > & xOutCurveCalculator,
241 const Reference< XDataSeries > & xSeries,
242 const Reference< frame::XModel > & xModel )
244 sal_Int32 nAxisType = ChartTypeHelper::getAxisType(
245 ChartModelHelper::getChartTypeOfSeries( xModel, xSeries ), 0 ); // x-axis
247 initializeCurveCalculator( xOutCurveCalculator,
248 uno::Reference< data::XDataSource >( xSeries, uno::UNO_QUERY ),
249 (nAxisType == AxisType::REALNUMBER) );
252 // ----------------------------------------
254 // static
255 bool RegressionCurveHelper::hasMeanValueLine(
256 const uno::Reference< XRegressionCurveContainer > & xRegCnt )
258 if( !xRegCnt.is())
259 return false;
263 uno::Sequence< uno::Reference< XRegressionCurve > > aCurves(
264 xRegCnt->getRegressionCurves());
265 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
267 if( isMeanValueLine( aCurves[i] ))
268 return true;
271 catch( Exception & ex )
273 ASSERT_EXCEPTION( ex );
276 return false;
279 // static
280 bool RegressionCurveHelper::isMeanValueLine(
281 const uno::Reference< chart2::XRegressionCurve > & xRegCurve )
283 uno::Reference< XServiceName > xServName( xRegCurve, uno::UNO_QUERY );
284 if( xServName.is() &&
285 xServName->getServiceName().equals(
286 C2U( "com.sun.star.chart2.MeanValueRegressionCurve" )))
287 return true;
288 return false;
291 // static
292 uno::Reference< chart2::XRegressionCurve >
293 RegressionCurveHelper::getMeanValueLine(
294 const uno::Reference< chart2::XRegressionCurveContainer > & xRegCnt )
296 if( xRegCnt.is())
300 uno::Sequence< uno::Reference< XRegressionCurve > > aCurves(
301 xRegCnt->getRegressionCurves());
302 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
304 if( isMeanValueLine( aCurves[i] ))
305 return aCurves[i];
308 catch( Exception & ex )
310 ASSERT_EXCEPTION( ex );
314 return uno::Reference< chart2::XRegressionCurve >();
317 // static
318 void RegressionCurveHelper::addMeanValueLine(
319 uno::Reference< XRegressionCurveContainer > & xRegCnt,
320 const uno::Reference< XComponentContext > & xContext,
321 const uno::Reference< XPropertySet > & xSeriesProp )
323 if( !xRegCnt.is() ||
324 ::chart::RegressionCurveHelper::hasMeanValueLine( xRegCnt ) )
325 return;
327 // todo: use a valid context
328 uno::Reference< XRegressionCurve > xCurve( createMeanValueLine( xContext ));
329 xRegCnt->addRegressionCurve( xCurve );
331 if( xSeriesProp.is())
333 uno::Reference< XPropertySet > xProp( xCurve, uno::UNO_QUERY );
334 if( xProp.is())
336 xProp->setPropertyValue( C2U( "LineColor" ),
337 xSeriesProp->getPropertyValue( C2U( "Color" )));
342 // static
343 void RegressionCurveHelper::removeMeanValueLine(
344 Reference< XRegressionCurveContainer > & xRegCnt )
346 if( !xRegCnt.is())
347 return;
351 Sequence< Reference< XRegressionCurve > > aCurves(
352 xRegCnt->getRegressionCurves());
353 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
355 if( isMeanValueLine( aCurves[i] ))
357 xRegCnt->removeRegressionCurve( aCurves[i] );
358 // attention: the iterator i has become invalid now
360 // note: assume that there is only one mean-value curve
361 // to remove multiple mean-value curves remove the break
362 break;
366 catch( Exception & ex )
368 ASSERT_EXCEPTION( ex );
372 void RegressionCurveHelper::addRegressionCurve(
373 tRegressionType eType,
374 uno::Reference< XRegressionCurveContainer > & xRegCnt,
375 const uno::Reference< XComponentContext > & /* xContext */,
376 const uno::Reference< beans::XPropertySet >& xPropertySource,
377 const uno::Reference< beans::XPropertySet >& xEquationProperties )
379 if( !xRegCnt.is() )
380 return;
382 if( eType == REGRESSION_TYPE_NONE )
384 OSL_ENSURE(false,"don't create a regression curve of type none");
385 return;
388 uno::Reference< chart2::XRegressionCurve > xCurve;
389 ::rtl::OUString aServiceName( lcl_getServiceNameForType( eType ));
391 if( aServiceName.getLength())
393 // todo: use a valid context
394 xCurve.set( createRegressionCurveByServiceName(
395 uno::Reference< uno::XComponentContext >(), aServiceName ));
397 if( xEquationProperties.is())
398 xCurve->setEquationProperties( xEquationProperties );
400 uno::Reference< beans::XPropertySet > xProp( xCurve, uno::UNO_QUERY );
401 if( xProp.is())
403 if( xPropertySource.is())
404 comphelper::copyProperties( xPropertySource, xProp );
405 else
407 uno::Reference< XPropertySet > xSeriesProp( xRegCnt, uno::UNO_QUERY );
408 if( xSeriesProp.is())
410 xProp->setPropertyValue( C2U( "LineColor" ),
411 xSeriesProp->getPropertyValue( C2U( "Color" )));
413 // xProp->setPropertyValue( C2U( "LineWidth" ), uno::makeAny( sal_Int32( 100 )));
417 xRegCnt->addRegressionCurve( xCurve );
420 /** removes all regression curves that are not of type mean value
421 and returns true, if anything was removed
423 bool RegressionCurveHelper::removeAllExceptMeanValueLine(
424 uno::Reference< chart2::XRegressionCurveContainer > & xRegCnt )
426 bool bRemovedSomething = false;
427 if( xRegCnt.is())
431 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves(
432 xRegCnt->getRegressionCurves());
433 ::std::vector< uno::Reference< chart2::XRegressionCurve > > aCurvesToDelete;
434 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
436 if( ! isMeanValueLine( aCurves[i] ))
438 aCurvesToDelete.push_back( aCurves[ i ] );
442 for( ::std::vector< uno::Reference< chart2::XRegressionCurve > >::const_iterator aIt = aCurvesToDelete.begin();
443 aIt != aCurvesToDelete.end(); ++aIt )
445 xRegCnt->removeRegressionCurve( *aIt );
446 bRemovedSomething = true;
449 catch( uno::Exception & ex )
451 ASSERT_EXCEPTION( ex );
454 return bRemovedSomething;
457 void RegressionCurveHelper::removeEquations(
458 uno::Reference< chart2::XRegressionCurveContainer > & xRegCnt )
460 if( xRegCnt.is())
464 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves(
465 xRegCnt->getRegressionCurves());
466 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
468 if( !isMeanValueLine( aCurves[i] ) )
470 uno::Reference< chart2::XRegressionCurve > xRegCurve( aCurves[ i ] );
471 if( xRegCurve.is() )
473 uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties() ) ;
474 if( xEqProp.is())
476 xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( false ));
477 xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false ));
483 catch( uno::Exception & ex )
485 ASSERT_EXCEPTION( ex );
490 // static
491 void RegressionCurveHelper::replaceOrAddCurveAndReduceToOne(
492 tRegressionType eType,
493 uno::Reference< XRegressionCurveContainer > & xRegCnt,
494 const uno::Reference< XComponentContext > & xContext )
496 uno::Reference< chart2::XRegressionCurve > xRegressionCurve( getFirstCurveNotMeanValueLine( xRegCnt ));
497 if( ! xRegressionCurve.is())
498 RegressionCurveHelper::addRegressionCurve( eType, xRegCnt, xContext );
499 else
501 OUString aServiceName( lcl_getServiceNameForType( eType ));
502 if( aServiceName.getLength())
504 RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCnt );
505 RegressionCurveHelper::addRegressionCurve(
506 eType, xRegCnt, xContext,
507 Reference< beans::XPropertySet >( xRegressionCurve, uno::UNO_QUERY ),
508 xRegressionCurve->getEquationProperties());
513 // static
514 uno::Reference< chart2::XRegressionCurve > RegressionCurveHelper::getFirstCurveNotMeanValueLine(
515 const Reference< XRegressionCurveContainer > & xRegCnt )
517 if( !xRegCnt.is())
518 return NULL;
522 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves(
523 xRegCnt->getRegressionCurves());
524 ::std::vector< uno::Reference< chart2::XRegressionCurve > > aCurvesToDelete;
525 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
527 if( ! isMeanValueLine( aCurves[i] ))
529 return aCurves[ i ];
533 catch( Exception & ex )
535 ASSERT_EXCEPTION( ex );
538 return NULL;
541 // static
542 RegressionCurveHelper::tRegressionType RegressionCurveHelper::getRegressionType(
543 const Reference< XRegressionCurve > & xCurve )
545 tRegressionType eResult = REGRESSION_TYPE_UNKNOWN;
549 Reference< lang::XServiceName > xServName( xCurve, uno::UNO_QUERY );
550 if( xServName.is())
552 ::rtl::OUString aServiceName( xServName->getServiceName() );
554 if( aServiceName.equalsAsciiL(
555 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.LinearRegressionCurve" )))
557 eResult = REGRESSION_TYPE_LINEAR;
559 else if( aServiceName.equalsAsciiL(
560 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.LogarithmicRegressionCurve" )))
562 eResult = REGRESSION_TYPE_LOG;
564 else if( aServiceName.equalsAsciiL(
565 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ExponentialRegressionCurve" )))
567 eResult = REGRESSION_TYPE_EXP;
569 else if( aServiceName.equalsAsciiL(
570 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.PotentialRegressionCurve" )))
572 eResult = REGRESSION_TYPE_POWER;
574 else if( aServiceName.equalsAsciiL(
575 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.MeanValueRegressionCurve" )))
577 eResult = REGRESSION_TYPE_MEAN_VALUE;
581 catch( Exception & ex )
583 ASSERT_EXCEPTION( ex );
586 return eResult;
589 // static
590 RegressionCurveHelper::tRegressionType RegressionCurveHelper::getFirstRegressTypeNotMeanValueLine(
591 const Reference< XRegressionCurveContainer > & xRegCnt )
593 tRegressionType eResult = REGRESSION_TYPE_NONE;
595 if( xRegCnt.is())
597 Sequence< Reference< XRegressionCurve > > aCurves(
598 xRegCnt->getRegressionCurves());
599 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
601 tRegressionType eType = getRegressionType( aCurves[i] );
602 if( eType != REGRESSION_TYPE_MEAN_VALUE &&
603 eType != REGRESSION_TYPE_UNKNOWN )
605 eResult = eType;
606 break;
611 return eResult;
614 OUString RegressionCurveHelper::getUINameForRegressionCurve( const Reference< XRegressionCurve >& xRegressionCurve )
616 OUString aResult;
617 Reference< lang::XServiceName > xServiceName( xRegressionCurve, uno::UNO_QUERY );
618 if( ! xServiceName.is())
619 return aResult;
621 OUString aServiceName( xServiceName->getServiceName());
622 if( aServiceName.equalsAsciiL(
623 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.MeanValueRegressionCurve" )))
625 OSL_ENSURE( false, "Meanvalue lines in legend not supported" );
626 aResult = OUString();
627 // aResult = ::chart::SchResId::getResString( STR_OBJECT_AVERAGE_LINE );
629 else if( aServiceName.equalsAsciiL(
630 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.LinearRegressionCurve" )))
632 aResult = ::chart::SchResId::getResString( STR_REGRESSION_LINEAR );
634 else if( aServiceName.equalsAsciiL(
635 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.LogarithmicRegressionCurve" )))
637 aResult = ::chart::SchResId::getResString( STR_REGRESSION_LOG );
639 else if( aServiceName.equalsAsciiL(
640 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ExponentialRegressionCurve" )))
642 aResult = ::chart::SchResId::getResString( STR_REGRESSION_EXP );
644 else if( aServiceName.equalsAsciiL(
645 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.PotentialRegressionCurve" )))
647 aResult = ::chart::SchResId::getResString( STR_REGRESSION_POWER );
650 return aResult;
653 // static
654 ::std::vector< Reference< chart2::XRegressionCurve > >
655 RegressionCurveHelper::getAllRegressionCurvesNotMeanValueLine(
656 const Reference< chart2::XDiagram > & xDiagram )
658 ::std::vector< Reference< chart2::XRegressionCurve > > aResult;
659 ::std::vector< Reference< chart2::XDataSeries > > aSeries( DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
660 for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeries.begin());
661 aIt != aSeries.end(); ++aIt )
663 Reference< chart2::XRegressionCurveContainer > xCurveCnt( *aIt, uno::UNO_QUERY );
664 if( xCurveCnt.is())
666 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves(
667 xCurveCnt->getRegressionCurves());
668 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
670 if( ! isMeanValueLine( aCurves[i] ))
671 aResult.push_back( aCurves[i] );
676 return aResult;
679 // static
680 void RegressionCurveHelper::resetEquationPosition(
681 const Reference< chart2::XRegressionCurve > & xCurve )
683 if( xCurve.is())
687 const OUString aPosPropertyName( RTL_CONSTASCII_USTRINGPARAM( "RelativePosition" ));
688 Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); // since m233: , uno::UNO_SET_THROW );
689 if( xEqProp->getPropertyValue( aPosPropertyName ).hasValue())
690 xEqProp->setPropertyValue( aPosPropertyName, uno::Any());
692 catch( const uno::Exception & ex )
694 ASSERT_EXCEPTION( ex );
699 sal_Int32 RegressionCurveHelper::getRegressionCurveIndex(
700 const Reference< chart2::XRegressionCurveContainer > & xContainer,
701 const Reference< chart2::XRegressionCurve > & xCurve )
703 if( xContainer.is())
705 uno::Sequence< uno::Reference< XRegressionCurve > > aCurves(
706 xContainer->getRegressionCurves());
707 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
709 if( xCurve == aCurves[i] )
710 return i;
713 return -1;
716 bool RegressionCurveHelper::hasEquation( const Reference< chart2::XRegressionCurve > & xCurve )
718 bool bHasEquation = false;
719 if( xCurve.is())
721 uno::Reference< beans::XPropertySet > xEquationProp( xCurve->getEquationProperties());
722 if( xEquationProp.is())
724 bool bShowEquation = false;
725 bool bShowCoefficient = false;
726 xEquationProp->getPropertyValue( C2U("ShowEquation")) >>= bShowEquation;
727 xEquationProp->getPropertyValue( C2U("ShowCorrelationCoefficient")) >>= bShowCoefficient;
728 bHasEquation = bShowEquation || bShowCoefficient;
731 return bHasEquation;
734 //.............................................................................
735 } //namespace chart
736 //.............................................................................