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