LibreOffice Module chart2 (master) 1
RegressionCurveHelper.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
22#include <cstddef>
23
32#include <CommonConverters.hxx>
34#include <ChartTypeHelper.hxx>
35#include <ChartType.hxx>
36#include <ChartModel.hxx>
37#include <ChartModelHelper.hxx>
38#include <DataSeries.hxx>
39#include <Diagram.hxx>
40#include <ResId.hxx>
41#include <strings.hrc>
42#include <DiagramHelper.hxx>
43#include <com/sun/star/chart2/AxisType.hpp>
44#include <com/sun/star/chart2/XRegressionCurveCalculator.hpp>
45#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
46#include <com/sun/star/chart2/XDataSeries.hpp>
47#include <com/sun/star/chart2/data/XDataSource.hpp>
48#include <o3tl/safeint.hxx>
51
52using namespace ::com::sun::star;
53using namespace ::com::sun::star::chart2;
54
55using ::com::sun::star::uno::Reference;
56using ::com::sun::star::uno::Sequence;
57using ::com::sun::star::lang::XServiceName;
58using ::com::sun::star::beans::XPropertySet;
59using ::com::sun::star::uno::Exception;
60
61namespace
62{
63OUString lcl_getServiceNameForType(SvxChartRegress eType)
64{
65 OUString aServiceName;
66 switch( eType )
67 {
68 case SvxChartRegress::Linear:
69 aServiceName = "com.sun.star.chart2.LinearRegressionCurve";
70 break;
71 case SvxChartRegress::Log:
72 aServiceName = "com.sun.star.chart2.LogarithmicRegressionCurve";
73 break;
74 case SvxChartRegress::Exp:
75 aServiceName = "com.sun.star.chart2.ExponentialRegressionCurve";
76 break;
77 case SvxChartRegress::Power:
78 aServiceName = "com.sun.star.chart2.PotentialRegressionCurve";
79 break;
80 case SvxChartRegress::Polynomial:
81 aServiceName = "com.sun.star.chart2.PolynomialRegressionCurve";
82 break;
83 case SvxChartRegress::MovingAverage:
84 aServiceName = "com.sun.star.chart2.MovingAverageRegressionCurve";
85 break;
86 default:
87 OSL_FAIL("unknown regression curve type - use linear instead");
88 aServiceName = "com.sun.star.chart2.LinearRegressionCurve";
89 break;
90 }
91 return aServiceName;
92}
93
94} // anonymous namespace
95
96namespace chart
97{
98
100{
101 return new MeanValueRegressionCurve;
102}
103
105 std::u16string_view aServiceName )
106{
108
109 // todo: use factory methods with service name
110 if( aServiceName == u"com.sun.star.chart2.LinearRegressionCurve" )
111 {
112 xResult.set( new LinearRegressionCurve );
113 }
114 else if( aServiceName == u"com.sun.star.chart2.LogarithmicRegressionCurve" )
115 {
116 xResult.set( new LogarithmicRegressionCurve );
117 }
118 else if( aServiceName == u"com.sun.star.chart2.ExponentialRegressionCurve" )
119 {
120 xResult.set( new ExponentialRegressionCurve );
121 }
122 else if( aServiceName == u"com.sun.star.chart2.PotentialRegressionCurve" )
123 {
124 xResult.set( new PotentialRegressionCurve );
125 }
126 else if( aServiceName == u"com.sun.star.chart2.PolynomialRegressionCurve" )
127 {
128 xResult.set( new PolynomialRegressionCurve );
129 }
130 else if( aServiceName == u"com.sun.star.chart2.MovingAverageRegressionCurve" )
131 {
132 xResult.set( new MovingAverageRegressionCurve );
133 }
134
135 return xResult;
136}
137
139 std::u16string_view aServiceName )
140{
142
143 // todo: use factory methods with service name
144 if( aServiceName == u"com.sun.star.chart2.MeanValueRegressionCurve" )
145 {
146 xResult.set( new MeanValueRegressionCurveCalculator() );
147 }
148 if( aServiceName == u"com.sun.star.chart2.LinearRegressionCurve" )
149 {
150 xResult.set( new LinearRegressionCurveCalculator() );
151 }
152 else if( aServiceName == u"com.sun.star.chart2.LogarithmicRegressionCurve" )
153 {
154 xResult.set( new LogarithmicRegressionCurveCalculator() );
155 }
156 else if( aServiceName == u"com.sun.star.chart2.ExponentialRegressionCurve" )
157 {
158 xResult.set( new ExponentialRegressionCurveCalculator() );
159 }
160 else if( aServiceName == u"com.sun.star.chart2.PotentialRegressionCurve" )
161 {
162 xResult.set( new PotentialRegressionCurveCalculator() );
163 }
164 else if( aServiceName == u"com.sun.star.chart2.PolynomialRegressionCurve" )
165 {
166 xResult.set( new PolynomialRegressionCurveCalculator() );
167 }
168 else if( aServiceName == u"com.sun.star.chart2.MovingAverageRegressionCurve" )
169 {
170 xResult.set( new MovingAverageRegressionCurveCalculator() );
171 }
172
173 return xResult;
174}
175
177 const Reference< XRegressionCurveCalculator > & xOutCurveCalculator,
178 const Reference< data::XDataSource > & xSource,
179 bool bUseXValuesIfAvailable /* = true */ )
180{
181 if( ! (xOutCurveCalculator.is() &&
182 xSource.is() ))
183 return;
184
185 Sequence< double > aXValues, aYValues;
186 bool bXValuesFound = false, bYValuesFound = false;
187
188 Sequence< Reference< data::XLabeledDataSequence > > aDataSeqs( xSource->getDataSequences());
189 sal_Int32 i = 0;
190 for( i=0;
191 ! (bXValuesFound && bYValuesFound) && i<aDataSeqs.getLength();
192 ++i )
193 {
194 try
195 {
196 Reference< data::XDataSequence > xSeq( aDataSeqs[i]->getValues());
197 Reference< XPropertySet > xProp( xSeq, uno::UNO_QUERY_THROW );
198 OUString aRole;
199 if( xProp->getPropertyValue( "Role" ) >>= aRole )
200 {
201 if( bUseXValuesIfAvailable && !bXValuesFound && aRole == "values-x" )
202 {
203 aXValues = DataSequenceToDoubleSequence( xSeq );
204 bXValuesFound = true;
205 }
206 else if( !bYValuesFound && aRole == "values-y" )
207 {
208 aYValues = DataSequenceToDoubleSequence( xSeq );
209 bYValuesFound = true;
210 }
211 }
212 }
213 catch( const Exception & )
214 {
215 DBG_UNHANDLED_EXCEPTION("chart2");
216 }
217 }
218
219 if( ! bXValuesFound &&
220 bYValuesFound )
221 {
222 // initialize with 1, 2, ...
223 //first category (index 0) matches with real number 1.0
224 aXValues.realloc( aYValues.getLength());
225 auto pXValues = aXValues.getArray();
226 for( i=0; i<aXValues.getLength(); ++i )
227 pXValues[i] = i+1;
228 bXValuesFound = true;
229 }
230
231 if( bXValuesFound && bYValuesFound &&
232 aXValues.hasElements() &&
233 aYValues.hasElements() )
234 xOutCurveCalculator->recalculateRegression( aXValues, aYValues );
235}
236
238 const Reference< XRegressionCurveCalculator > & xOutCurveCalculator,
241{
242 sal_Int32 nAxisType = ChartTypeHelper::getAxisType(
243 ChartModelHelper::getChartTypeOfSeries( xModel, xSeries ), 0 ); // x-axis
244
245 initializeCurveCalculator( xOutCurveCalculator,
246 xSeries,
247 (nAxisType == AxisType::REALNUMBER) );
248}
249
251 const uno::Reference< XRegressionCurveContainer > & xRegCnt )
252{
253 if( !xRegCnt.is())
254 return false;
255
256 try
257 {
258 const uno::Sequence< uno::Reference< XRegressionCurve > > aCurves(
259 xRegCnt->getRegressionCurves());
260 for( uno::Reference< XRegressionCurve > const & curve : aCurves )
261 {
262 if( isMeanValueLine( curve ))
263 return true;
264 }
265 }
266 catch( const Exception & )
267 {
268 DBG_UNHANDLED_EXCEPTION("chart2");
269 }
270
271 return false;
272}
273
275 const rtl::Reference< DataSeries > & xRegCnt )
276{
277 if( !xRegCnt.is())
278 return false;
279
280 try
281 {
282 for( rtl::Reference< RegressionCurveModel > const & curve : xRegCnt->getRegressionCurves2() )
283 {
284 if( isMeanValueLine( curve ))
285 return true;
286 }
287 }
288 catch( const Exception & )
289 {
290 DBG_UNHANDLED_EXCEPTION("chart2");
291 }
292
293 return false;
294}
295
297 const uno::Reference< chart2::XRegressionCurve > & xRegCurve )
298{
299 uno::Reference< XServiceName > xServName( xRegCurve, uno::UNO_QUERY );
300 return xServName.is() &&
301 xServName->getServiceName() ==
302 "com.sun.star.chart2.MeanValueRegressionCurve";
303}
304
307{
308 return xRegCurve.is() &&
309 xRegCurve->getServiceName() ==
310 "com.sun.star.chart2.MeanValueRegressionCurve";
311}
312
315 const uno::Reference< chart2::XRegressionCurveContainer > & xRegCnt )
316{
317 if( xRegCnt.is())
318 {
319 try
320 {
321 const uno::Sequence< uno::Reference< XRegressionCurve > > aCurves(
322 xRegCnt->getRegressionCurves());
323 for( uno::Reference< XRegressionCurve > const & curve : aCurves )
324 {
325 if( isMeanValueLine( curve ))
326 return dynamic_cast<RegressionCurveModel*>(curve.get());
327 }
328 }
329 catch( const Exception & )
330 {
331 DBG_UNHANDLED_EXCEPTION("chart2");
332 }
333 }
334
335 return nullptr;
336}
337
340 const rtl::Reference< DataSeries > & xRegCnt )
341{
342 if( xRegCnt.is())
343 {
344 try
345 {
346 for( rtl::Reference< RegressionCurveModel > const & curve : xRegCnt->getRegressionCurves2() )
347 {
348 if( isMeanValueLine( curve ))
349 return curve;
350 }
351 }
352 catch( const Exception & )
353 {
354 DBG_UNHANDLED_EXCEPTION("chart2");
355 }
356 }
357
358 return nullptr;
359}
360
362 uno::Reference< XRegressionCurveContainer > const & xRegCnt,
363 const uno::Reference< XPropertySet > & xSeriesProp )
364{
365 if( !xRegCnt.is() ||
367 return;
368
369 // todo: use a valid context
370 uno::Reference< XRegressionCurve > xCurve( createMeanValueLine() );
371 xRegCnt->addRegressionCurve( xCurve );
372
373 if( xSeriesProp.is())
374 {
375 uno::Reference< XPropertySet > xProp( xCurve, uno::UNO_QUERY );
376 if( xProp.is())
377 {
378 xProp->setPropertyValue( "LineColor",
379 xSeriesProp->getPropertyValue( "Color"));
380 }
381 }
382}
383
385 rtl::Reference< DataSeries > const & xRegCnt,
386 const uno::Reference< XPropertySet > & xSeriesProp )
387{
388 if( !xRegCnt.is() ||
390 return;
391
392 // todo: use a valid context
394 xRegCnt->addRegressionCurve( xCurve );
395
396 if( xSeriesProp.is())
397 {
398 xCurve->setPropertyValue( "LineColor",
399 xSeriesProp->getPropertyValue( "Color"));
400 }
401}
402
404 Reference< XRegressionCurveContainer > const & xRegCnt )
405{
406 if( !xRegCnt.is())
407 return;
408
409 try
410 {
411 const Sequence< Reference< XRegressionCurve > > aCurves(
412 xRegCnt->getRegressionCurves());
413 for( Reference< XRegressionCurve > const & curve : aCurves )
414 {
415 if( isMeanValueLine( curve ))
416 {
417 xRegCnt->removeRegressionCurve( curve );
418 // attention: the iterator i has become invalid now
419
420 // note: assume that there is only one mean-value curve
421 // to remove multiple mean-value curves remove the break
422 break;
423 }
424 }
425 }
426 catch( const Exception & )
427 {
428 DBG_UNHANDLED_EXCEPTION("chart2");
429 }
430}
431
433 rtl::Reference< DataSeries > const & xRegCnt )
434{
435 if( !xRegCnt.is())
436 return;
437
438 try
439 {
440 for( rtl::Reference< RegressionCurveModel > const & curve : xRegCnt->getRegressionCurves2() )
441 {
442 if( isMeanValueLine( curve ))
443 {
444 xRegCnt->removeRegressionCurve( curve );
445 // attention: the iterator i has become invalid now
446
447 // note: assume that there is only one mean-value curve
448 // to remove multiple mean-value curves remove the break
449 break;
450 }
451 }
452 }
453 catch( const Exception & )
454 {
455 DBG_UNHANDLED_EXCEPTION("chart2");
456 }
457}
458
460 SvxChartRegress eType,
461 uno::Reference< XRegressionCurveContainer > const & xRegressionCurveContainer,
462 const uno::Reference< beans::XPropertySet >& xPropertySource,
463 const uno::Reference< beans::XPropertySet >& xEquationProperties )
464{
466
467 if( !xRegressionCurveContainer.is() )
468 return xCurve;
469
470 if( eType == SvxChartRegress::NONE )
471 {
472 OSL_FAIL("don't create a regression curve of type none");
473 return xCurve;
474 }
475
476 OUString aServiceName( lcl_getServiceNameForType( eType ));
477 if( !aServiceName.isEmpty())
478 {
479 // todo: use a valid context
480 xCurve = createRegressionCurveByServiceName( aServiceName );
481
482 if( xEquationProperties.is())
483 xCurve->setEquationProperties( xEquationProperties );
484
485 if( xPropertySource.is())
486 comphelper::copyProperties( xPropertySource, xCurve );
487 else
488 {
489 uno::Reference< XPropertySet > xSeriesProp( xRegressionCurveContainer, uno::UNO_QUERY );
490 if( xSeriesProp.is())
491 {
492 xCurve->setPropertyValue( "LineColor",
493 xSeriesProp->getPropertyValue( "Color"));
494 }
495 }
496 }
497 xRegressionCurveContainer->addRegressionCurve( xCurve );
498
499 return xCurve;
500}
501
503 SvxChartRegress eType,
504 rtl::Reference< DataSeries > const & xRegressionCurveContainer,
505 const uno::Reference< beans::XPropertySet >& xPropertySource,
506 const uno::Reference< beans::XPropertySet >& xEquationProperties )
507{
509
510 if( !xRegressionCurveContainer.is() )
511 return xCurve;
512
513 if( eType == SvxChartRegress::NONE )
514 {
515 OSL_FAIL("don't create a regression curve of type none");
516 return xCurve;
517 }
518
519 OUString aServiceName( lcl_getServiceNameForType( eType ));
520 if( !aServiceName.isEmpty())
521 {
522 // todo: use a valid context
523 xCurve = createRegressionCurveByServiceName( aServiceName );
524
525 if( xEquationProperties.is())
526 xCurve->setEquationProperties( xEquationProperties );
527
528 if( xPropertySource.is())
529 comphelper::copyProperties( xPropertySource, xCurve );
530 else
531 {
532 xCurve->setPropertyValue( "LineColor",
533 xRegressionCurveContainer->getPropertyValue( "Color"));
534 }
535 }
536 xRegressionCurveContainer->addRegressionCurve( xCurve );
537
538 return xCurve;
539}
540
545 rtl::Reference< DataSeries > const & xRegCnt )
546{
547 if( !xRegCnt.is())
548 return false;
549
550 bool bRemovedSomething = false;
551 try
552 {
553 std::vector< rtl::Reference< RegressionCurveModel > > aCurvesToDelete;
554 for( rtl::Reference< RegressionCurveModel > const & curve : xRegCnt->getRegressionCurves2() )
555 {
556 if( ! isMeanValueLine( curve ))
557 {
558 aCurvesToDelete.push_back( curve );
559 }
560 }
561
562 for (auto const& curveToDelete : aCurvesToDelete)
563 {
564 xRegCnt->removeRegressionCurve(curveToDelete);
565 bRemovedSomething = true;
566 }
567 }
568 catch( const uno::Exception & )
569 {
570 DBG_UNHANDLED_EXCEPTION("chart2");
571 }
572 return bRemovedSomething;
573}
574
576 rtl::Reference< DataSeries > const & xRegCnt )
577{
578 if( !xRegCnt.is())
579 return;
580
581 try
582 {
583 for( rtl::Reference< RegressionCurveModel > const & curve : xRegCnt->getRegressionCurves2() )
584 {
585 if( !isMeanValueLine( curve ) )
586 {
587 uno::Reference< beans::XPropertySet > xEqProp( curve->getEquationProperties() ) ;
588 if( xEqProp.is())
589 {
590 xEqProp->setPropertyValue( "ShowEquation", uno::Any( false ));
591 xEqProp->setPropertyValue( "XName", uno::Any( OUString("x") ));
592 xEqProp->setPropertyValue( "YName", uno::Any( OUString("f(x) ") ));
593 xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( false ));
594 }
595 }
596 }
597 }
598 catch( const uno::Exception & )
599 {
600 DBG_UNHANDLED_EXCEPTION("chart2");
601 }
602}
603
605 SvxChartRegress eType,
606 uno::Reference< XRegressionCurveContainer > const & xRegressionCurveContainer,
607 uno::Reference< XRegressionCurve > const & xRegressionCurve )
608{
609 xRegressionCurveContainer->removeRegressionCurve( xRegressionCurve );
611 eType,
612 xRegressionCurveContainer,
613 uno::Reference< beans::XPropertySet >( xRegressionCurve, uno::UNO_QUERY ),
614 xRegressionCurve->getEquationProperties());
615}
616
618 const Reference< XRegressionCurveContainer > & xRegCnt )
619{
620 if( !xRegCnt.is())
621 return nullptr;
622
623 try
624 {
625 const uno::Sequence< uno::Reference< chart2::XRegressionCurve > > aCurves(
626 xRegCnt->getRegressionCurves());
627 for( uno::Reference< chart2::XRegressionCurve > const & curve : aCurves )
628 {
629 if( ! isMeanValueLine( curve ))
630 {
631 return dynamic_cast<RegressionCurveModel*>(curve.get());
632 }
633 }
634 }
635 catch( const Exception & )
636 {
637 DBG_UNHANDLED_EXCEPTION("chart2");
638 }
639
640 return nullptr;
641}
642
644 const rtl::Reference< DataSeries > & xRegCnt )
645{
646 if( !xRegCnt.is())
647 return nullptr;
648
649 try
650 {
651 for( rtl::Reference< RegressionCurveModel > const & curve : xRegCnt->getRegressionCurves2() )
652 {
653 if( ! isMeanValueLine( curve ))
654 {
655 return curve;
656 }
657 }
658 }
659 catch( const Exception & )
660 {
661 DBG_UNHANDLED_EXCEPTION("chart2");
662 }
663
664 return nullptr;
665}
666
668 const rtl::Reference< DataSeries >& xCurveContainer,
669 sal_Int32 aIndex )
670{
671 if( !xCurveContainer.is())
672 return nullptr;
673
674 try
675 {
676 const std::vector< rtl::Reference< RegressionCurveModel > > aCurves(xCurveContainer->getRegressionCurves2());
677 if(0 <= aIndex && o3tl::make_unsigned(aIndex) < aCurves.size())
678 {
679 if(!isMeanValueLine(aCurves[aIndex]))
680 return aCurves[aIndex];
681 }
682 }
683 catch( const Exception & )
684 {
685 DBG_UNHANDLED_EXCEPTION("chart2");
686 }
687
688 return nullptr;
689}
690
692 const Reference< XRegressionCurve > & xCurve )
693{
694 SvxChartRegress eResult = SvxChartRegress::Unknown;
695
696 try
697 {
698 Reference< lang::XServiceName > xServName( xCurve, uno::UNO_QUERY );
699 if( xServName.is())
700 {
701 OUString aServiceName( xServName->getServiceName() );
702
703 if( aServiceName == "com.sun.star.chart2.LinearRegressionCurve" )
704 {
705 eResult = SvxChartRegress::Linear;
706 }
707 else if( aServiceName == "com.sun.star.chart2.LogarithmicRegressionCurve" )
708 {
709 eResult = SvxChartRegress::Log;
710 }
711 else if( aServiceName == "com.sun.star.chart2.ExponentialRegressionCurve" )
712 {
713 eResult = SvxChartRegress::Exp;
714 }
715 else if( aServiceName == "com.sun.star.chart2.PotentialRegressionCurve" )
716 {
717 eResult = SvxChartRegress::Power;
718 }
719 else if( aServiceName == "com.sun.star.chart2.MeanValueRegressionCurve" )
720 {
721 eResult = SvxChartRegress::MeanValue;
722 }
723 else if( aServiceName == "com.sun.star.chart2.PolynomialRegressionCurve" )
724 {
725 eResult = SvxChartRegress::Polynomial;
726 }
727 else if( aServiceName == "com.sun.star.chart2.MovingAverageRegressionCurve" )
728 {
729 eResult = SvxChartRegress::MovingAverage;
730 }
731 }
732 }
733 catch( const Exception & )
734 {
735 DBG_UNHANDLED_EXCEPTION("chart2" );
736 }
737
738 return eResult;
739}
740
742 const Reference< XRegressionCurveContainer > & xRegCnt )
743{
744 SvxChartRegress eResult = SvxChartRegress::NONE;
745
746 if( xRegCnt.is())
747 {
748 const Sequence< Reference< XRegressionCurve > > aCurves(
749 xRegCnt->getRegressionCurves());
750 for( Reference< XRegressionCurve > const & curve : aCurves )
751 {
753 if( eType != SvxChartRegress::MeanValue &&
754 eType != SvxChartRegress::Unknown )
755 {
756 eResult = eType;
757 break;
758 }
759 }
760 }
761
762 return eResult;
763}
764
765OUString RegressionCurveHelper::getUINameForRegressionCurve( const Reference< XRegressionCurve >& xRegressionCurve )
766{
767 OUString aResult = getRegressionCurveSpecificName(xRegressionCurve);
768 if (aResult.isEmpty())
769 {
770 aResult = getRegressionCurveGenericName(xRegressionCurve);
771 if (!aResult.isEmpty())
772 {
773 aResult += " (%SERIESNAME)";
774 }
775 }
776 return aResult;
777}
778
779OUString RegressionCurveHelper::getRegressionCurveGenericName(const Reference< XRegressionCurve >& xRegressionCurve)
780{
781 OUString aResult;
782 if(!xRegressionCurve.is())
783 return aResult;
784
785 Reference< lang::XServiceName > xServiceName( xRegressionCurve, uno::UNO_QUERY );
786 if(!xServiceName.is())
787 return aResult;
788
789 OUString aServiceName(xServiceName->getServiceName());
790
791 if( aServiceName == "com.sun.star.chart2.MeanValueRegressionCurve" )
792 {
793 aResult = SchResId(STR_REGRESSION_MEAN);
794 }
795 else if( aServiceName == "com.sun.star.chart2.LinearRegressionCurve" )
796 {
797 aResult = SchResId(STR_REGRESSION_LINEAR);
798 }
799 else if( aServiceName == "com.sun.star.chart2.LogarithmicRegressionCurve" )
800 {
801 aResult = SchResId(STR_REGRESSION_LOG);
802 }
803 else if( aServiceName == "com.sun.star.chart2.ExponentialRegressionCurve" )
804 {
805 aResult = SchResId(STR_REGRESSION_EXP);
806 }
807 else if( aServiceName == "com.sun.star.chart2.PotentialRegressionCurve" )
808 {
809 aResult = SchResId(STR_REGRESSION_POWER);
810 }
811 else if( aServiceName == "com.sun.star.chart2.PolynomialRegressionCurve" )
812 {
813 aResult = SchResId(STR_REGRESSION_POLYNOMIAL);
814 }
815 else if( aServiceName == "com.sun.star.chart2.MovingAverageRegressionCurve" )
816 {
817 aResult = SchResId(STR_REGRESSION_MOVING_AVERAGE);
818 }
819 return aResult;
820}
821
822OUString RegressionCurveHelper::getRegressionCurveSpecificName(const Reference< XRegressionCurve >& xRegressionCurve)
823{
824 OUString aResult;
825
826 if(!xRegressionCurve.is())
827 return aResult;
828
829 Reference<XPropertySet> xProperties( xRegressionCurve, uno::UNO_QUERY );
830 if(!xProperties.is())
831 return aResult;
832
833 xProperties->getPropertyValue("CurveName") >>= aResult;
834
835 return aResult;
836}
837
838OUString RegressionCurveHelper::getRegressionCurveName( const Reference< XRegressionCurve >& xRegressionCurve )
839{
840 OUString aResult = getRegressionCurveSpecificName(xRegressionCurve);
841 if (aResult.isEmpty())
842 return getRegressionCurveGenericName(xRegressionCurve);
843 return aResult;
844}
845
847 const Reference< chart2::XRegressionCurve > & xCurve )
848{
849 if( !xCurve.is())
850 return;
851
852 try
853 {
854 static constexpr OUStringLiteral aPosPropertyName( u"RelativePosition" );
855 Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties()); // since m233: , uno::UNO_SET_THROW );
856 if( xEqProp->getPropertyValue( aPosPropertyName ).hasValue())
857 xEqProp->setPropertyValue( aPosPropertyName, uno::Any());
858 }
859 catch( const uno::Exception & )
860 {
861 DBG_UNHANDLED_EXCEPTION("chart2" );
862 }
863}
864
866 const rtl::Reference< DataSeries >& xContainer,
868{
869 if( xContainer.is())
870 {
871 const std::vector< rtl::Reference< RegressionCurveModel > > & aCurves(
872 xContainer->getRegressionCurves2());
873
874 for( std::size_t i = 0; i < aCurves.size(); ++i )
875 {
876 if( xCurve == aCurves[i] )
877 return i;
878 }
879 }
880 return -1;
881}
882
883bool RegressionCurveHelper::hasEquation( const Reference< chart2::XRegressionCurve > & xCurve )
884{
885 bool bHasEquation = false;
886 if( xCurve.is())
887 {
888 uno::Reference< beans::XPropertySet > xEquationProp( xCurve->getEquationProperties());
889 if( xEquationProp.is())
890 {
891 bool bShowEquation = false;
892 bool bShowCoefficient = false;
893 xEquationProp->getPropertyValue( "ShowEquation") >>= bShowEquation;
894 xEquationProp->getPropertyValue( "ShowCorrelationCoefficient") >>= bShowCoefficient;
895 bHasEquation = bShowEquation || bShowCoefficient;
896 }
897 }
898 return bHasEquation;
899}
900
901bool RegressionCurveHelper::MayHaveCorrelationCoefficient( const Reference< chart2::XRegressionCurve > & xCurve )
902{
903 bool bMayHaveCorrelationCoefficient = true;
904 if( xCurve.is())
905 {
906 uno::Reference< beans::XPropertySet > xEquationProp( xCurve->getEquationProperties() );
907 if( xEquationProp.is() )
908 {
909 xEquationProp->getPropertyValue( "MayHaveCorrelationCoefficient") >>= bMayHaveCorrelationCoefficient;
910 }
911 }
912 return bMayHaveCorrelationCoefficient;
913}
914
915} //namespace chart
916
917/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvxChartRegress
static rtl::Reference< ChartType > getChartTypeOfSeries(const rtl::Reference<::chart::ChartModel > &xModel, const rtl::Reference< ::chart::DataSeries > &xGivenDataSeries)
static sal_Int32 getAxisType(const rtl::Reference< ::chart::ChartType > &xChartType, sal_Int32 nDimensionIndex)
#define DBG_UNHANDLED_EXCEPTION(...)
float u
std::deque< AttacherIndex_Impl > aIndex
DocumentType eType
OOO_DLLPUBLIC_CHARTTOOLS SvxChartRegress getFirstRegressTypeNotMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xCurveContainer)
Returns the type of the first regression curve found that is not of type mean-value line.
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveCalculator > createRegressionCurveCalculatorByServiceName(std::u16string_view aServiceName)
returns a calculator object for regression curves (used by the view)
OOO_DLLPUBLIC_CHARTTOOLS bool isMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurve > &xRegCurve)
OOO_DLLPUBLIC_CHARTTOOLS bool MayHaveCorrelationCoefficient(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS bool removeAllExceptMeanValueLine(rtl::Reference<::chart::DataSeries > const &xCurveContainer)
void initializeCurveCalculator(const css::uno::Reference< css::chart2::XRegressionCurveCalculator > &xOutCurveCalculator, const css::uno::Reference< css::chart2::data::XDataSource > &xSource, bool bUseXValuesIfAvailable)
recalculates the regression parameters according to the data given in the data source.
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > getFirstCurveNotMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xCurveContainer)
Returns the first regression curve found that is not of type mean-value line.
OOO_DLLPUBLIC_CHARTTOOLS OUString getUINameForRegressionCurve(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS bool hasMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xRegCnt)
OOO_DLLPUBLIC_CHARTTOOLS void resetEquationPosition(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS void removeEquations(rtl::Reference<::chart::DataSeries > const &xCurveContainer)
OOO_DLLPUBLIC_CHARTTOOLS OUString getRegressionCurveGenericName(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > getRegressionCurveAtIndex(const rtl::Reference<::chart::DataSeries > &xCurveContainer, sal_Int32 aIndex)
Returns the regression curve found at the index provided.
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > changeRegressionCurveType(SvxChartRegress eType, css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xRegressionCurveContainer, css::uno::Reference< css::chart2::XRegressionCurve > const &xRegressionCurve)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > getMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xRegCnt)
OOO_DLLPUBLIC_CHARTTOOLS void removeMeanValueLine(css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xRegCnt)
OOO_DLLPUBLIC_CHARTTOOLS bool hasEquation(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS sal_Int32 getRegressionCurveIndex(const rtl::Reference<::chart::DataSeries > &xContainer, const rtl::Reference<::chart::RegressionCurveModel > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS SvxChartRegress getRegressionType(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS OUString getRegressionCurveSpecificName(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference<::chart::RegressionCurveModel > addRegressionCurve(SvxChartRegress eType, css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xCurveContainer, const css::uno::Reference< css::beans::XPropertySet > &xPropertySource=css::uno::Reference< css::beans::XPropertySet >(), const css::uno::Reference< css::beans::XPropertySet > &xEquationProperties=css::uno::Reference< css::beans::XPropertySet >())
rtl::Reference<::chart::RegressionCurveModel > createRegressionCurveByServiceName(std::u16string_view aServiceName)
returns a model regression curve
OOO_DLLPUBLIC_CHARTTOOLS OUString getRegressionCurveName(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
rtl::Reference<::chart::RegressionCurveModel > createMeanValueLine()
returns a model mean-value line
OOO_DLLPUBLIC_CHARTTOOLS void addMeanValueLine(css::uno::Reference< css::chart2::XRegressionCurveContainer > const &xRegCnt, const css::uno::Reference< css::beans::XPropertySet > &xSeriesProp)
creates a mean-value line and adds it to the container.
OOO_DLLPUBLIC_CHARTTOOLS css::uno::Sequence< double > DataSequenceToDoubleSequence(const css::uno::Reference< css::chart2::data::XDataSequence > &xDataSequence)
chart2::XDataSequence -> uno::Sequence< double >
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
Definition: ResId.cxx:24
void copyProperties(const Reference< XPropertySet > &_rxSource, const Reference< XPropertySet > &_rxDest)
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)