LibreOffice Module chart2 (master) 1
ObjectNameProvider.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 <string_view>
23
25#include <ResId.hxx>
26#include <strings.hrc>
27#include <Axis.hxx>
28#include <AxisHelper.hxx>
29#include <ChartModel.hxx>
30#include <ChartModelHelper.hxx>
31#include <ChartType.hxx>
32#include <DiagramHelper.hxx>
33#include <Diagram.hxx>
34#include <DataSeries.hxx>
35#include <DataSeriesHelper.hxx>
36#include <TitleHelper.hxx>
38#include <CommonConverters.hxx>
43#include <rtl/math.hxx>
44#include <rtl/ustring.hxx>
45#include <vcl/settings.hxx>
46#include <vcl/svapp.hxx>
48
49#include <com/sun/star/chart2/XTitle.hpp>
50#include <com/sun/star/chart2/MovingAverageType.hpp>
52#include <o3tl/string_view.hxx>
53
54namespace chart
55{
56using namespace ::com::sun::star;
57using namespace ::com::sun::star::chart2;
58using ::com::sun::star::uno::Reference;
59using ::com::sun::star::uno::Sequence;
60using ::com::sun::star::uno::Any;
61
62namespace
63{
64
65OUString lcl_getDataSeriesName( std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel>& xChartModel )
66{
67 OUString aRet;
68
69 rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() );
70 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel );
71 if( xDiagram.is() && xSeries.is() )
72 {
73 rtl::Reference< ChartType > xChartType( xDiagram->getChartTypeOfSeries( xSeries ) );
74 if( xChartType.is() )
75 {
76 aRet = xSeries->getLabelForRole(
77 xChartType->getRoleOfSequenceForSeriesLabel() ) ;
78 }
79 }
80
81 return aRet;
82}
83
84OUString lcl_getFullSeriesName( std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel>& xChartModel )
85{
86 OUString aRet(SchResId(STR_TIP_DATASERIES));
87 OUString aWildcard( "%SERIESNAME" );
88 sal_Int32 nIndex = aRet.indexOf( aWildcard );
89 if( nIndex != -1 )
90 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
91 return aRet;
92}
93
94void lcl_addText( OUString& rOut, std::u16string_view rSeparator, std::u16string_view rNext )
95{
96 if( !(rOut.isEmpty() || rNext.empty()) )
97 rOut+=rSeparator;
98 if( !rNext.empty() )
99 rOut+=rNext;
100}
101
102OUString lcl_getDataPointValueText( const rtl::Reference< DataSeries >& xSeries, sal_Int32 nPointIndex,
104 const Reference< frame::XModel >& xChartModel )
105{
106
107 OUString aRet;
108
109 if(!xSeries.is())
110 return aRet;
111
112 const std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > & aDataSequences = xSeries->getDataSequences2();
113
114 OUString aX, aY, aY_Min, aY_Max, aY_First, aY_Last, a_Size;
115 double fValue = 0;
116
117 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY );
118 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
119 Color nLabelColor;//dummy
120 bool bColorChanged;//dummy
121
122 for(sal_Int32 nN = aDataSequences.size();nN--;)
123 {
124 uno::Reference<data::XDataSequence> xDataSequence( aDataSequences[nN]->getValues());
125 if( !xDataSequence.is() )
126 continue;
127
128 try
129 {
130 Sequence< Any > aData( xDataSequence->getData() );
131
132 if( nPointIndex >= aData.getLength() )
133 continue;
134 uno::Reference<beans::XPropertySet> xProp(xDataSequence, uno::UNO_QUERY );
135 if( xProp.is())
136 {
137 uno::Any aARole = xProp->getPropertyValue( "Role" );
138 OUString aRole;
139 aARole >>= aRole;
140
141 if( aRole == "values-x" )
142 {
143 aData[nPointIndex]>>= fValue;
144 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
145 aX = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
146 }
147 else if( aRole == "values-y")
148 {
149 aData[nPointIndex]>>= fValue;
150 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
151 aY = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
152 }
153 else if( aRole == "values-first" )
154 {
155 aData[nPointIndex]>>= fValue;
156 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
157 aY_First = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
158 }
159 else if( aRole == "values-min" )
160 {
161 aData[nPointIndex]>>= fValue;
162 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
163 aY_Min = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
164 }
165 else if( aRole == "values-max" )
166 {
167 aData[nPointIndex]>>= fValue;
168 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
169 aY_Max = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
170 }
171 else if( aRole == "values-last" )
172 {
173 aData[nPointIndex]>>= fValue;
174 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
175 aY_Last = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
176 }
177 else if( aRole == "values-size" )
178 {
179 aData[nPointIndex]>>= fValue;
180 sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
181 a_Size = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
182 }
183 }
184 }
185 catch (const lang::DisposedException&)
186 {
187 TOOLS_WARN_EXCEPTION( "chart2", "unexpected exception caught" );
188 }
189 catch( const uno::Exception& )
190 {
191 TOOLS_WARN_EXCEPTION("chart2", "" );
192 }
193 }
194
195 if( aX.isEmpty() )
196 {
197 ChartModel& rModel = dynamic_cast<ChartModel&>(*xChartModel);
198 aRet = ExplicitCategoriesProvider::getCategoryByIndex( xCooSys, rModel, nPointIndex );
199 }
200 else
201 {
202 aRet = aX;
203 }
204
205 OUString aSeparator( " " );
206
207 lcl_addText( aRet, aSeparator, aY );
208 lcl_addText( aRet, aSeparator, aY_First );
209 lcl_addText( aRet, aSeparator, aY_Min );
210 lcl_addText( aRet, aSeparator, aY_Max );
211 lcl_addText( aRet, aSeparator, aY_Last );
212 lcl_addText( aRet, aSeparator, a_Size );
213
214 return aRet;
215}
216
217} //end anonymous namespace
218
219OUString ObjectNameProvider::getName( ObjectType eObjectType, bool bPlural )
220{
221 OUString aRet;
222 switch( eObjectType )
223 {
224 case OBJECTTYPE_PAGE:
225 aRet=SchResId(STR_OBJECT_PAGE);
226 break;
227 case OBJECTTYPE_TITLE:
228 {
229 if(bPlural)
230 aRet=SchResId(STR_OBJECT_TITLES);
231 else
232 aRet=SchResId(STR_OBJECT_TITLE);
233 }
234 break;
236 aRet=SchResId(STR_OBJECT_LEGEND);
237 break;
239 aRet=SchResId(STR_OBJECT_LEGEND_SYMBOL);//@todo change string if we do differentiate symbol and legend entry in future
240 break;
242 aRet=SchResId(STR_OBJECT_DIAGRAM);
243 break;
245 aRet=SchResId(STR_OBJECT_DIAGRAM_WALL);
246 break;
248 aRet=SchResId(STR_OBJECT_DIAGRAM_FLOOR);
249 break;
250 case OBJECTTYPE_AXIS:
251 {
252 if(bPlural)
253 aRet=SchResId(STR_OBJECT_AXES);
254 else
255 aRet=SchResId(STR_OBJECT_AXIS);
256 }
257 break;
259 aRet=SchResId(STR_OBJECT_LABEL);//@todo maybe a more concrete name
260 break;
261 case OBJECTTYPE_GRID:
262 case OBJECTTYPE_SUBGRID: //maybe todo: different names for subgrids
263 {
264 if(bPlural)
265 aRet=SchResId(STR_OBJECT_GRIDS);
266 else
267 aRet=SchResId(STR_OBJECT_GRID);
268 }
269 break;
271 {
272 if(bPlural)
273 aRet=SchResId(STR_OBJECT_DATASERIES_PLURAL);
274 else
275 aRet=SchResId(STR_OBJECT_DATASERIES);
276 }
277 break;
279 {
280 if(bPlural)
281 aRet=SchResId(STR_OBJECT_DATAPOINTS);
282 else
283 aRet=SchResId(STR_OBJECT_DATAPOINT);
284 }
285 break;
287 aRet=SchResId(STR_OBJECT_DATALABELS);
288 break;
290 aRet=SchResId(STR_OBJECT_LABEL);
291 break;
293 aRet=SchResId(STR_OBJECT_ERROR_BARS_X);
294 break;
296 aRet=SchResId(STR_OBJECT_ERROR_BARS_Y);
297 break;
299 aRet=SchResId(STR_OBJECT_ERROR_BARS_Z);
300 break;
302 aRet=SchResId(STR_OBJECT_AVERAGE_LINE);
303 break;
305 {
306 if(bPlural)
307 aRet=SchResId(STR_OBJECT_CURVES);
308 else
309 aRet=SchResId(STR_OBJECT_CURVE);
310 }
311 break;
313 break;
315 aRet=SchResId(STR_OBJECT_STOCK_LOSS);
316 break;
318 aRet=SchResId(STR_OBJECT_STOCK_GAIN);
319 break;
321 aRet=SchResId(STR_OBJECT_CURVE_EQUATION);
322 break;
324 aRet=SchResId(STR_DATA_TABLE);
325 break;
326 default: //OBJECTTYPE_UNKNOWN
327 ;
328 }
329 return aRet;
330}
331
332OUString ObjectNameProvider::getAxisName( std::u16string_view rObjectCID
333 , const rtl::Reference<::chart::ChartModel>& xChartModel )
334{
335 OUString aRet;
336
338 dynamic_cast<::chart::Axis*>(ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ).get());
339
340 sal_Int32 nCooSysIndex = 0;
341 sal_Int32 nDimensionIndex = 0;
342 sal_Int32 nAxisIndex = 0;
343 AxisHelper::getIndicesForAxis( xAxis, xChartModel->getFirstChartDiagram(), nCooSysIndex, nDimensionIndex, nAxisIndex );
344
345 switch(nDimensionIndex)
346 {
347 case 0://x-axis
348 if( nAxisIndex == 0 )
349 aRet=SchResId(STR_OBJECT_AXIS_X);
350 else
351 aRet=SchResId(STR_OBJECT_SECONDARY_X_AXIS);
352 break;
353 case 1://y-axis
354 if( nAxisIndex == 0 )
355 aRet=SchResId(STR_OBJECT_AXIS_Y);
356 else
357 aRet=SchResId(STR_OBJECT_SECONDARY_Y_AXIS);
358 break;
359 case 2://z-axis
360 aRet=SchResId(STR_OBJECT_AXIS_Z);
361 break;
362 default://axis
363 aRet=SchResId(STR_OBJECT_AXIS);
364 break;
365 }
366
367 return aRet;
368}
369
371{
372 OUString aRet;
373
374 switch(eType)
375 {
377 aRet=SchResId(STR_OBJECT_TITLE_MAIN);
378 break;
380 aRet=SchResId(STR_OBJECT_TITLE_SUB);
381 break;
383 aRet=SchResId(STR_OBJECT_TITLE_X_AXIS);
384 break;
386 aRet=SchResId(STR_OBJECT_TITLE_Y_AXIS);
387 break;
389 aRet=SchResId(STR_OBJECT_TITLE_Z_AXIS);
390 break;
392 aRet=SchResId(STR_OBJECT_TITLE_SECONDARY_X_AXIS);
393 break;
395 aRet=SchResId(STR_OBJECT_TITLE_SECONDARY_Y_AXIS);
396 break;
397 default:
398 OSL_FAIL("unknown title type");
399 break;
400 }
401
402 if( aRet.isEmpty() )
403 aRet=SchResId(STR_OBJECT_TITLE);
404
405 return aRet;
406}
407
408OUString ObjectNameProvider::getTitleName( std::u16string_view rObjectCID
409 , const rtl::Reference<::chart::ChartModel>& xChartModel )
410{
411 OUString aRet;
412
413 rtl::Reference<Title> xTitle =
414 dynamic_cast<Title*>(ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ).get());
415 if( xTitle )
416 {
418 if( TitleHelper::getTitleType( eType, xTitle, xChartModel ) )
420 }
421 if( aRet.isEmpty() )
422 aRet=SchResId(STR_OBJECT_TITLE);
423
424 return aRet;
425}
426
427OUString ObjectNameProvider::getGridName( std::u16string_view rObjectCID
428 , const rtl::Reference<::chart::ChartModel>& xChartModel )
429{
430 OUString aRet;
431
432 sal_Int32 nCooSysIndex = -1;
433 sal_Int32 nDimensionIndex = -1;
434 sal_Int32 nAxisIndex = -1;
435 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( rObjectCID , xChartModel );
436 AxisHelper::getIndicesForAxis( xAxis, xChartModel->getFirstChartDiagram()
437 , nCooSysIndex , nDimensionIndex, nAxisIndex );
438
439 bool bMainGrid = (ObjectIdentifier::getObjectType( rObjectCID ) == OBJECTTYPE_GRID);
440
441 if( bMainGrid )
442 {
443 switch(nDimensionIndex)
444 {
445 case 0://x-axis
446 aRet=SchResId(STR_OBJECT_GRID_MAJOR_X);
447 break;
448 case 1://y-axis
449 aRet=SchResId(STR_OBJECT_GRID_MAJOR_Y);
450 break;
451 case 2://z-axis
452 aRet=SchResId(STR_OBJECT_GRID_MAJOR_Z);
453 break;
454 default://axis
455 aRet=SchResId(STR_OBJECT_GRID);
456 break;
457 }
458 }
459 else
460 {
461 switch(nDimensionIndex)
462 {
463 case 0://x-axis
464 aRet=SchResId(STR_OBJECT_GRID_MINOR_X);
465 break;
466 case 1://y-axis
467 aRet=SchResId(STR_OBJECT_GRID_MINOR_Y);
468 break;
469 case 2://z-axis
470 aRet=SchResId(STR_OBJECT_GRID_MINOR_Z);
471 break;
472 default://axis
473 aRet=SchResId(STR_OBJECT_GRID);
474 break;
475 }
476 }
477 return aRet;
478}
479
480OUString ObjectNameProvider::getHelpText( std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel>& xChartModel, bool bVerbose )
481{
482 OUString aRet;
483 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
484 if( eObjectType == OBJECTTYPE_AXIS )
485 {
486 aRet=ObjectNameProvider::getAxisName( rObjectCID, xChartModel );
487 }
488 else if( eObjectType == OBJECTTYPE_GRID
489 || eObjectType == OBJECTTYPE_SUBGRID )
490 {
491 aRet=ObjectNameProvider::getGridName( rObjectCID, xChartModel );
492 }
493 else if( eObjectType == OBJECTTYPE_TITLE )
494 {
495 aRet=ObjectNameProvider::getTitleName( rObjectCID, xChartModel );
496 }
497 else if( eObjectType == OBJECTTYPE_DATA_SERIES )
498 {
499 aRet = lcl_getFullSeriesName( rObjectCID, xChartModel );
500 }
501 else if( eObjectType == OBJECTTYPE_DATA_POINT )
502 {
503 if( bVerbose )
504 {
505 aRet= SchResId(STR_TIP_DATAPOINT_INDEX) + "\n"
506 + SchResId(STR_TIP_DATASERIES) + "\n"
507 + SchResId(STR_TIP_DATAPOINT_VALUES);
508 }
509 else
510 aRet=SchResId(STR_TIP_DATAPOINT);
511
512 rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() );
513 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel );
514 if( xDiagram.is() && xSeries.is() )
515 {
516 sal_Int32 nPointIndex = o3tl::toInt32(ObjectIdentifier::getParticleID(rObjectCID));
517
518 //replace data point index
519 OUString aWildcard( "%POINTNUMBER" );
520 sal_Int32 nIndex = aRet.indexOf( aWildcard );
521 if( nIndex != -1 )
522 {
523 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), OUString::number(nPointIndex+1) );
524 }
525
526 //replace data series index
527 aWildcard = "%SERIESNUMBER";
528 nIndex = aRet.indexOf( aWildcard );
529 if( nIndex != -1 )
530 {
531 std::vector< rtl::Reference< DataSeries > > aSeriesVector =
532 xDiagram->getDataSeries();
533 sal_Int32 nSeriesIndex = -1;
534 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
535 {
536 if( aSeriesVector[nSeriesIndex] == xSeries )
537 {
538 break;
539 }
540 }
541
542 OUString aReplacement( OUString::number(nSeriesIndex+1) );
543 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), aReplacement );
544 }
545
546 //replace point values
547 aWildcard = "%POINTVALUES";
548 nIndex = aRet.indexOf( aWildcard );
549 if( nIndex != -1 )
550 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataPointValueText(
551 xSeries,nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
552
553 //replace series name
554 aWildcard = "%SERIESNAME";
555 nIndex = aRet.indexOf( aWildcard );
556 if( nIndex != -1 )
557 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
558 }
559 }
560 else if( eObjectType == OBJECTTYPE_DATA_CURVE )
561 {
562 if( bVerbose )
563 {
564 aRet = SchResId( STR_OBJECT_CURVE_WITH_PARAMETERS );
565 rtl::Reference< DataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
566
567 if( xSeries.is())
568 {
569 sal_Int32 nCurveIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
571 if( xCurve.is())
572 {
573 try
574 {
575 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_SET_THROW );
576 sal_Int32 aDegree = 2;
577 sal_Int32 aPeriod = 2;
578 sal_Int32 aMovingType = css::chart2::MovingAverageType::Prior;
579 bool bForceIntercept = false;
580 double aInterceptValue = 0.0;
581 OUString aXName ("x"), aYName ("f(x)");
583 const OUString& aNumDecimalSep = rLocaleDataWrapper.getNumDecimalSep();
584 sal_Unicode cDecSeparator = aNumDecimalSep[0];
585
586 xCurve->getPropertyValue( "PolynomialDegree") >>= aDegree;
587 xCurve->getPropertyValue( "MovingAveragePeriod") >>= aPeriod;
588 xCurve->getPropertyValue( "MovingAverageType") >>= aMovingType;
589 xCurve->getPropertyValue( "ForceIntercept") >>= bForceIntercept;
590 if (bForceIntercept)
591 xCurve->getPropertyValue( "InterceptValue") >>= aInterceptValue;
592 uno::Reference< beans::XPropertySet > xEqProp( xCurve->getEquationProperties());
593 if( xEqProp.is())
594 {
595 if ( !(xEqProp->getPropertyValue( "XName") >>= aXName) )
596 aXName = "x";
597 if ( !(xEqProp->getPropertyValue( "YName") >>= aYName) )
598 aYName = "f(x)";
599 }
600 xCalculator->setRegressionProperties(aDegree, bForceIntercept, aInterceptValue, aPeriod, aMovingType);
601 xCalculator->setXYNames ( aXName, aYName );
602 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
603
604 // change text for Moving Average
605 if ( RegressionCurveHelper::getRegressionType( xCurve ) == SvxChartRegress::MovingAverage )
606 {
607 aRet = xCalculator->getRepresentation();
608 }
609 else
610 {
611 // replace formula
612 OUString aWildcard = "%FORMULA";
613 sal_Int32 nIndex = aRet.indexOf( aWildcard );
614 if( nIndex != -1 )
615 {
616 OUString aFormula ( xCalculator->getRepresentation() );
617 if ( cDecSeparator != '.' )
618 {
619 aFormula = aFormula.replace( '.', cDecSeparator );
620 }
621 aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), aFormula );
622 }
623
624 // replace r^2
625 aWildcard = "%RSQUARED";
626 nIndex = aRet.indexOf( aWildcard );
627 if( nIndex != -1 )
628 {
629 double fR( xCalculator->getCorrelationCoefficient());
630 aRet = aRet.replaceAt(
631 nIndex, aWildcard.getLength(),
632 ::rtl::math::doubleToUString(
633 fR*fR, rtl_math_StringFormat_G, 4, cDecSeparator, true ));
634 }
635 }
636 }
637 catch( const uno::Exception & )
638 {
639 DBG_UNHANDLED_EXCEPTION("chart2");
640 }
641 }
642 }
643 }
644 else
645 {
647 aRet += getName(eObjectType);
648
649 if( xSeries.is())
650 {
651 sal_Int32 nCurveIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
653 if( xCurve.is())
654 {
655 aRet += " (" + RegressionCurveHelper::getRegressionCurveName(xCurve) + " )";
656 }
657 }
658 }
659 }
660 else if( eObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
661 {
662 if( bVerbose )
663 {
664 aRet = SchResId(STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS);
665 rtl::Reference< DataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
666 if( xSeries.is())
667 {
669 if( xCurve.is())
670 {
671 try
672 {
673 Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_SET_THROW );
674 RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
675
677 const OUString& aNumDecimalSep = rLocaleDataWrapper.getNumDecimalSep();
678 sal_Unicode cDecSeparator = aNumDecimalSep[0];
679
680 OUString aWildcard( "%AVERAGE_VALUE" );
681 sal_Int32 nIndex = aRet.indexOf( aWildcard );
682 // as the curve is constant, the value at any x-value is ok
683 if( nIndex != -1 )
684 {
685 const double fMeanValue( xCalculator->getCurveValue( 0.0 ));
686 aRet = aRet.replaceAt(
687 nIndex, aWildcard.getLength(),
688 ::rtl::math::doubleToUString(
689 fMeanValue, rtl_math_StringFormat_G, 4, cDecSeparator, true ));
690 }
691
692 // replace standard deviation
693 aWildcard = "%STD_DEVIATION";
694 nIndex = aRet.indexOf( aWildcard );
695 if( nIndex != -1 )
696 {
697 const double fStdDev( xCalculator->getCorrelationCoefficient());
698 aRet = aRet.replaceAt(
699 nIndex, aWildcard.getLength(),
700 ::rtl::math::doubleToUString(
701 fStdDev, rtl_math_StringFormat_G, 4, cDecSeparator, true ));
702 }
703 }
704 catch( const uno::Exception & )
705 {
706 DBG_UNHANDLED_EXCEPTION("chart2");
707 }
708 }
709 }
710 }
711 else
712 {
713 // non-verbose
714 aRet = ObjectNameProvider::getName( eObjectType );
715 }
716 }
717 else
718 {
719 aRet = ObjectNameProvider::getName( eObjectType );
720 }
721 return aRet;
722}
723
724OUString ObjectNameProvider::getSelectedObjectText( std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel>& xChartDocument )
725{
726 OUString aRet;
727 ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
728
729 if( eObjectType == OBJECTTYPE_DATA_POINT )
730 {
731 aRet = SchResId( STR_STATUS_DATAPOINT_MARKED );
732
733 rtl::Reference< Diagram > xDiagram( xChartDocument->getFirstChartDiagram() );
734 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartDocument );
735 if( xDiagram.is() && xSeries.is() )
736 {
737 sal_Int32 nPointIndex = o3tl::toInt32( ObjectIdentifier::getParticleID(rObjectCID) );
738
739 // replace data point index
740 replaceParamterInString( aRet, u"%POINTNUMBER", OUString::number( nPointIndex + 1 ));
741
742 // replace data series index
743 {
744 std::vector< rtl::Reference< DataSeries > > aSeriesVector(
745 xDiagram->getDataSeries() );
746 sal_Int32 nSeriesIndex = -1;
747 for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
748 {
749 if( aSeriesVector[nSeriesIndex] == xSeries )
750 break;
751 }
752 replaceParamterInString( aRet, u"%SERIESNUMBER", OUString::number( nSeriesIndex + 1 ) );
753 }
754
755 // replace point value
756 replaceParamterInString( aRet, u"%POINTVALUES", lcl_getDataPointValueText(
757 xSeries, nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartDocument ) );
758 }
759 }
760 else
761 {
762 // use the verbose text including the formula for trend lines
763 const bool bVerbose( eObjectType == OBJECTTYPE_DATA_CURVE || eObjectType == OBJECTTYPE_DATA_AVERAGE_LINE );
764 const OUString aHelpText( getHelpText( rObjectCID, xChartDocument, bVerbose ));
765 if( !aHelpText.isEmpty())
766 {
767 aRet = SchResId( STR_STATUS_OBJECT_MARKED );
768 replaceParamterInString( aRet, u"%OBJECTNAME", aHelpText );
769 }
770 }
771
772 return aRet;
773}
774
776 std::u16string_view rObjectCID,
777 const rtl::Reference<::chart::ChartModel>& xChartDocument )
778{
780
781 switch( eType )
782 {
783 case OBJECTTYPE_AXIS:
784 return getAxisName( rObjectCID, xChartDocument );
785 case OBJECTTYPE_TITLE:
786 return getTitleName( rObjectCID, xChartDocument );
787 case OBJECTTYPE_GRID:
789 return getGridName( rObjectCID, xChartDocument );
791 return lcl_getFullSeriesName( rObjectCID, xChartDocument );
801 {
802 OUString aRet = lcl_getFullSeriesName( rObjectCID, xChartDocument ) + " ";
804 {
806 sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
807 aRet += " " + OUString::number(nPointIndex+1);
809 {
810 aRet += " " + getName( OBJECTTYPE_DATA_LABEL );
811 }
812 }
814 {
815 rtl::Reference< DataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartDocument ));
816
817 aRet += " " + getName(eType);
818
819 if( xSeries.is())
820 {
821 sal_Int32 nCurveIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
823 if( xCurve.is())
824 {
825 aRet += " (" + RegressionCurveHelper::getRegressionCurveName(xCurve) + ")";
826 }
827 }
828 }
829 else
830 {
831 aRet += getName( eType );
832 }
833 return aRet;
834 }
835 default:
836 break;
837 }
838
839 return getName( eType );
840}
841
843 ObjectType eObjectType,
844 std::u16string_view rSeriesCID,
845 const rtl::Reference<::chart::ChartModel>& xChartDocument )
846{
847 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSeriesCID , xChartDocument );
848 if( xSeries.is() )
849 {
850 OUString aRet = SchResId(STR_OBJECT_FOR_SERIES);
851 replaceParamterInString( aRet, u"%OBJECTNAME", getName( eObjectType ) );
852 replaceParamterInString( aRet, u"%SERIESNAME", lcl_getDataSeriesName( rSeriesCID, xChartDocument ) );
853 return aRet;
854 }
855 else
857}
858
860{
861 OUString aRet = SchResId(STR_OBJECT_FOR_ALL_SERIES);
862 replaceParamterInString( aRet, u"%OBJECTNAME", getName( eObjectType, true /*bPlural*/ ) );
863 return aRet;
864}
865
866} //namespace chart
867
868/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const LocaleDataWrapper & GetLocaleDataWrapper() const
static const AllSettings & GetSettings()
const OUString & getNumDecimalSep() const
static bool getIndicesForAxis(const rtl::Reference< ::chart::Axis > &xAxis, const rtl::Reference< ::chart::BaseCoordinateSystem > &xCooSys, sal_Int32 &rOutDimensionIndex, sal_Int32 &rOutAxisIndex)
static OUString getCategoryByIndex(const rtl::Reference< ::chart::BaseCoordinateSystem > &xCooSysModel, ChartModel &rModel, sal_Int32 nIndex)
static rtl::Reference< ::chart::DataSeries > getDataSeriesForCID(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel)
static std::u16string_view getParticleID(std::u16string_view rCID)
static css::uno::Reference< css::beans::XPropertySet > getObjectPropertySet(std::u16string_view rObjectCID, const rtl::Reference< ::chart::ChartModel > &xChartDocument)
static rtl::Reference< ::chart::Axis > getAxisForCID(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel)
static sal_Int32 getIndexFromParticleOrCID(std::u16string_view rParticleOrCID)
ObjectType getObjectType() const
static OUString getName_ObjectForSeries(ObjectType eObjectType, std::u16string_view rSeriesCID, const rtl::Reference<::chart::ChartModel > &xChartDocument)
static OUString getName(ObjectType eObjectType, bool bPlural=false)
static OUString getAxisName(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel)
static OUString getSelectedObjectText(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartDocument)
This is used for showing the currently selected object in the status bar (command "Context")
static OUString getGridName(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel)
static OUString getTitleName(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel)
static OUString getTitleNameByType(TitleHelper::eTitleType eType)
static OUString getName_ObjectForAllSeries(ObjectType eObjectType)
static OUString getHelpText(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel, bool bVerbose=false)
Provides help texts for the various chart elements.
static OUString getNameForCID(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartDocument)
static bool getTitleType(eTitleType &rType, const rtl::Reference< ::chart::Title > &xTitle, const rtl::Reference< ::chart::ChartModel > &xModel)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
float u
OUString aWildcard
DocumentType eType
sal_Int32 nIndex
constexpr OUStringLiteral aData
OOO_DLLPUBLIC_CHARTTOOLS rtl::Reference< ::chart::BaseCoordinateSystem > getCoordinateSystemOfSeries(const rtl::Reference< ::chart::DataSeries > &xSeries, const rtl::Reference< ::chart::Diagram > &xDiagram)
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 > 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 > getMeanValueLine(const css::uno::Reference< css::chart2::XRegressionCurveContainer > &xRegCnt)
OOO_DLLPUBLIC_CHARTTOOLS SvxChartRegress getRegressionType(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
OOO_DLLPUBLIC_CHARTTOOLS OUString getRegressionCurveName(const css::uno::Reference< css::chart2::XRegressionCurve > &xCurve)
@ OBJECTTYPE_DATA_SERIES
@ OBJECTTYPE_DATA_LABELS
@ OBJECTTYPE_DATA_TABLE
@ OBJECTTYPE_DIAGRAM
@ OBJECTTYPE_LEGEND_ENTRY
@ OBJECTTYPE_DATA_ERRORS_X
@ OBJECTTYPE_DATA_STOCK_LOSS
@ OBJECTTYPE_DIAGRAM_FLOOR
@ OBJECTTYPE_DATA_POINT
@ OBJECTTYPE_DATA_STOCK_RANGE
@ OBJECTTYPE_SUBGRID
@ OBJECTTYPE_DATA_ERRORS_Y
@ OBJECTTYPE_AXIS_UNITLABEL
@ OBJECTTYPE_DATA_CURVE_EQUATION
@ OBJECTTYPE_DATA_STOCK_GAIN
@ OBJECTTYPE_DATA_AVERAGE_LINE
@ OBJECTTYPE_DATA_ERRORS_Z
@ OBJECTTYPE_DATA_CURVE
@ OBJECTTYPE_DATA_LABEL
@ OBJECTTYPE_DIAGRAM_WALL
OOO_DLLPUBLIC_CHARTTOOLS bool replaceParamterInString(OUString &rInOutResourceString, std::u16string_view rParamToReplace, std::u16string_view rReplaceWith)
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
Definition: ResId.cxx:24
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
sal_uInt16 sal_Unicode