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
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: VDataSeries.cxx,v $
* $Revision: 1.32.8.2 $
*
* 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 "VDataSeries.hxx"
#include "ObjectIdentifier.hxx"
#include "macros.hxx"
#include "CommonConverters.hxx"
#include "LabelPositionHelper.hxx"
#include "ChartTypeHelper.hxx"
#include "ContainerHelper.hxx"
#include "DataSeriesHelper.hxx"
#include "RegressionCurveHelper.hxx"
#include <com/sun/star/chart/MissingValueTreatment.hpp>
#include <com/sun/star/chart2/Symbol.hpp>
//#include "CommonConverters.hxx"
#include <rtl/math.hxx>
#include <tools/debug.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XPropertyState.hpp>
#include <com/sun/star/drawing/LineStyle.hpp>
#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
#include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
#include <com/sun/star/text/WritingMode.hpp>
#include <com/sun/star/chart2/data/XDataSource.hpp>
//.............................................................................
namespace chart
{
//.............................................................................
using namespace ::com::sun::star;
using namespace ::com::sun::star::chart2;
using ::com::sun::star::uno::Reference;
void VDataSequence::init( const uno::Reference< data::XDataSequence >& xModel )
{
Model = xModel;
Doubles = DataSequenceToDoubleSequence( xModel );
}
bool VDataSequence::is() const
{
return Model.is();
}
void VDataSequence::clear()
{
Model = NULL;
Doubles.realloc(0);
}
double VDataSequence::getValue( sal_Int32 index ) const
{
if( 0<=index && index<Doubles.getLength() )
return Doubles[index];
else
{
double fNan;
::rtl::math::setNan( & fNan );
return fNan;
}
}
sal_Int32 VDataSequence::detectNumberFormatKey( sal_Int32 index ) const
{
sal_Int32 nNumberFormatKey = -1;
// -1 is allowed and means a key for the whole sequence
if( -1<=index && index<Doubles.getLength() &&
Model.is())
{
nNumberFormatKey = Model->getNumberFormatKeyByIndex( index );
}
return nNumberFormatKey;
}
sal_Int32 VDataSequence::getLength() const
{
return Doubles.getLength();
}
namespace
{
struct lcl_LessXOfPoint
{
inline bool operator() ( const std::vector< double >& first,
const std::vector< double >& second )
{
if( first.size() > 0 && second.size() > 0 )
{
return first[0]<second[0];
}
return false;
}
};
void lcl_clearIfTextIsContained( VDataSequence& rData, const uno::Reference<data::XDataSequence>& xDataSequence )
{
uno::Sequence< rtl::OUString > aStrings( DataSequenceToStringSequence( xDataSequence ) );
for( sal_Int32 i = 0; i < rData.Doubles.getLength(); ++i )
{
if( ::rtl::math::isNan( rData.Doubles[i] ) )
{
if( i < aStrings.getLength() && aStrings[i].getLength() )
{
rData.clear();
break;
}
}
}
}
}
VDataSeries::VDataSeries( const uno::Reference< XDataSeries >& xDataSeries )
: m_nPolygonIndex(0)
, m_fLogicMinX(0.0)
, m_fLogicMaxX(0.0)
, m_fLogicZPos(0.0)
, m_xGroupShape(NULL)
, m_xLabelsGroupShape(NULL)
, m_xErrorBarsGroupShape(NULL)
, m_xFrontSubGroupShape(NULL)
, m_xBackSubGroupShape(NULL)
, m_xDataSeries(xDataSeries)
, m_aDataSequences()
, m_nPointCount(0)
, m_aValues_X()
, m_aValues_Y()
, m_aValues_Z()
, m_aValues_Y_Min()
, m_aValues_Y_Max()
, m_aValues_Y_First()
, m_aValues_Y_Last()
, m_fYMeanValue(1.0)
, m_aAttributedDataPointIndexList()
, m_eStackingDirection(StackingDirection_NO_STACKING)
, m_nAxisIndex(0)
, m_bConnectBars(sal_False)
, m_bGroupBarsPerAxis(sal_True)
, m_nStartingAngle(90)
, m_aSeriesParticle()
, m_aCID()
, m_aPointCID_Stub()
, m_aLabelCID_Stub()
, m_nGlobalSeriesIndex(0)
, m_apLabel_Series(NULL)
, m_apLabelPropNames_Series(NULL)
, m_apLabelPropValues_Series(NULL)
, m_apSymbolProperties_Series(NULL)
, m_apLabel_AttributedPoint(NULL)
, m_apLabelPropNames_AttributedPoint(NULL)
, m_apLabelPropValues_AttributedPoint(NULL)
, m_apSymbolProperties_AttributedPoint(NULL)
, m_apSymbolProperties_InvisibleSymbolForSelection(NULL)
, m_nCurrentAttributedPoint(-1)
, m_nMissingValueTreatment(::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP)
{
::rtl::math::setNan( & m_fYMeanValue );
uno::Reference<data::XDataSource> xDataSource =
uno::Reference<data::XDataSource>( xDataSeries, uno::UNO_QUERY );
m_aDataSequences = xDataSource->getDataSequences();
for(sal_Int32 nN = m_aDataSequences.getLength();nN--;)
{
if(!m_aDataSequences[nN].is())
continue;
uno::Reference<data::XDataSequence> xDataSequence( m_aDataSequences[nN]->getValues());
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")) )
{
m_aValues_X.init( xDataSequence );
lcl_clearIfTextIsContained( m_aValues_X, xDataSequence );
}
else if( aRole.equals(C2U("values-y")) )
m_aValues_Y.init( xDataSequence );
else if( aRole.equals(C2U("values-min")) )
m_aValues_Y_Min.init( xDataSequence );
else if( aRole.equals(C2U("values-max")) )
m_aValues_Y_Max.init( xDataSequence );
else if( aRole.equals(C2U("values-first")) )
m_aValues_Y_First.init( xDataSequence );
else if( aRole.equals(C2U("values-last")) )
m_aValues_Y_Last.init( xDataSequence );
//@todo assign the other roles (+ error for unknown?)
}
catch( uno::Exception& e )
{
ASSERT_EXCEPTION( e );
}
}
}
//determine the point count
m_nPointCount = m_aValues_Y.getLength();
{
if( m_nPointCount < m_aValues_Y_Min.getLength() )
m_nPointCount = m_aValues_Y_Min.getLength();
if( m_nPointCount < m_aValues_Y_Max.getLength() )
m_nPointCount = m_aValues_Y_Max.getLength();
if( m_nPointCount < m_aValues_Y_First.getLength() )
m_nPointCount = m_aValues_Y_First.getLength();
if( m_nPointCount < m_aValues_Y_Last.getLength() )
m_nPointCount = m_aValues_Y_Last.getLength();
}
uno::Reference<beans::XPropertySet> xProp(xDataSeries, uno::UNO_QUERY );
if( xProp.is())
{
try
{
//get AttributedDataPoints
xProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= m_aAttributedDataPointIndexList;
xProp->getPropertyValue( C2U( "StackingDirection" ) ) >>= m_eStackingDirection;
xProp->getPropertyValue( C2U( "AttachedAxisIndex" ) ) >>= m_nAxisIndex;
if(m_nAxisIndex<0)
m_nAxisIndex=0;
}
catch( uno::Exception& e )
{
ASSERT_EXCEPTION( e );
}
}
}
VDataSeries::~VDataSeries()
{
}
void VDataSeries::doSortByXValues()
{
if( m_aValues_X.is() && m_aValues_X.Doubles.getLength() )
{
//prepare a vector vor sorting
std::vector< ::std::vector< double > > aTmp;//outer vector are points, inner vector are the different values of athe point
double fNan;
::rtl::math::setNan( & fNan );
sal_Int32 nPointIndex = 0;
for( nPointIndex=0; nPointIndex < m_nPointCount; nPointIndex++ )
{
std::vector< double > aSinglePoint;
aSinglePoint.push_back( (nPointIndex < m_aValues_X.Doubles.getLength()) ? m_aValues_X.Doubles[nPointIndex] : fNan );
aSinglePoint.push_back( (nPointIndex < m_aValues_Y.Doubles.getLength()) ? m_aValues_Y.Doubles[nPointIndex] : fNan );
aTmp.push_back( aSinglePoint );
}
//do sort
std::sort( aTmp.begin(), aTmp.end(), lcl_LessXOfPoint() );
//fill the sorted points back to the mambers
m_aValues_X.Doubles.realloc( m_nPointCount );
m_aValues_Y.Doubles.realloc( m_nPointCount );
for( nPointIndex=0; nPointIndex < m_nPointCount; nPointIndex++ )
{
m_aValues_X.Doubles[nPointIndex]=aTmp[nPointIndex][0];
m_aValues_Y.Doubles[nPointIndex]=aTmp[nPointIndex][1];
}
}
}
uno::Reference< XDataSeries > VDataSeries::getModel() const
{
return m_xDataSeries;
}
void VDataSeries::releaseShapes()
{
m_xGroupShape.set(0);
m_xLabelsGroupShape.set(0);
m_xErrorBarsGroupShape.set(0);
m_xFrontSubGroupShape.set(0);
m_xBackSubGroupShape.set(0);
m_aPolyPolygonShape3D.SequenceX.realloc(0);
m_aPolyPolygonShape3D.SequenceY.realloc(0);
m_aPolyPolygonShape3D.SequenceZ.realloc(0);
m_nPolygonIndex = 0;
}
void VDataSeries::setCategoryXAxis()
{
m_aValues_X.clear();
}
void VDataSeries::setGlobalSeriesIndex( sal_Int32 nGlobalSeriesIndex )
{
m_nGlobalSeriesIndex = nGlobalSeriesIndex;
}
void VDataSeries::setParticle( const rtl::OUString& rSeriesParticle )
{
m_aSeriesParticle = rSeriesParticle;
//get CID
m_aCID = ObjectIdentifier::createClassifiedIdentifierForParticle( m_aSeriesParticle );
m_aPointCID_Stub = ObjectIdentifier::createSeriesSubObjectStub( OBJECTTYPE_DATA_POINT, m_aSeriesParticle );
m_aLabelCID_Stub = ObjectIdentifier::createClassifiedIdentifierWithParent(
OBJECTTYPE_DATA_LABEL, ::rtl::OUString(), getLabelsCID() );
}
rtl::OUString VDataSeries::getSeriesParticle() const
{
return m_aSeriesParticle;
}
rtl::OUString VDataSeries::getCID() const
{
return m_aCID;
}
rtl::OUString VDataSeries::getPointCID_Stub() const
{
return m_aPointCID_Stub;
}
rtl::OUString VDataSeries::getErrorBarsCID() const
{
rtl::OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_ERRORS ) );
aChildParticle+=(C2U("="));
return ObjectIdentifier::createClassifiedIdentifierForParticles(
m_aSeriesParticle, aChildParticle );
}
rtl::OUString VDataSeries::getLabelsCID() const
{
rtl::OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) );
aChildParticle+=(C2U("="));
return ObjectIdentifier::createClassifiedIdentifierForParticles(
m_aSeriesParticle, aChildParticle );
}
rtl::OUString VDataSeries::getLabelCID_Stub() const
{
return m_aLabelCID_Stub;
}
rtl::OUString VDataSeries::getDataCurveCID( sal_Int32 nCurveIndex, bool bAverageLine ) const
{
rtl::OUString aRet;
aRet = ObjectIdentifier::createDataCurveCID( m_aSeriesParticle, nCurveIndex, bAverageLine );
return aRet;
}
rtl::OUString VDataSeries::getDataCurveEquationCID( sal_Int32 nCurveIndex ) const
{
rtl::OUString aRet;
aRet = ObjectIdentifier::createDataCurveEquationCID( m_aSeriesParticle, nCurveIndex );
return aRet;
}
void VDataSeries::setPageReferenceSize( const awt::Size & rPageRefSize )
{
m_aReferenceSize = rPageRefSize;
}
StackingDirection VDataSeries::getStackingDirection() const
{
return m_eStackingDirection;
}
sal_Int32 VDataSeries::getAttachedAxisIndex() const
{
return m_nAxisIndex;
}
void VDataSeries::setConnectBars( sal_Bool bConnectBars )
{
m_bConnectBars = bConnectBars;
}
sal_Bool VDataSeries::getConnectBars() const
{
return m_bConnectBars;
}
void VDataSeries::setGroupBarsPerAxis( sal_Bool bGroupBarsPerAxis )
{
m_bGroupBarsPerAxis = bGroupBarsPerAxis;
}
sal_Bool VDataSeries::getGroupBarsPerAxis() const
{
return m_bGroupBarsPerAxis;
}
void VDataSeries::setStartingAngle( sal_Int32 nStartingAngle )
{
m_nStartingAngle = nStartingAngle;
}
sal_Int32 VDataSeries::getStartingAngle() const
{
return m_nStartingAngle;
}
void VDataSeries::setAttachedAxisIndex( sal_Int32 nAttachedAxisIndex )
{
if( nAttachedAxisIndex < 0 )
nAttachedAxisIndex = 0;
m_nAxisIndex = nAttachedAxisIndex;
}
sal_Int32 VDataSeries::getTotalPointCount() const
{
return m_nPointCount;
}
double VDataSeries::getX( sal_Int32 index ) const
{
if(m_aValues_X.is())
{
if( 0<=index && index<m_aValues_X.getLength() )
return m_aValues_X.Doubles[index];
}
else
{
// #i70133# always return correct X position - needed for short data series
if( 0<=index /*&& index < m_nPointCount*/ )
return index+1;//first category (index 0) matches with real number 1.0
}
double fNan;
::rtl::math::setNan( & fNan );
return fNan;
}
double VDataSeries::getY( sal_Int32 index ) const
{
return m_aValues_Y.getValue( index );
}
double VDataSeries::getY_Min( sal_Int32 index ) const
{
return m_aValues_Y_Min.getValue( index );
}
double VDataSeries::getY_Max( sal_Int32 index ) const
{
return m_aValues_Y_Max.getValue( index );
}
double VDataSeries::getY_First( sal_Int32 index ) const
{
return m_aValues_Y_First.getValue( index );
}
double VDataSeries::getY_Last( sal_Int32 index ) const
{
return m_aValues_Y_Last.getValue( index );
}
bool VDataSeries::hasExplicitNumberFormat( sal_Int32 nPointIndex, bool bForPercentage ) const
{
rtl::OUString aPropName( bForPercentage ? C2U( "PercentageNumberFormat" ) : C2U( "NumberFormat" ) );
bool bHasNumberFormat = false;
uno::Reference< beans::XPropertySet > xPointProp( this->getPropertiesOfPoint( nPointIndex ));
sal_Int32 nNumberFormat = -1;
if( xPointProp.is() && (xPointProp->getPropertyValue(aPropName) >>= nNumberFormat) )
bHasNumberFormat = true;
return bHasNumberFormat;
}
sal_Int32 VDataSeries::getExplicitNumberFormat( sal_Int32 nPointIndex, bool bForPercentage ) const
{
rtl::OUString aPropName( bForPercentage ? C2U( "PercentageNumberFormat" ) : C2U( "NumberFormat" ) );
sal_Int32 nNumberFormat = -1;
uno::Reference< beans::XPropertySet > xPointProp( this->getPropertiesOfPoint( nPointIndex ));
if( xPointProp.is() )
xPointProp->getPropertyValue(aPropName) >>= nNumberFormat;
return nNumberFormat;
}
sal_Int32 VDataSeries::detectNumberFormatKey( sal_Int32 index ) const
{
return m_aValues_Y.detectNumberFormatKey( index );
}
sal_Int32 VDataSeries::getLabelPlacement( sal_Int32 nPointIndex, const uno::Reference< chart2::XChartType >& xChartType, sal_Int32 nDimensionCount, sal_Bool bSwapXAndY ) const
{
sal_Int32 nLabelPlacement=0;
try
{
uno::Reference< beans::XPropertySet > xPointProps( this->getPropertiesOfPoint( nPointIndex ) );
if( xPointProps.is() )
xPointProps->getPropertyValue( C2U( "LabelPlacement" ) ) >>= nLabelPlacement;
//ensure that the set label placement is supported by this charttype
uno::Sequence < sal_Int32 > aAvailablePlacements( ChartTypeHelper::getSupportedLabelPlacements(
xChartType, nDimensionCount, bSwapXAndY, m_xDataSeries ) );
for( sal_Int32 nN = 0; nN < aAvailablePlacements.getLength(); nN++ )
if( aAvailablePlacements[nN] == nLabelPlacement )
return nLabelPlacement; //ok
//otherwise use the first supported one
if( aAvailablePlacements.getLength() )
{
nLabelPlacement = aAvailablePlacements[0];
return nLabelPlacement;
}
DBG_ERROR("no label placement supported");
}
catch( uno::Exception& e )
{
ASSERT_EXCEPTION( e );
}
return nLabelPlacement;
}
double VDataSeries::getMinimumofAllDifferentYValues( sal_Int32 index ) const
{
double fY = getY( index );
double fY_Min = getY_Min( index );
double fY_Max = getY_Max( index );
double fY_First = getY_First( index );
double fY_Last = getY_Last( index );
double fMin=0.0;
::rtl::math::setInf(&fMin, false);
if(fMin>fY)
fMin=fY;
if(fMin>fY_First)
fMin=fY_First;
if(fMin>fY_Last)
fMin=fY_Last;
if(fMin>fY_Min)
fMin=fY_Min;
if(fMin>fY_Max)
fMin=fY_Max;
if( ::rtl::math::isInf(fMin) )
::rtl::math::setNan(&fMin);
return fMin;
}
double VDataSeries::getMaximumofAllDifferentYValues( sal_Int32 index ) const
{
double fY = getY( index );
double fY_Min = getY_Min( index );
double fY_Max = getY_Max( index );
double fY_First = getY_First( index );
double fY_Last = getY_Last( index );
double fMax=0.0;
::rtl::math::setInf(&fMax, true);
if(fMax<fY)
fMax=fY;
if(fMax<fY_First)
fMax=fY_First;
if(fMax<fY_Last)
fMax=fY_Last;
if(fMax<fY_Min)
fMax=fY_Min;
if(fMax<fY_Max)
fMax=fY_Max;
if( ::rtl::math::isInf(fMax) )
::rtl::math::setNan(&fMax);
return fMax;
}
uno::Sequence< double > VDataSeries::getAllX() const
{
if(!m_aValues_X.is() && !m_aValues_X.getLength() && m_nPointCount)
{
//init x values from category indexes
//first category (index 0) matches with real number 1.0
m_aValues_X.Doubles.realloc( m_nPointCount );
for(sal_Int32 nN=m_aValues_X.getLength();nN--;)
m_aValues_X.Doubles[nN] = nN+1;
}
return m_aValues_X.Doubles;
}
uno::Sequence< double > VDataSeries::getAllY() const
{
return m_aValues_Y.Doubles;
}
double VDataSeries::getYMeanValue() const
{
if( ::rtl::math::isNan( m_fYMeanValue ) )
{
uno::Reference< XRegressionCurveCalculator > xCalculator( RegressionCurveHelper::createRegressionCurveCalculatorByServiceName( C2U("com.sun.star.chart2.MeanValueRegressionCurve") ) );
uno::Sequence< double > aXValuesDummy;
xCalculator->recalculateRegression( aXValuesDummy, getAllY() );
double fXDummy = 1.0;
m_fYMeanValue = xCalculator->getCurveValue( fXDummy );
}
return m_fYMeanValue;
}
::std::auto_ptr< Symbol > getSymbolPropertiesFromPropertySet(
const uno::Reference< beans::XPropertySet >& xProp )
{
::std::auto_ptr< Symbol > apSymbolProps( new Symbol() );
try
{
if( xProp->getPropertyValue( C2U( "Symbol" ) ) >>= *apSymbolProps )
{
// border of symbols always black
apSymbolProps->BorderColor = 0x000000;
//use main color to fill symbols
xProp->getPropertyValue( C2U( "Color" ) ) >>= apSymbolProps->FillColor;
}
else
apSymbolProps.reset();
}
catch( uno::Exception &e)
{
ASSERT_EXCEPTION( e );
}
return apSymbolProps;
}
Symbol* VDataSeries::getSymbolProperties( sal_Int32 index ) const
{
Symbol* pRet=NULL;
if( isAttributedDataPoint( index ) )
{
adaptPointCache( index );
if(!m_apSymbolProperties_AttributedPoint.get())
m_apSymbolProperties_AttributedPoint = getSymbolPropertiesFromPropertySet( this->getPropertiesOfPoint( index ) );
pRet = m_apSymbolProperties_AttributedPoint.get();
//if a single data point does not have symbols but the dataseries itself has symbols
//we create an invisible symbol shape to enable selection of that point
if( !pRet || pRet->Style == SymbolStyle_NONE )
{
if(!m_apSymbolProperties_Series.get())
m_apSymbolProperties_Series = getSymbolPropertiesFromPropertySet( this->getPropertiesOfSeries() );
if( m_apSymbolProperties_Series.get() && m_apSymbolProperties_Series->Style != SymbolStyle_NONE )
{
if(!m_apSymbolProperties_InvisibleSymbolForSelection.get())
{
m_apSymbolProperties_InvisibleSymbolForSelection = ::std::auto_ptr< Symbol >( new Symbol() );
m_apSymbolProperties_InvisibleSymbolForSelection->Style = SymbolStyle_STANDARD;
m_apSymbolProperties_InvisibleSymbolForSelection->StandardSymbol = 0;//square
m_apSymbolProperties_InvisibleSymbolForSelection->Size = m_apSymbolProperties_Series->Size;
m_apSymbolProperties_InvisibleSymbolForSelection->BorderColor = 0xff000000;//invisible
m_apSymbolProperties_InvisibleSymbolForSelection->FillColor = 0xff000000;//invisible
}
pRet = m_apSymbolProperties_InvisibleSymbolForSelection.get();
}
}
}
else
{
if(!m_apSymbolProperties_Series.get())
m_apSymbolProperties_Series = getSymbolPropertiesFromPropertySet( this->getPropertiesOfSeries() );
pRet = m_apSymbolProperties_Series.get();
}
if( pRet && pRet->Style == SymbolStyle_AUTO )
{
pRet->Style = SymbolStyle_STANDARD;
sal_Int32 nIndex = m_nGlobalSeriesIndex;
if(m_aValues_X.is())
nIndex++;
pRet->StandardSymbol = nIndex;
}
return pRet;
}
uno::Reference< beans::XPropertySet > VDataSeries::getYErrorBarProperties( sal_Int32 index ) const
{
uno::Reference< beans::XPropertySet > xErrorBarProp;
uno::Reference< beans::XPropertySet > xPointProp( this->getPropertiesOfPoint( index ));
if( xPointProp.is() )
xPointProp->getPropertyValue( C2U( "ErrorBarY" )) >>= xErrorBarProp;
return xErrorBarProp;
}
bool VDataSeries::hasPointOwnColor( sal_Int32 index ) const
{
if( !isAttributedDataPoint(index) )
return false;
try
{
uno::Reference< beans::XPropertyState > xPointState( this->getPropertiesOfPoint(index), uno::UNO_QUERY_THROW );
return (xPointState->getPropertyState( C2U("Color")) != beans::PropertyState_DEFAULT_VALUE );
}
catch( uno::Exception& e)
{
ASSERT_EXCEPTION( e );
}
return false;
}
bool VDataSeries::isAttributedDataPoint( sal_Int32 index ) const
{
//returns true if the data point assigned by the given index has set it's own properties
if( index>=m_nPointCount || m_nPointCount==0)
return false;
for(sal_Int32 nN=m_aAttributedDataPointIndexList.getLength();nN--;)
{
if(index==m_aAttributedDataPointIndexList[nN])
return true;
}
return false;
}
bool VDataSeries::isVaryColorsByPoint() const
{
bool bVaryColorsByPoint = false;
Reference< beans::XPropertySet > xSeriesProp( this->getPropertiesOfSeries() );
if( xSeriesProp.is() )
xSeriesProp->getPropertyValue( C2U("VaryColorsByPoint") ) >>= bVaryColorsByPoint;
return bVaryColorsByPoint;
}
uno::Reference< beans::XPropertySet > VDataSeries::getPropertiesOfPoint( sal_Int32 index ) const
{
if( isAttributedDataPoint( index ) )
return m_xDataSeries->getDataPointByIndex(index);
return this->getPropertiesOfSeries();
}
uno::Reference< beans::XPropertySet > VDataSeries::getPropertiesOfSeries() const
{
return uno::Reference<beans::XPropertySet>(m_xDataSeries, uno::UNO_QUERY );
}
::std::auto_ptr< DataPointLabel > getDataPointLabelFromPropertySet(
const uno::Reference< beans::XPropertySet >& xProp )
{
::std::auto_ptr< DataPointLabel > apLabel( new DataPointLabel() );
try
{
if( !(xProp->getPropertyValue( C2U( "Label" ) ) >>= *apLabel) )
apLabel.reset();
}
catch( uno::Exception &e)
{
ASSERT_EXCEPTION( e );
}
return apLabel;
}
void VDataSeries::adaptPointCache( sal_Int32 nNewPointIndex ) const
{
if( m_nCurrentAttributedPoint != nNewPointIndex )
{
m_apLabel_AttributedPoint.reset();
m_apLabelPropNames_AttributedPoint.reset();
m_apLabelPropValues_AttributedPoint.reset();
m_apSymbolProperties_AttributedPoint.reset();
m_nCurrentAttributedPoint = nNewPointIndex;
}
}
DataPointLabel* VDataSeries::getDataPointLabel( sal_Int32 index ) const
{
DataPointLabel* pRet = NULL;
if( isAttributedDataPoint( index ) )
{
adaptPointCache( index );
if( !m_apLabel_AttributedPoint.get() )
m_apLabel_AttributedPoint = getDataPointLabelFromPropertySet( this->getPropertiesOfPoint( index ) );
pRet = m_apLabel_AttributedPoint.get();
}
else
{
if(!m_apLabel_Series.get())
m_apLabel_Series = getDataPointLabelFromPropertySet( this->getPropertiesOfPoint( index ) );
pRet = m_apLabel_Series.get();
}
return pRet;
}
DataPointLabel* VDataSeries::getDataPointLabelIfLabel( sal_Int32 index ) const
{
DataPointLabel* pLabel = this->getDataPointLabel( index );
if( !pLabel || (!pLabel->ShowNumber && !pLabel->ShowNumberInPercent
&& !pLabel->ShowCategoryName ) )
return 0;
return pLabel;
}
bool VDataSeries::getTextLabelMultiPropertyLists( sal_Int32 index
, tNameSequence*& pPropNames
, tAnySequence*& pPropValues ) const
{
pPropNames = NULL; pPropValues = NULL;
uno::Reference< beans::XPropertySet > xTextProp;
bool bDoDynamicFontResize = false;
if( isAttributedDataPoint( index ) )
{
adaptPointCache( index );
if(!m_apLabelPropValues_AttributedPoint.get())
{
pPropNames = new tNameSequence();
pPropValues = new tAnySequence();
xTextProp.set( this->getPropertiesOfPoint( index ));
PropertyMapper::getTextLabelMultiPropertyLists( xTextProp, *pPropNames, *pPropValues );
m_apLabelPropNames_AttributedPoint = ::std::auto_ptr< tNameSequence >(pPropNames);
m_apLabelPropValues_AttributedPoint = ::std::auto_ptr< tAnySequence >(pPropValues);
bDoDynamicFontResize = true;
}
pPropNames = m_apLabelPropNames_AttributedPoint.get();
pPropValues = m_apLabelPropValues_AttributedPoint.get();
}
else
{
if(!m_apLabelPropValues_Series.get())
{
pPropNames = new tNameSequence();
pPropValues = new tAnySequence();
xTextProp.set( this->getPropertiesOfPoint( index ));
PropertyMapper::getTextLabelMultiPropertyLists( xTextProp, *pPropNames, *pPropValues );
m_apLabelPropNames_Series = ::std::auto_ptr< tNameSequence >(pPropNames);
m_apLabelPropValues_Series = ::std::auto_ptr< tAnySequence >(pPropValues);
bDoDynamicFontResize = true;
}
pPropNames = m_apLabelPropNames_Series.get();
pPropValues = m_apLabelPropValues_Series.get();
}
if( bDoDynamicFontResize &&
pPropNames && pPropValues &&
xTextProp.is())
{
LabelPositionHelper::doDynamicFontResize( *pPropValues, *pPropNames, xTextProp, m_aReferenceSize );
}
if(pPropNames&&pPropValues)
return true;
return false;
}
void VDataSeries::setMissingValueTreatment( sal_Int32 nMissingValueTreatment )
{
m_nMissingValueTreatment = nMissingValueTreatment;
}
sal_Int32 VDataSeries::getMissingValueTreatment() const
{
return m_nMissingValueTreatment;
}
//.............................................................................
} //namespace chart
//.............................................................................
|