1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
22 #include <string_view>
24 #include <ObjectNameProvider.hxx>
26 #include <strings.hrc>
28 #include <AxisHelper.hxx>
29 #include <ChartModel.hxx>
30 #include <ChartType.hxx>
31 #include <Diagram.hxx>
32 #include <DataSeries.hxx>
33 #include <DataSeriesHelper.hxx>
34 #include <TitleHelper.hxx>
35 #include <ExplicitCategoriesProvider.hxx>
36 #include <CommonConverters.hxx>
37 #include <NumberFormatterWrapper.hxx>
38 #include <RegressionCurveHelper.hxx>
39 #include <BaseCoordinateSystem.hxx>
40 #include <RegressionCurveModel.hxx>
41 #include <rtl/math.hxx>
42 #include <rtl/ustring.hxx>
43 #include <vcl/settings.hxx>
44 #include <vcl/svapp.hxx>
45 #include <unotools/localedatawrapper.hxx>
47 #include <com/sun/star/chart2/MovingAverageType.hpp>
48 #include <comphelper/diagnose_ex.hxx>
49 #include <o3tl/string_view.hxx>
53 using namespace ::com::sun::star
;
54 using namespace ::com::sun::star::chart2
;
55 using ::com::sun::star::uno::Reference
;
56 using ::com::sun::star::uno::Sequence
;
57 using ::com::sun::star::uno::Any
;
62 OUString
lcl_getDataSeriesName( std::u16string_view rObjectCID
, const rtl::Reference
<::chart::ChartModel
>& xChartModel
)
66 rtl::Reference
< Diagram
> xDiagram( xChartModel
->getFirstChartDiagram() );
67 rtl::Reference
< DataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
);
68 if( xDiagram
.is() && xSeries
.is() )
70 rtl::Reference
< ChartType
> xChartType( xDiagram
->getChartTypeOfSeries( xSeries
) );
73 aRet
= xSeries
->getLabelForRole(
74 xChartType
->getRoleOfSequenceForSeriesLabel() ) ;
81 OUString
lcl_getFullSeriesName( std::u16string_view rObjectCID
, const rtl::Reference
<::chart::ChartModel
>& xChartModel
)
83 OUString
aRet(SchResId(STR_TIP_DATASERIES
));
84 OUString
aWildcard( u
"%SERIESNAME"_ustr
);
85 sal_Int32 nIndex
= aRet
.indexOf( aWildcard
);
87 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), lcl_getDataSeriesName( rObjectCID
, xChartModel
) );
91 void lcl_addText( OUString
& rOut
, std::u16string_view rSeparator
, std::u16string_view rNext
)
93 if( !(rOut
.isEmpty() || rNext
.empty()) )
99 OUString
lcl_getDataPointValueText( const rtl::Reference
< DataSeries
>& xSeries
, sal_Int32 nPointIndex
,
100 const rtl::Reference
< BaseCoordinateSystem
>& xCooSys
,
101 const Reference
< frame::XModel
>& xChartModel
)
109 const std::vector
< uno::Reference
< chart2::data::XLabeledDataSequence
> > & aDataSequences
= xSeries
->getDataSequences2();
111 OUString aX
, aY
, aY_Min
, aY_Max
, aY_First
, aY_Last
, a_Size
;
114 uno::Reference
< util::XNumberFormatsSupplier
> xNumberFormatsSupplier( xChartModel
, uno::UNO_QUERY
);
115 NumberFormatterWrapper
aNumberFormatterWrapper( xNumberFormatsSupplier
);
116 Color nLabelColor
;//dummy
117 bool bColorChanged
;//dummy
119 for(sal_Int32 nN
= aDataSequences
.size();nN
--;)
121 uno::Reference
<data::XDataSequence
> xDataSequence( aDataSequences
[nN
]->getValues());
122 if( !xDataSequence
.is() )
127 Sequence
< Any
> aData( xDataSequence
->getData() );
129 if( nPointIndex
>= aData
.getLength() )
131 uno::Reference
<beans::XPropertySet
> xProp(xDataSequence
, uno::UNO_QUERY
);
134 uno::Any aARole
= xProp
->getPropertyValue( u
"Role"_ustr
);
138 if( aRole
== "values-x" )
140 aData
[nPointIndex
]>>= fValue
;
141 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
142 aX
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
144 else if( aRole
== "values-y")
146 aData
[nPointIndex
]>>= fValue
;
147 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
148 aY
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
150 else if( aRole
== "values-first" )
152 aData
[nPointIndex
]>>= fValue
;
153 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
154 aY_First
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
156 else if( aRole
== "values-min" )
158 aData
[nPointIndex
]>>= fValue
;
159 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
160 aY_Min
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
162 else if( aRole
== "values-max" )
164 aData
[nPointIndex
]>>= fValue
;
165 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
166 aY_Max
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
168 else if( aRole
== "values-last" )
170 aData
[nPointIndex
]>>= fValue
;
171 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
172 aY_Last
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
174 else if( aRole
== "values-size" )
176 aData
[nPointIndex
]>>= fValue
;
177 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
178 a_Size
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
182 catch (const lang::DisposedException
&)
184 TOOLS_WARN_EXCEPTION( "chart2", "unexpected exception caught" );
186 catch( const uno::Exception
& )
188 TOOLS_WARN_EXCEPTION("chart2", "" );
194 ChartModel
& rModel
= dynamic_cast<ChartModel
&>(*xChartModel
);
195 aRet
= ExplicitCategoriesProvider::getCategoryByIndex( xCooSys
, rModel
, nPointIndex
);
202 OUString
aSeparator( u
" "_ustr
);
204 lcl_addText( aRet
, aSeparator
, aY
);
205 lcl_addText( aRet
, aSeparator
, aY_First
);
206 lcl_addText( aRet
, aSeparator
, aY_Min
);
207 lcl_addText( aRet
, aSeparator
, aY_Max
);
208 lcl_addText( aRet
, aSeparator
, aY_Last
);
209 lcl_addText( aRet
, aSeparator
, a_Size
);
214 } //end anonymous namespace
216 OUString
ObjectNameProvider::getName( ObjectType eObjectType
, bool bPlural
)
219 switch( eObjectType
)
221 case OBJECTTYPE_PAGE
:
222 aRet
=SchResId(STR_OBJECT_PAGE
);
224 case OBJECTTYPE_TITLE
:
227 aRet
=SchResId(STR_OBJECT_TITLES
);
229 aRet
=SchResId(STR_OBJECT_TITLE
);
232 case OBJECTTYPE_LEGEND
:
233 aRet
=SchResId(STR_OBJECT_LEGEND
);
235 case OBJECTTYPE_LEGEND_ENTRY
:
236 aRet
=SchResId(STR_OBJECT_LEGEND_SYMBOL
);//@todo change string if we do differentiate symbol and legend entry in future
238 case OBJECTTYPE_DIAGRAM
:
239 aRet
=SchResId(STR_OBJECT_DIAGRAM
);
241 case OBJECTTYPE_DIAGRAM_WALL
:
242 aRet
=SchResId(STR_OBJECT_DIAGRAM_WALL
);
244 case OBJECTTYPE_DIAGRAM_FLOOR
:
245 aRet
=SchResId(STR_OBJECT_DIAGRAM_FLOOR
);
247 case OBJECTTYPE_AXIS
:
250 aRet
=SchResId(STR_OBJECT_AXES
);
252 aRet
=SchResId(STR_OBJECT_AXIS
);
255 case OBJECTTYPE_AXIS_UNITLABEL
:
256 case OBJECTTYPE_DATA_LABEL
:
257 aRet
=SchResId(STR_OBJECT_LABEL
);//@todo maybe a more concrete name
259 case OBJECTTYPE_GRID
:
260 case OBJECTTYPE_SUBGRID
: //maybe todo: different names for subgrids
263 aRet
=SchResId(STR_OBJECT_GRIDS
);
265 aRet
=SchResId(STR_OBJECT_GRID
);
268 case OBJECTTYPE_DATA_SERIES
:
271 aRet
=SchResId(STR_OBJECT_DATASERIES_PLURAL
);
273 aRet
=SchResId(STR_OBJECT_DATASERIES
);
276 case OBJECTTYPE_DATA_POINT
:
279 aRet
=SchResId(STR_OBJECT_DATAPOINTS
);
281 aRet
=SchResId(STR_OBJECT_DATAPOINT
);
284 case OBJECTTYPE_DATA_LABELS
:
285 aRet
=SchResId(STR_OBJECT_DATALABELS
);
287 case OBJECTTYPE_DATA_ERRORS_X
:
288 aRet
=SchResId(STR_OBJECT_ERROR_BARS_X
);
290 case OBJECTTYPE_DATA_ERRORS_Y
:
291 aRet
=SchResId(STR_OBJECT_ERROR_BARS_Y
);
293 case OBJECTTYPE_DATA_ERRORS_Z
:
294 aRet
=SchResId(STR_OBJECT_ERROR_BARS_Z
);
296 case OBJECTTYPE_DATA_AVERAGE_LINE
:
297 aRet
=SchResId(STR_OBJECT_AVERAGE_LINE
);
299 case OBJECTTYPE_DATA_CURVE
:
302 aRet
=SchResId(STR_OBJECT_CURVES
);
304 aRet
=SchResId(STR_OBJECT_CURVE
);
307 case OBJECTTYPE_DATA_STOCK_RANGE
:
309 case OBJECTTYPE_DATA_STOCK_LOSS
:
310 aRet
=SchResId(STR_OBJECT_STOCK_LOSS
);
312 case OBJECTTYPE_DATA_STOCK_GAIN
:
313 aRet
=SchResId(STR_OBJECT_STOCK_GAIN
);
315 case OBJECTTYPE_DATA_CURVE_EQUATION
:
316 aRet
=SchResId(STR_OBJECT_CURVE_EQUATION
);
318 case OBJECTTYPE_DATA_TABLE
:
319 aRet
=SchResId(STR_DATA_TABLE
);
321 default: //OBJECTTYPE_UNKNOWN
327 OUString
ObjectNameProvider::getAxisName( std::u16string_view rObjectCID
328 , const rtl::Reference
<::chart::ChartModel
>& xChartModel
)
332 rtl::Reference
< ::chart::Axis
> xAxis
=
333 dynamic_cast<::chart::Axis
*>(ObjectIdentifier::getObjectPropertySet( rObjectCID
, xChartModel
).get());
335 sal_Int32 nCooSysIndex
= 0;
336 sal_Int32 nDimensionIndex
= 0;
337 sal_Int32 nAxisIndex
= 0;
338 AxisHelper::getIndicesForAxis( xAxis
, xChartModel
->getFirstChartDiagram(), nCooSysIndex
, nDimensionIndex
, nAxisIndex
);
340 switch(nDimensionIndex
)
343 if( nAxisIndex
== 0 )
344 aRet
=SchResId(STR_OBJECT_AXIS_X
);
346 aRet
=SchResId(STR_OBJECT_SECONDARY_X_AXIS
);
349 if( nAxisIndex
== 0 )
350 aRet
=SchResId(STR_OBJECT_AXIS_Y
);
352 aRet
=SchResId(STR_OBJECT_SECONDARY_Y_AXIS
);
355 aRet
=SchResId(STR_OBJECT_AXIS_Z
);
358 aRet
=SchResId(STR_OBJECT_AXIS
);
365 OUString
ObjectNameProvider::getTitleNameByType( TitleHelper::eTitleType eType
)
371 case TitleHelper::MAIN_TITLE
:
372 aRet
=SchResId(STR_OBJECT_TITLE_MAIN
);
374 case TitleHelper::SUB_TITLE
:
375 aRet
=SchResId(STR_OBJECT_TITLE_SUB
);
377 case TitleHelper::X_AXIS_TITLE
:
378 aRet
=SchResId(STR_OBJECT_TITLE_X_AXIS
);
380 case TitleHelper::Y_AXIS_TITLE
:
381 aRet
=SchResId(STR_OBJECT_TITLE_Y_AXIS
);
383 case TitleHelper::Z_AXIS_TITLE
:
384 aRet
=SchResId(STR_OBJECT_TITLE_Z_AXIS
);
386 case TitleHelper::SECONDARY_X_AXIS_TITLE
:
387 aRet
=SchResId(STR_OBJECT_TITLE_SECONDARY_X_AXIS
);
389 case TitleHelper::SECONDARY_Y_AXIS_TITLE
:
390 aRet
=SchResId(STR_OBJECT_TITLE_SECONDARY_Y_AXIS
);
393 OSL_FAIL("unknown title type");
398 aRet
=SchResId(STR_OBJECT_TITLE
);
403 OUString
ObjectNameProvider::getTitleName( std::u16string_view rObjectCID
404 , const rtl::Reference
<::chart::ChartModel
>& xChartModel
)
408 rtl::Reference
<Title
> xTitle
=
409 dynamic_cast<Title
*>(ObjectIdentifier::getObjectPropertySet( rObjectCID
, xChartModel
).get());
412 TitleHelper::eTitleType eType
;
413 if( TitleHelper::getTitleType( eType
, xTitle
, xChartModel
) )
414 aRet
= ObjectNameProvider::getTitleNameByType( eType
);
417 aRet
=SchResId(STR_OBJECT_TITLE
);
422 OUString
ObjectNameProvider::getGridName( std::u16string_view rObjectCID
423 , const rtl::Reference
<::chart::ChartModel
>& xChartModel
)
427 sal_Int32 nCooSysIndex
= -1;
428 sal_Int32 nDimensionIndex
= -1;
429 sal_Int32 nAxisIndex
= -1;
430 rtl::Reference
< Axis
> xAxis
= ObjectIdentifier::getAxisForCID( rObjectCID
, xChartModel
);
431 AxisHelper::getIndicesForAxis( xAxis
, xChartModel
->getFirstChartDiagram()
432 , nCooSysIndex
, nDimensionIndex
, nAxisIndex
);
434 bool bMainGrid
= (ObjectIdentifier::getObjectType( rObjectCID
) == OBJECTTYPE_GRID
);
438 switch(nDimensionIndex
)
441 aRet
=SchResId(STR_OBJECT_GRID_MAJOR_X
);
444 aRet
=SchResId(STR_OBJECT_GRID_MAJOR_Y
);
447 aRet
=SchResId(STR_OBJECT_GRID_MAJOR_Z
);
450 aRet
=SchResId(STR_OBJECT_GRID
);
456 switch(nDimensionIndex
)
459 aRet
=SchResId(STR_OBJECT_GRID_MINOR_X
);
462 aRet
=SchResId(STR_OBJECT_GRID_MINOR_Y
);
465 aRet
=SchResId(STR_OBJECT_GRID_MINOR_Z
);
468 aRet
=SchResId(STR_OBJECT_GRID
);
475 OUString
ObjectNameProvider::getHelpText( std::u16string_view rObjectCID
, const rtl::Reference
<::chart::ChartModel
>& xChartModel
, bool bVerbose
)
478 ObjectType
eObjectType( ObjectIdentifier::getObjectType(rObjectCID
) );
479 if( eObjectType
== OBJECTTYPE_AXIS
)
481 aRet
=ObjectNameProvider::getAxisName( rObjectCID
, xChartModel
);
483 else if( eObjectType
== OBJECTTYPE_GRID
484 || eObjectType
== OBJECTTYPE_SUBGRID
)
486 aRet
=ObjectNameProvider::getGridName( rObjectCID
, xChartModel
);
488 else if( eObjectType
== OBJECTTYPE_TITLE
)
490 aRet
=ObjectNameProvider::getTitleName( rObjectCID
, xChartModel
);
492 else if( eObjectType
== OBJECTTYPE_DATA_SERIES
)
494 aRet
= lcl_getFullSeriesName( rObjectCID
, xChartModel
);
496 else if( eObjectType
== OBJECTTYPE_DATA_POINT
)
500 aRet
= SchResId(STR_TIP_DATAPOINT_INDEX
) + "\n"
501 + SchResId(STR_TIP_DATASERIES
) + "\n"
502 + SchResId(STR_TIP_DATAPOINT_VALUES
);
505 aRet
=SchResId(STR_TIP_DATAPOINT
);
507 rtl::Reference
< Diagram
> xDiagram( xChartModel
->getFirstChartDiagram() );
508 rtl::Reference
< DataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
);
509 if( xDiagram
.is() && xSeries
.is() )
511 sal_Int32 nPointIndex
= o3tl::toInt32(ObjectIdentifier::getParticleID(rObjectCID
));
513 //replace data point index
514 OUString
aWildcard( u
"%POINTNUMBER"_ustr
);
515 sal_Int32 nIndex
= aRet
.indexOf( aWildcard
);
518 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), OUString::number(nPointIndex
+1) );
521 //replace data series index
522 aWildcard
= "%SERIESNUMBER";
523 nIndex
= aRet
.indexOf( aWildcard
);
526 std::vector
< rtl::Reference
< DataSeries
> > aSeriesVector
=
527 xDiagram
->getDataSeries();
528 sal_Int32 nSeriesIndex
= -1;
529 for( nSeriesIndex
=aSeriesVector
.size();nSeriesIndex
--;)
531 if( aSeriesVector
[nSeriesIndex
] == xSeries
)
537 OUString
aReplacement( OUString::number(nSeriesIndex
+1) );
538 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), aReplacement
);
541 //replace point values
542 aWildcard
= "%POINTVALUES";
543 nIndex
= aRet
.indexOf( aWildcard
);
545 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), lcl_getDataPointValueText(
546 xSeries
,nPointIndex
, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries
, xDiagram
), xChartModel
) );
548 //replace series name
549 aWildcard
= "%SERIESNAME";
550 nIndex
= aRet
.indexOf( aWildcard
);
552 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), lcl_getDataSeriesName( rObjectCID
, xChartModel
) );
555 else if( eObjectType
== OBJECTTYPE_DATA_CURVE
)
559 aRet
= SchResId( STR_OBJECT_CURVE_WITH_PARAMETERS
);
560 rtl::Reference
< DataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
));
564 sal_Int32 nCurveIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
565 rtl::Reference
< RegressionCurveModel
> xCurve
= RegressionCurveHelper::getRegressionCurveAtIndex(xSeries
, nCurveIndex
);
570 Reference
< chart2::XRegressionCurveCalculator
> xCalculator( xCurve
->getCalculator(), uno::UNO_SET_THROW
);
571 sal_Int32 aDegree
= 2;
572 sal_Int32 aPeriod
= 2;
573 sal_Int32 aMovingType
= css::chart2::MovingAverageType::Prior
;
574 bool bForceIntercept
= false;
575 double aInterceptValue
= 0.0;
576 OUString
aXName (u
"x"_ustr
), aYName (u
"f(x)"_ustr
);
577 const LocaleDataWrapper
& rLocaleDataWrapper
= Application::GetSettings().GetLocaleDataWrapper();
578 const OUString
& aNumDecimalSep
= rLocaleDataWrapper
.getNumDecimalSep();
579 sal_Unicode cDecSeparator
= aNumDecimalSep
[0];
581 xCurve
->getPropertyValue( u
"PolynomialDegree"_ustr
) >>= aDegree
;
582 xCurve
->getPropertyValue( u
"MovingAveragePeriod"_ustr
) >>= aPeriod
;
583 xCurve
->getPropertyValue( u
"MovingAverageType"_ustr
) >>= aMovingType
;
584 xCurve
->getPropertyValue( u
"ForceIntercept"_ustr
) >>= bForceIntercept
;
586 xCurve
->getPropertyValue( u
"InterceptValue"_ustr
) >>= aInterceptValue
;
587 uno::Reference
< beans::XPropertySet
> xEqProp( xCurve
->getEquationProperties());
590 if ( !(xEqProp
->getPropertyValue( u
"XName"_ustr
) >>= aXName
) )
592 if ( !(xEqProp
->getPropertyValue( u
"YName"_ustr
) >>= aYName
) )
595 xCalculator
->setRegressionProperties(aDegree
, bForceIntercept
, aInterceptValue
, aPeriod
, aMovingType
);
596 xCalculator
->setXYNames ( aXName
, aYName
);
597 RegressionCurveHelper::initializeCurveCalculator( xCalculator
, xSeries
, xChartModel
);
599 // change text for Moving Average
600 if ( RegressionCurveHelper::getRegressionType( xCurve
) == SvxChartRegress::MovingAverage
)
602 aRet
= xCalculator
->getRepresentation();
607 OUString aWildcard
= u
"%FORMULA"_ustr
;
608 sal_Int32 nIndex
= aRet
.indexOf( aWildcard
);
611 OUString
aFormula ( xCalculator
->getRepresentation() );
612 if ( cDecSeparator
!= '.' )
614 aFormula
= aFormula
.replace( '.', cDecSeparator
);
616 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), aFormula
);
620 aWildcard
= "%RSQUARED";
621 nIndex
= aRet
.indexOf( aWildcard
);
624 double fR( xCalculator
->getCorrelationCoefficient());
625 aRet
= aRet
.replaceAt(
626 nIndex
, aWildcard
.getLength(),
627 ::rtl::math::doubleToUString(
628 fR
*fR
, rtl_math_StringFormat_G
, 4, cDecSeparator
, true ));
632 catch( const uno::Exception
& )
634 DBG_UNHANDLED_EXCEPTION("chart2");
641 rtl::Reference
< DataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID(rObjectCID
, xChartModel
));
642 aRet
+= getName(eObjectType
);
646 sal_Int32 nCurveIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
647 rtl::Reference
< RegressionCurveModel
> xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xSeries
, nCurveIndex
) );
650 aRet
+= " (" + RegressionCurveHelper::getRegressionCurveName(xCurve
) + " )";
655 else if( eObjectType
== OBJECTTYPE_DATA_AVERAGE_LINE
)
659 aRet
= SchResId(STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS
);
660 rtl::Reference
< DataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
));
663 rtl::Reference
< RegressionCurveModel
> xCurve( RegressionCurveHelper::getMeanValueLine( xSeries
));
668 Reference
< chart2::XRegressionCurveCalculator
> xCalculator( xCurve
->getCalculator(), uno::UNO_SET_THROW
);
669 RegressionCurveHelper::initializeCurveCalculator( xCalculator
, xSeries
, xChartModel
);
671 const LocaleDataWrapper
& rLocaleDataWrapper
= Application::GetSettings().GetLocaleDataWrapper();
672 const OUString
& aNumDecimalSep
= rLocaleDataWrapper
.getNumDecimalSep();
673 sal_Unicode cDecSeparator
= aNumDecimalSep
[0];
675 OUString
aWildcard( u
"%AVERAGE_VALUE"_ustr
);
676 sal_Int32 nIndex
= aRet
.indexOf( aWildcard
);
677 // as the curve is constant, the value at any x-value is ok
680 const double fMeanValue( xCalculator
->getCurveValue( 0.0 ));
681 aRet
= aRet
.replaceAt(
682 nIndex
, aWildcard
.getLength(),
683 ::rtl::math::doubleToUString(
684 fMeanValue
, rtl_math_StringFormat_G
, 4, cDecSeparator
, true ));
687 // replace standard deviation
688 aWildcard
= "%STD_DEVIATION";
689 nIndex
= aRet
.indexOf( aWildcard
);
692 const double fStdDev( xCalculator
->getCorrelationCoefficient());
693 aRet
= aRet
.replaceAt(
694 nIndex
, aWildcard
.getLength(),
695 ::rtl::math::doubleToUString(
696 fStdDev
, rtl_math_StringFormat_G
, 4, cDecSeparator
, true ));
699 catch( const uno::Exception
& )
701 DBG_UNHANDLED_EXCEPTION("chart2");
709 aRet
= ObjectNameProvider::getName( eObjectType
);
714 aRet
= ObjectNameProvider::getName( eObjectType
);
719 OUString
ObjectNameProvider::getSelectedObjectText( std::u16string_view rObjectCID
, const rtl::Reference
<::chart::ChartModel
>& xChartDocument
)
722 ObjectType
eObjectType( ObjectIdentifier::getObjectType(rObjectCID
) );
724 if( eObjectType
== OBJECTTYPE_DATA_POINT
)
726 aRet
= SchResId( STR_STATUS_DATAPOINT_MARKED
);
728 rtl::Reference
< Diagram
> xDiagram( xChartDocument
->getFirstChartDiagram() );
729 rtl::Reference
< DataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartDocument
);
730 if( xDiagram
.is() && xSeries
.is() )
732 sal_Int32 nPointIndex
= o3tl::toInt32( ObjectIdentifier::getParticleID(rObjectCID
) );
734 // replace data point index
735 replaceParamterInString( aRet
, u
"%POINTNUMBER", OUString::number( nPointIndex
+ 1 ));
737 // replace data series index
739 std::vector
< rtl::Reference
< DataSeries
> > aSeriesVector(
740 xDiagram
->getDataSeries() );
741 sal_Int32 nSeriesIndex
= -1;
742 for( nSeriesIndex
=aSeriesVector
.size();nSeriesIndex
--;)
744 if( aSeriesVector
[nSeriesIndex
] == xSeries
)
747 replaceParamterInString( aRet
, u
"%SERIESNUMBER", OUString::number( nSeriesIndex
+ 1 ) );
750 // replace point value
751 replaceParamterInString( aRet
, u
"%POINTVALUES", lcl_getDataPointValueText(
752 xSeries
, nPointIndex
, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries
, xDiagram
), xChartDocument
) );
757 // use the verbose text including the formula for trend lines
758 const bool bVerbose( eObjectType
== OBJECTTYPE_DATA_CURVE
|| eObjectType
== OBJECTTYPE_DATA_AVERAGE_LINE
);
759 const OUString
aHelpText( getHelpText( rObjectCID
, xChartDocument
, bVerbose
));
760 if( !aHelpText
.isEmpty())
762 aRet
= SchResId( STR_STATUS_OBJECT_MARKED
);
763 replaceParamterInString( aRet
, u
"%OBJECTNAME", aHelpText
);
770 OUString
ObjectNameProvider::getNameForCID(
771 std::u16string_view rObjectCID
,
772 const rtl::Reference
<::chart::ChartModel
>& xChartDocument
)
774 ObjectType
eType( ObjectIdentifier::getObjectType( rObjectCID
));
778 case OBJECTTYPE_AXIS
:
779 return getAxisName( rObjectCID
, xChartDocument
);
780 case OBJECTTYPE_TITLE
:
781 return getTitleName( rObjectCID
, xChartDocument
);
782 case OBJECTTYPE_GRID
:
783 case OBJECTTYPE_SUBGRID
:
784 return getGridName( rObjectCID
, xChartDocument
);
785 case OBJECTTYPE_DATA_SERIES
:
786 return lcl_getFullSeriesName( rObjectCID
, xChartDocument
);
787 case OBJECTTYPE_DATA_POINT
:
788 case OBJECTTYPE_DATA_LABELS
:
789 case OBJECTTYPE_DATA_LABEL
:
790 case OBJECTTYPE_DATA_ERRORS_X
:
791 case OBJECTTYPE_DATA_ERRORS_Y
:
792 case OBJECTTYPE_DATA_ERRORS_Z
:
793 case OBJECTTYPE_DATA_AVERAGE_LINE
:
794 case OBJECTTYPE_DATA_CURVE
:
795 case OBJECTTYPE_DATA_CURVE_EQUATION
:
797 OUString aRet
= lcl_getFullSeriesName( rObjectCID
, xChartDocument
) + " ";
798 if( eType
== OBJECTTYPE_DATA_POINT
|| eType
== OBJECTTYPE_DATA_LABEL
)
800 aRet
+= getName( OBJECTTYPE_DATA_POINT
);
801 sal_Int32 nPointIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
802 aRet
+= " " + OUString::number(nPointIndex
+1);
803 if( eType
== OBJECTTYPE_DATA_LABEL
)
805 aRet
+= " " + getName( OBJECTTYPE_DATA_LABEL
);
808 else if (eType
== OBJECTTYPE_DATA_CURVE
|| eType
== OBJECTTYPE_DATA_CURVE_EQUATION
)
810 rtl::Reference
< DataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartDocument
));
812 aRet
+= " " + getName(eType
);
816 sal_Int32 nCurveIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
817 rtl::Reference
< RegressionCurveModel
> xCurve( RegressionCurveHelper::getRegressionCurveAtIndex(xSeries
, nCurveIndex
) );
820 aRet
+= " (" + RegressionCurveHelper::getRegressionCurveName(xCurve
) + ")";
826 aRet
+= getName( eType
);
834 return getName( eType
);
837 OUString
ObjectNameProvider::getName_ObjectForSeries(
838 ObjectType eObjectType
,
839 std::u16string_view rSeriesCID
,
840 const rtl::Reference
<::chart::ChartModel
>& xChartDocument
)
842 rtl::Reference
< DataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( rSeriesCID
, xChartDocument
);
845 OUString aRet
= SchResId(STR_OBJECT_FOR_SERIES
);
846 replaceParamterInString( aRet
, u
"%OBJECTNAME", getName( eObjectType
) );
847 replaceParamterInString( aRet
, u
"%SERIESNAME", lcl_getDataSeriesName( rSeriesCID
, xChartDocument
) );
851 return ObjectNameProvider::getName_ObjectForAllSeries( eObjectType
);
854 OUString
ObjectNameProvider::getName_ObjectForAllSeries( ObjectType eObjectType
)
856 OUString aRet
= SchResId(STR_OBJECT_FOR_ALL_SERIES
);
857 replaceParamterInString( aRet
, u
"%OBJECTNAME", getName( eObjectType
, true /*bPlural*/ ) );
863 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */