Branch data Line data Source code
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 "PieChartTypeTemplate.hxx"
21 : : #include "macros.hxx"
22 : : #include "CommonConverters.hxx"
23 : : #include "DiagramHelper.hxx"
24 : : #include "servicenames_charttypes.hxx"
25 : : #include "DataSeriesHelper.hxx"
26 : : #include "ContainerHelper.hxx"
27 : : #include "BaseGFXHelper.hxx"
28 : : #include "AxisHelper.hxx"
29 : : #include "ThreeDHelper.hxx"
30 : : #include "PropertyHelper.hxx"
31 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
32 : : #include <com/sun/star/drawing/LineStyle.hpp>
33 : : #include <com/sun/star/drawing/FillStyle.hpp>
34 : : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
35 : : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
36 : :
37 : : #include <rtl/math.hxx>
38 : :
39 : : #include <algorithm>
40 : :
41 : : using namespace ::com::sun::star;
42 : :
43 : : using ::rtl::OUString;
44 : : using ::com::sun::star::beans::Property;
45 : : using ::com::sun::star::uno::Sequence;
46 : : using ::com::sun::star::uno::Reference;
47 : : using ::com::sun::star::uno::Any;
48 : : using ::osl::MutexGuard;
49 : :
50 : : namespace
51 : : {
52 : :
53 : 16 : static const ::rtl::OUString lcl_aServiceName(
54 : : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.PieChartTypeTemplate" ));
55 : :
56 : : enum
57 : : {
58 : : PROP_PIE_TEMPLATE_DEFAULT_OFFSET,
59 : : PROP_PIE_TEMPLATE_OFFSET_MODE,
60 : : PROP_PIE_TEMPLATE_DIMENSION,
61 : : PROP_PIE_TEMPLATE_USE_RINGS
62 : : };
63 : :
64 : 2 : static void lcl_AddPropertiesToVector(
65 : : ::std::vector< Property > & rOutProperties )
66 : : {
67 : : rOutProperties.push_back(
68 : : Property( C2U( "OffsetMode" ),
69 : : PROP_PIE_TEMPLATE_OFFSET_MODE,
70 [ + - ]: 2 : ::getCppuType( reinterpret_cast< const chart2::PieChartOffsetMode * >(0)),
71 : : beans::PropertyAttribute::BOUND
72 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
73 : : rOutProperties.push_back(
74 : : Property( C2U( "DefaultOffset" ),
75 : : PROP_PIE_TEMPLATE_DEFAULT_OFFSET,
76 [ + - ]: 2 : ::getCppuType( reinterpret_cast< const double * >(0)),
77 : : beans::PropertyAttribute::BOUND
78 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
79 : : rOutProperties.push_back(
80 : : Property( C2U( "Dimension" ),
81 : : PROP_PIE_TEMPLATE_DIMENSION,
82 [ + - ]: 2 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
83 : : beans::PropertyAttribute::BOUND
84 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
85 : : rOutProperties.push_back(
86 : : Property( C2U( "UseRings" ),
87 : : PROP_PIE_TEMPLATE_USE_RINGS,
88 [ + - ]: 2 : ::getBooleanCppuType(),
89 : : beans::PropertyAttribute::BOUND
90 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
91 : 2 : }
92 : :
93 : : struct StaticPieChartTypeTemplateDefaults_Initializer
94 : : {
95 : 2 : ::chart::tPropertyValueMap* operator()()
96 : : {
97 [ + - ][ + - ]: 2 : static ::chart::tPropertyValueMap aStaticDefaults;
[ + - ][ # # ]
98 : 2 : lcl_AddDefaultsToMap( aStaticDefaults );
99 : 2 : return &aStaticDefaults;
100 : : }
101 : : private:
102 : 2 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
103 : : {
104 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIE_TEMPLATE_OFFSET_MODE, chart2::PieChartOffsetMode_NONE );
105 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_PIE_TEMPLATE_DEFAULT_OFFSET, 0.5 );
106 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_PIE_TEMPLATE_DIMENSION, 2 );
107 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIE_TEMPLATE_USE_RINGS, false );
108 : 2 : }
109 : : };
110 : :
111 : : struct StaticPieChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticPieChartTypeTemplateDefaults_Initializer >
112 : : {
113 : : };
114 : :
115 : : struct StaticPieChartTypeTemplateInfoHelper_Initializer
116 : : {
117 : 2 : ::cppu::OPropertyArrayHelper* operator()()
118 : : {
119 [ + - ][ + - ]: 2 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
[ + - ][ + - ]
[ + - ][ # # ]
120 : 2 : return &aPropHelper;
121 : : }
122 : :
123 : : private:
124 : 2 : uno::Sequence< Property > lcl_GetPropertySequence()
125 : : {
126 [ + - ]: 2 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
127 [ + - ]: 2 : lcl_AddPropertiesToVector( aProperties );
128 : :
129 : : ::std::sort( aProperties.begin(), aProperties.end(),
130 [ + - ]: 2 : ::chart::PropertyNameLess() );
131 : :
132 [ + - ]: 2 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
133 : : }
134 : :
135 : : };
136 : :
137 : : struct StaticPieChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticPieChartTypeTemplateInfoHelper_Initializer >
138 : : {
139 : : };
140 : :
141 : : struct StaticPieChartTypeTemplateInfo_Initializer
142 : : {
143 : 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
144 : : {
145 : : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
146 [ # # ][ # # ]: 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticPieChartTypeTemplateInfoHelper::get() ) );
[ # # ][ # # ]
[ # # ]
147 : 0 : return &xPropertySetInfo;
148 : : }
149 : : };
150 : :
151 : : struct StaticPieChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticPieChartTypeTemplateInfo_Initializer >
152 : : {
153 : : };
154 : :
155 : : } // anonymous namespace
156 : :
157 : : namespace chart
158 : : {
159 : :
160 : 82 : PieChartTypeTemplate::PieChartTypeTemplate(
161 : : uno::Reference<
162 : : uno::XComponentContext > const & xContext,
163 : : const ::rtl::OUString & rServiceName,
164 : : chart2::PieChartOffsetMode eMode,
165 : : bool bRings /* = false */,
166 : : sal_Int32 nDim /* = 2 */ ) :
167 : : ChartTypeTemplate( xContext, rServiceName ),
168 [ + - ][ + - ]: 82 : ::property::OPropertySet( m_aMutex )
169 : : {
170 [ + - ][ + - ]: 82 : setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_OFFSET_MODE, uno::makeAny( eMode ));
171 [ + - ][ + - ]: 82 : setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_DIMENSION, uno::makeAny( nDim ));
172 [ + - ][ + - ]: 82 : setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_USE_RINGS, uno::makeAny( sal_Bool( bRings )));
173 : 82 : }
174 : :
175 [ + - ][ + - ]: 82 : PieChartTypeTemplate::~PieChartTypeTemplate()
176 [ - + ]: 164 : {}
177 : :
178 : : // ____ OPropertySet ____
179 : 482 : uno::Any PieChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
180 : : throw(beans::UnknownPropertyException)
181 : : {
182 [ + - ]: 482 : const tPropertyValueMap& rStaticDefaults = *StaticPieChartTypeTemplateDefaults::get();
183 [ + - ]: 482 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
184 [ - + ]: 482 : if( aFound == rStaticDefaults.end() )
185 : 0 : return uno::Any();
186 : 482 : return (*aFound).second;
187 : : }
188 : :
189 : 376 : ::cppu::IPropertyArrayHelper & SAL_CALL PieChartTypeTemplate::getInfoHelper()
190 : : {
191 : 376 : return *StaticPieChartTypeTemplateInfoHelper::get();
192 : : }
193 : :
194 : : // ____ XPropertySet ____
195 : 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL PieChartTypeTemplate::getPropertySetInfo()
196 : : throw (uno::RuntimeException)
197 : : {
198 : 0 : return *StaticPieChartTypeTemplateInfo::get();
199 : : }
200 : :
201 : : // ____ ChartTypeTemplate ____
202 : 94 : sal_Int32 PieChartTypeTemplate::getDimension() const
203 : : {
204 : 94 : sal_Int32 nDim = 2;
205 : : try
206 : : {
207 : : // note: UNO-methods are never const
208 : : const_cast< PieChartTypeTemplate * >( this )->
209 [ + - ]: 94 : getFastPropertyValue( PROP_PIE_TEMPLATE_DIMENSION ) >>= nDim;
210 : : }
211 [ # # ]: 0 : catch( const beans::UnknownPropertyException & ex )
212 : : {
213 : : ASSERT_EXCEPTION( ex );
214 : : }
215 : :
216 [ # # ]: 94 : return nDim;
217 : : }
218 : :
219 : 8 : sal_Int32 PieChartTypeTemplate::getAxisCountByDimension( sal_Int32 /*nDimension*/ )
220 : : {
221 : 8 : return 0;
222 : : }
223 : :
224 : 4 : void PieChartTypeTemplate::adaptAxes(
225 : : const uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > & /*rCoordSys*/ )
226 : : {
227 : : // hide existing axes
228 : : //hhhh todo
229 : 4 : }
230 : :
231 : 4 : void PieChartTypeTemplate::adaptScales(
232 : : const Sequence< Reference< chart2::XCoordinateSystem > > & aCooSysSeq,
233 : : const Reference< chart2::data::XLabeledDataSequence > & xCategories //@todo: in future there may be more than one sequence of categories (e.g. charttype with categories at x and y axis )
234 : : )
235 : : {
236 : 4 : ChartTypeTemplate::adaptScales( aCooSysSeq, xCategories );
237 : :
238 : : //remove explicit scalings from radius axis
239 : : //and ensure correct orientation of scales for donuts
240 : :
241 [ + + ]: 8 : for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx )
242 : : {
243 : : try
244 : : {
245 : : Reference< chart2::XAxis > xAxis( AxisHelper::getAxis( 1 /*nDimensionIndex*/,0 /*nAxisIndex*/
246 [ + - ]: 4 : , aCooSysSeq[nCooSysIdx] ) );
247 [ + - ]: 4 : if( xAxis.is() )
248 : : {
249 [ + - ][ + - ]: 4 : chart2::ScaleData aScaleData( xAxis->getScaleData() );
250 [ + - ]: 4 : AxisHelper::removeExplicitScaling( aScaleData );
251 : 4 : aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
252 [ + - ][ + - ]: 4 : xAxis->setScaleData( aScaleData );
[ + - ]
253 : : }
254 : :
255 : : xAxis = AxisHelper::getAxis( 0 /*nDimensionIndex*/,0 /*nAxisIndex*/
256 [ + - ][ + - ]: 4 : , aCooSysSeq[nCooSysIdx] );
257 [ + - ]: 4 : if( xAxis.is() )
258 : : {
259 [ + - ][ + - ]: 4 : chart2::ScaleData aScaleData( xAxis->getScaleData() );
260 : 4 : aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
261 [ + - ][ + - ]: 4 : xAxis->setScaleData( aScaleData );
[ + - ]
262 [ # # ]: 4 : }
263 : : }
264 : 0 : catch( const uno::Exception & ex )
265 : : {
266 : : ASSERT_EXCEPTION( ex );
267 : : }
268 : : }
269 : 4 : }
270 : :
271 : 4 : void PieChartTypeTemplate::createChartTypes(
272 : : const Sequence< Sequence< Reference< chart2::XDataSeries > > > & aSeriesSeq,
273 : : const Sequence< Reference< chart2::XCoordinateSystem > > & rCoordSys,
274 : : const Sequence< Reference< chart2::XChartType > >& /* aOldChartTypesSeq */ )
275 : : {
276 [ + - - + ]: 8 : if( rCoordSys.getLength() == 0 ||
[ - + ]
277 : 4 : ! rCoordSys[0].is() )
278 : 4 : return;
279 : :
280 : : try
281 : : {
282 : : Reference< lang::XMultiServiceFactory > xFact(
283 [ + - ][ + - ]: 4 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
[ + - ][ + - ]
284 : :
285 : : Reference< chart2::XChartType > xCT(
286 [ + - ][ + - ]: 4 : xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW );
[ + - ][ + - ]
287 [ + - ]: 4 : Reference< beans::XPropertySet > xCTProp( xCT, uno::UNO_QUERY );
288 [ + - ]: 4 : if( xCTProp.is())
289 : : {
290 [ + - ]: 4 : xCTProp->setPropertyValue(
291 [ + - ][ + - ]: 4 : C2U( "UseRings" ), getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ));
[ + - ]
292 : : }
293 [ + - ]: 4 : Reference< chart2::XChartTypeContainer > xCTCnt( rCoordSys[0], uno::UNO_QUERY_THROW );
294 [ + - ][ + - ]: 4 : xCTCnt->setChartTypes( Sequence< Reference< chart2::XChartType > >( &xCT, 1 ));
[ + - ][ + - ]
295 : :
296 [ + - ]: 4 : if( aSeriesSeq.getLength() > 0 )
297 : : {
298 [ + - ]: 4 : Reference< chart2::XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW );
299 [ + - ]: 4 : Sequence< Reference< chart2::XDataSeries > > aFlatSeriesSeq( FlattenSequence( aSeriesSeq ));
300 [ + - ][ + - ]: 4 : xDSCnt->setDataSeries( aFlatSeriesSeq );
301 : :
302 : : DataSeriesHelper::setStackModeAtSeries(
303 [ + - ][ + - ]: 4 : aFlatSeriesSeq, rCoordSys[0], getStackMode( 0 ));
[ + - ]
304 [ # # ]: 4 : }
305 : : }
306 : 0 : catch( const uno::Exception & ex )
307 : : {
308 : : ASSERT_EXCEPTION( ex );
309 : : }
310 : : }
311 : :
312 : : // ____ XChartTypeTemplate ____
313 : 78 : sal_Bool SAL_CALL PieChartTypeTemplate::matchesTemplate(
314 : : const uno::Reference< chart2::XDiagram >& xDiagram,
315 : : sal_Bool bAdaptProperties )
316 : : throw (uno::RuntimeException)
317 : : {
318 [ + - ]: 78 : sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
319 : :
320 : 78 : sal_Bool bTemplateUsesRings = sal_False;
321 [ + - ]: 78 : getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ) >>= bTemplateUsesRings;
322 : : chart2::PieChartOffsetMode ePieOffsetMode;
323 [ + - ][ + - ]: 78 : getFastPropertyValue( PROP_PIE_TEMPLATE_OFFSET_MODE ) >>= ePieOffsetMode;
324 : :
325 : : //check offset-mode
326 [ + + ]: 78 : if( bResult )
327 : : {
328 : : try
329 : : {
330 : 18 : double fOffset=0.0;
331 : 18 : bool bAllOffsetsEqual = true;
332 : :
333 : : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
334 [ + - ]: 18 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
335 : :
336 : : //check offset of outer series
337 [ + - ]: 18 : if( !aSeriesVec.empty() )
338 : : {
339 : 18 : sal_Int32 nOuterSeriesIndex = 0; //@todo in future this will depend on Orientation of the radius axis scale
340 : 18 : Reference< chart2::XDataSeries > xSeries( aSeriesVec[nOuterSeriesIndex] );
341 [ + - ]: 18 : Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
342 [ + - ][ + - ]: 18 : xProp->getPropertyValue( C2U( "Offset" )) >>= fOffset;
[ + - ]
343 : :
344 : : //get AttributedDataPoints
345 [ + - ]: 18 : uno::Sequence< sal_Int32 > aAttributedDataPointIndexList;
346 [ + - ][ + - ]: 18 : if( xProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList )
[ + - ][ + - ]
[ + - ]
347 : : {
348 [ - + ]: 18 : for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;)
349 : : {
350 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]) );
[ # # ]
351 [ # # ]: 0 : if(xPointProp.is())
352 : : {
353 : 0 : double fPointOffset=0.0;
354 [ # # ][ # # ]: 0 : if( (xProp->getPropertyValue( C2U( "Offset" )) >>= fPointOffset ) )
[ # # ][ # # ]
355 : : {
356 [ # # ]: 0 : if( ! ::rtl::math::approxEqual( fPointOffset, fOffset ) )
357 : : {
358 : 0 : bAllOffsetsEqual = false;
359 : : break;
360 : : }
361 : : }
362 : : }
363 [ # # ]: 0 : }
364 [ + - ]: 18 : }
365 : : }
366 : :
367 : 18 : chart2::PieChartOffsetMode eOffsetMode = chart2::PieChartOffsetMode_NONE;
368 [ + - ][ - + ]: 18 : if( bAllOffsetsEqual && fOffset > 0.0 )
369 : : {
370 : 0 : eOffsetMode = chart2::PieChartOffsetMode_ALL_EXPLODED;
371 [ # # ]: 0 : if( bAdaptProperties )
372 [ # # ][ # # ]: 0 : setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_DEFAULT_OFFSET, uno::makeAny( fOffset ));
373 : : }
374 : :
375 [ # # ]: 18 : bResult = ( eOffsetMode == ePieOffsetMode );
376 : : }
377 [ # # ]: 0 : catch( const uno::Exception & ex )
378 : : {
379 : : ASSERT_EXCEPTION( ex );
380 : 0 : bResult = false;
381 : : }
382 : : }
383 : :
384 : : //check UseRings
385 [ + + ]: 78 : if( bResult )
386 : : {
387 : : uno::Reference< beans::XPropertySet > xCTProp(
388 [ + - ][ + - ]: 12 : DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), uno::UNO_QUERY_THROW );
389 : 12 : sal_Bool bUseRings = false;
390 [ + - ][ + - ]: 12 : if( xCTProp->getPropertyValue( C2U( "UseRings" )) >>= bUseRings )
[ + - ][ + - ]
391 : : {
392 : 12 : bResult = ( bTemplateUsesRings == bUseRings );
393 : 12 : }
394 : : }
395 : :
396 : 78 : return bResult;
397 : : }
398 : :
399 : 16 : Reference< chart2::XChartType > PieChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
400 : : {
401 : 16 : Reference< chart2::XChartType > xResult;
402 : :
403 : : try
404 : : {
405 : : Reference< lang::XMultiServiceFactory > xFact(
406 [ + - ][ + - ]: 16 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
[ + - ][ + - ]
407 [ + - ]: 16 : xResult.set( xFact->createInstance(
408 [ + - ][ + - ]: 16 : CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW );
[ + - ]
409 [ + - ]: 16 : Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
410 [ + - ]: 16 : if( xCTProp.is())
411 : : {
412 [ + - ]: 16 : xCTProp->setPropertyValue(
413 [ + - ][ + - ]: 16 : C2U( "UseRings" ), getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ));
[ + - ]
414 [ # # ]: 16 : }
415 : :
416 : : }
417 [ # # ]: 0 : catch( const uno::Exception & ex )
418 : : {
419 : : ASSERT_EXCEPTION( ex );
420 : : }
421 : :
422 : 16 : return xResult;
423 : : }
424 : :
425 : 86 : Reference< chart2::XChartType > SAL_CALL PieChartTypeTemplate::getChartTypeForNewSeries(
426 : : const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
427 : : throw (uno::RuntimeException)
428 : : {
429 : 86 : Reference< chart2::XChartType > xResult;
430 : :
431 : : try
432 : : {
433 : : Reference< lang::XMultiServiceFactory > xFact(
434 [ + - ][ + - ]: 86 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
[ + - ][ + - ]
435 [ + - ]: 86 : xResult.set( xFact->createInstance(
436 [ + - ][ + - ]: 86 : CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW );
[ + - ]
437 [ + - ]: 86 : ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
438 [ + - ]: 86 : Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
439 [ + - ]: 86 : if( xCTProp.is())
440 : : {
441 [ + - ]: 86 : xCTProp->setPropertyValue(
442 [ + - ][ + - ]: 86 : C2U( "UseRings" ), getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ));
[ + - ]
443 [ # # ]: 86 : }
444 : :
445 : : }
446 [ # # ]: 0 : catch( const uno::Exception & ex )
447 : : {
448 : : ASSERT_EXCEPTION( ex );
449 : : }
450 : :
451 : 86 : return xResult;
452 : : }
453 : :
454 : 12 : void SAL_CALL PieChartTypeTemplate::applyStyle(
455 : : const Reference< chart2::XDataSeries >& xSeries,
456 : : ::sal_Int32 nChartTypeIndex,
457 : : ::sal_Int32 nSeriesIndex,
458 : : ::sal_Int32 nSeriesCount )
459 : : throw (uno::RuntimeException)
460 : : {
461 : 12 : ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
462 : :
463 : : try
464 : : {
465 [ + - ]: 12 : uno::Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
466 : :
467 : 12 : sal_Bool bTemplateUsesRings = sal_False;
468 [ + - ]: 12 : getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ) >>= bTemplateUsesRings;
469 : 12 : sal_Int32 nOuterSeriesIndex = 0; //@todo in future this will depend on Orientation of the radius axis scale
470 [ + + ]: 12 : if( nSeriesIndex == nOuterSeriesIndex )
471 : : {
472 [ + - ]: 4 : const OUString aOffsetPropName( RTL_CONSTASCII_USTRINGPARAM("Offset"));
473 : : // get offset mode
474 : : chart2::PieChartOffsetMode ePieOffsetMode;
475 [ + - ][ + - ]: 4 : this->getFastPropertyValue( PROP_PIE_TEMPLATE_OFFSET_MODE ) >>= ePieOffsetMode;
476 : :
477 : : // get default offset
478 : 4 : double fDefaultOffset = 0.5;
479 [ + - ]: 4 : this->getFastPropertyValue( PROP_PIE_TEMPLATE_DEFAULT_OFFSET ) >>= fDefaultOffset;
480 : 4 : double fOffsetToSet = fDefaultOffset;
481 : :
482 [ + - ]: 4 : uno::Sequence< sal_Int32 > aAttributedDataPointIndexList;
483 [ + - ][ + - ]: 4 : xProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList;
[ + - ][ + - ]
484 : :
485 : : // determine whether to set the new offset
486 : 4 : bool bSetOffset = ( ePieOffsetMode == chart2::PieChartOffsetMode_ALL_EXPLODED );
487 [ + - ][ + - ]: 4 : if( !bSetOffset &&
488 : : (ePieOffsetMode == chart2::PieChartOffsetMode_NONE) )
489 : : {
490 : : // set offset to 0 if the offset was exactly "all exploded"
491 : : // before (individual offsets are kept)
492 : 4 : double fOffset = 0.0;
493 [ + - ][ + - ]: 8 : if( (xProp->getPropertyValue( aOffsetPropName ) >>= fOffset) &&
[ + - - + ]
[ + - ]
[ - + # # ]
494 : 4 : ::rtl::math::approxEqual( fOffset, fDefaultOffset ))
495 : : {
496 : 0 : fOffsetToSet = 0.0;
497 : 0 : bSetOffset = true;
498 [ # # ]: 4 : for( sal_Int32 nPtIdx=0; nPtIdx<aAttributedDataPointIndexList.getLength(); ++nPtIdx )
499 : : {
500 : : uno::Reference< beans::XPropertySet > xPointProp(
501 [ # # ][ # # ]: 0 : xSeries->getDataPointByIndex( aAttributedDataPointIndexList[ nPtIdx ] ));
[ # # ]
502 [ # # ]: 0 : uno::Reference< beans::XPropertyState > xPointState( xPointProp, uno::UNO_QUERY );
503 : 0 : double fPointOffset = 0.0;
504 [ # # ][ # # : 0 : if( xPointState.is() &&
# # # # #
# ][ # # ]
505 [ # # ][ # # ]: 0 : (xPointState->getPropertyState( aOffsetPropName ) == beans::PropertyState_DIRECT_VALUE) &&
506 : 0 : xPointProp.is() &&
507 [ # # ][ # # ]: 0 : (xPointProp->getPropertyValue( aOffsetPropName ) >>= fPointOffset ) &&
[ # # ][ # # ]
508 : 0 : ! ::rtl::math::approxEqual( fPointOffset, fDefaultOffset ) )
509 : : {
510 : 0 : bSetOffset = false;
511 : : break;
512 : : }
513 [ # # ][ # # ]: 0 : }
514 : : }
515 : : }
516 : :
517 [ - + ]: 4 : if( bSetOffset )
518 : : {
519 : : // set the offset to the series and to the attributed data points
520 [ # # ][ # # ]: 0 : xProp->setPropertyValue( aOffsetPropName, uno::makeAny( fOffsetToSet ));
[ # # ]
521 : :
522 : : // remove hard attributes from data points
523 [ # # ]: 0 : for( sal_Int32 nPtIdx=0; nPtIdx<aAttributedDataPointIndexList.getLength(); ++nPtIdx )
524 : : {
525 : : uno::Reference< beans::XPropertyState > xPointState(
526 [ # # ][ # # ]: 0 : xSeries->getDataPointByIndex( aAttributedDataPointIndexList[ nPtIdx ] ), uno::UNO_QUERY );
[ # # ][ # # ]
527 [ # # ]: 0 : if( xPointState.is())
528 [ # # ][ # # ]: 0 : xPointState->setPropertyToDefault( aOffsetPropName );
529 : 0 : }
530 [ + - ]: 4 : }
531 : : }
532 : :
533 : : // line style
534 [ + - ][ + - ]: 12 : DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) );
[ + - ]
535 : :
536 : : // vary colors by point
537 [ + - ][ + - ]: 12 : xProp->setPropertyValue( C2U("VaryColorsByPoint"), uno::makeAny( true ));
[ + - ][ # # ]
[ + - ]
538 : : }
539 : 0 : catch( const uno::Exception & ex )
540 : : {
541 : : ASSERT_EXCEPTION( ex );
542 : : }
543 : 12 : }
544 : :
545 : :
546 : 0 : void SAL_CALL PieChartTypeTemplate::resetStyles( const Reference< chart2::XDiagram >& xDiagram )
547 : : throw (uno::RuntimeException)
548 : : {
549 : : // reset axes and grids
550 [ # # ]: 0 : Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY );
551 [ # # ]: 0 : if( xCooSysCnt.is())
552 : : {
553 [ # # ][ # # ]: 0 : Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems());
554 [ # # ]: 0 : ChartTypeTemplate::createAxes( aCooSysSeq );
555 : :
556 : : //reset scale orientation
557 [ # # ]: 0 : for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx )
558 : : {
559 : : try
560 : : {
561 : : Reference< chart2::XAxis > xAxis( AxisHelper::getAxis( 0 /*nDimensionIndex*/,0 /*nAxisIndex*/
562 [ # # ][ # # ]: 0 : , aCooSysSeq[nCooSysIdx] ) );
563 [ # # ]: 0 : if( xAxis.is() )
564 : : {
565 [ # # ][ # # ]: 0 : chart2::ScaleData aScaleData( xAxis->getScaleData() );
566 : 0 : aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
567 [ # # ][ # # ]: 0 : xAxis->setScaleData( aScaleData );
[ # # ]
568 : : }
569 : :
570 [ # # ][ # # ]: 0 : xAxis = AxisHelper::getAxis( 1, 0, aCooSysSeq[nCooSysIdx] );
[ # # ]
571 [ # # ]: 0 : if( xAxis.is() )
572 : : {
573 [ # # ][ # # ]: 0 : chart2::ScaleData aScaleData( xAxis->getScaleData() );
574 : 0 : aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
575 [ # # ][ # # ]: 0 : xAxis->setScaleData( aScaleData );
[ # # ]
576 [ # # ]: 0 : }
577 : : }
578 [ # # ]: 0 : catch( const uno::Exception & ex )
579 : : {
580 : : ASSERT_EXCEPTION( ex );
581 : : }
582 [ # # ]: 0 : }
583 : : }
584 : :
585 [ # # ]: 0 : ChartTypeTemplate::resetStyles( xDiagram );
586 : :
587 : : // vary colors by point,
588 : : // line style
589 : : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
590 [ # # ]: 0 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
591 [ # # ]: 0 : uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE ));
592 [ # # ][ # # ]: 0 : for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
593 : 0 : aIt != aSeriesVec.end(); ++aIt )
594 : : {
595 [ # # ]: 0 : Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY );
596 [ # # ]: 0 : if( xState.is())
597 : : {
598 [ # # ][ # # ]: 0 : xState->setPropertyToDefault( C2U("VaryColorsByPoint"));
[ # # ]
599 [ # # ]: 0 : Reference< beans::XPropertySet > xProp( xState, uno::UNO_QUERY );
600 [ # # # # ]: 0 : if( xProp.is() &&
[ # # ]
601 [ # # ][ # # ]: 0 : xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
602 : : {
603 [ # # ][ # # ]: 0 : xState->setPropertyToDefault( C2U("BorderStyle"));
[ # # ]
604 : 0 : }
605 : : }
606 : 0 : }
607 : :
608 : : //reset scene properties
609 [ # # ][ # # ]: 0 : ThreeDHelper::setDefaultRotation( uno::Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY ), false );
610 : 0 : }
611 : :
612 : : // ____ XChartTypeTemplate ____
613 : 4 : void PieChartTypeTemplate::adaptDiagram( const uno::Reference< chart2::XDiagram >& xDiagram )
614 : : {
615 [ - + ]: 4 : if( !xDiagram.is() )
616 : 4 : return;
617 : :
618 : : //different default for scene geometry:
619 [ + - ]: 4 : ThreeDHelper::setDefaultRotation( uno::Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY ), true );
620 : : }
621 : :
622 : : // ----------------------------------------
623 : :
624 : 0 : uno::Sequence< ::rtl::OUString > PieChartTypeTemplate::getSupportedServiceNames_Static()
625 : : {
626 : 0 : uno::Sequence< ::rtl::OUString > aServices( 2 );
627 [ # # ]: 0 : aServices[ 0 ] = lcl_aServiceName;
628 [ # # ][ # # ]: 0 : aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
629 : 0 : return aServices;
630 : : }
631 : :
632 : : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
633 [ # # ][ # # ]: 0 : APPHELPER_XSERVICEINFO_IMPL( PieChartTypeTemplate, lcl_aServiceName );
[ # # ][ # # ]
[ # # ]
634 : :
635 [ - + ][ # # ]: 680 : IMPLEMENT_FORWARD_XINTERFACE2( PieChartTypeTemplate, ChartTypeTemplate, OPropertySet )
636 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( PieChartTypeTemplate, ChartTypeTemplate, OPropertySet )
[ # # ]
637 : :
638 [ + - ][ + - ]: 48 : } // namespace chart
639 : :
640 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|