cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / chart2 / source / tools / ChartTypeHelper.cxx
blobdec8fcec29bfb392734b2b7bb9f189b766fc5183
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <ChartTypeHelper.hxx>
21 #include <ChartType.hxx>
22 #include <BaseCoordinateSystem.hxx>
23 #include <DataSeriesProperties.hxx>
24 #include <DiagramHelper.hxx>
25 #include <servicenames_charttypes.hxx>
27 #include <com/sun/star/chart/DataLabelPlacement.hpp>
28 #include <com/sun/star/chart/MissingValueTreatment.hpp>
29 #include <com/sun/star/chart2/AxisType.hpp>
30 #include <com/sun/star/chart2/StackingDirection.hpp>
31 #include <comphelper/diagnose_ex.hxx>
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::chart2;
35 using namespace ::chart::DataSeriesProperties;
37 namespace chart
40 bool ChartTypeHelper::isSupportingAxisSideBySide(
41 const rtl::Reference< ::chart::ChartType >& xChartType, sal_Int32 nDimensionCount )
43 bool bResult = false;
45 if( xChartType.is() &&
46 nDimensionCount < 3 )
48 bool bFound=false;
49 bool bAmbiguous=false;
50 StackMode eStackMode = DiagramHelper::getStackModeFromChartType( xChartType, bFound, bAmbiguous, nullptr );
51 if( eStackMode == StackMode::NONE && !bAmbiguous )
53 OUString aChartTypeName = xChartType->getChartType();
54 bResult = ( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN) ||
55 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR) );
59 return bResult;
62 bool ChartTypeHelper::isSupportingGeometryProperties( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
64 //form tab only for 3D-bar and 3D-column charts.
66 //@todo ask charttype itself --> need model change first
67 if(xChartType.is())
69 if(nDimensionCount==3)
71 OUString aChartTypeName = xChartType->getChartType();
72 if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_BAR )
73 return true;
74 if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_COLUMN )
75 return true;
78 return false;
81 bool ChartTypeHelper::isSupportingStatisticProperties( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
83 //3D charts, pie, net and stock do not support statistic properties
85 //@todo ask charttype itself (and series? --> stock chart?) --> need model change first
86 if(xChartType.is())
88 if(nDimensionCount==3)
89 return false;
91 OUString aChartTypeName = xChartType->getChartType();
92 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
93 return false;
94 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
95 return false;
96 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
97 return false;
98 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
99 return false;
100 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE) ) //todo: BubbleChart support error bars and trend lines
101 return false;
103 return true;
106 bool ChartTypeHelper::isSupportingRegressionProperties( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
108 // note: old chart: only scatter chart
109 return isSupportingStatisticProperties( xChartType, nDimensionCount );
112 bool ChartTypeHelper::isSupportingAreaProperties( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
114 //2D line charts, net and stock do not support area properties
116 //@todo ask charttype itself --> need model change first
117 if(xChartType.is())
119 if(nDimensionCount==2)
121 OUString aChartTypeName = xChartType->getChartType();
122 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_LINE) )
123 return false;
124 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER) )
125 return false;
126 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
127 return false;
128 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
129 return false;
132 return true;
135 bool ChartTypeHelper::isSupportingSymbolProperties( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
137 //2D line charts, 2D scatter charts and 2D net charts do support symbols
139 //@todo ask charttype itself --> need model change first
140 if(xChartType.is())
142 if(nDimensionCount==3)
143 return false;
145 OUString aChartTypeName = xChartType->getChartType();
146 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_LINE) )
147 return true;
148 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER) )
149 return true;
150 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
151 return true;
153 return false;
156 bool ChartTypeHelper::isSupportingMainAxis( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount, sal_Int32 nDimensionIndex )
158 //pie charts do not support axis at all
159 //no 3rd axis for 2D charts
161 //@todo ask charttype itself --> need model change first
162 if(xChartType.is())
164 OUString aChartTypeName = xChartType->getChartType();
165 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
166 return false;
168 if( nDimensionIndex == 2 )
169 return nDimensionCount == 3;
171 return true;
174 bool ChartTypeHelper::isSupportingSecondaryAxis( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
176 //3D, pie and net charts do not support a secondary axis at all
178 //@todo ask charttype itself --> need model change first
179 if(xChartType.is())
181 if(nDimensionCount==3)
182 return false;
184 OUString aChartTypeName = xChartType->getChartType();
185 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
186 return false;
187 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
188 return false;
189 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
190 return false;
192 return true;
195 bool ChartTypeHelper::isSupportingOverlapAndGapWidthProperties(
196 const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
198 //2D bar charts do support a this special properties
200 //@todo ask charttype itself --> need model change first
201 if(xChartType.is())
203 if(nDimensionCount==3)
204 return false;
206 OUString aChartTypeName = xChartType->getChartType();
207 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN) )
208 return true;
209 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR) )
210 return true;
211 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_HISTOGRAM) )
212 return true;
214 return false;
217 bool ChartTypeHelper::isSupportingBarConnectors(
218 const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
220 //2D bar charts with stacked series support this
222 //@todo ask charttype itself --> need model change first
223 if(xChartType.is())
225 if(nDimensionCount==3)
226 return false;
228 bool bFound=false;
229 bool bAmbiguous=false;
230 StackMode eStackMode = DiagramHelper::getStackModeFromChartType( xChartType, bFound, bAmbiguous, nullptr );
231 if( eStackMode != StackMode::YStacked || bAmbiguous )
232 return false;
234 OUString aChartTypeName = xChartType->getChartType();
235 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN) )
236 return true;
237 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR) )
238 return true; // note: old chart was false here
240 return false;
243 uno::Sequence < sal_Int32 > ChartTypeHelper::getSupportedLabelPlacements( const rtl::Reference< ChartType >& xChartType
244 , bool bSwapXAndY
245 , const rtl::Reference< DataSeries >& xSeries )
247 uno::Sequence < sal_Int32 > aRet;
248 if( !xChartType.is() )
249 return aRet;
251 OUString aChartTypeName = xChartType->getChartType();
252 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
254 bool bDonut = false;
255 xChartType->getFastPropertyValue( PROP_PIECHARTTYPE_USE_RINGS ) >>= bDonut; // "UseRings"
257 if(!bDonut)
259 aRet.realloc(5);
260 sal_Int32* pSeq = aRet.getArray();
261 *pSeq++ = css::chart::DataLabelPlacement::AVOID_OVERLAP;
262 *pSeq++ = css::chart::DataLabelPlacement::OUTSIDE;
263 *pSeq++ = css::chart::DataLabelPlacement::INSIDE;
264 *pSeq++ = css::chart::DataLabelPlacement::CENTER;
265 *pSeq++ = css::chart::DataLabelPlacement::CUSTOM;
267 else
269 aRet.realloc(1);
270 sal_Int32* pSeq = aRet.getArray();
271 *pSeq++ = css::chart::DataLabelPlacement::CENTER;
274 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER)
275 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_LINE)
276 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE)
279 aRet.realloc(5);
280 sal_Int32* pSeq = aRet.getArray();
281 *pSeq++ = css::chart::DataLabelPlacement::TOP;
282 *pSeq++ = css::chart::DataLabelPlacement::BOTTOM;
283 *pSeq++ = css::chart::DataLabelPlacement::LEFT;
284 *pSeq++ = css::chart::DataLabelPlacement::RIGHT;
285 *pSeq++ = css::chart::DataLabelPlacement::CENTER;
287 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN)
288 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR) )
291 bool bStacked = false;
293 chart2::StackingDirection eStacking = chart2::StackingDirection_NO_STACKING;
294 xSeries->getFastPropertyValue( PROP_DATASERIES_STACKING_DIRECTION ) >>= eStacking; // "StackingDirection"
295 bStacked = (eStacking == chart2::StackingDirection_Y_STACKING);
298 aRet.realloc( bStacked ? 3 : 6 );
299 sal_Int32* pSeq = aRet.getArray();
300 if(!bStacked)
302 if(bSwapXAndY)
304 *pSeq++ = css::chart::DataLabelPlacement::RIGHT;
305 *pSeq++ = css::chart::DataLabelPlacement::LEFT;
307 else
309 *pSeq++ = css::chart::DataLabelPlacement::TOP;
310 *pSeq++ = css::chart::DataLabelPlacement::BOTTOM;
313 *pSeq++ = css::chart::DataLabelPlacement::CENTER;
314 if(!bStacked)
315 *pSeq++ = css::chart::DataLabelPlacement::OUTSIDE;
316 *pSeq++ = css::chart::DataLabelPlacement::INSIDE;
317 *pSeq++ = css::chart::DataLabelPlacement::NEAR_ORIGIN;
319 else if (aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_HISTOGRAM))
321 aRet.realloc(6);
322 sal_Int32* pSeq = aRet.getArray();
324 *pSeq++ = css::chart::DataLabelPlacement::TOP;
325 *pSeq++ = css::chart::DataLabelPlacement::BOTTOM;
326 *pSeq++ = css::chart::DataLabelPlacement::CENTER;
327 *pSeq++ = css::chart::DataLabelPlacement::OUTSIDE;
328 *pSeq++ = css::chart::DataLabelPlacement::INSIDE;
329 *pSeq++ = css::chart::DataLabelPlacement::NEAR_ORIGIN;
331 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_AREA) )
333 bool bStacked = false;
335 chart2::StackingDirection eStacking = chart2::StackingDirection_NO_STACKING;
336 xSeries->getFastPropertyValue(PROP_DATASERIES_STACKING_DIRECTION) >>= eStacking; // "StackingDirection"
337 bStacked = (eStacking == chart2::StackingDirection_Y_STACKING);
340 aRet.realloc(2);
341 sal_Int32* pSeq = aRet.getArray();
342 if (bStacked)
344 *pSeq++ = css::chart::DataLabelPlacement::CENTER;
345 *pSeq++ = css::chart::DataLabelPlacement::TOP;
347 else
349 *pSeq++ = css::chart::DataLabelPlacement::TOP;
350 *pSeq++ = css::chart::DataLabelPlacement::CENTER;
353 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
355 aRet.realloc(6);
356 sal_Int32* pSeq = aRet.getArray();
357 *pSeq++ = css::chart::DataLabelPlacement::OUTSIDE;
358 *pSeq++ = css::chart::DataLabelPlacement::TOP;
359 *pSeq++ = css::chart::DataLabelPlacement::BOTTOM;
360 *pSeq++ = css::chart::DataLabelPlacement::LEFT;
361 *pSeq++ = css::chart::DataLabelPlacement::RIGHT;
362 *pSeq++ = css::chart::DataLabelPlacement::CENTER;
364 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
366 aRet.realloc(1);
367 sal_Int32* pSeq = aRet.getArray();
368 *pSeq++ = css::chart::DataLabelPlacement::OUTSIDE;
370 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
372 aRet.realloc( 1 );
373 sal_Int32* pSeq = aRet.getArray();
374 *pSeq++ = css::chart::DataLabelPlacement::OUTSIDE;
376 else
378 OSL_FAIL( "unknown charttype" );
381 return aRet;
384 bool ChartTypeHelper::isSupportingRightAngledAxes( const rtl::Reference< ChartType >& xChartType )
386 if(xChartType.is())
388 OUString aChartTypeName = xChartType->getChartType();
389 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
390 return false;
392 return true;
395 bool ChartTypeHelper::isSupportingStartingAngle( const rtl::Reference< ChartType >& xChartType )
397 if(xChartType.is())
399 OUString aChartTypeName = xChartType->getChartType();
400 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
401 return true;
403 return false;
405 bool ChartTypeHelper::isSupportingBaseValue( const rtl::Reference< ChartType >& xChartType )
407 if(xChartType.is())
409 OUString aChartTypeName = xChartType->getChartType();
410 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN)
411 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR)
412 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_AREA)
414 return true;
416 return false;
419 bool ChartTypeHelper::isSupportingAxisPositioning( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount, sal_Int32 nDimensionIndex )
421 if(xChartType.is())
423 OUString aChartTypeName = xChartType->getChartType();
424 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
425 return false;
426 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
427 return false;
429 if( nDimensionCount==3 )
430 return nDimensionIndex<2;
431 return true;
434 bool ChartTypeHelper::isSupportingDateAxis( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionIndex )
436 if( nDimensionIndex!=0 )
437 return false;
438 if( xChartType.is() )
440 sal_Int32 nType = ChartTypeHelper::getAxisType( xChartType, nDimensionIndex );
441 if( nType != AxisType::CATEGORY )
442 return false;
443 OUString aChartTypeName = xChartType->getChartType();
444 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
445 return false;
446 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
447 return false;
448 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
449 return false;
451 return true;
454 bool ChartTypeHelper::isSupportingComplexCategory( const rtl::Reference< ChartType >& xChartType )
456 if( xChartType.is() )
458 OUString aChartTypeName = xChartType->getChartType();
459 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
460 return false;
462 return true;
465 bool ChartTypeHelper::isSupportingCategoryPositioning( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
467 if( xChartType.is() )
469 OUString aChartTypeName = xChartType->getChartType();
470 if (aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_AREA) ||
471 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_LINE) ||
472 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK))
473 return true;
474 else if (nDimensionCount == 2 &&
475 (aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN) ||
476 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR) ||
477 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_HISTOGRAM)))
478 return true;
480 return false;
483 bool ChartTypeHelper::shiftCategoryPosAtXAxisPerDefault( const rtl::Reference< ChartType >& xChartType )
485 if(xChartType.is())
487 OUString aChartTypeName = xChartType->getChartType();
488 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN)
489 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR)
490 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
491 return true;
493 return false;
496 bool ChartTypeHelper::noBordersForSimpleScheme( const rtl::Reference< ChartType >& xChartType )
498 if(xChartType.is())
500 OUString aChartTypeName = xChartType->getChartType();
501 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
502 return true;
504 return false;
507 sal_Int32 ChartTypeHelper::getDefaultDirectLightColor( bool bSimple, const rtl::Reference< ChartType >& xChartType )
509 sal_Int32 nRet = static_cast< sal_Int32 >( 0x808080 ); // grey
510 if( xChartType .is() )
512 OUString aChartType = xChartType->getChartType();
513 if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_PIE )
515 if( bSimple )
516 nRet = static_cast< sal_Int32 >( 0x333333 ); // grey80
517 else
518 nRet = static_cast< sal_Int32 >( 0xb3b3b3 ); // grey30
520 else if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_LINE
521 || aChartType == CHART2_SERVICE_NAME_CHARTTYPE_SCATTER )
522 nRet = static_cast< sal_Int32 >( 0x666666 ); // grey60
524 return nRet;
527 sal_Int32 ChartTypeHelper::getDefaultAmbientLightColor( bool bSimple, const rtl::Reference< ChartType >& xChartType )
529 sal_Int32 nRet = static_cast< sal_Int32 >( 0x999999 ); // grey40
530 if( xChartType .is() )
532 OUString aChartType = xChartType->getChartType();
533 if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_PIE )
535 if( bSimple )
536 nRet = static_cast< sal_Int32 >( 0xcccccc ); // grey20
537 else
538 nRet = static_cast< sal_Int32 >( 0x666666 ); // grey60
541 return nRet;
544 drawing::Direction3D ChartTypeHelper::getDefaultSimpleLightDirection( const rtl::Reference< ChartType >& xChartType )
546 drawing::Direction3D aRet(0.0, 0.0, 1.0);
547 if( xChartType .is() )
549 OUString aChartType = xChartType->getChartType();
550 if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_PIE )
551 aRet = drawing::Direction3D(0.0, 0.8, 0.5);
552 else if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_LINE
553 || aChartType == CHART2_SERVICE_NAME_CHARTTYPE_SCATTER )
554 aRet = drawing::Direction3D(0.9, 0.5, 0.05);
556 return aRet;
559 drawing::Direction3D ChartTypeHelper::getDefaultRealisticLightDirection( const rtl::Reference< ChartType >& xChartType )
561 drawing::Direction3D aRet(0.0, 0.0, 1.0);
562 if( xChartType .is() )
564 OUString aChartType = xChartType->getChartType();
565 if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_PIE )
566 aRet = drawing::Direction3D(0.6, 0.6, 0.6);
567 else if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_LINE
568 || aChartType == CHART2_SERVICE_NAME_CHARTTYPE_SCATTER )
569 aRet = drawing::Direction3D(0.9, 0.5, 0.05);
571 return aRet;
574 sal_Int32 ChartTypeHelper::getAxisType( const rtl::Reference<
575 ChartType >& xChartType, sal_Int32 nDimensionIndex )
577 //returned is a constant from constant group css::chart2::AxisType
579 //@todo ask charttype itself --> need model change first
580 if(!xChartType.is())
581 return AxisType::CATEGORY;
583 OUString aChartTypeName = xChartType->getChartType();
584 if(nDimensionIndex==2)//z-axis
585 return AxisType::SERIES;
586 if(nDimensionIndex==1)//y-axis
587 return AxisType::REALNUMBER;
588 if(nDimensionIndex==0)//x-axis
590 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER)
591 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE) )
592 return AxisType::REALNUMBER;
593 return AxisType::CATEGORY;
595 return AxisType::CATEGORY;
598 sal_Int32 ChartTypeHelper::getNumberOfDisplayedSeries(
599 const rtl::Reference< ChartType >& xChartType,
600 sal_Int32 nNumberOfSeries )
602 if( xChartType.is() )
606 OUString aChartTypeName = xChartType->getChartType();
607 if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_PIE )
609 bool bDonut = false;
610 if( (xChartType->getFastPropertyValue( PROP_PIECHARTTYPE_USE_RINGS ) >>= bDonut) // "UseRings"
611 && !bDonut )
613 return nNumberOfSeries>0 ? 1 : 0;
617 catch( const uno::Exception & )
619 DBG_UNHANDLED_EXCEPTION("chart2");
622 return nNumberOfSeries;
625 uno::Sequence < sal_Int32 > ChartTypeHelper::getSupportedMissingValueTreatments( const rtl::Reference< ChartType >& xChartType )
627 uno::Sequence < sal_Int32 > aRet;
628 if( !xChartType.is() )
629 return aRet;
631 bool bFound=false;
632 bool bAmbiguous=false;
633 StackMode eStackMode = DiagramHelper::getStackModeFromChartType( xChartType, bFound, bAmbiguous, nullptr );
634 bool bStacked = bFound && (eStackMode == StackMode::YStacked);
636 OUString aChartTypeName = xChartType->getChartType();
637 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN) ||
638 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR) ||
639 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE) )
641 aRet.realloc( 2 );
642 sal_Int32* pSeq = aRet.getArray();
643 *pSeq++ = css::chart::MissingValueTreatment::LEAVE_GAP;
644 *pSeq++ = css::chart::MissingValueTreatment::USE_ZERO;
646 else if (aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_HISTOGRAM))
648 // Assuming histograms typically use zero for missing values
649 aRet.realloc(1);
650 sal_Int32* pSeq = aRet.getArray();
651 *pSeq++ = css::chart::MissingValueTreatment::USE_ZERO;
653 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_AREA) )
655 aRet.realloc( bStacked ? 1 : 2 );
656 sal_Int32* pSeq = aRet.getArray();
657 *pSeq++ = css::chart::MissingValueTreatment::USE_ZERO;
658 if( !bStacked )
659 *pSeq++ = css::chart::MissingValueTreatment::CONTINUE;
661 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_LINE) ||
662 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) ||
663 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
665 aRet.realloc( bStacked ? 2 : 3 );
666 sal_Int32* pSeq = aRet.getArray();
667 *pSeq++ = css::chart::MissingValueTreatment::LEAVE_GAP;
668 *pSeq++ = css::chart::MissingValueTreatment::USE_ZERO;
669 if( !bStacked )
670 *pSeq++ = css::chart::MissingValueTreatment::CONTINUE;
672 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER) )
674 aRet.realloc( 3 );
675 sal_Int32* pSeq = aRet.getArray();
676 *pSeq++ = css::chart::MissingValueTreatment::CONTINUE;
677 *pSeq++ = css::chart::MissingValueTreatment::LEAVE_GAP;
678 *pSeq++ = css::chart::MissingValueTreatment::USE_ZERO;
680 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) ||
681 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
683 aRet.realloc( 0 );
685 else
687 OSL_FAIL( "unknown charttype" );
690 return aRet;
693 bool ChartTypeHelper::isSeriesInFrontOfAxisLine( const rtl::Reference< ChartType >& xChartType )
695 if( xChartType.is() )
697 OUString aChartTypeName = xChartType->getChartType();
698 if( aChartTypeName.match( CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET ) )
699 return false;
701 return true;
704 OUString ChartTypeHelper::getRoleOfSequenceForYAxisNumberFormatDetection( const rtl::Reference< ChartType >& xChartType )
706 OUString aRet( u"values-y"_ustr );
707 if( !xChartType.is() )
708 return aRet;
709 OUString aChartTypeName = xChartType->getChartType();
710 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
711 aRet = xChartType->getRoleOfSequenceForSeriesLabel();
712 return aRet;
715 OUString ChartTypeHelper::getRoleOfSequenceForDataLabelNumberFormatDetection( const rtl::Reference< ChartType >& xChartType )
717 OUString aRet( u"values-y"_ustr );
718 if( !xChartType.is() )
719 return aRet;
720 OUString aChartTypeName = xChartType->getChartType();
721 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK)
722 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE) )
723 aRet = xChartType->getRoleOfSequenceForSeriesLabel();
724 return aRet;
727 bool ChartTypeHelper::isSupportingOnlyDeepStackingFor3D( const rtl::Reference< ChartType >& xChartType )
729 bool bRet = false;
730 if( !xChartType.is() )
731 return bRet;
733 OUString aChartTypeName = xChartType->getChartType();
734 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_LINE) ||
735 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER) ||
736 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_AREA) )
738 bRet = true;
740 return bRet;
743 } //namespace chart
745 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */