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 1 : 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 0 : 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 0 : ::getCppuType( reinterpret_cast< const chart2::PieChartOffsetMode * >(0)),
71 : beans::PropertyAttribute::BOUND
72 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
73 : rOutProperties.push_back(
74 : Property( C2U( "DefaultOffset" ),
75 : PROP_PIE_TEMPLATE_DEFAULT_OFFSET,
76 0 : ::getCppuType( reinterpret_cast< const double * >(0)),
77 : beans::PropertyAttribute::BOUND
78 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
79 : rOutProperties.push_back(
80 : Property( C2U( "Dimension" ),
81 : PROP_PIE_TEMPLATE_DIMENSION,
82 0 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
83 : beans::PropertyAttribute::BOUND
84 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
85 : rOutProperties.push_back(
86 : Property( C2U( "UseRings" ),
87 : PROP_PIE_TEMPLATE_USE_RINGS,
88 0 : ::getBooleanCppuType(),
89 : beans::PropertyAttribute::BOUND
90 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
91 0 : }
92 :
93 : struct StaticPieChartTypeTemplateDefaults_Initializer
94 : {
95 0 : ::chart::tPropertyValueMap* operator()()
96 : {
97 0 : static ::chart::tPropertyValueMap aStaticDefaults;
98 0 : lcl_AddDefaultsToMap( aStaticDefaults );
99 0 : return &aStaticDefaults;
100 : }
101 : private:
102 0 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
103 : {
104 0 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIE_TEMPLATE_OFFSET_MODE, chart2::PieChartOffsetMode_NONE );
105 0 : ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_PIE_TEMPLATE_DEFAULT_OFFSET, 0.5 );
106 0 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_PIE_TEMPLATE_DIMENSION, 2 );
107 0 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIE_TEMPLATE_USE_RINGS, false );
108 0 : }
109 : };
110 :
111 : struct StaticPieChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticPieChartTypeTemplateDefaults_Initializer >
112 : {
113 : };
114 :
115 : struct StaticPieChartTypeTemplateInfoHelper_Initializer
116 : {
117 0 : ::cppu::OPropertyArrayHelper* operator()()
118 : {
119 0 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
120 0 : return &aPropHelper;
121 : }
122 :
123 : private:
124 0 : uno::Sequence< Property > lcl_GetPropertySequence()
125 : {
126 0 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
127 0 : lcl_AddPropertiesToVector( aProperties );
128 :
129 : ::std::sort( aProperties.begin(), aProperties.end(),
130 0 : ::chart::PropertyNameLess() );
131 :
132 0 : 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 0 : 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 0 : ::property::OPropertySet( m_aMutex )
169 : {
170 0 : setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_OFFSET_MODE, uno::makeAny( eMode ));
171 0 : setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_DIMENSION, uno::makeAny( nDim ));
172 0 : setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_USE_RINGS, uno::makeAny( sal_Bool( bRings )));
173 0 : }
174 :
175 0 : PieChartTypeTemplate::~PieChartTypeTemplate()
176 0 : {}
177 :
178 : // ____ OPropertySet ____
179 0 : uno::Any PieChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
180 : throw(beans::UnknownPropertyException)
181 : {
182 0 : const tPropertyValueMap& rStaticDefaults = *StaticPieChartTypeTemplateDefaults::get();
183 0 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
184 0 : if( aFound == rStaticDefaults.end() )
185 0 : return uno::Any();
186 0 : return (*aFound).second;
187 : }
188 :
189 0 : ::cppu::IPropertyArrayHelper & SAL_CALL PieChartTypeTemplate::getInfoHelper()
190 : {
191 0 : 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 0 : sal_Int32 PieChartTypeTemplate::getDimension() const
203 : {
204 0 : sal_Int32 nDim = 2;
205 : try
206 : {
207 : // note: UNO-methods are never const
208 : const_cast< PieChartTypeTemplate * >( this )->
209 0 : getFastPropertyValue( PROP_PIE_TEMPLATE_DIMENSION ) >>= nDim;
210 : }
211 0 : catch( const beans::UnknownPropertyException & ex )
212 : {
213 : ASSERT_EXCEPTION( ex );
214 : }
215 :
216 0 : return nDim;
217 : }
218 :
219 0 : sal_Int32 PieChartTypeTemplate::getAxisCountByDimension( sal_Int32 /*nDimension*/ )
220 : {
221 0 : return 0;
222 : }
223 :
224 0 : void PieChartTypeTemplate::adaptAxes(
225 : const uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > & /*rCoordSys*/ )
226 : {
227 : // hide existing axes
228 : //hhhh todo
229 0 : }
230 :
231 0 : 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 0 : ChartTypeTemplate::adaptScales( aCooSysSeq, xCategories );
237 :
238 : //remove explicit scalings from radius axis
239 : //and ensure correct orientation of scales for donuts
240 :
241 0 : 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 0 : , aCooSysSeq[nCooSysIdx] ) );
247 0 : if( xAxis.is() )
248 : {
249 0 : chart2::ScaleData aScaleData( xAxis->getScaleData() );
250 0 : AxisHelper::removeExplicitScaling( aScaleData );
251 0 : aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
252 0 : xAxis->setScaleData( aScaleData );
253 : }
254 :
255 : xAxis = AxisHelper::getAxis( 0 /*nDimensionIndex*/,0 /*nAxisIndex*/
256 0 : , aCooSysSeq[nCooSysIdx] );
257 0 : if( xAxis.is() )
258 : {
259 0 : chart2::ScaleData aScaleData( xAxis->getScaleData() );
260 0 : aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
261 0 : xAxis->setScaleData( aScaleData );
262 0 : }
263 : }
264 0 : catch( const uno::Exception & ex )
265 : {
266 : ASSERT_EXCEPTION( ex );
267 : }
268 : }
269 0 : }
270 :
271 0 : 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 0 : if( rCoordSys.getLength() == 0 ||
277 0 : ! rCoordSys[0].is() )
278 0 : return;
279 :
280 : try
281 : {
282 : Reference< lang::XMultiServiceFactory > xFact(
283 0 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
284 :
285 : Reference< chart2::XChartType > xCT(
286 0 : xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW );
287 0 : Reference< beans::XPropertySet > xCTProp( xCT, uno::UNO_QUERY );
288 0 : if( xCTProp.is())
289 : {
290 0 : xCTProp->setPropertyValue(
291 0 : C2U( "UseRings" ), getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ));
292 : }
293 0 : Reference< chart2::XChartTypeContainer > xCTCnt( rCoordSys[0], uno::UNO_QUERY_THROW );
294 0 : xCTCnt->setChartTypes( Sequence< Reference< chart2::XChartType > >( &xCT, 1 ));
295 :
296 0 : if( aSeriesSeq.getLength() > 0 )
297 : {
298 0 : Reference< chart2::XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW );
299 0 : Sequence< Reference< chart2::XDataSeries > > aFlatSeriesSeq( FlattenSequence( aSeriesSeq ));
300 0 : xDSCnt->setDataSeries( aFlatSeriesSeq );
301 :
302 : DataSeriesHelper::setStackModeAtSeries(
303 0 : aFlatSeriesSeq, rCoordSys[0], getStackMode( 0 ));
304 0 : }
305 : }
306 0 : catch( const uno::Exception & ex )
307 : {
308 : ASSERT_EXCEPTION( ex );
309 : }
310 : }
311 :
312 : // ____ XChartTypeTemplate ____
313 0 : sal_Bool SAL_CALL PieChartTypeTemplate::matchesTemplate(
314 : const uno::Reference< chart2::XDiagram >& xDiagram,
315 : sal_Bool bAdaptProperties )
316 : throw (uno::RuntimeException)
317 : {
318 0 : sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
319 :
320 0 : sal_Bool bTemplateUsesRings = sal_False;
321 0 : getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ) >>= bTemplateUsesRings;
322 : chart2::PieChartOffsetMode ePieOffsetMode;
323 0 : getFastPropertyValue( PROP_PIE_TEMPLATE_OFFSET_MODE ) >>= ePieOffsetMode;
324 :
325 : //check offset-mode
326 0 : if( bResult )
327 : {
328 : try
329 : {
330 0 : double fOffset=0.0;
331 0 : bool bAllOffsetsEqual = true;
332 :
333 : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
334 0 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
335 :
336 : //check offset of outer series
337 0 : if( !aSeriesVec.empty() )
338 : {
339 0 : sal_Int32 nOuterSeriesIndex = 0; //@todo in future this will depend on Orientation of the radius axis scale
340 0 : Reference< chart2::XDataSeries > xSeries( aSeriesVec[nOuterSeriesIndex] );
341 0 : Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
342 0 : xProp->getPropertyValue( C2U( "Offset" )) >>= fOffset;
343 :
344 : //get AttributedDataPoints
345 0 : uno::Sequence< sal_Int32 > aAttributedDataPointIndexList;
346 0 : if( xProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList )
347 : {
348 0 : 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 0 : }
365 : }
366 :
367 0 : chart2::PieChartOffsetMode eOffsetMode = chart2::PieChartOffsetMode_NONE;
368 0 : 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 0 : 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 0 : if( bResult )
386 : {
387 : uno::Reference< beans::XPropertySet > xCTProp(
388 0 : DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), uno::UNO_QUERY_THROW );
389 0 : sal_Bool bUseRings = false;
390 0 : if( xCTProp->getPropertyValue( C2U( "UseRings" )) >>= bUseRings )
391 : {
392 0 : bResult = ( bTemplateUsesRings == bUseRings );
393 0 : }
394 : }
395 :
396 0 : return bResult;
397 : }
398 :
399 0 : Reference< chart2::XChartType > PieChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
400 : {
401 0 : Reference< chart2::XChartType > xResult;
402 :
403 : try
404 : {
405 : Reference< lang::XMultiServiceFactory > xFact(
406 0 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
407 0 : xResult.set( xFact->createInstance(
408 0 : CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW );
409 0 : Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
410 0 : if( xCTProp.is())
411 : {
412 0 : xCTProp->setPropertyValue(
413 0 : C2U( "UseRings" ), getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ));
414 0 : }
415 :
416 : }
417 0 : catch( const uno::Exception & ex )
418 : {
419 : ASSERT_EXCEPTION( ex );
420 : }
421 :
422 0 : return xResult;
423 : }
424 :
425 0 : Reference< chart2::XChartType > SAL_CALL PieChartTypeTemplate::getChartTypeForNewSeries(
426 : const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
427 : throw (uno::RuntimeException)
428 : {
429 0 : Reference< chart2::XChartType > xResult;
430 :
431 : try
432 : {
433 : Reference< lang::XMultiServiceFactory > xFact(
434 0 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
435 0 : xResult.set( xFact->createInstance(
436 0 : CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW );
437 0 : ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
438 0 : Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
439 0 : if( xCTProp.is())
440 : {
441 0 : xCTProp->setPropertyValue(
442 0 : C2U( "UseRings" ), getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ));
443 0 : }
444 :
445 : }
446 0 : catch( const uno::Exception & ex )
447 : {
448 : ASSERT_EXCEPTION( ex );
449 : }
450 :
451 0 : return xResult;
452 : }
453 :
454 0 : 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 0 : ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
462 :
463 : try
464 : {
465 0 : uno::Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
466 :
467 0 : sal_Bool bTemplateUsesRings = sal_False;
468 0 : getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ) >>= bTemplateUsesRings;
469 0 : sal_Int32 nOuterSeriesIndex = 0; //@todo in future this will depend on Orientation of the radius axis scale
470 0 : if( nSeriesIndex == nOuterSeriesIndex )
471 : {
472 0 : const OUString aOffsetPropName( RTL_CONSTASCII_USTRINGPARAM("Offset"));
473 : // get offset mode
474 : chart2::PieChartOffsetMode ePieOffsetMode;
475 0 : this->getFastPropertyValue( PROP_PIE_TEMPLATE_OFFSET_MODE ) >>= ePieOffsetMode;
476 :
477 : // get default offset
478 0 : double fDefaultOffset = 0.5;
479 0 : this->getFastPropertyValue( PROP_PIE_TEMPLATE_DEFAULT_OFFSET ) >>= fDefaultOffset;
480 0 : double fOffsetToSet = fDefaultOffset;
481 :
482 0 : uno::Sequence< sal_Int32 > aAttributedDataPointIndexList;
483 0 : xProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList;
484 :
485 : // determine whether to set the new offset
486 0 : bool bSetOffset = ( ePieOffsetMode == chart2::PieChartOffsetMode_ALL_EXPLODED );
487 0 : 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 0 : double fOffset = 0.0;
493 0 : if( (xProp->getPropertyValue( aOffsetPropName ) >>= fOffset) &&
494 0 : ::rtl::math::approxEqual( fOffset, fDefaultOffset ))
495 : {
496 0 : fOffsetToSet = 0.0;
497 0 : bSetOffset = true;
498 0 : 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 0 : 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 0 : }
531 : }
532 :
533 : // line style
534 0 : DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) );
535 :
536 : // vary colors by point
537 0 : xProp->setPropertyValue( C2U("VaryColorsByPoint"), uno::makeAny( true ));
538 : }
539 0 : catch( const uno::Exception & ex )
540 : {
541 : ASSERT_EXCEPTION( ex );
542 : }
543 0 : }
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 0 : void PieChartTypeTemplate::adaptDiagram( const uno::Reference< chart2::XDiagram >& xDiagram )
614 : {
615 0 : if( !xDiagram.is() )
616 0 : return;
617 :
618 : //different default for scene geometry:
619 0 : 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 0 : IMPLEMENT_FORWARD_XINTERFACE2( PieChartTypeTemplate, ChartTypeTemplate, OPropertySet )
636 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( PieChartTypeTemplate, ChartTypeTemplate, OPropertySet )
637 :
638 3 : } // namespace chart
639 :
640 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|