1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ObjectNameProvider.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "ObjectNameProvider.hxx"
36 #include "Strings.hrc"
38 #include "AxisHelper.hxx"
39 #include "ChartModelHelper.hxx"
40 #include "DiagramHelper.hxx"
41 #include "DataSeriesHelper.hxx"
42 #include "TitleHelper.hxx"
43 #include "AxisIndexDefines.hxx"
44 #include "ExplicitCategoriesProvider.hxx"
45 #include "CommonConverters.hxx"
46 #include "chartview/NumberFormatterWrapper.hxx"
47 #include "RegressionCurveHelper.hxx"
48 #include <rtl/math.hxx>
49 #include <tools/debug.hxx>
50 #include <tools/string.hxx>
52 // #include <svtools/syslocale.hxx>
54 #include <com/sun/star/chart2/XTitle.hpp>
55 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
57 //.............................................................................
60 //.............................................................................
61 using namespace ::com::sun::star
;
62 using namespace ::com::sun::star::chart2
;
63 using ::com::sun::star::uno::Reference
;
64 using ::com::sun::star::uno::Sequence
;
65 using ::com::sun::star::uno::Any
;
71 OUString
lcl_getDataSeriesName( const rtl::OUString
& rObjectCID
, const Reference
< frame::XModel
>& xChartModel
)
75 Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram( xChartModel
) );
76 Reference
< XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
77 if( xDiagram
.is() && xSeries
.is() )
79 Reference
< XChartType
> xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram
, xSeries
) );
82 aRet
= ::chart::DataSeriesHelper::getDataSeriesLabel(
83 xSeries
, xChartType
->getRoleOfSequenceForSeriesLabel() ) ;
90 OUString
lcl_getFullSeriesName( const rtl::OUString
& rObjectCID
, const Reference
< frame::XModel
>& xChartModel
)
92 OUString aRet
= String(SchResId(STR_TIP_DATASERIES
));
93 OUString
aWildcard( C2U("%SERIESNAME") );
94 sal_Int32 nIndex
= aRet
.indexOf( aWildcard
);
96 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), lcl_getDataSeriesName( rObjectCID
, xChartModel
) );
100 void lcl_addText( OUString
& rOut
, const OUString
& rSeparator
, const OUString
& rNext
)
102 if( rOut
.getLength() && rNext
.getLength() )
104 if( rNext
.getLength() )
108 OUString
lcl_getDataPointValueText( const Reference
< XDataSeries
>& xSeries
, sal_Int32 nPointIndex
,
109 const Reference
< XCoordinateSystem
>& xCooSys
,
110 const Reference
< frame::XModel
>& xChartModel
)
115 Reference
<data::XDataSource
> xDataSource(
116 uno::Reference
<data::XDataSource
>( xSeries
, uno::UNO_QUERY
) );
117 if(!xDataSource
.is())
120 Sequence
< Reference
< data::XLabeledDataSequence
> > aDataSequences( xDataSource
->getDataSequences() );
122 rtl::OUString aX
, aY
, aY_Min
, aY_Max
, aY_First
, aY_Last
, a_Size
;
125 uno::Reference
< util::XNumberFormatsSupplier
> xNumberFormatsSupplier( xChartModel
, uno::UNO_QUERY
);
126 NumberFormatterWrapper
aNumberFormatterWrapper( xNumberFormatsSupplier
);
127 sal_Int32 nLabelColor
= 0;//dummy
128 bool bColorChanged
;//dummy
130 for(sal_Int32 nN
= aDataSequences
.getLength();nN
--;)
132 uno::Reference
<data::XDataSequence
> xDataSequence( aDataSequences
[nN
]->getValues());
133 if( !xDataSequence
.is() )
135 Sequence
< Any
> aData( xDataSequence
->getData() );
136 if( nPointIndex
>= aData
.getLength() )
138 uno::Reference
<beans::XPropertySet
> xProp(xDataSequence
, uno::UNO_QUERY
);
143 uno::Any aARole
= xProp
->getPropertyValue( C2U( "Role" ) );
147 if( aRole
.equals(C2U("values-x")) )
149 aData
[nPointIndex
]>>= fValue
;
150 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
151 aX
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
153 else if( aRole
.equals(C2U("values-y")) )
155 aData
[nPointIndex
]>>= fValue
;
156 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
157 aY
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
159 else if( aRole
.equals(C2U("values-first")) )
161 aData
[nPointIndex
]>>= fValue
;
162 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
163 aY_First
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
165 else if( aRole
.equals(C2U("values-min")) )
167 aData
[nPointIndex
]>>= fValue
;
168 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
169 aY_Min
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
171 else if( aRole
.equals(C2U("values-max")) )
173 aData
[nPointIndex
]>>= fValue
;
174 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
175 aY_Max
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
177 else if( aRole
.equals(C2U("values-last")) )
179 aData
[nPointIndex
]>>= fValue
;
180 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
181 aY_Last
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
183 else if( aRole
.equals(C2U("values-size")) )
185 aData
[nPointIndex
]>>= fValue
;
186 sal_Int32 nNumberFormatKey
= xDataSequence
->getNumberFormatKeyByIndex( nPointIndex
);
187 a_Size
= aNumberFormatterWrapper
.getFormattedString( nNumberFormatKey
, fValue
, nLabelColor
, bColorChanged
);
190 catch( uno::Exception
& e
)
192 ASSERT_EXCEPTION( e
);
197 if( aX
.getLength() == 0 )
199 rtl::OUString aCategory
= ::rtl::OUString( String(SchResId(STR_TIP_CATEGORY_VALUE
)));
201 replaceParamterInString( aCategory
202 , C2U("%CATEGORYVALUE")
203 , ExplicitCategoriesProvider::getCategoryByIndex( xCooSys
, nPointIndex
)
213 OUString
aSeparator(C2U(" "));
215 lcl_addText( aRet
, aSeparator
, aY
);
216 lcl_addText( aRet
, aSeparator
, aY_First
);
217 lcl_addText( aRet
, aSeparator
, aY_Min
);
218 lcl_addText( aRet
, aSeparator
, aY_Max
);
219 lcl_addText( aRet
, aSeparator
, aY_Last
);
220 lcl_addText( aRet
, aSeparator
, a_Size
);
225 } //end anonymous namespace
227 rtl::OUString
ObjectNameProvider::getName( ObjectType eObjectType
, bool bPlural
)
230 switch( eObjectType
)
232 case OBJECTTYPE_PAGE
:
233 aRet
=String(SchResId(STR_OBJECT_PAGE
));
235 case OBJECTTYPE_TITLE
:
238 aRet
=String(SchResId(STR_OBJECT_TITLES
));
240 aRet
=String(SchResId(STR_OBJECT_TITLE
));
243 case OBJECTTYPE_LEGEND
:
244 aRet
=String(SchResId(STR_OBJECT_LEGEND
));
246 case OBJECTTYPE_LEGEND_ENTRY
:
247 aRet
=String(SchResId(STR_OBJECT_LEGEND_SYMBOL
));//@todo change string if we do differenciate symbol and legend entry in future
249 case OBJECTTYPE_DIAGRAM
:
250 aRet
=String(SchResId(STR_OBJECT_DIAGRAM
));
252 case OBJECTTYPE_DIAGRAM_WALL
:
253 aRet
=String(SchResId(STR_OBJECT_DIAGRAM_WALL
));
255 case OBJECTTYPE_DIAGRAM_FLOOR
:
256 aRet
=String(SchResId(STR_OBJECT_DIAGRAM_FLOOR
));
258 case OBJECTTYPE_AXIS
:
261 aRet
=String(SchResId(STR_OBJECT_AXES
));
263 aRet
=String(SchResId(STR_OBJECT_AXIS
));
266 case OBJECTTYPE_AXIS_UNITLABEL
:
267 aRet
=String(SchResId(STR_OBJECT_LABEL
));//@todo maybe a more concrete name
269 case OBJECTTYPE_GRID
:
270 case OBJECTTYPE_SUBGRID
: //maybe todo: different names for subgrids
273 aRet
=String(SchResId(STR_OBJECT_GRIDS
));
275 aRet
=String(SchResId(STR_OBJECT_GRID
));
278 case OBJECTTYPE_DATA_SERIES
:
281 aRet
=String(SchResId(STR_OBJECT_DATASERIES_PLURAL
));
283 aRet
=String(SchResId(STR_OBJECT_DATASERIES
));
286 case OBJECTTYPE_DATA_POINT
:
289 aRet
=String(SchResId(STR_OBJECT_DATAPOINTS
));
291 aRet
=String(SchResId(STR_OBJECT_DATAPOINT
));
294 case OBJECTTYPE_DATA_LABELS
:
295 aRet
=String(SchResId(STR_OBJECT_DATALABELS
));
297 case OBJECTTYPE_DATA_LABEL
:
298 aRet
=String(SchResId(STR_OBJECT_LABEL
));
300 case OBJECTTYPE_DATA_ERRORS
:
301 aRet
=String(SchResId(STR_OBJECT_ERROR_BARS
));//@todo? maybe distinguish plural singular
303 case OBJECTTYPE_DATA_ERRORS_X
:
304 aRet
=String(SchResId(STR_OBJECT_ERROR_BARS
));//@todo? maybe specialize in future
306 case OBJECTTYPE_DATA_ERRORS_Y
:
307 aRet
=String(SchResId(STR_OBJECT_ERROR_BARS
));//@todo? maybe specialize in future
309 case OBJECTTYPE_DATA_ERRORS_Z
:
310 aRet
=String(SchResId(STR_OBJECT_ERROR_BARS
));//@todo? maybe specialize in future
312 case OBJECTTYPE_DATA_AVERAGE_LINE
:
313 aRet
=String(SchResId(STR_OBJECT_AVERAGE_LINE
));
315 case OBJECTTYPE_DATA_CURVE
:
318 aRet
=String(SchResId(STR_OBJECT_CURVES
));
320 aRet
=String(SchResId(STR_OBJECT_CURVE
));
323 case OBJECTTYPE_DATA_STOCK_RANGE
:
324 //aRet=String(SchResId());
326 case OBJECTTYPE_DATA_STOCK_LOSS
:
327 aRet
=String(SchResId(STR_OBJECT_STOCK_LOSS
));
329 case OBJECTTYPE_DATA_STOCK_GAIN
:
330 aRet
=String(SchResId(STR_OBJECT_STOCK_GAIN
));
332 case OBJECTTYPE_DATA_CURVE_EQUATION
:
333 aRet
=String(SchResId(STR_OBJECT_CURVE_EQUATION
));
335 default: //OBJECTTYPE_UNKNOWN
341 rtl::OUString
ObjectNameProvider::getAxisName( const rtl::OUString
& rObjectCID
342 , const uno::Reference
< frame::XModel
>& xChartModel
)
348 Reference
< XAxis
> xAxis(
349 ObjectIdentifier::getObjectPropertySet( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
351 sal_Int32 nCooSysIndex
= 0;
352 sal_Int32 nDimensionIndex
= 0;
353 sal_Int32 nAxisIndex
= 0;
354 AxisHelper::getIndicesForAxis( xAxis
, ChartModelHelper::findDiagram( xChartModel
), nCooSysIndex
, nDimensionIndex
, nAxisIndex
);
356 switch(nDimensionIndex
)
359 if( nAxisIndex
== 0 )
360 aRet
=String(SchResId(STR_OBJECT_AXIS_X
));
362 aRet
=String(SchResId(STR_OBJECT_SECONDARY_X_AXIS
));
365 if( nAxisIndex
== 0 )
366 aRet
=String(SchResId(STR_OBJECT_AXIS_Y
));
368 aRet
=String(SchResId(STR_OBJECT_SECONDARY_Y_AXIS
));
371 aRet
=String(SchResId(STR_OBJECT_AXIS_Z
));
374 aRet
=String(SchResId(STR_OBJECT_AXIS
));
382 OUString
ObjectNameProvider::getTitleNameByType( TitleHelper::eTitleType eType
)
388 case TitleHelper::MAIN_TITLE
:
389 aRet
=String(SchResId(STR_OBJECT_TITLE_MAIN
));
391 case TitleHelper::SUB_TITLE
:
392 aRet
=String(SchResId(STR_OBJECT_TITLE_SUB
));
394 case TitleHelper::X_AXIS_TITLE
:
395 aRet
=String(SchResId(STR_OBJECT_TITLE_X_AXIS
));
397 case TitleHelper::Y_AXIS_TITLE
:
398 aRet
=String(SchResId(STR_OBJECT_TITLE_Y_AXIS
));
400 case TitleHelper::Z_AXIS_TITLE
:
401 aRet
=String(SchResId(STR_OBJECT_TITLE_Z_AXIS
));
403 case TitleHelper::SECONDARY_X_AXIS_TITLE
:
404 aRet
=String(SchResId(STR_OBJECT_TITLE_SECONDARY_X_AXIS
));
406 case TitleHelper::SECONDARY_Y_AXIS_TITLE
:
407 aRet
=String(SchResId(STR_OBJECT_TITLE_SECONDARY_Y_AXIS
));
410 DBG_ERROR("unknown title type");
414 if( !aRet
.getLength() )
415 aRet
=String(SchResId(STR_OBJECT_TITLE
));
421 OUString
ObjectNameProvider::getTitleName( const OUString
& rObjectCID
422 , const Reference
< frame::XModel
>& xChartModel
)
426 Reference
< XTitle
> xTitle(
427 ObjectIdentifier::getObjectPropertySet( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
430 TitleHelper::eTitleType eType
;
431 if( TitleHelper::getTitleType( eType
, xTitle
, xChartModel
) )
432 aRet
= ObjectNameProvider::getTitleNameByType( eType
);
434 if( !aRet
.getLength() )
435 aRet
=String(SchResId(STR_OBJECT_TITLE
));
441 rtl::OUString
ObjectNameProvider::getGridName( const rtl::OUString
& rObjectCID
442 , const uno::Reference
< frame::XModel
>& xChartModel
)
447 sal_Int32 nCooSysIndex
= -1;
448 sal_Int32 nDimensionIndex
= -1;
449 sal_Int32 nAxisIndex
= -1;
450 Reference
< XAxis
> xAxis( ObjectIdentifier::getAxisForCID( rObjectCID
, xChartModel
) );
451 AxisHelper::getIndicesForAxis( xAxis
, ChartModelHelper::findDiagram( xChartModel
)
452 , nCooSysIndex
, nDimensionIndex
, nAxisIndex
);
454 bool bMainGrid
= (ObjectIdentifier::getObjectType( rObjectCID
) == OBJECTTYPE_GRID
);
458 switch(nDimensionIndex
)
461 aRet
=String(SchResId(STR_OBJECT_GRID_MAJOR_X
));
464 aRet
=String(SchResId(STR_OBJECT_GRID_MAJOR_Y
));
467 aRet
=String(SchResId(STR_OBJECT_GRID_MAJOR_Z
));
470 aRet
=String(SchResId(STR_OBJECT_GRID
));
476 switch(nDimensionIndex
)
479 aRet
=String(SchResId(STR_OBJECT_GRID_MINOR_X
));
482 aRet
=String(SchResId(STR_OBJECT_GRID_MINOR_Y
));
485 aRet
=String(SchResId(STR_OBJECT_GRID_MINOR_Z
));
488 aRet
=String(SchResId(STR_OBJECT_GRID
));
495 rtl::OUString
ObjectNameProvider::getHelpText( const rtl::OUString
& rObjectCID
, const Reference
< chart2::XChartDocument
>& xChartDocument
, bool bVerbose
)
497 return getHelpText( rObjectCID
, Reference
< frame::XModel
>( xChartDocument
, uno::UNO_QUERY
), bVerbose
);
500 rtl::OUString
ObjectNameProvider::getHelpText( const rtl::OUString
& rObjectCID
, const Reference
< frame::XModel
>& xChartModel
, bool bVerbose
)
503 ObjectType
eObjectType( ObjectIdentifier::getObjectType(rObjectCID
) );
504 if( OBJECTTYPE_AXIS
== eObjectType
)
506 aRet
=ObjectNameProvider::getAxisName( rObjectCID
, xChartModel
);
508 else if( OBJECTTYPE_GRID
== eObjectType
509 || OBJECTTYPE_SUBGRID
== eObjectType
)
511 aRet
=ObjectNameProvider::getGridName( rObjectCID
, xChartModel
);
513 else if( OBJECTTYPE_TITLE
== eObjectType
)
515 aRet
=ObjectNameProvider::getTitleName( rObjectCID
, xChartModel
);
517 else if( OBJECTTYPE_DATA_SERIES
== eObjectType
)
519 aRet
= lcl_getFullSeriesName( rObjectCID
, xChartModel
);
521 else if( OBJECTTYPE_DATA_POINT
== eObjectType
)
525 OUString
aNewLine(C2U("\n"));
527 aRet
=String(SchResId(STR_TIP_DATAPOINT_INDEX
));
529 aRet
+=String(SchResId(STR_TIP_DATASERIES
));
531 aRet
+=String(SchResId(STR_TIP_DATAPOINT_VALUES
));
534 aRet
=String(SchResId(STR_TIP_DATAPOINT
));
536 Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram( xChartModel
) );
537 Reference
< XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
538 if( xDiagram
.is() && xSeries
.is() )
540 sal_Int32
nPointIndex( ObjectIdentifier::getParticleID(rObjectCID
).toInt32() );
542 //replace data point index
543 sal_Int32 nIndex
= -1;
544 OUString
aWildcard( C2U("%POINTNUMBER") );
545 nIndex
= aRet
.indexOf( aWildcard
);
548 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), OUString::valueOf(nPointIndex
+1) );
551 //replace data series index
552 aWildcard
= C2U("%SERIESNUMBER");
553 nIndex
= aRet
.indexOf( aWildcard
);
556 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVector(
557 DiagramHelper::getDataSeriesFromDiagram( xDiagram
) );
558 sal_Int32 nSeriesIndex
= -1;
559 for( nSeriesIndex
=aSeriesVector
.size();nSeriesIndex
--;)
561 if( aSeriesVector
[nSeriesIndex
] == xSeries
)
567 OUString
aReplacement( OUString::valueOf(nSeriesIndex
+1) );
568 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), aReplacement
);
571 //replace point values
572 aWildcard
= C2U("%POINTVALUES");
573 nIndex
= aRet
.indexOf( aWildcard
);
575 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), lcl_getDataPointValueText(
576 xSeries
,nPointIndex
, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries
, xDiagram
), xChartModel
) );
578 //replace series name
579 aWildcard
= C2U("%SERIESNAME");
580 nIndex
= aRet
.indexOf( aWildcard
);
582 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), lcl_getDataSeriesName( rObjectCID
, xChartModel
) );
586 else if( OBJECTTYPE_DIAGRAM == eObjectType )
588 //todo different names for different diagram types ???
589 //or different names for series of diferent charttypes
592 else if( OBJECTTYPE_DATA_CURVE
== eObjectType
)
596 aRet
= String( SchResId( STR_OBJECT_CURVE_WITH_PARAMETERS
));
597 Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
));
598 Reference
< chart2::XRegressionCurveContainer
> xCurveCnt( xSeries
, uno::UNO_QUERY
);
601 Reference
< chart2::XRegressionCurve
> xCurve( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xCurveCnt
));
606 Reference
< chart2::XRegressionCurveCalculator
> xCalculator( xCurve
->getCalculator(), uno::UNO_QUERY_THROW
);
607 RegressionCurveHelper::initializeCurveCalculator( xCalculator
, xSeries
, xChartModel
);
610 sal_Int32 nIndex
= -1;
611 OUString
aWildcard( C2U("%FORMULA") );
612 nIndex
= aRet
.indexOf( aWildcard
);
614 aRet
= aRet
.replaceAt( nIndex
, aWildcard
.getLength(), xCalculator
->getRepresentation());
617 aWildcard
= C2U("%RSQUARED");
618 nIndex
= aRet
.indexOf( aWildcard
);
621 sal_Unicode
aDecimalSep( '.' );
622 //@todo: enable this code when a localized decimal
623 //separator is also available for the formula
624 // SvtSysLocale aSysLocale;
625 // OUString aSep( aSysLocale.GetLocaleData().getNumDecimalSep());
626 // if( aSep.getLength() == 1 )
627 // aDecimalSep = aSep.toChar();
628 double fR( xCalculator
->getCorrelationCoefficient());
629 aRet
= aRet
.replaceAt(
630 nIndex
, aWildcard
.getLength(),
631 ::rtl::math::doubleToUString(
632 fR
*fR
, rtl_math_StringFormat_G
, 4, aDecimalSep
, true ));
635 catch( const uno::Exception
& ex
)
637 ASSERT_EXCEPTION( ex
);
645 aRet
= ObjectNameProvider::getName( eObjectType
, false );
648 else if( OBJECTTYPE_DATA_AVERAGE_LINE
== eObjectType
)
652 aRet
= String( SchResId( STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS
));
653 Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
));
654 Reference
< chart2::XRegressionCurveContainer
> xCurveCnt( xSeries
, uno::UNO_QUERY
);
657 Reference
< chart2::XRegressionCurve
> xCurve( RegressionCurveHelper::getMeanValueLine( xCurveCnt
));
662 Reference
< chart2::XRegressionCurveCalculator
> xCalculator( xCurve
->getCalculator(), uno::UNO_QUERY_THROW
);
663 RegressionCurveHelper::initializeCurveCalculator( xCalculator
, xSeries
, xChartModel
);
665 sal_Unicode
aDecimalSep( '.' );
666 // replace average value
667 // SvtSysLocale aSysLocale;
668 // OUString aSep( aSysLocale.GetLocaleData().getNumDecimalSep());
669 // if( aSep.getLength() == 1 )
670 // aDecimalSep = aSep.toChar();
672 sal_Int32 nIndex
= -1;
673 OUString
aWildcard( C2U("%AVERAGE_VALUE") );
674 nIndex
= aRet
.indexOf( aWildcard
);
675 // as the curve is constant, the value at any x-value is ok
678 const double fMeanValue( xCalculator
->getCurveValue( 0.0 ));
679 aRet
= aRet
.replaceAt(
680 nIndex
, aWildcard
.getLength(),
681 ::rtl::math::doubleToUString(
682 fMeanValue
, rtl_math_StringFormat_G
, 4, aDecimalSep
, true ));
685 // replace standard deviation
686 aWildcard
= C2U("%STD_DEVIATION");
687 nIndex
= aRet
.indexOf( aWildcard
);
690 const double fStdDev( xCalculator
->getCorrelationCoefficient());
691 aRet
= aRet
.replaceAt(
692 nIndex
, aWildcard
.getLength(),
693 ::rtl::math::doubleToUString(
694 fStdDev
, rtl_math_StringFormat_G
, 4, aDecimalSep
, true ));
697 catch( const uno::Exception
& ex
)
699 ASSERT_EXCEPTION( ex
);
707 aRet
= ObjectNameProvider::getName( eObjectType
, false );
712 aRet
= ObjectNameProvider::getName( eObjectType
, false );
718 rtl::OUString
ObjectNameProvider::getSelectedObjectText( const rtl::OUString
& rObjectCID
, const ::com::sun::star::uno::Reference
< ::com::sun::star::chart2::XChartDocument
>& xChartDocument
)
721 ObjectType
eObjectType( ObjectIdentifier::getObjectType(rObjectCID
) );
722 Reference
< frame::XModel
> xChartModel( xChartDocument
, uno::UNO_QUERY
);
724 if( OBJECTTYPE_DATA_POINT
== eObjectType
)
726 aRet
= String( SchResId( STR_STATUS_DATAPOINT_MARKED
));
728 Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram( xChartModel
) );
729 Reference
< XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
730 if( xDiagram
.is() && xSeries
.is() )
732 sal_Int32
nPointIndex( ObjectIdentifier::getParticleID(rObjectCID
).toInt32() );
734 // replace data point index
735 replaceParamterInString( aRet
, C2U("%POINTNUMBER"), OUString::valueOf( nPointIndex
+ 1 ));
737 // replace data series index
739 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVector(
740 DiagramHelper::getDataSeriesFromDiagram( xDiagram
) );
741 sal_Int32 nSeriesIndex
= -1;
742 for( nSeriesIndex
=aSeriesVector
.size();nSeriesIndex
--;)
744 if( aSeriesVector
[nSeriesIndex
] == xSeries
)
747 replaceParamterInString( aRet
, C2U("%SERIESNUMBER"), OUString::valueOf( nSeriesIndex
+ 1 ) );
750 // replace point value
751 replaceParamterInString( aRet
, C2U("%POINTVALUES"), lcl_getDataPointValueText(
752 xSeries
, nPointIndex
, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries
, xDiagram
), xChartModel
) );
757 // use the verbose text including the formula for trend lines
758 const bool bVerbose( OBJECTTYPE_DATA_CURVE
== eObjectType
|| OBJECTTYPE_DATA_AVERAGE_LINE
== eObjectType
);
759 const OUString
aHelpText( getHelpText( rObjectCID
, xChartModel
, bVerbose
));
760 if( aHelpText
.getLength())
762 aRet
= String( SchResId( STR_STATUS_OBJECT_MARKED
));
763 replaceParamterInString( aRet
, C2U("%OBJECTNAME"), aHelpText
);
772 rtl::OUString
ObjectNameProvider::getNameForCID(
773 const rtl::OUString
& rObjectCID
,
774 const uno::Reference
< chart2::XChartDocument
>& xChartDocument
)
776 ObjectType
eType( ObjectIdentifier::getObjectType( rObjectCID
));
777 Reference
< frame::XModel
> xModel( xChartDocument
, uno::UNO_QUERY
);
781 case OBJECTTYPE_AXIS
:
782 return getAxisName( rObjectCID
, xModel
);
783 case OBJECTTYPE_TITLE
:
784 return getTitleName( rObjectCID
, xModel
);
785 case OBJECTTYPE_GRID
:
786 case OBJECTTYPE_SUBGRID
:
787 return getGridName( rObjectCID
, xModel
);
788 case OBJECTTYPE_DATA_SERIES
:
789 return lcl_getFullSeriesName( rObjectCID
, xModel
);
790 //case OBJECTTYPE_LEGEND_ENTRY:
791 case OBJECTTYPE_DATA_POINT
:
792 case OBJECTTYPE_DATA_LABELS
:
793 case OBJECTTYPE_DATA_LABEL
:
794 case OBJECTTYPE_DATA_ERRORS
:
795 case OBJECTTYPE_DATA_ERRORS_X
:
796 case OBJECTTYPE_DATA_ERRORS_Y
:
797 case OBJECTTYPE_DATA_ERRORS_Z
:
798 case OBJECTTYPE_DATA_CURVE
:
799 case OBJECTTYPE_DATA_AVERAGE_LINE
:
800 case OBJECTTYPE_DATA_CURVE_EQUATION
:
802 rtl::OUString aRet
= lcl_getFullSeriesName( rObjectCID
, xModel
);
804 if( eType
== OBJECTTYPE_DATA_POINT
|| eType
== OBJECTTYPE_DATA_LABEL
)
806 aRet
+= getName( OBJECTTYPE_DATA_POINT
);
807 sal_Int32 nPointIndex
= ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID
);
809 aRet
+= OUString::valueOf(nPointIndex
+1);
811 if( eType
== OBJECTTYPE_DATA_LABEL
)
814 aRet
+= getName( OBJECTTYPE_DATA_LABEL
);
818 aRet
+= getName( eType
);
825 return getName( eType
);
829 rtl::OUString
ObjectNameProvider::getName_ObjectForSeries(
830 ObjectType eObjectType
,
831 const rtl::OUString
& rSeriesCID
,
832 const uno::Reference
< chart2::XChartDocument
>& xChartDocument
)
834 uno::Reference
< frame::XModel
> xChartModel( xChartDocument
, uno::UNO_QUERY
);
835 Reference
< XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( rSeriesCID
, xChartModel
), uno::UNO_QUERY
);
838 OUString aRet
= String(SchResId(STR_OBJECT_FOR_SERIES
));
839 replaceParamterInString( aRet
, C2U("%OBJECTNAME"), getName( eObjectType
, false /*bPlural*/ ) );
840 replaceParamterInString( aRet
, C2U("%SERIESNAME"), lcl_getDataSeriesName( rSeriesCID
, xChartModel
) );
844 return ObjectNameProvider::getName_ObjectForAllSeries( eObjectType
);
848 rtl::OUString
ObjectNameProvider::getName_ObjectForAllSeries( ObjectType eObjectType
)
850 OUString aRet
= String(SchResId(STR_OBJECT_FOR_ALL_SERIES
));
851 replaceParamterInString( aRet
, C2U("%OBJECTNAME"), getName( eObjectType
, true /*bPlural*/ ) );
855 //.............................................................................
857 //.............................................................................