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