Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / tools / RegressionCurveHelper.cxx
blob5d3d41a0a0f020801752a3196607859d0f4d6d22
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <RegressionCurveHelper.hxx>
21 #include <MeanValueRegressionCurveCalculator.hxx>
22 #include <LinearRegressionCurveCalculator.hxx>
23 #include <PolynomialRegressionCurveCalculator.hxx>
24 #include <MovingAverageRegressionCurveCalculator.hxx>
25 #include <LogarithmicRegressionCurveCalculator.hxx>
26 #include <ExponentialRegressionCurveCalculator.hxx>
27 #include <PotentialRegressionCurveCalculator.hxx>
28 #include <CommonConverters.hxx>
29 #include "RegressionCurveModel.hxx"
30 #include <ChartTypeHelper.hxx>
31 #include <ChartModelHelper.hxx>
32 #include <ResId.hxx>
33 #include <strings.hrc>
34 #include <DiagramHelper.hxx>
35 #include <com/sun/star/chart2/AxisType.hpp>
36 #include <com/sun/star/chart2/XRegressionCurveCalculator.hpp>
37 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
38 #include <tools/diagnose_ex.h>
39 #include <comphelper/property.hxx>
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::chart2;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::lang::XServiceName;
47 using ::com::sun::star::beans::XPropertySet;
48 using ::com::sun::star::uno::Exception;
50 namespace
52 OUString lcl_getServiceNameForType(SvxChartRegress eType)
54 OUString aServiceName;
55 switch( eType )
57 case SvxChartRegress::Linear:
58 aServiceName = "com.sun.star.chart2.LinearRegressionCurve";
59 break;
60 case SvxChartRegress::Log:
61 aServiceName = "com.sun.star.chart2.LogarithmicRegressionCurve";
62 break;
63 case SvxChartRegress::Exp:
64 aServiceName = "com.sun.star.chart2.ExponentialRegressionCurve";
65 break;
66 case SvxChartRegress::Power:
67 aServiceName = "com.sun.star.chart2.PotentialRegressionCurve";
68 break;
69 case SvxChartRegress::Polynomial:
70 aServiceName = "com.sun.star.chart2.PolynomialRegressionCurve";
71 break;
72 case SvxChartRegress::MovingAverage:
73 aServiceName = "com.sun.star.chart2.MovingAverageRegressionCurve";
74 break;
75 default:
76 OSL_FAIL("unknown regression curve type - use linear instead");
77 aServiceName = "com.sun.star.chart2.LinearRegressionCurve";
78 break;
80 return aServiceName;
83 } // anonymous namespace
85 namespace chart
88 Reference< XRegressionCurve > RegressionCurveHelper::createMeanValueLine()
90 return Reference< XRegressionCurve >( new MeanValueRegressionCurve );
93 Reference< XRegressionCurve > RegressionCurveHelper::createRegressionCurveByServiceName(
94 const OUString& aServiceName )
96 Reference< XRegressionCurve > xResult;
98 // todo: use factory methods with service name
99 if( aServiceName == "com.sun.star.chart2.LinearRegressionCurve" )
101 xResult.set( new LinearRegressionCurve );
103 else if( aServiceName == "com.sun.star.chart2.LogarithmicRegressionCurve" )
105 xResult.set( new LogarithmicRegressionCurve );
107 else if( aServiceName == "com.sun.star.chart2.ExponentialRegressionCurve" )
109 xResult.set( new ExponentialRegressionCurve );
111 else if( aServiceName == "com.sun.star.chart2.PotentialRegressionCurve" )
113 xResult.set( new PotentialRegressionCurve );
115 else if( aServiceName == "com.sun.star.chart2.PolynomialRegressionCurve" )
117 xResult.set( new PolynomialRegressionCurve );
119 else if( aServiceName == "com.sun.star.chart2.MovingAverageRegressionCurve" )
121 xResult.set( new MovingAverageRegressionCurve );
124 return xResult;
127 Reference< XRegressionCurveCalculator > RegressionCurveHelper::createRegressionCurveCalculatorByServiceName(
128 const OUString& aServiceName )
130 Reference< XRegressionCurveCalculator > xResult;
132 // todo: use factory methods with service name
133 if( aServiceName == "com.sun.star.chart2.MeanValueRegressionCurve" )
135 xResult.set( new MeanValueRegressionCurveCalculator() );
137 if( aServiceName == "com.sun.star.chart2.LinearRegressionCurve" )
139 xResult.set( new LinearRegressionCurveCalculator() );
141 else if( aServiceName == "com.sun.star.chart2.LogarithmicRegressionCurve" )
143 xResult.set( new LogarithmicRegressionCurveCalculator() );
145 else if( aServiceName == "com.sun.star.chart2.ExponentialRegressionCurve" )
147 xResult.set( new ExponentialRegressionCurveCalculator() );
149 else if( aServiceName == "com.sun.star.chart2.PotentialRegressionCurve" )
151 xResult.set( new PotentialRegressionCurveCalculator() );
153 else if( aServiceName == "com.sun.star.chart2.PolynomialRegressionCurve" )
155 xResult.set( new PolynomialRegressionCurveCalculator() );
157 else if( aServiceName == "com.sun.star.chart2.MovingAverageRegressionCurve" )
159 xResult.set( new MovingAverageRegressionCurveCalculator() );
162 return xResult;
165 void RegressionCurveHelper::initializeCurveCalculator(
166 const Reference< XRegressionCurveCalculator > & xOutCurveCalculator,
167 const Reference< data::XDataSource > & xSource,
168 bool bUseXValuesIfAvailable /* = true */ )
170 if( ! (xOutCurveCalculator.is() &&
171 xSource.is() ))
172 return;
174 Sequence< double > aXValues, aYValues;
175 bool bXValuesFound = false, bYValuesFound = false;
177 Sequence< Reference< data::XLabeledDataSequence > > aDataSeqs( xSource->getDataSequences());
178 sal_Int32 i = 0;
179 for( i=0;
180 ! (bXValuesFound && bYValuesFound) && i<aDataSeqs.getLength();
181 ++i )
185 Reference< data::XDataSequence > xSeq( aDataSeqs[i]->getValues());
186 Reference< XPropertySet > xProp( xSeq, uno::UNO_QUERY_THROW );
187 OUString aRole;
188 if( xProp->getPropertyValue( "Role" ) >>= aRole )
190 if( bUseXValuesIfAvailable && !bXValuesFound && aRole == "values-x" )
192 aXValues = DataSequenceToDoubleSequence( xSeq );
193 bXValuesFound = true;
195 else if( !bYValuesFound && aRole == "values-y" )
197 aYValues = DataSequenceToDoubleSequence( xSeq );
198 bYValuesFound = true;
202 catch( const Exception & )
204 DBG_UNHANDLED_EXCEPTION("chart2");
208 if( ! bXValuesFound &&
209 bYValuesFound )
211 // initialize with 1, 2, ...
212 //first category (index 0) matches with real number 1.0
213 aXValues.realloc( aYValues.getLength());
214 for( i=0; i<aXValues.getLength(); ++i )
215 aXValues[i] = i+1;
216 bXValuesFound = true;
219 if( bXValuesFound && bYValuesFound &&
220 aXValues.hasElements() &&
221 aYValues.hasElements() )
222 xOutCurveCalculator->recalculateRegression( aXValues, aYValues );
225 void RegressionCurveHelper::initializeCurveCalculator(
226 const Reference< XRegressionCurveCalculator > & xOutCurveCalculator,
227 const Reference< XDataSeries > & xSeries,
228 const Reference< frame::XModel > & xModel )
230 sal_Int32 nAxisType = ChartTypeHelper::getAxisType(
231 ChartModelHelper::getChartTypeOfSeries( xModel, xSeries ), 0 ); // x-axis
233 initializeCurveCalculator( xOutCurveCalculator,
234 uno::Reference< data::XDataSource >( xSeries, uno::UNO_QUERY ),
235 (nAxisType == AxisType::REALNUMBER) );
238 bool RegressionCurveHelper::hasMeanValueLine(
239 const uno::Reference< XRegressionCurveContainer > & xRegCnt )
241 if( !xRegCnt.is())
242 return false;
246 uno::Sequence< uno::Reference< XRegressionCurve > > aCurves(
247 xRegCnt->getRegressionCurves());
248 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
250 if( isMeanValueLine( aCurves[i] ))
251 return true;
254 catch( const Exception & )
256 DBG_UNHANDLED_EXCEPTION("chart2");
259 return false;
262 bool RegressionCurveHelper::isMeanValueLine(
263 const uno::Reference< chart2::XRegressionCurve > & xRegCurve )
265 uno::Reference< XServiceName > xServName( xRegCurve, uno::UNO_QUERY );
266 return xServName.is() &&
267 xServName->getServiceName() ==
268 "com.sun.star.chart2.MeanValueRegressionCurve";
271 uno::Reference< chart2::XRegressionCurve >
272 RegressionCurveHelper::getMeanValueLine(
273 const uno::Reference< chart2::XRegressionCurveContainer > & xRegCnt )
275 if( xRegCnt.is())
279 uno::Sequence< uno::Reference< XRegressionCurve > > aCurves(
280 xRegCnt->getRegressionCurves());
281 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
283 if( isMeanValueLine( aCurves[i] ))
284 return aCurves[i];
287 catch( const Exception & )
289 DBG_UNHANDLED_EXCEPTION("chart2");
293 return uno::Reference< chart2::XRegressionCurve >();
296 void RegressionCurveHelper::addMeanValueLine(
297 uno::Reference< XRegressionCurveContainer > const & xRegCnt,
298 const uno::Reference< XPropertySet > & xSeriesProp )
300 if( !xRegCnt.is() ||
301 ::chart::RegressionCurveHelper::hasMeanValueLine( xRegCnt ) )
302 return;
304 // todo: use a valid context
305 uno::Reference< XRegressionCurve > xCurve( createMeanValueLine() );
306 xRegCnt->addRegressionCurve( xCurve );
308 if( xSeriesProp.is())
310 uno::Reference< XPropertySet > xProp( xCurve, uno::UNO_QUERY );
311 if( xProp.is())
313 xProp->setPropertyValue( "LineColor",
314 xSeriesProp->getPropertyValue( "Color"));
319 void RegressionCurveHelper::removeMeanValueLine(
320 Reference< XRegressionCurveContainer > const & xRegCnt )
322 if( !xRegCnt.is())
323 return;
327 Sequence< Reference< XRegressionCurve > > aCurves(
328 xRegCnt->getRegressionCurves());
329 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
331 if( isMeanValueLine( aCurves[i] ))
333 xRegCnt->removeRegressionCurve( aCurves[i] );
334 // attention: the iterator i has become invalid now
336 // note: assume that there is only one mean-value curve
337 // to remove multiple mean-value curves remove the break
338 break;
342 catch( const Exception & )
344 DBG_UNHANDLED_EXCEPTION("chart2");
348 uno::Reference< chart2::XRegressionCurve > RegressionCurveHelper::addRegressionCurve(
349 SvxChartRegress eType,
350 uno::Reference< XRegressionCurveContainer > const & xRegressionCurveContainer,
351 const uno::Reference< beans::XPropertySet >& xPropertySource,
352 const uno::Reference< beans::XPropertySet >& xEquationProperties )
354 uno::Reference< chart2::XRegressionCurve > xCurve;
356 if( !xRegressionCurveContainer.is() )
357 return xCurve;
359 if( eType == SvxChartRegress::NONE )
361 OSL_FAIL("don't create a regression curve of type none");
362 return xCurve;
365 OUString aServiceName( lcl_getServiceNameForType( eType ));
366 if( !aServiceName.isEmpty())
368 // todo: use a valid context
369 xCurve.set( createRegressionCurveByServiceName( aServiceName ) );
371 if( xEquationProperties.is())
372 xCurve->setEquationProperties( xEquationProperties );
374 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
375 if( xProperties.is())
377 if( xPropertySource.is())
378 comphelper::copyProperties( xPropertySource, xProperties );
379 else
381 uno::Reference< XPropertySet > xSeriesProp( xRegressionCurveContainer, uno::UNO_QUERY );
382 if( xSeriesProp.is())
384 xProperties->setPropertyValue( "LineColor",
385 xSeriesProp->getPropertyValue( "Color"));
390 xRegressionCurveContainer->addRegressionCurve( xCurve );
392 return xCurve;
395 /** removes all regression curves that are not of type mean value
396 and returns true, if anything was removed
398 bool RegressionCurveHelper::removeAllExceptMeanValueLine(
399 uno::Reference< chart2::XRegressionCurveContainer > const & xRegCnt )
401 bool bRemovedSomething = false;
402 if( xRegCnt.is())
406 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves(
407 xRegCnt->getRegressionCurves());
408 std::vector< uno::Reference< chart2::XRegressionCurve > > aCurvesToDelete;
409 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
411 if( ! isMeanValueLine( aCurves[i] ))
413 aCurvesToDelete.push_back( aCurves[ i ] );
417 for (auto const& curveToDelete : aCurvesToDelete)
419 xRegCnt->removeRegressionCurve(curveToDelete);
420 bRemovedSomething = true;
423 catch( const uno::Exception & )
425 DBG_UNHANDLED_EXCEPTION("chart2");
428 return bRemovedSomething;
431 void RegressionCurveHelper::removeEquations(
432 uno::Reference< chart2::XRegressionCurveContainer > const & xRegCnt )
434 if( xRegCnt.is())
438 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves(
439 xRegCnt->getRegressionCurves());
440 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
442 if( !isMeanValueLine( aCurves[i] ) )
444 uno::Reference< chart2::XRegressionCurve > xRegCurve( aCurves[ i ] );
445 if( xRegCurve.is() )
447 uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties() ) ;
448 if( xEqProp.is())
450 xEqProp->setPropertyValue( "ShowEquation", uno::Any( false ));
451 xEqProp->setPropertyValue( "XName", uno::Any( OUString("x") ));
452 xEqProp->setPropertyValue( "YName", uno::Any( OUString("f(x) ") ));
453 xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( false ));
459 catch( const uno::Exception & )
461 DBG_UNHANDLED_EXCEPTION("chart2");
466 uno::Reference< XRegressionCurve > RegressionCurveHelper::changeRegressionCurveType(
467 SvxChartRegress eType,
468 uno::Reference< XRegressionCurveContainer > const & xRegressionCurveContainer,
469 uno::Reference< XRegressionCurve > const & xRegressionCurve )
471 xRegressionCurveContainer->removeRegressionCurve( xRegressionCurve );
472 return RegressionCurveHelper::addRegressionCurve(
473 eType,
474 xRegressionCurveContainer,
475 uno::Reference< beans::XPropertySet >( xRegressionCurve, uno::UNO_QUERY ),
476 xRegressionCurve->getEquationProperties());
479 uno::Reference< chart2::XRegressionCurve > RegressionCurveHelper::getFirstCurveNotMeanValueLine(
480 const Reference< XRegressionCurveContainer > & xRegCnt )
482 if( !xRegCnt.is())
483 return nullptr;
487 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves(
488 xRegCnt->getRegressionCurves());
489 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
491 if( ! isMeanValueLine( aCurves[i] ))
493 return aCurves[ i ];
497 catch( const Exception & )
499 DBG_UNHANDLED_EXCEPTION("chart2");
502 return nullptr;
505 uno::Reference< chart2::XRegressionCurve > RegressionCurveHelper::getRegressionCurveAtIndex(
506 const Reference< XRegressionCurveContainer >& xCurveContainer,
507 sal_Int32 aIndex )
509 if( !xCurveContainer.is())
510 return nullptr;
514 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves(xCurveContainer->getRegressionCurves());
515 if(0 <= aIndex && aIndex < aCurves.getLength())
517 if(!isMeanValueLine(aCurves[aIndex]))
518 return aCurves[aIndex];
521 catch( const Exception & )
523 DBG_UNHANDLED_EXCEPTION("chart2");
526 return nullptr;
529 SvxChartRegress RegressionCurveHelper::getRegressionType(
530 const Reference< XRegressionCurve > & xCurve )
532 SvxChartRegress eResult = SvxChartRegress::Unknown;
536 Reference< lang::XServiceName > xServName( xCurve, uno::UNO_QUERY );
537 if( xServName.is())
539 OUString aServiceName( xServName->getServiceName() );
541 if( aServiceName == "com.sun.star.chart2.LinearRegressionCurve" )
543 eResult = SvxChartRegress::Linear;
545 else if( aServiceName == "com.sun.star.chart2.LogarithmicRegressionCurve" )
547 eResult = SvxChartRegress::Log;
549 else if( aServiceName == "com.sun.star.chart2.ExponentialRegressionCurve" )
551 eResult = SvxChartRegress::Exp;
553 else if( aServiceName == "com.sun.star.chart2.PotentialRegressionCurve" )
555 eResult = SvxChartRegress::Power;
557 else if( aServiceName == "com.sun.star.chart2.MeanValueRegressionCurve" )
559 eResult = SvxChartRegress::MeanValue;
561 else if( aServiceName == "com.sun.star.chart2.PolynomialRegressionCurve" )
563 eResult = SvxChartRegress::Polynomial;
565 else if( aServiceName == "com.sun.star.chart2.MovingAverageRegressionCurve" )
567 eResult = SvxChartRegress::MovingAverage;
571 catch( const Exception & )
573 DBG_UNHANDLED_EXCEPTION("chart2" );
576 return eResult;
579 SvxChartRegress RegressionCurveHelper::getFirstRegressTypeNotMeanValueLine(
580 const Reference< XRegressionCurveContainer > & xRegCnt )
582 SvxChartRegress eResult = SvxChartRegress::NONE;
584 if( xRegCnt.is())
586 Sequence< Reference< XRegressionCurve > > aCurves(
587 xRegCnt->getRegressionCurves());
588 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
590 SvxChartRegress eType = getRegressionType( aCurves[i] );
591 if( eType != SvxChartRegress::MeanValue &&
592 eType != SvxChartRegress::Unknown )
594 eResult = eType;
595 break;
600 return eResult;
603 OUString RegressionCurveHelper::getUINameForRegressionCurve( const Reference< XRegressionCurve >& xRegressionCurve )
605 OUString aResult = getRegressionCurveSpecificName(xRegressionCurve);
606 if (aResult.isEmpty())
608 aResult = getRegressionCurveGenericName(xRegressionCurve);
609 if (!aResult.isEmpty())
611 aResult += " (%SERIESNAME)";
614 return aResult;
617 OUString RegressionCurveHelper::getRegressionCurveGenericName(const Reference< XRegressionCurve >& xRegressionCurve)
619 OUString aResult;
620 if(!xRegressionCurve.is())
621 return aResult;
623 Reference< lang::XServiceName > xServiceName( xRegressionCurve, uno::UNO_QUERY );
624 if(!xServiceName.is())
625 return aResult;
627 OUString aServiceName(xServiceName->getServiceName());
629 if( aServiceName == "com.sun.star.chart2.MeanValueRegressionCurve" )
631 aResult = SchResId(STR_REGRESSION_MEAN);
633 else if( aServiceName == "com.sun.star.chart2.LinearRegressionCurve" )
635 aResult = SchResId(STR_REGRESSION_LINEAR);
637 else if( aServiceName == "com.sun.star.chart2.LogarithmicRegressionCurve" )
639 aResult = SchResId(STR_REGRESSION_LOG);
641 else if( aServiceName == "com.sun.star.chart2.ExponentialRegressionCurve" )
643 aResult = SchResId(STR_REGRESSION_EXP);
645 else if( aServiceName == "com.sun.star.chart2.PotentialRegressionCurve" )
647 aResult = SchResId(STR_REGRESSION_POWER);
649 else if( aServiceName == "com.sun.star.chart2.PolynomialRegressionCurve" )
651 aResult = SchResId(STR_REGRESSION_POLYNOMIAL);
653 else if( aServiceName == "com.sun.star.chart2.MovingAverageRegressionCurve" )
655 aResult = SchResId(STR_REGRESSION_MOVING_AVERAGE);
657 return aResult;
660 OUString RegressionCurveHelper::getRegressionCurveSpecificName(const Reference< XRegressionCurve >& xRegressionCurve)
662 OUString aResult;
664 if(!xRegressionCurve.is())
665 return aResult;
667 Reference<XPropertySet> xProperties( xRegressionCurve, uno::UNO_QUERY );
668 if(!xProperties.is())
669 return aResult;
671 xProperties->getPropertyValue("CurveName") >>= aResult;
673 return aResult;
676 OUString RegressionCurveHelper::getRegressionCurveName( const Reference< XRegressionCurve >& xRegressionCurve )
678 OUString aResult = getRegressionCurveSpecificName(xRegressionCurve);
679 if (aResult.isEmpty())
680 return getRegressionCurveGenericName(xRegressionCurve);
681 return aResult;
684 std::vector< Reference< chart2::XRegressionCurve > >
685 RegressionCurveHelper::getAllRegressionCurvesNotMeanValueLine(
686 const Reference< chart2::XDiagram > & xDiagram )
688 std::vector< Reference< chart2::XRegressionCurve > > aResult;
689 std::vector< Reference< chart2::XDataSeries > > aSeries( DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
690 for (auto const& elem : aSeries)
692 Reference< chart2::XRegressionCurveContainer > xContainer(elem, uno::UNO_QUERY);
693 if(xContainer.is())
695 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves(xContainer->getRegressionCurves());
696 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
698 if( ! isMeanValueLine( aCurves[i] ))
699 aResult.push_back( aCurves[i] );
704 return aResult;
707 void RegressionCurveHelper::resetEquationPosition(
708 const Reference< chart2::XRegressionCurve > & xCurve )
710 if( xCurve.is())
714 const OUString aPosPropertyName( "RelativePosition" );
715 Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); // since m233: , uno::UNO_SET_THROW );
716 if( xEqProp->getPropertyValue( aPosPropertyName ).hasValue())
717 xEqProp->setPropertyValue( aPosPropertyName, uno::Any());
719 catch( const uno::Exception & )
721 DBG_UNHANDLED_EXCEPTION("chart2" );
726 sal_Int32 RegressionCurveHelper::getRegressionCurveIndex(
727 const Reference< chart2::XRegressionCurveContainer >& xContainer,
728 const Reference< chart2::XRegressionCurve >& xCurve )
730 if( xContainer.is())
732 uno::Sequence< uno::Reference< XRegressionCurve > > aCurves(
733 xContainer->getRegressionCurves());
735 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i )
737 if( xCurve == aCurves[i] )
738 return i;
741 return -1;
744 bool RegressionCurveHelper::hasEquation( const Reference< chart2::XRegressionCurve > & xCurve )
746 bool bHasEquation = false;
747 if( xCurve.is())
749 uno::Reference< beans::XPropertySet > xEquationProp( xCurve->getEquationProperties());
750 if( xEquationProp.is())
752 bool bShowEquation = false;
753 bool bShowCoefficient = false;
754 xEquationProp->getPropertyValue( "ShowEquation") >>= bShowEquation;
755 xEquationProp->getPropertyValue( "ShowCorrelationCoefficient") >>= bShowCoefficient;
756 bHasEquation = bShowEquation || bShowCoefficient;
759 return bHasEquation;
762 } //namespace chart
764 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */