Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / tools / ChartTypeHelper.cxx
blob15f00eac6fa9da92f1d0d23daf266290904dd55a
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/beans/XPropertySet.hpp>
28 #include <com/sun/star/chart/DataLabelPlacement.hpp>
29 #include <com/sun/star/chart/MissingValueTreatment.hpp>
30 #include <com/sun/star/chart2/AxisType.hpp>
31 #include <com/sun/star/chart2/StackingDirection.hpp>
32 #include <com/sun/star/chart2/XDataSeries.hpp>
33 #include <comphelper/diagnose_ex.hxx>
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::chart2;
37 using namespace ::chart::DataSeriesProperties;
39 namespace chart
42 bool ChartTypeHelper::isSupportingAxisSideBySide(
43 const rtl::Reference< ::chart::ChartType >& xChartType, sal_Int32 nDimensionCount )
45 bool bResult = false;
47 if( xChartType.is() &&
48 nDimensionCount < 3 )
50 bool bFound=false;
51 bool bAmbiguous=false;
52 StackMode eStackMode = DiagramHelper::getStackModeFromChartType( xChartType, bFound, bAmbiguous, nullptr );
53 if( eStackMode == StackMode::NONE && !bAmbiguous )
55 OUString aChartTypeName = xChartType->getChartType();
56 bResult = ( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN) ||
57 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR) );
61 return bResult;
64 bool ChartTypeHelper::isSupportingGeometryProperties( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
66 //form tab only for 3D-bar and 3D-column charts.
68 //@todo ask charttype itself --> need model change first
69 if(xChartType.is())
71 if(nDimensionCount==3)
73 OUString aChartTypeName = xChartType->getChartType();
74 if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_BAR )
75 return true;
76 if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_COLUMN )
77 return true;
80 return false;
83 bool ChartTypeHelper::isSupportingStatisticProperties( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
85 //3D charts, pie, net and stock do not support statistic properties
87 //@todo ask charttype itself (and series? --> stock chart?) --> need model change first
88 if(xChartType.is())
90 if(nDimensionCount==3)
91 return false;
93 OUString aChartTypeName = xChartType->getChartType();
94 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
95 return false;
96 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
97 return false;
98 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
99 return false;
100 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
101 return false;
102 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE) ) //todo: BubbleChart support error bars and trend lines
103 return false;
105 return true;
108 bool ChartTypeHelper::isSupportingRegressionProperties( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
110 // note: old chart: only scatter chart
111 return isSupportingStatisticProperties( xChartType, nDimensionCount );
114 bool ChartTypeHelper::isSupportingAreaProperties( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
116 //2D line charts, net and stock do not support area properties
118 //@todo ask charttype itself --> need model change first
119 if(xChartType.is())
121 if(nDimensionCount==2)
123 OUString aChartTypeName = xChartType->getChartType();
124 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_LINE) )
125 return false;
126 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER) )
127 return false;
128 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
129 return false;
130 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
131 return false;
134 return true;
137 bool ChartTypeHelper::isSupportingSymbolProperties( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
139 //2D line charts, 2D scatter charts and 2D net charts do support symbols
141 //@todo ask charttype itself --> need model change first
142 if(xChartType.is())
144 if(nDimensionCount==3)
145 return false;
147 OUString aChartTypeName = xChartType->getChartType();
148 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_LINE) )
149 return true;
150 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER) )
151 return true;
152 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
153 return true;
155 return false;
158 bool ChartTypeHelper::isSupportingMainAxis( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount, sal_Int32 nDimensionIndex )
160 //pie charts do not support axis at all
161 //no 3rd axis for 2D charts
163 //@todo ask charttype itself --> need model change first
164 if(xChartType.is())
166 OUString aChartTypeName = xChartType->getChartType();
167 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
168 return false;
170 if( nDimensionIndex == 2 )
171 return nDimensionCount == 3;
173 return true;
176 bool ChartTypeHelper::isSupportingSecondaryAxis( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
178 //3D, pie and net charts do not support a secondary axis at all
180 //@todo ask charttype itself --> need model change first
181 if(xChartType.is())
183 if(nDimensionCount==3)
184 return false;
186 OUString aChartTypeName = xChartType->getChartType();
187 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
188 return false;
189 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
190 return false;
191 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
192 return false;
194 return true;
197 bool ChartTypeHelper::isSupportingOverlapAndGapWidthProperties(
198 const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
200 //2D bar charts do support a this special properties
202 //@todo ask charttype itself --> need model change first
203 if(xChartType.is())
205 if(nDimensionCount==3)
206 return false;
208 OUString aChartTypeName = xChartType->getChartType();
209 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN) )
210 return true;
211 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR) )
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_AREA) )
321 bool bStacked = false;
323 chart2::StackingDirection eStacking = chart2::StackingDirection_NO_STACKING;
324 xSeries->getFastPropertyValue(PROP_DATASERIES_STACKING_DIRECTION) >>= eStacking; // "StackingDirection"
325 bStacked = (eStacking == chart2::StackingDirection_Y_STACKING);
328 aRet.realloc(2);
329 sal_Int32* pSeq = aRet.getArray();
330 if (bStacked)
332 *pSeq++ = css::chart::DataLabelPlacement::CENTER;
333 *pSeq++ = css::chart::DataLabelPlacement::TOP;
335 else
337 *pSeq++ = css::chart::DataLabelPlacement::TOP;
338 *pSeq++ = css::chart::DataLabelPlacement::CENTER;
341 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
343 aRet.realloc(6);
344 sal_Int32* pSeq = aRet.getArray();
345 *pSeq++ = css::chart::DataLabelPlacement::OUTSIDE;
346 *pSeq++ = css::chart::DataLabelPlacement::TOP;
347 *pSeq++ = css::chart::DataLabelPlacement::BOTTOM;
348 *pSeq++ = css::chart::DataLabelPlacement::LEFT;
349 *pSeq++ = css::chart::DataLabelPlacement::RIGHT;
350 *pSeq++ = css::chart::DataLabelPlacement::CENTER;
352 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
354 aRet.realloc(1);
355 sal_Int32* pSeq = aRet.getArray();
356 *pSeq++ = css::chart::DataLabelPlacement::OUTSIDE;
358 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
360 aRet.realloc( 1 );
361 sal_Int32* pSeq = aRet.getArray();
362 *pSeq++ = css::chart::DataLabelPlacement::OUTSIDE;
364 else
366 OSL_FAIL( "unknown charttype" );
369 return aRet;
372 bool ChartTypeHelper::isSupportingRightAngledAxes( const rtl::Reference< ChartType >& xChartType )
374 if(xChartType.is())
376 OUString aChartTypeName = xChartType->getChartType();
377 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
378 return false;
380 return true;
383 bool ChartTypeHelper::isSupportingStartingAngle( const rtl::Reference< ChartType >& xChartType )
385 if(xChartType.is())
387 OUString aChartTypeName = xChartType->getChartType();
388 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
389 return true;
391 return false;
393 bool ChartTypeHelper::isSupportingBaseValue( const rtl::Reference< ChartType >& xChartType )
395 if(xChartType.is())
397 OUString aChartTypeName = xChartType->getChartType();
398 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN)
399 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR)
400 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_AREA)
402 return true;
404 return false;
407 bool ChartTypeHelper::isSupportingAxisPositioning( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount, sal_Int32 nDimensionIndex )
409 if(xChartType.is())
411 OUString aChartTypeName = xChartType->getChartType();
412 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
413 return false;
414 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
415 return false;
417 if( nDimensionCount==3 )
418 return nDimensionIndex<2;
419 return true;
422 bool ChartTypeHelper::isSupportingDateAxis( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionIndex )
424 if( nDimensionIndex!=0 )
425 return false;
426 if( xChartType.is() )
428 sal_Int32 nType = ChartTypeHelper::getAxisType( xChartType, nDimensionIndex );
429 if( nType != AxisType::CATEGORY )
430 return false;
431 OUString aChartTypeName = xChartType->getChartType();
432 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
433 return false;
434 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
435 return false;
436 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
437 return false;
439 return true;
442 bool ChartTypeHelper::isSupportingComplexCategory( const rtl::Reference< ChartType >& xChartType )
444 if( xChartType.is() )
446 OUString aChartTypeName = xChartType->getChartType();
447 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
448 return false;
450 return true;
453 bool ChartTypeHelper::isSupportingCategoryPositioning( const rtl::Reference< ChartType >& xChartType, sal_Int32 nDimensionCount )
455 if( xChartType.is() )
457 OUString aChartTypeName = xChartType->getChartType();
458 if (aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_AREA) ||
459 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_LINE) ||
460 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK))
461 return true;
462 else if (nDimensionCount == 2 &&
463 (aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN) || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR)))
464 return true;
466 return false;
469 bool ChartTypeHelper::shiftCategoryPosAtXAxisPerDefault( const rtl::Reference< ChartType >& xChartType )
471 if(xChartType.is())
473 OUString aChartTypeName = xChartType->getChartType();
474 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN)
475 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR)
476 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
477 return true;
479 return false;
482 bool ChartTypeHelper::noBordersForSimpleScheme( const rtl::Reference< ChartType >& xChartType )
484 if(xChartType.is())
486 OUString aChartTypeName = xChartType->getChartType();
487 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
488 return true;
490 return false;
493 sal_Int32 ChartTypeHelper::getDefaultDirectLightColor( bool bSimple, const rtl::Reference< ChartType >& xChartType )
495 sal_Int32 nRet = static_cast< sal_Int32 >( 0x808080 ); // grey
496 if( xChartType .is() )
498 OUString aChartType = xChartType->getChartType();
499 if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_PIE )
501 if( bSimple )
502 nRet = static_cast< sal_Int32 >( 0x333333 ); // grey80
503 else
504 nRet = static_cast< sal_Int32 >( 0xb3b3b3 ); // grey30
506 else if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_LINE
507 || aChartType == CHART2_SERVICE_NAME_CHARTTYPE_SCATTER )
508 nRet = static_cast< sal_Int32 >( 0x666666 ); // grey60
510 return nRet;
513 sal_Int32 ChartTypeHelper::getDefaultAmbientLightColor( bool bSimple, const rtl::Reference< ChartType >& xChartType )
515 sal_Int32 nRet = static_cast< sal_Int32 >( 0x999999 ); // grey40
516 if( xChartType .is() )
518 OUString aChartType = xChartType->getChartType();
519 if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_PIE )
521 if( bSimple )
522 nRet = static_cast< sal_Int32 >( 0xcccccc ); // grey20
523 else
524 nRet = static_cast< sal_Int32 >( 0x666666 ); // grey60
527 return nRet;
530 drawing::Direction3D ChartTypeHelper::getDefaultSimpleLightDirection( const rtl::Reference< ChartType >& xChartType )
532 drawing::Direction3D aRet(0.0, 0.0, 1.0);
533 if( xChartType .is() )
535 OUString aChartType = xChartType->getChartType();
536 if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_PIE )
537 aRet = drawing::Direction3D(0.0, 0.8, 0.5);
538 else if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_LINE
539 || aChartType == CHART2_SERVICE_NAME_CHARTTYPE_SCATTER )
540 aRet = drawing::Direction3D(0.9, 0.5, 0.05);
542 return aRet;
545 drawing::Direction3D ChartTypeHelper::getDefaultRealisticLightDirection( const rtl::Reference< ChartType >& xChartType )
547 drawing::Direction3D aRet(0.0, 0.0, 1.0);
548 if( xChartType .is() )
550 OUString aChartType = xChartType->getChartType();
551 if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_PIE )
552 aRet = drawing::Direction3D(0.6, 0.6, 0.6);
553 else if( aChartType == CHART2_SERVICE_NAME_CHARTTYPE_LINE
554 || aChartType == CHART2_SERVICE_NAME_CHARTTYPE_SCATTER )
555 aRet = drawing::Direction3D(0.9, 0.5, 0.05);
557 return aRet;
560 sal_Int32 ChartTypeHelper::getAxisType( const rtl::Reference<
561 ChartType >& xChartType, sal_Int32 nDimensionIndex )
563 //returned is a constant from constant group css::chart2::AxisType
565 //@todo ask charttype itself --> need model change first
566 if(!xChartType.is())
567 return AxisType::CATEGORY;
569 OUString aChartTypeName = xChartType->getChartType();
570 if(nDimensionIndex==2)//z-axis
571 return AxisType::SERIES;
572 if(nDimensionIndex==1)//y-axis
573 return AxisType::REALNUMBER;
574 if(nDimensionIndex==0)//x-axis
576 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER)
577 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE) )
578 return AxisType::REALNUMBER;
579 return AxisType::CATEGORY;
581 return AxisType::CATEGORY;
584 sal_Int32 ChartTypeHelper::getNumberOfDisplayedSeries(
585 const rtl::Reference< ChartType >& xChartType,
586 sal_Int32 nNumberOfSeries )
588 if( xChartType.is() )
592 OUString aChartTypeName = xChartType->getChartType();
593 if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_PIE )
595 bool bDonut = false;
596 if( (xChartType->getFastPropertyValue( PROP_PIECHARTTYPE_USE_RINGS ) >>= bDonut) // "UseRings"
597 && !bDonut )
599 return nNumberOfSeries>0 ? 1 : 0;
603 catch( const uno::Exception & )
605 DBG_UNHANDLED_EXCEPTION("chart2");
608 return nNumberOfSeries;
611 uno::Sequence < sal_Int32 > ChartTypeHelper::getSupportedMissingValueTreatments( const rtl::Reference< ChartType >& xChartType )
613 uno::Sequence < sal_Int32 > aRet;
614 if( !xChartType.is() )
615 return aRet;
617 bool bFound=false;
618 bool bAmbiguous=false;
619 StackMode eStackMode = DiagramHelper::getStackModeFromChartType( xChartType, bFound, bAmbiguous, nullptr );
620 bool bStacked = bFound && (eStackMode == StackMode::YStacked);
622 OUString aChartTypeName = xChartType->getChartType();
623 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN) ||
624 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR) ||
625 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE) )
627 aRet.realloc( 2 );
628 sal_Int32* pSeq = aRet.getArray();
629 *pSeq++ = css::chart::MissingValueTreatment::LEAVE_GAP;
630 *pSeq++ = css::chart::MissingValueTreatment::USE_ZERO;
632 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_AREA) )
634 aRet.realloc( bStacked ? 1 : 2 );
635 sal_Int32* pSeq = aRet.getArray();
636 *pSeq++ = css::chart::MissingValueTreatment::USE_ZERO;
637 if( !bStacked )
638 *pSeq++ = css::chart::MissingValueTreatment::CONTINUE;
640 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_LINE) ||
641 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) ||
642 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
644 aRet.realloc( bStacked ? 2 : 3 );
645 sal_Int32* pSeq = aRet.getArray();
646 *pSeq++ = css::chart::MissingValueTreatment::LEAVE_GAP;
647 *pSeq++ = css::chart::MissingValueTreatment::USE_ZERO;
648 if( !bStacked )
649 *pSeq++ = css::chart::MissingValueTreatment::CONTINUE;
651 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER) )
653 aRet.realloc( 3 );
654 sal_Int32* pSeq = aRet.getArray();
655 *pSeq++ = css::chart::MissingValueTreatment::CONTINUE;
656 *pSeq++ = css::chart::MissingValueTreatment::LEAVE_GAP;
657 *pSeq++ = css::chart::MissingValueTreatment::USE_ZERO;
659 else if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) ||
660 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
662 aRet.realloc( 0 );
664 else
666 OSL_FAIL( "unknown charttype" );
669 return aRet;
672 bool ChartTypeHelper::isSeriesInFrontOfAxisLine( const rtl::Reference< ChartType >& xChartType )
674 if( xChartType.is() )
676 OUString aChartTypeName = xChartType->getChartType();
677 if( aChartTypeName.match( CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET ) )
678 return false;
680 return true;
683 OUString ChartTypeHelper::getRoleOfSequenceForYAxisNumberFormatDetection( const rtl::Reference< ChartType >& xChartType )
685 OUString aRet( "values-y" );
686 if( !xChartType.is() )
687 return aRet;
688 OUString aChartTypeName = xChartType->getChartType();
689 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
690 aRet = xChartType->getRoleOfSequenceForSeriesLabel();
691 return aRet;
694 OUString ChartTypeHelper::getRoleOfSequenceForDataLabelNumberFormatDetection( const rtl::Reference< ChartType >& xChartType )
696 OUString aRet( "values-y" );
697 if( !xChartType.is() )
698 return aRet;
699 OUString aChartTypeName = xChartType->getChartType();
700 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK)
701 || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE) )
702 aRet = xChartType->getRoleOfSequenceForSeriesLabel();
703 return aRet;
706 bool ChartTypeHelper::isSupportingOnlyDeepStackingFor3D( const rtl::Reference< ChartType >& xChartType )
708 bool bRet = false;
709 if( !xChartType.is() )
710 return bRet;
712 OUString aChartTypeName = xChartType->getChartType();
713 if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_LINE) ||
714 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER) ||
715 aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_AREA) )
717 bRet = true;
719 return bRet;
722 } //namespace chart
724 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */