1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_chart2.hxx"
#include "ObjectNameProvider.hxx"
#include "ResId.hxx"
#include "Strings.hrc"
#include "macros.hxx"
#include "AxisHelper.hxx"
#include "ChartModelHelper.hxx"
#include "DiagramHelper.hxx"
#include "DataSeriesHelper.hxx"
#include "TitleHelper.hxx"
#include "AxisIndexDefines.hxx"
#include "ExplicitCategoriesProvider.hxx"
#include "CommonConverters.hxx"
#include "chartview/NumberFormatterWrapper.hxx"
#include "RegressionCurveHelper.hxx"
#include <rtl/math.hxx>
#include <tools/debug.hxx>
#include <tools/string.hxx>
#include <com/sun/star/chart2/XTitle.hpp>
#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
//.............................................................................
namespace chart
{
//.............................................................................
using namespace ::com::sun::star;
using namespace ::com::sun::star::chart2;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::Any;
using rtl::OUString;
namespace
{
OUString lcl_getDataSeriesName( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
{
OUString aRet;
Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
if( xDiagram.is() && xSeries.is() )
{
Reference< XChartType > xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries ) );
if( xChartType.is() )
{
aRet = ::chart::DataSeriesHelper::getDataSeriesLabel(
xSeries, xChartType->getRoleOfSequenceForSeriesLabel() ) ;
}
}
return aRet;
}
OUString lcl_getFullSeriesName( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel )
{
OUString aRet = String(SchResId(STR_TIP_DATASERIES));
OUString aWildcard( C2U("%SERIESNAME") );
sal_Int32 nIndex = aRet.indexOf( aWildcard );
if( nIndex != -1 )
aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
return aRet;
}
void lcl_addText( OUString& rOut, const OUString& rSeparator, const OUString& rNext )
{
if( rOut.getLength() && rNext.getLength() )
rOut+=rSeparator;
if( rNext.getLength() )
rOut+=rNext;
}
OUString lcl_getDataPointValueText( const Reference< XDataSeries >& xSeries, sal_Int32 nPointIndex,
const Reference< XCoordinateSystem >& xCooSys,
const Reference< frame::XModel >& xChartModel )
{
OUString aRet;
Reference<data::XDataSource> xDataSource(
uno::Reference<data::XDataSource>( xSeries, uno::UNO_QUERY ) );
if(!xDataSource.is())
return aRet;
Sequence< Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
rtl::OUString aX, aY, aY_Min, aY_Max, aY_First, aY_Last, a_Size;
double fValue = 0;
uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY );
NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
sal_Int32 nLabelColor = 0;//dummy
bool bColorChanged;//dummy
for(sal_Int32 nN = aDataSequences.getLength();nN--;)
{
uno::Reference<data::XDataSequence> xDataSequence( aDataSequences[nN]->getValues());
if( !xDataSequence.is() )
continue;
Sequence< Any > aData( xDataSequence->getData() );
if( nPointIndex >= aData.getLength() )
continue;
uno::Reference<beans::XPropertySet> xProp(xDataSequence, uno::UNO_QUERY );
if( xProp.is())
{
try
{
uno::Any aARole = xProp->getPropertyValue( C2U( "Role" ) );
rtl::OUString aRole;
aARole >>= aRole;
if( aRole.equals(C2U("values-x")) )
{
aData[nPointIndex]>>= fValue;
sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
aX = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
}
else if( aRole.equals(C2U("values-y")) )
{
aData[nPointIndex]>>= fValue;
sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
aY = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
}
else if( aRole.equals(C2U("values-first")) )
{
aData[nPointIndex]>>= fValue;
sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
aY_First = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
}
else if( aRole.equals(C2U("values-min")) )
{
aData[nPointIndex]>>= fValue;
sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
aY_Min = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
}
else if( aRole.equals(C2U("values-max")) )
{
aData[nPointIndex]>>= fValue;
sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
aY_Max = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
}
else if( aRole.equals(C2U("values-last")) )
{
aData[nPointIndex]>>= fValue;
sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
aY_Last = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
}
else if( aRole.equals(C2U("values-size")) )
{
aData[nPointIndex]>>= fValue;
sal_Int32 nNumberFormatKey = xDataSequence->getNumberFormatKeyByIndex( nPointIndex );
a_Size = aNumberFormatterWrapper.getFormattedString( nNumberFormatKey, fValue, nLabelColor, bColorChanged );
}
}
catch( uno::Exception& e )
{
ASSERT_EXCEPTION( e );
}
}
}
if( aX.getLength() == 0 )
{
rtl::OUString aCategory = ::rtl::OUString( String(SchResId(STR_TIP_CATEGORY_VALUE)));
replaceParamterInString( aCategory
, C2U("%CATEGORYVALUE")
, ExplicitCategoriesProvider::getCategoryByIndex( xCooSys, xChartModel, nPointIndex )
);
aRet = aCategory;
}
else
{
aRet = aX;
}
OUString aSeparator(C2U(" "));
lcl_addText( aRet, aSeparator, aY );
lcl_addText( aRet, aSeparator, aY_First );
lcl_addText( aRet, aSeparator, aY_Min );
lcl_addText( aRet, aSeparator, aY_Max );
lcl_addText( aRet, aSeparator, aY_Last );
lcl_addText( aRet, aSeparator, a_Size );
return aRet;
}
} //end anonymous namespace
rtl::OUString ObjectNameProvider::getName( ObjectType eObjectType, bool bPlural )
{
rtl::OUString aRet;
switch( eObjectType )
{
case OBJECTTYPE_PAGE:
aRet=String(SchResId(STR_OBJECT_PAGE));
break;
case OBJECTTYPE_TITLE:
{
if(bPlural)
aRet=String(SchResId(STR_OBJECT_TITLES));
else
aRet=String(SchResId(STR_OBJECT_TITLE));
}
break;
case OBJECTTYPE_LEGEND:
aRet=String(SchResId(STR_OBJECT_LEGEND));
break;
case OBJECTTYPE_LEGEND_ENTRY:
aRet=String(SchResId(STR_OBJECT_LEGEND_SYMBOL));//@todo change string if we do differenciate symbol and legend entry in future
break;
case OBJECTTYPE_DIAGRAM:
aRet=String(SchResId(STR_OBJECT_DIAGRAM));
break;
case OBJECTTYPE_DIAGRAM_WALL:
aRet=String(SchResId(STR_OBJECT_DIAGRAM_WALL));
break;
case OBJECTTYPE_DIAGRAM_FLOOR:
aRet=String(SchResId(STR_OBJECT_DIAGRAM_FLOOR));
break;
case OBJECTTYPE_AXIS:
{
if(bPlural)
aRet=String(SchResId(STR_OBJECT_AXES));
else
aRet=String(SchResId(STR_OBJECT_AXIS));
}
break;
case OBJECTTYPE_AXIS_UNITLABEL:
aRet=String(SchResId(STR_OBJECT_LABEL));//@todo maybe a more concrete name
break;
case OBJECTTYPE_GRID:
case OBJECTTYPE_SUBGRID: //maybe todo: different names for subgrids
{
if(bPlural)
aRet=String(SchResId(STR_OBJECT_GRIDS));
else
aRet=String(SchResId(STR_OBJECT_GRID));
}
break;
case OBJECTTYPE_DATA_SERIES:
{
if(bPlural)
aRet=String(SchResId(STR_OBJECT_DATASERIES_PLURAL));
else
aRet=String(SchResId(STR_OBJECT_DATASERIES));
}
break;
case OBJECTTYPE_DATA_POINT:
{
if(bPlural)
aRet=String(SchResId(STR_OBJECT_DATAPOINTS));
else
aRet=String(SchResId(STR_OBJECT_DATAPOINT));
}
break;
case OBJECTTYPE_DATA_LABELS:
aRet=String(SchResId(STR_OBJECT_DATALABELS));
break;
case OBJECTTYPE_DATA_LABEL:
aRet=String(SchResId(STR_OBJECT_LABEL));
break;
case OBJECTTYPE_DATA_ERRORS:
aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe distinguish plural singular
break;
case OBJECTTYPE_DATA_ERRORS_X:
aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe specialize in future
break;
case OBJECTTYPE_DATA_ERRORS_Y:
aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe specialize in future
break;
case OBJECTTYPE_DATA_ERRORS_Z:
aRet=String(SchResId(STR_OBJECT_ERROR_BARS));//@todo? maybe specialize in future
break;
case OBJECTTYPE_DATA_AVERAGE_LINE:
aRet=String(SchResId(STR_OBJECT_AVERAGE_LINE));
break;
case OBJECTTYPE_DATA_CURVE:
{
if(bPlural)
aRet=String(SchResId(STR_OBJECT_CURVES));
else
aRet=String(SchResId(STR_OBJECT_CURVE));
}
break;
case OBJECTTYPE_DATA_STOCK_RANGE:
break;
case OBJECTTYPE_DATA_STOCK_LOSS:
aRet=String(SchResId(STR_OBJECT_STOCK_LOSS));
break;
case OBJECTTYPE_DATA_STOCK_GAIN:
aRet=String(SchResId(STR_OBJECT_STOCK_GAIN));
break;
case OBJECTTYPE_DATA_CURVE_EQUATION:
aRet=String(SchResId(STR_OBJECT_CURVE_EQUATION));
break;
default: //OBJECTTYPE_UNKNOWN
;
}
return aRet;
}
rtl::OUString ObjectNameProvider::getAxisName( const rtl::OUString& rObjectCID
, const uno::Reference< frame::XModel >& xChartModel )
{
rtl::OUString aRet;
Reference< XAxis > xAxis(
ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
sal_Int32 nCooSysIndex = 0;
sal_Int32 nDimensionIndex = 0;
sal_Int32 nAxisIndex = 0;
AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel ), nCooSysIndex, nDimensionIndex, nAxisIndex );
switch(nDimensionIndex)
{
case 0://x-axis
if( nAxisIndex == 0 )
aRet=String(SchResId(STR_OBJECT_AXIS_X));
else
aRet=String(SchResId(STR_OBJECT_SECONDARY_X_AXIS));
break;
case 1://y-axis
if( nAxisIndex == 0 )
aRet=String(SchResId(STR_OBJECT_AXIS_Y));
else
aRet=String(SchResId(STR_OBJECT_SECONDARY_Y_AXIS));
break;
case 2://z-axis
aRet=String(SchResId(STR_OBJECT_AXIS_Z));
break;
default://axis
aRet=String(SchResId(STR_OBJECT_AXIS));
break;
}
return aRet;
}
OUString ObjectNameProvider::getTitleNameByType( TitleHelper::eTitleType eType )
{
OUString aRet;
switch(eType)
{
case TitleHelper::MAIN_TITLE:
aRet=String(SchResId(STR_OBJECT_TITLE_MAIN));
break;
case TitleHelper::SUB_TITLE:
aRet=String(SchResId(STR_OBJECT_TITLE_SUB));
break;
case TitleHelper::X_AXIS_TITLE:
aRet=String(SchResId(STR_OBJECT_TITLE_X_AXIS));
break;
case TitleHelper::Y_AXIS_TITLE:
aRet=String(SchResId(STR_OBJECT_TITLE_Y_AXIS));
break;
case TitleHelper::Z_AXIS_TITLE:
aRet=String(SchResId(STR_OBJECT_TITLE_Z_AXIS));
break;
case TitleHelper::SECONDARY_X_AXIS_TITLE:
aRet=String(SchResId(STR_OBJECT_TITLE_SECONDARY_X_AXIS));
break;
case TitleHelper::SECONDARY_Y_AXIS_TITLE:
aRet=String(SchResId(STR_OBJECT_TITLE_SECONDARY_Y_AXIS));
break;
default:
OSL_FAIL("unknown title type");
break;
}
if( !aRet.getLength() )
aRet=String(SchResId(STR_OBJECT_TITLE));
return aRet;
}
OUString ObjectNameProvider::getTitleName( const OUString& rObjectCID
, const Reference< frame::XModel >& xChartModel )
{
OUString aRet;
Reference< XTitle > xTitle(
ObjectIdentifier::getObjectPropertySet( rObjectCID , xChartModel ), uno::UNO_QUERY );
if( xTitle.is() )
{
TitleHelper::eTitleType eType;
if( TitleHelper::getTitleType( eType, xTitle, xChartModel ) )
aRet = ObjectNameProvider::getTitleNameByType( eType );
}
if( !aRet.getLength() )
aRet=String(SchResId(STR_OBJECT_TITLE));
return aRet;
}
rtl::OUString ObjectNameProvider::getGridName( const rtl::OUString& rObjectCID
, const uno::Reference< frame::XModel >& xChartModel )
{
rtl::OUString aRet;
sal_Int32 nCooSysIndex = -1;
sal_Int32 nDimensionIndex = -1;
sal_Int32 nAxisIndex = -1;
Reference< XAxis > xAxis( ObjectIdentifier::getAxisForCID( rObjectCID , xChartModel ) );
AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram( xChartModel )
, nCooSysIndex , nDimensionIndex, nAxisIndex );
bool bMainGrid = (ObjectIdentifier::getObjectType( rObjectCID ) == OBJECTTYPE_GRID);
if( bMainGrid )
{
switch(nDimensionIndex)
{
case 0://x-axis
aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_X));
break;
case 1://y-axis
aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_Y));
break;
case 2://z-axis
aRet=String(SchResId(STR_OBJECT_GRID_MAJOR_Z));
break;
default://axis
aRet=String(SchResId(STR_OBJECT_GRID));
break;
}
}
else
{
switch(nDimensionIndex)
{
case 0://x-axis
aRet=String(SchResId(STR_OBJECT_GRID_MINOR_X));
break;
case 1://y-axis
aRet=String(SchResId(STR_OBJECT_GRID_MINOR_Y));
break;
case 2://z-axis
aRet=String(SchResId(STR_OBJECT_GRID_MINOR_Z));
break;
default://axis
aRet=String(SchResId(STR_OBJECT_GRID));
break;
}
}
return aRet;
}
rtl::OUString ObjectNameProvider::getHelpText( const rtl::OUString& rObjectCID, const Reference< chart2::XChartDocument >& xChartDocument, bool bVerbose )
{
return getHelpText( rObjectCID, Reference< frame::XModel >( xChartDocument, uno::UNO_QUERY ), bVerbose );
}
rtl::OUString ObjectNameProvider::getHelpText( const rtl::OUString& rObjectCID, const Reference< frame::XModel >& xChartModel, bool bVerbose )
{
rtl::OUString aRet;
ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
if( OBJECTTYPE_AXIS == eObjectType )
{
aRet=ObjectNameProvider::getAxisName( rObjectCID, xChartModel );
}
else if( OBJECTTYPE_GRID == eObjectType
|| OBJECTTYPE_SUBGRID == eObjectType )
{
aRet=ObjectNameProvider::getGridName( rObjectCID, xChartModel );
}
else if( OBJECTTYPE_TITLE == eObjectType )
{
aRet=ObjectNameProvider::getTitleName( rObjectCID, xChartModel );
}
else if( OBJECTTYPE_DATA_SERIES == eObjectType )
{
aRet = lcl_getFullSeriesName( rObjectCID, xChartModel );
}
else if( OBJECTTYPE_DATA_POINT == eObjectType )
{
if( bVerbose )
{
OUString aNewLine(C2U("\n"));
aRet=String(SchResId(STR_TIP_DATAPOINT_INDEX));
aRet+=aNewLine;
aRet+=String(SchResId(STR_TIP_DATASERIES));
aRet+=aNewLine;
aRet+=String(SchResId(STR_TIP_DATAPOINT_VALUES));
}
else
aRet=String(SchResId(STR_TIP_DATAPOINT));
Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
if( xDiagram.is() && xSeries.is() )
{
sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
//replace data point index
sal_Int32 nIndex = -1;
OUString aWildcard( C2U("%POINTNUMBER") );
nIndex = aRet.indexOf( aWildcard );
if( nIndex != -1 )
{
aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), OUString::valueOf(nPointIndex+1) );
}
//replace data series index
aWildcard = C2U("%SERIESNUMBER");
nIndex = aRet.indexOf( aWildcard );
if( nIndex != -1 )
{
::std::vector< Reference< chart2::XDataSeries > > aSeriesVector(
DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
sal_Int32 nSeriesIndex = -1;
for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
{
if( aSeriesVector[nSeriesIndex] == xSeries )
{
break;
}
}
OUString aReplacement( OUString::valueOf(nSeriesIndex+1) );
aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), aReplacement );
}
//replace point values
aWildcard = C2U("%POINTVALUES");
nIndex = aRet.indexOf( aWildcard );
if( nIndex != -1 )
aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataPointValueText(
xSeries,nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
//replace series name
aWildcard = C2U("%SERIESNAME");
nIndex = aRet.indexOf( aWildcard );
if( nIndex != -1 )
aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), lcl_getDataSeriesName( rObjectCID, xChartModel ) );
}
}
else if( OBJECTTYPE_DATA_CURVE == eObjectType )
{
if( bVerbose )
{
aRet = String( SchResId( STR_OBJECT_CURVE_WITH_PARAMETERS ));
Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
if( xCurveCnt.is())
{
Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xCurveCnt ));
if( xCurve.is())
{
try
{
Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
// replace formula
sal_Int32 nIndex = -1;
OUString aWildcard( C2U("%FORMULA") );
nIndex = aRet.indexOf( aWildcard );
if( nIndex != -1 )
aRet = aRet.replaceAt( nIndex, aWildcard.getLength(), xCalculator->getRepresentation());
// replace r^2
aWildcard = C2U("%RSQUARED");
nIndex = aRet.indexOf( aWildcard );
if( nIndex != -1 )
{
sal_Unicode aDecimalSep( '.' );
double fR( xCalculator->getCorrelationCoefficient());
aRet = aRet.replaceAt(
nIndex, aWildcard.getLength(),
::rtl::math::doubleToUString(
fR*fR, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
}
}
catch( const uno::Exception & ex )
{
ASSERT_EXCEPTION( ex );
}
}
}
}
else
{
// non-verbose
aRet = ObjectNameProvider::getName( eObjectType, false );
}
}
else if( OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType )
{
if( bVerbose )
{
aRet = String( SchResId( STR_OBJECT_AVERAGE_LINE_WITH_PARAMETERS ));
Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ));
Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
if( xCurveCnt.is())
{
Reference< chart2::XRegressionCurve > xCurve( RegressionCurveHelper::getMeanValueLine( xCurveCnt ));
if( xCurve.is())
{
try
{
Reference< chart2::XRegressionCurveCalculator > xCalculator( xCurve->getCalculator(), uno::UNO_QUERY_THROW );
RegressionCurveHelper::initializeCurveCalculator( xCalculator, xSeries, xChartModel );
sal_Unicode aDecimalSep( '.' );
sal_Int32 nIndex = -1;
OUString aWildcard( C2U("%AVERAGE_VALUE") );
nIndex = aRet.indexOf( aWildcard );
// as the curve is constant, the value at any x-value is ok
if( nIndex != -1 )
{
const double fMeanValue( xCalculator->getCurveValue( 0.0 ));
aRet = aRet.replaceAt(
nIndex, aWildcard.getLength(),
::rtl::math::doubleToUString(
fMeanValue, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
}
// replace standard deviation
aWildcard = C2U("%STD_DEVIATION");
nIndex = aRet.indexOf( aWildcard );
if( nIndex != -1 )
{
const double fStdDev( xCalculator->getCorrelationCoefficient());
aRet = aRet.replaceAt(
nIndex, aWildcard.getLength(),
::rtl::math::doubleToUString(
fStdDev, rtl_math_StringFormat_G, 4, aDecimalSep, true ));
}
}
catch( const uno::Exception & ex )
{
ASSERT_EXCEPTION( ex );
}
}
}
}
else
{
// non-verbose
aRet = ObjectNameProvider::getName( eObjectType, false );
}
}
else
{
aRet = ObjectNameProvider::getName( eObjectType, false );
}
return aRet;
}
rtl::OUString ObjectNameProvider::getSelectedObjectText( const rtl::OUString & rObjectCID, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& xChartDocument )
{
rtl::OUString aRet;
ObjectType eObjectType( ObjectIdentifier::getObjectType(rObjectCID) );
Reference< frame::XModel > xChartModel( xChartDocument, uno::UNO_QUERY );
if( OBJECTTYPE_DATA_POINT == eObjectType )
{
aRet = String( SchResId( STR_STATUS_DATAPOINT_MARKED ));
Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rObjectCID , xChartModel ), uno::UNO_QUERY );
if( xDiagram.is() && xSeries.is() )
{
sal_Int32 nPointIndex( ObjectIdentifier::getParticleID(rObjectCID).toInt32() );
// replace data point index
replaceParamterInString( aRet, C2U("%POINTNUMBER"), OUString::valueOf( nPointIndex + 1 ));
// replace data series index
{
::std::vector< Reference< chart2::XDataSeries > > aSeriesVector(
DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
sal_Int32 nSeriesIndex = -1;
for( nSeriesIndex=aSeriesVector.size();nSeriesIndex--;)
{
if( aSeriesVector[nSeriesIndex] == xSeries )
break;
}
replaceParamterInString( aRet, C2U("%SERIESNUMBER"), OUString::valueOf( nSeriesIndex + 1 ) );
}
// replace point value
replaceParamterInString( aRet, C2U("%POINTVALUES"), lcl_getDataPointValueText(
xSeries, nPointIndex, DataSeriesHelper::getCoordinateSystemOfSeries(xSeries, xDiagram), xChartModel ) );
}
}
else
{
// use the verbose text including the formula for trend lines
const bool bVerbose( OBJECTTYPE_DATA_CURVE == eObjectType || OBJECTTYPE_DATA_AVERAGE_LINE == eObjectType );
const OUString aHelpText( getHelpText( rObjectCID, xChartModel, bVerbose ));
if( aHelpText.getLength())
{
aRet = String( SchResId( STR_STATUS_OBJECT_MARKED ));
replaceParamterInString( aRet, C2U("%OBJECTNAME"), aHelpText );
}
}
return aRet;
}
rtl::OUString ObjectNameProvider::getNameForCID(
const rtl::OUString& rObjectCID,
const uno::Reference< chart2::XChartDocument >& xChartDocument )
{
ObjectType eType( ObjectIdentifier::getObjectType( rObjectCID ));
Reference< frame::XModel > xModel( xChartDocument, uno::UNO_QUERY );
switch( eType )
{
case OBJECTTYPE_AXIS:
return getAxisName( rObjectCID, xModel );
case OBJECTTYPE_TITLE:
return getTitleName( rObjectCID, xModel );
case OBJECTTYPE_GRID:
case OBJECTTYPE_SUBGRID:
return getGridName( rObjectCID, xModel );
case OBJECTTYPE_DATA_SERIES:
return lcl_getFullSeriesName( rObjectCID, xModel );
case OBJECTTYPE_DATA_POINT:
case OBJECTTYPE_DATA_LABELS:
case OBJECTTYPE_DATA_LABEL:
case OBJECTTYPE_DATA_ERRORS:
case OBJECTTYPE_DATA_ERRORS_X:
case OBJECTTYPE_DATA_ERRORS_Y:
case OBJECTTYPE_DATA_ERRORS_Z:
case OBJECTTYPE_DATA_CURVE:
case OBJECTTYPE_DATA_AVERAGE_LINE:
case OBJECTTYPE_DATA_CURVE_EQUATION:
{
rtl::OUString aRet = lcl_getFullSeriesName( rObjectCID, xModel );
aRet += C2U(" ");
if( eType == OBJECTTYPE_DATA_POINT || eType == OBJECTTYPE_DATA_LABEL )
{
aRet += getName( OBJECTTYPE_DATA_POINT );
sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( rObjectCID );
aRet += C2U(" ");
aRet += OUString::valueOf(nPointIndex+1);
if( eType == OBJECTTYPE_DATA_LABEL )
{
aRet += C2U(" ");
aRet += getName( OBJECTTYPE_DATA_LABEL );
}
}
else
aRet += getName( eType );
return aRet;
}
default:
break;
}
return getName( eType );
}
rtl::OUString ObjectNameProvider::getName_ObjectForSeries(
ObjectType eObjectType,
const rtl::OUString& rSeriesCID,
const uno::Reference< chart2::XChartDocument >& xChartDocument )
{
uno::Reference< frame::XModel> xChartModel( xChartDocument, uno::UNO_QUERY );
Reference< XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( rSeriesCID , xChartModel ), uno::UNO_QUERY );
if( xSeries.is() )
{
OUString aRet = String(SchResId(STR_OBJECT_FOR_SERIES));
replaceParamterInString( aRet, C2U("%OBJECTNAME"), getName( eObjectType, false /*bPlural*/ ) );
replaceParamterInString( aRet, C2U("%SERIESNAME"), lcl_getDataSeriesName( rSeriesCID, xChartModel ) );
return aRet;
}
else
return ObjectNameProvider::getName_ObjectForAllSeries( eObjectType );
}
rtl::OUString ObjectNameProvider::getName_ObjectForAllSeries( ObjectType eObjectType )
{
OUString aRet = String(SchResId(STR_OBJECT_FOR_ALL_SERIES));
replaceParamterInString( aRet, C2U("%OBJECTNAME"), getName( eObjectType, true /*bPlural*/ ) );
return aRet;
}
//.............................................................................
} //namespace chart
//.............................................................................
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|