1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 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> 46 47 using namespace ::com::sun::star; 48 using namespace ::com::sun::star::chart2; 49 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; 57 58 namespace 59 { 60 OUString lcl_getServiceNameForType( ::chart::RegressionCurveHelper::tRegressionType eType ) 61 { 62 OUString aServiceName; 63 switch( eType ) 64 { 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; 81 } 82 return aServiceName; 83 } 84 } // anonymous namespace 85 86 //............................................................................. 87 namespace chart 88 { 89 //............................................................................. 90 91 Reference< XRegressionCurve > RegressionCurveHelper::createMeanValueLine( 92 const Reference< XComponentContext > & xContext ) 93 { 94 return Reference< XRegressionCurve >( 95 new MeanValueRegressionCurve( xContext )); 96 } 97 98 Reference< XRegressionCurve > RegressionCurveHelper::createRegressionCurveByServiceName( 99 const Reference< XComponentContext > & xContext, 100 ::rtl::OUString aServiceName ) 101 { 102 Reference< XRegressionCurve > xResult; 103 104 // todo: use factory methods with service name 105 if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( 106 "com.sun.star.chart2.LinearRegressionCurve" ))) 107 { 108 xResult.set( 109 new LinearRegressionCurve( xContext )); 110 } 111 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( 112 "com.sun.star.chart2.LogarithmicRegressionCurve" ))) 113 { 114 xResult.set( 115 new LogarithmicRegressionCurve( xContext )); 116 } 117 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( 118 "com.sun.star.chart2.ExponentialRegressionCurve" ))) 119 { 120 xResult.set( 121 new ExponentialRegressionCurve( xContext )); 122 } 123 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( 124 "com.sun.star.chart2.PotentialRegressionCurve" ))) 125 { 126 xResult.set( 127 new PotentialRegressionCurve( xContext )); 128 } 129 130 return xResult; 131 } 132 133 // ------------------------------------------------------------ 134 135 Reference< XRegressionCurveCalculator > RegressionCurveHelper::createRegressionCurveCalculatorByServiceName( 136 ::rtl::OUString aServiceName ) 137 { 138 Reference< XRegressionCurveCalculator > xResult; 139 140 // todo: use factory methods with service name 141 if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( 142 "com.sun.star.chart2.MeanValueRegressionCurve" ))) 143 { 144 xResult.set( new MeanValueRegressionCurveCalculator()); 145 } 146 if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( 147 "com.sun.star.chart2.LinearRegressionCurve" ))) 148 { 149 xResult.set( new LinearRegressionCurveCalculator()); 150 } 151 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( 152 "com.sun.star.chart2.LogarithmicRegressionCurve" ))) 153 { 154 xResult.set( new LogarithmicRegressionCurveCalculator()); 155 } 156 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( 157 "com.sun.star.chart2.ExponentialRegressionCurve" ))) 158 { 159 xResult.set( new ExponentialRegressionCurveCalculator()); 160 } 161 else if( aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( 162 "com.sun.star.chart2.PotentialRegressionCurve" ))) 163 { 164 xResult.set( new PotentialRegressionCurveCalculator()); 165 } 166 167 return xResult; 168 } 169 170 void RegressionCurveHelper::initializeCurveCalculator( 171 const Reference< XRegressionCurveCalculator > & xOutCurveCalculator, 172 const Reference< data::XDataSource > & xSource, 173 bool bUseXValuesIfAvailable /* = true */ ) 174 { 175 if( ! (xOutCurveCalculator.is() && 176 xSource.is() )) 177 return; 178 179 Sequence< double > aXValues, aYValues; 180 bool bXValuesFound = false, bYValuesFound = false; 181 182 Sequence< Reference< data::XLabeledDataSequence > > aDataSeqs( xSource->getDataSequences()); 183 sal_Int32 i = 0; 184 for( i=0; 185 ! (bXValuesFound && bYValuesFound) && i<aDataSeqs.getLength(); 186 ++i ) 187 { 188 try 189 { 190 Reference< data::XDataSequence > xSeq( aDataSeqs[i]->getValues()); 191 Reference< XPropertySet > xProp( xSeq, uno::UNO_QUERY_THROW ); 192 ::rtl::OUString aRole; 193 if( xProp->getPropertyValue( 194 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Role" ))) >>= aRole ) 195 { 196 if( bUseXValuesIfAvailable && 197 ! bXValuesFound && 198 aRole.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "values-x" ))) 199 { 200 aXValues = DataSequenceToDoubleSequence( xSeq ); 201 bXValuesFound = true; 202 } 203 else if( ! bYValuesFound && 204 aRole.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "values-y" ))) 205 { 206 aYValues = DataSequenceToDoubleSequence( xSeq ); 207 bYValuesFound = true; 208 } 209 } 210 } 211 catch( Exception & ex ) 212 { 213 ASSERT_EXCEPTION( ex ); 214 } 215 } 216 217 if( ! bXValuesFound && 218 bYValuesFound ) 219 { 220 // initialize with 1, 2, ... 221 //first category (index 0) matches with real number 1.0 222 aXValues.realloc( aYValues.getLength()); 223 for( i=0; i<aXValues.getLength(); ++i ) 224 aXValues[i] = i+1; 225 bXValuesFound = true; 226 } 227 228 if( bXValuesFound && bYValuesFound && 229 aXValues.getLength() > 0 && 230 aYValues.getLength() > 0 ) 231 xOutCurveCalculator->recalculateRegression( aXValues, aYValues ); 232 } 233 234 void RegressionCurveHelper::initializeCurveCalculator( 235 const Reference< XRegressionCurveCalculator > & xOutCurveCalculator, 236 const Reference< XDataSeries > & xSeries, 237 const Reference< frame::XModel > & xModel ) 238 { 239 sal_Int32 nAxisType = ChartTypeHelper::getAxisType( 240 ChartModelHelper::getChartTypeOfSeries( xModel, xSeries ), 0 ); // x-axis 241 242 initializeCurveCalculator( xOutCurveCalculator, 243 uno::Reference< data::XDataSource >( xSeries, uno::UNO_QUERY ), 244 (nAxisType == AxisType::REALNUMBER) ); 245 } 246 247 // ---------------------------------------- 248 249 bool RegressionCurveHelper::hasMeanValueLine( 250 const uno::Reference< XRegressionCurveContainer > & xRegCnt ) 251 { 252 if( !xRegCnt.is()) 253 return false; 254 255 try 256 { 257 uno::Sequence< uno::Reference< XRegressionCurve > > aCurves( 258 xRegCnt->getRegressionCurves()); 259 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i ) 260 { 261 if( isMeanValueLine( aCurves[i] )) 262 return true; 263 } 264 } 265 catch( Exception & ex ) 266 { 267 ASSERT_EXCEPTION( ex ); 268 } 269 270 return false; 271 } 272 273 bool RegressionCurveHelper::isMeanValueLine( 274 const uno::Reference< chart2::XRegressionCurve > & xRegCurve ) 275 { 276 uno::Reference< XServiceName > xServName( xRegCurve, uno::UNO_QUERY ); 277 if( xServName.is() && 278 xServName->getServiceName().equals( 279 C2U( "com.sun.star.chart2.MeanValueRegressionCurve" ))) 280 return true; 281 return false; 282 } 283 284 uno::Reference< chart2::XRegressionCurve > 285 RegressionCurveHelper::getMeanValueLine( 286 const uno::Reference< chart2::XRegressionCurveContainer > & xRegCnt ) 287 { 288 if( xRegCnt.is()) 289 { 290 try 291 { 292 uno::Sequence< uno::Reference< XRegressionCurve > > aCurves( 293 xRegCnt->getRegressionCurves()); 294 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i ) 295 { 296 if( isMeanValueLine( aCurves[i] )) 297 return aCurves[i]; 298 } 299 } 300 catch( Exception & ex ) 301 { 302 ASSERT_EXCEPTION( ex ); 303 } 304 } 305 306 return uno::Reference< chart2::XRegressionCurve >(); 307 } 308 309 void RegressionCurveHelper::addMeanValueLine( 310 uno::Reference< XRegressionCurveContainer > & xRegCnt, 311 const uno::Reference< XComponentContext > & xContext, 312 const uno::Reference< XPropertySet > & xSeriesProp ) 313 { 314 if( !xRegCnt.is() || 315 ::chart::RegressionCurveHelper::hasMeanValueLine( xRegCnt ) ) 316 return; 317 318 // todo: use a valid context 319 uno::Reference< XRegressionCurve > xCurve( createMeanValueLine( xContext )); 320 xRegCnt->addRegressionCurve( xCurve ); 321 322 if( xSeriesProp.is()) 323 { 324 uno::Reference< XPropertySet > xProp( xCurve, uno::UNO_QUERY ); 325 if( xProp.is()) 326 { 327 xProp->setPropertyValue( C2U( "LineColor" ), 328 xSeriesProp->getPropertyValue( C2U( "Color" ))); 329 } 330 } 331 } 332 333 void RegressionCurveHelper::removeMeanValueLine( 334 Reference< XRegressionCurveContainer > & xRegCnt ) 335 { 336 if( !xRegCnt.is()) 337 return; 338 339 try 340 { 341 Sequence< Reference< XRegressionCurve > > aCurves( 342 xRegCnt->getRegressionCurves()); 343 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i ) 344 { 345 if( isMeanValueLine( aCurves[i] )) 346 { 347 xRegCnt->removeRegressionCurve( aCurves[i] ); 348 // attention: the iterator i has become invalid now 349 350 // note: assume that there is only one mean-value curve 351 // to remove multiple mean-value curves remove the break 352 break; 353 } 354 } 355 } 356 catch( Exception & ex ) 357 { 358 ASSERT_EXCEPTION( ex ); 359 } 360 } 361 362 void RegressionCurveHelper::addRegressionCurve( 363 tRegressionType eType, 364 uno::Reference< XRegressionCurveContainer > & xRegCnt, 365 const uno::Reference< XComponentContext > & /* xContext */, 366 const uno::Reference< beans::XPropertySet >& xPropertySource, 367 const uno::Reference< beans::XPropertySet >& xEquationProperties ) 368 { 369 if( !xRegCnt.is() ) 370 return; 371 372 if( eType == REGRESSION_TYPE_NONE ) 373 { 374 OSL_ENSURE(false,"don't create a regression curve of type none"); 375 return; 376 } 377 378 uno::Reference< chart2::XRegressionCurve > xCurve; 379 ::rtl::OUString aServiceName( lcl_getServiceNameForType( eType )); 380 381 if( aServiceName.getLength()) 382 { 383 // todo: use a valid context 384 xCurve.set( createRegressionCurveByServiceName( 385 uno::Reference< uno::XComponentContext >(), aServiceName )); 386 387 if( xEquationProperties.is()) 388 xCurve->setEquationProperties( xEquationProperties ); 389 390 uno::Reference< beans::XPropertySet > xProp( xCurve, uno::UNO_QUERY ); 391 if( xProp.is()) 392 { 393 if( xPropertySource.is()) 394 comphelper::copyProperties( xPropertySource, xProp ); 395 else 396 { 397 uno::Reference< XPropertySet > xSeriesProp( xRegCnt, uno::UNO_QUERY ); 398 if( xSeriesProp.is()) 399 { 400 xProp->setPropertyValue( C2U( "LineColor" ), 401 xSeriesProp->getPropertyValue( C2U( "Color" ))); 402 } 403 // xProp->setPropertyValue( C2U( "LineWidth" ), uno::makeAny( sal_Int32( 100 ))); 404 } 405 } 406 } 407 xRegCnt->addRegressionCurve( xCurve ); 408 } 409 410 /** removes all regression curves that are not of type mean value 411 and returns true, if anything was removed 412 */ 413 bool RegressionCurveHelper::removeAllExceptMeanValueLine( 414 uno::Reference< chart2::XRegressionCurveContainer > & xRegCnt ) 415 { 416 bool bRemovedSomething = false; 417 if( xRegCnt.is()) 418 { 419 try 420 { 421 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves( 422 xRegCnt->getRegressionCurves()); 423 ::std::vector< uno::Reference< chart2::XRegressionCurve > > aCurvesToDelete; 424 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i ) 425 { 426 if( ! isMeanValueLine( aCurves[i] )) 427 { 428 aCurvesToDelete.push_back( aCurves[ i ] ); 429 } 430 } 431 432 for( ::std::vector< uno::Reference< chart2::XRegressionCurve > >::const_iterator aIt = aCurvesToDelete.begin(); 433 aIt != aCurvesToDelete.end(); ++aIt ) 434 { 435 xRegCnt->removeRegressionCurve( *aIt ); 436 bRemovedSomething = true; 437 } 438 } 439 catch( uno::Exception & ex ) 440 { 441 ASSERT_EXCEPTION( ex ); 442 } 443 } 444 return bRemovedSomething; 445 } 446 447 void RegressionCurveHelper::removeEquations( 448 uno::Reference< chart2::XRegressionCurveContainer > & xRegCnt ) 449 { 450 if( xRegCnt.is()) 451 { 452 try 453 { 454 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves( 455 xRegCnt->getRegressionCurves()); 456 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i ) 457 { 458 if( !isMeanValueLine( aCurves[i] ) ) 459 { 460 uno::Reference< chart2::XRegressionCurve > xRegCurve( aCurves[ i ] ); 461 if( xRegCurve.is() ) 462 { 463 uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties() ) ; 464 if( xEqProp.is()) 465 { 466 xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( false )); 467 xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false )); 468 } 469 } 470 } 471 } 472 } 473 catch( uno::Exception & ex ) 474 { 475 ASSERT_EXCEPTION( ex ); 476 } 477 } 478 } 479 480 void RegressionCurveHelper::replaceOrAddCurveAndReduceToOne( 481 tRegressionType eType, 482 uno::Reference< XRegressionCurveContainer > & xRegCnt, 483 const uno::Reference< XComponentContext > & xContext ) 484 { 485 uno::Reference< chart2::XRegressionCurve > xRegressionCurve( getFirstCurveNotMeanValueLine( xRegCnt )); 486 if( ! xRegressionCurve.is()) 487 RegressionCurveHelper::addRegressionCurve( eType, xRegCnt, xContext ); 488 else 489 { 490 OUString aServiceName( lcl_getServiceNameForType( eType )); 491 if( aServiceName.getLength()) 492 { 493 RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCnt ); 494 RegressionCurveHelper::addRegressionCurve( 495 eType, xRegCnt, xContext, 496 Reference< beans::XPropertySet >( xRegressionCurve, uno::UNO_QUERY ), 497 xRegressionCurve->getEquationProperties()); 498 } 499 } 500 } 501 502 uno::Reference< chart2::XRegressionCurve > RegressionCurveHelper::getFirstCurveNotMeanValueLine( 503 const Reference< XRegressionCurveContainer > & xRegCnt ) 504 { 505 if( !xRegCnt.is()) 506 return NULL; 507 508 try 509 { 510 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves( 511 xRegCnt->getRegressionCurves()); 512 ::std::vector< uno::Reference< chart2::XRegressionCurve > > aCurvesToDelete; 513 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i ) 514 { 515 if( ! isMeanValueLine( aCurves[i] )) 516 { 517 return aCurves[ i ]; 518 } 519 } 520 } 521 catch( Exception & ex ) 522 { 523 ASSERT_EXCEPTION( ex ); 524 } 525 526 return NULL; 527 } 528 529 RegressionCurveHelper::tRegressionType RegressionCurveHelper::getRegressionType( 530 const Reference< XRegressionCurve > & xCurve ) 531 { 532 tRegressionType eResult = REGRESSION_TYPE_UNKNOWN; 533 534 try 535 { 536 Reference< lang::XServiceName > xServName( xCurve, uno::UNO_QUERY ); 537 if( xServName.is()) 538 { 539 ::rtl::OUString aServiceName( xServName->getServiceName() ); 540 541 if( aServiceName.equalsAsciiL( 542 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.LinearRegressionCurve" ))) 543 { 544 eResult = REGRESSION_TYPE_LINEAR; 545 } 546 else if( aServiceName.equalsAsciiL( 547 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.LogarithmicRegressionCurve" ))) 548 { 549 eResult = REGRESSION_TYPE_LOG; 550 } 551 else if( aServiceName.equalsAsciiL( 552 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ExponentialRegressionCurve" ))) 553 { 554 eResult = REGRESSION_TYPE_EXP; 555 } 556 else if( aServiceName.equalsAsciiL( 557 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.PotentialRegressionCurve" ))) 558 { 559 eResult = REGRESSION_TYPE_POWER; 560 } 561 else if( aServiceName.equalsAsciiL( 562 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.MeanValueRegressionCurve" ))) 563 { 564 eResult = REGRESSION_TYPE_MEAN_VALUE; 565 } 566 } 567 } 568 catch( Exception & ex ) 569 { 570 ASSERT_EXCEPTION( ex ); 571 } 572 573 return eResult; 574 } 575 576 RegressionCurveHelper::tRegressionType RegressionCurveHelper::getFirstRegressTypeNotMeanValueLine( 577 const Reference< XRegressionCurveContainer > & xRegCnt ) 578 { 579 tRegressionType eResult = REGRESSION_TYPE_NONE; 580 581 if( xRegCnt.is()) 582 { 583 Sequence< Reference< XRegressionCurve > > aCurves( 584 xRegCnt->getRegressionCurves()); 585 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i ) 586 { 587 tRegressionType eType = getRegressionType( aCurves[i] ); 588 if( eType != REGRESSION_TYPE_MEAN_VALUE && 589 eType != REGRESSION_TYPE_UNKNOWN ) 590 { 591 eResult = eType; 592 break; 593 } 594 } 595 } 596 597 return eResult; 598 } 599 600 OUString RegressionCurveHelper::getUINameForRegressionCurve( const Reference< XRegressionCurve >& xRegressionCurve ) 601 { 602 OUString aResult; 603 Reference< lang::XServiceName > xServiceName( xRegressionCurve, uno::UNO_QUERY ); 604 if( ! xServiceName.is()) 605 return aResult; 606 607 OUString aServiceName( xServiceName->getServiceName()); 608 if( aServiceName.equalsAsciiL( 609 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.MeanValueRegressionCurve" ))) 610 { 611 aResult = ::chart::SchResId::getResString( STR_REGRESSION_MEAN ); 612 } 613 else if( aServiceName.equalsAsciiL( 614 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.LinearRegressionCurve" ))) 615 { 616 aResult = ::chart::SchResId::getResString( STR_REGRESSION_LINEAR ); 617 } 618 else if( aServiceName.equalsAsciiL( 619 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.LogarithmicRegressionCurve" ))) 620 { 621 aResult = ::chart::SchResId::getResString( STR_REGRESSION_LOG ); 622 } 623 else if( aServiceName.equalsAsciiL( 624 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ExponentialRegressionCurve" ))) 625 { 626 aResult = ::chart::SchResId::getResString( STR_REGRESSION_EXP ); 627 } 628 else if( aServiceName.equalsAsciiL( 629 RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.PotentialRegressionCurve" ))) 630 { 631 aResult = ::chart::SchResId::getResString( STR_REGRESSION_POWER ); 632 } 633 634 return aResult; 635 } 636 637 ::std::vector< Reference< chart2::XRegressionCurve > > 638 RegressionCurveHelper::getAllRegressionCurvesNotMeanValueLine( 639 const Reference< chart2::XDiagram > & xDiagram ) 640 { 641 ::std::vector< Reference< chart2::XRegressionCurve > > aResult; 642 ::std::vector< Reference< chart2::XDataSeries > > aSeries( DiagramHelper::getDataSeriesFromDiagram( xDiagram )); 643 for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeries.begin()); 644 aIt != aSeries.end(); ++aIt ) 645 { 646 Reference< chart2::XRegressionCurveContainer > xCurveCnt( *aIt, uno::UNO_QUERY ); 647 if( xCurveCnt.is()) 648 { 649 uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves( 650 xCurveCnt->getRegressionCurves()); 651 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i ) 652 { 653 if( ! isMeanValueLine( aCurves[i] )) 654 aResult.push_back( aCurves[i] ); 655 } 656 } 657 } 658 659 return aResult; 660 } 661 662 void RegressionCurveHelper::resetEquationPosition( 663 const Reference< chart2::XRegressionCurve > & xCurve ) 664 { 665 if( xCurve.is()) 666 { 667 try 668 { 669 const OUString aPosPropertyName( RTL_CONSTASCII_USTRINGPARAM( "RelativePosition" )); 670 Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); // since m233: , uno::UNO_SET_THROW ); 671 if( xEqProp->getPropertyValue( aPosPropertyName ).hasValue()) 672 xEqProp->setPropertyValue( aPosPropertyName, uno::Any()); 673 } 674 catch( const uno::Exception & ex ) 675 { 676 ASSERT_EXCEPTION( ex ); 677 } 678 } 679 } 680 681 sal_Int32 RegressionCurveHelper::getRegressionCurveIndex( 682 const Reference< chart2::XRegressionCurveContainer > & xContainer, 683 const Reference< chart2::XRegressionCurve > & xCurve ) 684 { 685 if( xContainer.is()) 686 { 687 uno::Sequence< uno::Reference< XRegressionCurve > > aCurves( 688 xContainer->getRegressionCurves()); 689 for( sal_Int32 i = 0; i < aCurves.getLength(); ++i ) 690 { 691 if( xCurve == aCurves[i] ) 692 return i; 693 } 694 } 695 return -1; 696 } 697 698 bool RegressionCurveHelper::hasEquation( const Reference< chart2::XRegressionCurve > & xCurve ) 699 { 700 bool bHasEquation = false; 701 if( xCurve.is()) 702 { 703 uno::Reference< beans::XPropertySet > xEquationProp( xCurve->getEquationProperties()); 704 if( xEquationProp.is()) 705 { 706 bool bShowEquation = false; 707 bool bShowCoefficient = false; 708 xEquationProp->getPropertyValue( C2U("ShowEquation")) >>= bShowEquation; 709 xEquationProp->getPropertyValue( C2U("ShowCorrelationCoefficient")) >>= bShowCoefficient; 710 bHasEquation = bShowEquation || bShowCoefficient; 711 } 712 } 713 return bHasEquation; 714 } 715 716 //............................................................................. 717 } //namespace chart 718 //............................................................................. 719