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