update dev300-m58
[ooovba.git] / chart2 / source / tools / AxisHelper.cxx
blobccfdc0d2b8bf7239f45587914d015c2227e35885
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AxisHelper.cxx,v $
10 * $Revision: 1.4.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "AxisHelper.hxx"
35 #include "DiagramHelper.hxx"
36 #include "ChartTypeHelper.hxx"
37 #include "macros.hxx"
38 #include "AxisIndexDefines.hxx"
39 #include "LineProperties.hxx"
40 #include "ContainerHelper.hxx"
41 #include "servicenames_coosystems.hxx"
42 #include "DataSeriesHelper.hxx"
43 #include "Scaling.hxx"
45 #include <svtools/saveopt.hxx>
47 #include <com/sun/star/chart/ChartAxisPosition.hpp>
49 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
50 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
51 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
52 #include <com/sun/star/chart2/data/XDataSource.hpp>
54 // header for class OUStringBuffer
55 #include <rtl/ustrbuf.hxx>
56 #include <com/sun/star/util/XCloneable.hpp>
57 #include <com/sun/star/lang/XServiceName.hpp>
59 #include <map>
61 //.............................................................................
62 namespace chart
64 //.............................................................................
65 using namespace ::com::sun::star;
66 using namespace ::com::sun::star::chart2;
67 using ::com::sun::star::uno::Reference;
68 using ::com::sun::star::uno::Sequence;
70 //static
71 Reference< chart2::XScaling > AxisHelper::createLinearScaling()
73 return new LinearScaling( 1.0, 0.0 );
76 //static
77 Reference< chart2::XScaling > AxisHelper::createLogarithmicScaling( double fBase )
79 return new LogarithmicScaling( fBase );
82 //static
83 ScaleData AxisHelper::createDefaultScale()
85 ScaleData aScaleData;
86 aScaleData.AxisType = chart2::AxisType::REALNUMBER;
87 Sequence< SubIncrement > aSubIncrements(1);
88 aSubIncrements[0] = SubIncrement();
89 aScaleData.IncrementData.SubIncrements = aSubIncrements;
90 return aScaleData;
93 //static
94 void AxisHelper::removeExplicitScaling( ScaleData& rScaleData )
96 uno::Any aEmpty;
97 rScaleData.Minimum = rScaleData.Maximum = rScaleData.Origin = aEmpty;
98 rScaleData.Scaling = 0;
101 //static
102 bool AxisHelper::isLogarithmic( const Reference< XScaling >& xScaling )
104 bool bReturn = false;
105 Reference< lang::XServiceName > xServiceName( xScaling, uno::UNO_QUERY );
106 bReturn =( xServiceName.is() && (xServiceName->getServiceName()).equals(
107 C2U( "com.sun.star.chart2.LogarithmicScaling" )));
108 return bReturn;
111 //static
112 Reference< XAxis > AxisHelper::createAxis(
113 sal_Int32 nDimensionIndex
114 , sal_Int32 nAxisIndex // 0==main or 1==secondary axis
115 , const Reference< XCoordinateSystem >& xCooSys
116 , const Reference< uno::XComponentContext > & xContext
117 , ReferenceSizeProvider * pRefSizeProvider )
119 if( !xContext.is() || !xCooSys.is() )
120 return NULL;
121 if( nDimensionIndex >= xCooSys->getDimension() )
122 return NULL;
124 Reference< XAxis > xAxis( xContext->getServiceManager()->createInstanceWithContext(
125 C2U( "com.sun.star.chart2.Axis" ), xContext ), uno::UNO_QUERY );
127 OSL_ASSERT( xAxis.is());
128 if( xAxis.is())
130 xCooSys->setAxisByDimension( nDimensionIndex, xAxis, nAxisIndex );
132 if( nAxisIndex>0 )//when inserting secondary axes copy some things from the main axis
134 ::com::sun::star::chart::ChartAxisPosition eNewAxisPos( ::com::sun::star::chart::ChartAxisPosition_END );
136 Reference< XAxis > xMainAxis( xCooSys->getAxisByDimension( nDimensionIndex, 0 ) );
137 if( xMainAxis.is() )
139 ScaleData aScale = xAxis->getScaleData();
140 ScaleData aMainScale = xMainAxis->getScaleData();
142 aScale.AxisType = aMainScale.AxisType;
143 aScale.Categories = aMainScale.Categories;
144 aScale.Orientation = aMainScale.Orientation;
146 xAxis->setScaleData( aScale );
148 //ensure that the second axis is not placed on the main axis
149 Reference< beans::XPropertySet > xMainProp( xMainAxis, uno::UNO_QUERY );
150 if( xMainProp.is() )
152 ::com::sun::star::chart::ChartAxisPosition eMainAxisPos( ::com::sun::star::chart::ChartAxisPosition_ZERO );
153 xMainProp->getPropertyValue(C2U( "CrossoverPosition" )) >>= eMainAxisPos;
154 if( ::com::sun::star::chart::ChartAxisPosition_END == eMainAxisPos )
155 eNewAxisPos = ::com::sun::star::chart::ChartAxisPosition_START;
159 Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY );
160 if( xProp.is() )
161 xProp->setPropertyValue(C2U( "CrossoverPosition" ), uno::makeAny(eNewAxisPos) );
164 Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY );
165 if( xProp.is() ) try
167 // set correct initial AutoScale
168 if( pRefSizeProvider )
169 pRefSizeProvider->setValuesAtPropertySet( xProp );
171 catch( uno::Exception& e )
173 ASSERT_EXCEPTION( e );
176 return xAxis;
179 //static
180 Reference< XAxis > AxisHelper::createAxis( sal_Int32 nDimensionIndex, bool bMainAxis
181 , const Reference< chart2::XDiagram >& xDiagram
182 , const Reference< uno::XComponentContext >& xContext
183 , ReferenceSizeProvider * pRefSizeProvider )
185 OSL_ENSURE( xContext.is(), "need a context to create an axis" );
186 if( !xContext.is() )
187 return NULL;
189 sal_Int32 nAxisIndex = bMainAxis ? MAIN_AXIS_INDEX : SECONDARY_AXIS_INDEX;
190 sal_Int32 nCooSysIndex = 0;
191 Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
193 // create axis
194 return AxisHelper::createAxis(
195 nDimensionIndex, nAxisIndex, xCooSys, xContext, pRefSizeProvider );
198 //static
199 void AxisHelper::showAxis( sal_Int32 nDimensionIndex, bool bMainAxis
200 , const Reference< chart2::XDiagram >& xDiagram
201 , const Reference< uno::XComponentContext >& xContext
202 , ReferenceSizeProvider * pRefSizeProvider )
204 if( !xDiagram.is() )
205 return;
207 bool bNewAxisCreated = false;
208 Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
209 if( !xAxis.is() && xContext.is() )
211 // create axis
212 bNewAxisCreated = true;
213 xAxis.set( AxisHelper::createAxis( nDimensionIndex, bMainAxis, xDiagram, xContext, pRefSizeProvider ) );
216 OSL_ASSERT( xAxis.is());
217 if( !bNewAxisCreated ) //default is true already if created
218 AxisHelper::makeAxisVisible( xAxis );
221 //static
222 void AxisHelper::showGrid( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
223 , const Reference< XDiagram >& xDiagram
224 , const Reference< uno::XComponentContext >& /*xContext*/ )
226 if( !xDiagram.is() )
227 return;
229 Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
230 if(!xCooSys.is())
231 return;
233 Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
234 if(!xAxis.is())
236 //hhhh todo create axis without axis visibility
238 if(!xAxis.is())
239 return;
241 if( bMainGrid )
242 AxisHelper::makeGridVisible( xAxis->getGridProperties() );
243 else
245 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
246 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
247 AxisHelper::makeGridVisible( aSubGrids[nN] );
251 //static
252 void AxisHelper::makeAxisVisible( const Reference< XAxis >& xAxis )
254 Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
255 if( xProps.is() )
257 xProps->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_True ) );
258 LineProperties::SetLineVisible( xProps );
259 xProps->setPropertyValue( C2U( "DisplayLabels" ), uno::makeAny( sal_True ) );
263 //static
264 void AxisHelper::makeGridVisible( const Reference< beans::XPropertySet >& xGridProperties )
266 if( xGridProperties.is() )
268 xGridProperties->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_True ) );
269 LineProperties::SetLineVisible( xGridProperties );
273 //static
274 void AxisHelper::hideAxis( sal_Int32 nDimensionIndex, bool bMainAxis
275 , const Reference< XDiagram >& xDiagram )
277 AxisHelper::makeAxisInvisible( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
280 //static
281 void AxisHelper::makeAxisInvisible( const Reference< XAxis >& xAxis )
283 Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
284 if( xProps.is() )
286 xProps->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) );
290 void AxisHelper::hideGrid( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
291 , const Reference< XDiagram >& xDiagram )
293 if( !xDiagram.is() )
294 return;
296 Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
297 if(!xCooSys.is())
298 return;
300 Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
301 if(!xAxis.is())
302 return;
304 if( bMainGrid )
305 AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
306 else
308 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
309 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
310 AxisHelper::makeGridInvisible( aSubGrids[nN] );
314 //static
315 void AxisHelper::makeGridInvisible( const Reference< beans::XPropertySet >& xGridProperties )
317 if( xGridProperties.is() )
319 xGridProperties->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) );
323 sal_Bool AxisHelper::isGridShown( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
324 , const Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
326 sal_Bool bRet = false;
328 Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
329 if(!xCooSys.is())
330 return bRet;
332 Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
333 if(!xAxis.is())
334 return bRet;
336 if( bMainGrid )
337 bRet = AxisHelper::isGridVisible( xAxis->getGridProperties() );
338 else
340 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
341 if( aSubGrids.getLength() )
342 bRet = AxisHelper::isGridVisible( aSubGrids[0] );
345 return bRet;
348 //static
349 Reference< XCoordinateSystem > AxisHelper::getCoordinateSystemByIndex(
350 const Reference< XDiagram >& xDiagram, sal_Int32 nIndex )
352 Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
353 if(!xCooSysContainer.is())
354 return NULL;
355 Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
356 if(0<=nIndex && nIndex<aCooSysList.getLength())
357 return aCooSysList[nIndex];
358 return NULL;
361 //static
362 Reference< XAxis > AxisHelper::getAxis( sal_Int32 nDimensionIndex, bool bMainAxis
363 , const Reference< XDiagram >& xDiagram )
365 Reference< XAxis > xRet;
368 Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 );
369 xRet.set( AxisHelper::getAxis( nDimensionIndex, bMainAxis ? 0 : 1, xCooSys ) );
371 catch( const uno::Exception & )
374 return xRet;
377 //static
378 Reference< XAxis > AxisHelper::getAxis( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex
379 , const Reference< XCoordinateSystem >& xCooSys )
381 Reference< XAxis > xRet;
384 if( xCooSys.is() )
385 xRet.set( xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) );
387 catch( const uno::Exception & )
390 return xRet;
393 //static
394 Reference< XAxis > AxisHelper::getCrossingMainAxis( const Reference< XAxis >& xAxis
395 , const Reference< XCoordinateSystem >& xCooSys )
397 sal_Int32 nDimensionIndex = 0;
398 sal_Int32 nAxisIndex = 0;
399 AxisHelper::getIndicesForAxis( xAxis, xCooSys, nDimensionIndex, nAxisIndex );
400 if( 2==nDimensionIndex )
402 nDimensionIndex=1;
403 bool bSwapXY = false;
404 Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY );
405 if( xCooSysProp.is() && (xCooSysProp->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bSwapXY) && bSwapXY )
406 nDimensionIndex=0;
408 else if( 1==nDimensionIndex )
409 nDimensionIndex=0;
410 else
411 nDimensionIndex=1;
412 return AxisHelper::getAxis( nDimensionIndex, 0, xCooSys );
415 //static
416 Reference< XAxis > AxisHelper::getParallelAxis( const Reference< XAxis >& xAxis
417 , const Reference< XDiagram >& xDiagram )
421 sal_Int32 nCooSysIndex=-1;
422 sal_Int32 nDimensionIndex=-1;
423 sal_Int32 nAxisIndex=-1;
424 if( getIndicesForAxis( xAxis, xDiagram, nCooSysIndex, nDimensionIndex, nAxisIndex ) )
426 sal_Int32 nParallelAxisIndex = (nAxisIndex==1) ?0 :1;
427 return getAxis( nDimensionIndex, nParallelAxisIndex, getCoordinateSystemByIndex( xDiagram, nCooSysIndex ) );
430 catch( uno::RuntimeException& )
433 return 0;
436 sal_Bool AxisHelper::isAxisShown( sal_Int32 nDimensionIndex, bool bMainAxis
437 , const Reference< XDiagram >& xDiagram )
439 return AxisHelper::isAxisVisible( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
442 //static
443 sal_Bool AxisHelper::isAxisVisible( const Reference< XAxis >& xAxis )
445 sal_Bool bRet = false;
447 Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
448 if( xProps.is() )
450 xProps->getPropertyValue( C2U( "Show" ) ) >>= bRet;
451 bRet = bRet && ( LineProperties::IsLineVisible( xProps )
452 || areAxisLabelsVisible( xProps ) );
455 return bRet;
458 sal_Bool AxisHelper::areAxisLabelsVisible( const Reference< beans::XPropertySet >& xAxisProperties )
460 sal_Bool bRet = false;
461 if( xAxisProperties.is() )
463 xAxisProperties->getPropertyValue( C2U( "DisplayLabels" ) ) >>= bRet;
465 return bRet;
468 //static
469 sal_Bool AxisHelper::isGridVisible( const Reference< beans::XPropertySet >& xGridProperies )
471 sal_Bool bRet = false;
473 if( xGridProperies.is() )
475 xGridProperies->getPropertyValue( C2U( "Show" ) ) >>= bRet;
476 bRet = bRet && LineProperties::IsLineVisible( xGridProperies );
479 return bRet;
482 //static
483 Reference< beans::XPropertySet > AxisHelper::getGridProperties(
484 const Reference< XCoordinateSystem >& xCooSys
485 , sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex, sal_Int32 nSubGridIndex )
487 Reference< beans::XPropertySet > xRet;
489 Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, nAxisIndex, xCooSys ) );
490 if( xAxis.is() )
492 if( nSubGridIndex<0 )
493 xRet.set( xAxis->getGridProperties() );
494 else
496 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
497 if( nSubGridIndex >= 0 && nSubGridIndex < aSubGrids.getLength() )
498 xRet.set( aSubGrids[nSubGridIndex] );
502 return xRet;
505 //static
506 sal_Int32 AxisHelper::getDimensionIndexOfAxis(
507 const Reference< XAxis >& xAxis
508 , const Reference< XDiagram >& xDiagram )
510 sal_Int32 nDimensionIndex = -1;
511 sal_Int32 nCooSysIndex = -1;
512 sal_Int32 nAxisIndex = -1;
513 AxisHelper::getIndicesForAxis( xAxis, xDiagram, nCooSysIndex , nDimensionIndex, nAxisIndex );
514 return nDimensionIndex;
517 //static
518 bool AxisHelper::getIndicesForAxis(
519 const Reference< XAxis >& xAxis
520 , const Reference< XCoordinateSystem >& xCooSys
521 , sal_Int32& rOutDimensionIndex, sal_Int32& rOutAxisIndex )
523 //returns true if indices are found
525 rOutDimensionIndex = -1;
526 rOutAxisIndex = -1;
528 if( xCooSys.is() && xAxis.is() )
530 Reference< XAxis > xCurrentAxis;
531 sal_Int32 nDimensionCount( xCooSys->getDimension() );
532 for( sal_Int32 nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
534 sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
535 for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
537 xCurrentAxis = xCooSys->getAxisByDimension(nDimensionIndex,nAxisIndex);
538 if( xCurrentAxis == xAxis )
540 rOutDimensionIndex = nDimensionIndex;
541 rOutAxisIndex = nAxisIndex;
542 return true;
547 return false;
550 //static
551 bool AxisHelper::getIndicesForAxis( const Reference< XAxis >& xAxis, const Reference< XDiagram >& xDiagram
552 , sal_Int32& rOutCooSysIndex, sal_Int32& rOutDimensionIndex, sal_Int32& rOutAxisIndex )
554 //returns true if indices are found
556 rOutCooSysIndex = -1;
557 rOutDimensionIndex = -1;
558 rOutAxisIndex = -1;
560 Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
561 if(xCooSysContainer.is())
563 Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
564 for( sal_Int32 nC=0; nC<aCooSysList.getLength(); ++nC )
566 if( AxisHelper::getIndicesForAxis( xAxis, aCooSysList[nC], rOutDimensionIndex, rOutAxisIndex ) )
568 rOutCooSysIndex = nC;
569 return true;
574 return false;
577 //static
578 std::vector< Reference< XAxis > > AxisHelper::getAllAxesOfCoordinateSystem(
579 const Reference< XCoordinateSystem >& xCooSys
580 , bool bOnlyVisible /* = false */ )
582 std::vector< Reference< XAxis > > aAxisVector;
584 if(xCooSys.is())
586 sal_Int32 nDimensionIndex = 0;
587 sal_Int32 nMaxDimensionIndex = xCooSys->getDimension() -1;
588 if( nMaxDimensionIndex>=0 )
590 for(nDimensionIndex=0; nDimensionIndex<=nMaxDimensionIndex; ++nDimensionIndex)
592 const sal_Int32 nMaximumAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
593 for(sal_Int32 nAxisIndex=0; nAxisIndex<=nMaximumAxisIndex; ++nAxisIndex)
597 Reference< XAxis > xAxis( xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) );
598 bool bAddAxis = true;
599 if( xAxis.is() )
601 if( bOnlyVisible )
603 Reference< beans::XPropertySet > xAxisProp( xAxis, uno::UNO_QUERY );
604 if( !xAxisProp.is() ||
605 !(xAxisProp->getPropertyValue( C2U("Show")) >>= bAddAxis) )
606 bAddAxis = false;
608 if( bAddAxis )
609 aAxisVector.push_back( xAxis );
612 catch( const uno::Exception & ex )
614 ASSERT_EXCEPTION( ex );
621 return aAxisVector;
624 //static
625 Sequence< Reference< XAxis > > AxisHelper::getAllAxesOfDiagram(
626 const Reference< XDiagram >& xDiagram
627 , bool bOnlyVisible )
629 std::vector< Reference< XAxis > > aAxisVector;
631 Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
632 if(xCooSysContainer.is())
634 Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
635 sal_Int32 nC = 0;
636 for( nC=0; nC<aCooSysList.getLength(); ++nC )
638 std::vector< Reference< XAxis > > aAxesPerCooSys( AxisHelper::getAllAxesOfCoordinateSystem( aCooSysList[nC], bOnlyVisible ) );
639 aAxisVector.insert( aAxisVector.end(), aAxesPerCooSys.begin(), aAxesPerCooSys.end() );
643 return ContainerHelper::ContainerToSequence( aAxisVector );
646 //static
647 Sequence< Reference< beans::XPropertySet > > AxisHelper::getAllGrids( const Reference< XDiagram >& xDiagram )
649 Sequence< Reference< XAxis > > aAllAxes( AxisHelper::getAllAxesOfDiagram( xDiagram ) );
650 std::vector< Reference< beans::XPropertySet > > aGridVector;
652 sal_Int32 nA = 0;
653 for( nA=0; nA<aAllAxes.getLength(); ++nA )
655 Reference< XAxis > xAxis( aAllAxes[nA] );
656 if(!xAxis.is())
657 continue;
658 Reference< beans::XPropertySet > xGridProperties( xAxis->getGridProperties() );
659 if( xGridProperties.is() )
660 aGridVector.push_back( xGridProperties );
662 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );;
663 sal_Int32 nSubGrid = 0;
664 for( nSubGrid = 0; nSubGrid < aSubGrids.getLength(); ++nSubGrid )
666 Reference< beans::XPropertySet > xSubGrid( aSubGrids[nSubGrid] );
667 if( xSubGrid.is() )
668 aGridVector.push_back( xSubGrid );
672 return ContainerHelper::ContainerToSequence( aGridVector );
675 //static
676 void AxisHelper::getAxisOrGridPossibilities( Sequence< sal_Bool >& rPossibilityList
677 , const Reference< XDiagram>& xDiagram, sal_Bool bAxis )
679 rPossibilityList.realloc(6);
681 sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
683 //set possibilities:
684 sal_Int32 nIndex=0;
685 Reference< XChartType > xChartType = DiagramHelper::getChartTypeByIndex( xDiagram, 0 );
686 for(nIndex=0;nIndex<3;nIndex++)
687 rPossibilityList[nIndex]=ChartTypeHelper::isSupportingMainAxis(xChartType,nDimensionCount,nIndex);
688 for(nIndex=3;nIndex<6;nIndex++)
689 if( bAxis )
690 rPossibilityList[nIndex]=ChartTypeHelper::isSupportingSecondaryAxis(xChartType,nDimensionCount,nIndex-3);
691 else
692 rPossibilityList[nIndex] = rPossibilityList[nIndex-3];
695 //static
696 bool AxisHelper::isSecondaryYAxisNeeded( const Reference< XCoordinateSystem >& xCooSys )
698 Reference< chart2::XChartTypeContainer > xCTCnt( xCooSys, uno::UNO_QUERY );
699 if( xCTCnt.is() )
701 Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes() );
702 for( sal_Int32 i=0; i<aChartTypes.getLength(); ++i )
704 Reference< XDataSeriesContainer > xSeriesContainer( aChartTypes[i] , uno::UNO_QUERY );
705 if( !xSeriesContainer.is() )
706 continue;
708 Sequence< Reference< XDataSeries > > aSeriesList( xSeriesContainer->getDataSeries() );
709 for( sal_Int32 nS = aSeriesList.getLength(); nS-- ; )
711 Reference< beans::XPropertySet > xProp( aSeriesList[nS], uno::UNO_QUERY );
712 if(xProp.is())
714 sal_Int32 nAttachedAxisIndex = 0;
715 if( ( xProp->getPropertyValue( C2U( "AttachedAxisIndex" ) ) >>= nAttachedAxisIndex ) && nAttachedAxisIndex>0 )
716 return true;
721 return false;
724 //static
725 bool AxisHelper::shouldAxisBeDisplayed( const Reference< XAxis >& xAxis
726 , const Reference< XCoordinateSystem >& xCooSys )
728 bool bRet = false;
730 if( xAxis.is() && xCooSys.is() )
732 sal_Int32 nDimensionIndex=-1;
733 sal_Int32 nAxisIndex=-1;
734 if( AxisHelper::getIndicesForAxis( xAxis, xCooSys, nDimensionIndex, nAxisIndex ) )
736 sal_Int32 nDimensionCount = xCooSys->getDimension();
737 Reference< XChartType > xChartType( AxisHelper::getChartTypeByIndex( xCooSys, 0 ) );
739 bool bMainAxis = (nAxisIndex==MAIN_AXIS_INDEX);
740 if( bMainAxis )
741 bRet = ChartTypeHelper::isSupportingMainAxis(xChartType,nDimensionCount,nDimensionIndex);
742 else
743 bRet = ChartTypeHelper::isSupportingSecondaryAxis(xChartType,nDimensionCount,nDimensionIndex);
747 return bRet;
750 //static
751 void AxisHelper::getAxisOrGridExcistence( Sequence< sal_Bool >& rExistenceList
752 , const Reference< XDiagram>& xDiagram, sal_Bool bAxis )
754 rExistenceList.realloc(6);
756 if(bAxis)
758 sal_Int32 nN;
759 Reference< XAxis > xAxis;
760 for(nN=0;nN<3;nN++)
761 rExistenceList[nN] = AxisHelper::isAxisShown( nN, true, xDiagram );
762 for(nN=3;nN<6;nN++)
763 rExistenceList[nN] = AxisHelper::isAxisShown( nN%3, false, xDiagram );
765 else
767 sal_Int32 nN;
769 for(nN=0;nN<3;nN++)
770 rExistenceList[nN] = AxisHelper::isGridShown( nN, 0, true, xDiagram );
771 for(nN=3;nN<6;nN++)
772 rExistenceList[nN] = AxisHelper::isGridShown( nN%3, 0, false, xDiagram );
776 //static
777 bool AxisHelper::changeVisibilityOfAxes( const Reference< XDiagram >& xDiagram
778 , const Sequence< sal_Bool >& rOldExistenceList
779 , const Sequence< sal_Bool >& rNewExistenceList
780 , const Reference< uno::XComponentContext >& xContext
781 , ReferenceSizeProvider * pRefSizeProvider )
783 bool bChanged = false;
784 for(sal_Int32 nN=0;nN<6;nN++)
786 if(rOldExistenceList[nN]!=rNewExistenceList[nN])
788 bChanged = true;
789 if(rNewExistenceList[nN])
791 AxisHelper::showAxis( nN%3, nN<3, xDiagram, xContext, pRefSizeProvider );
793 else
794 AxisHelper::hideAxis( nN%3, nN<3, xDiagram );
797 return bChanged;
800 //static
801 bool AxisHelper::changeVisibilityOfGrids( const Reference< XDiagram >& xDiagram
802 , const Sequence< sal_Bool >& rOldExistenceList
803 , const Sequence< sal_Bool >& rNewExistenceList
804 , const Reference< uno::XComponentContext >& xContext )
806 bool bChanged = false;
807 for(sal_Int32 nN=0;nN<6;nN++)
809 if(rOldExistenceList[nN]!=rNewExistenceList[nN])
811 bChanged = true;
812 if(rNewExistenceList[nN])
813 AxisHelper::showGrid( nN%3, 0, nN<3, xDiagram, xContext );
814 else
815 AxisHelper::hideGrid( nN%3, 0, nN<3, xDiagram );
818 return bChanged;
821 //static
822 Reference< XCoordinateSystem > AxisHelper::getCoordinateSystemOfAxis(
823 const Reference< XAxis >& xAxis
824 , const Reference< XDiagram >& xDiagram )
826 Reference< XCoordinateSystem > xRet;
828 Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
829 if( xCooSysContainer.is() )
831 Reference< XCoordinateSystem > xCooSys;
832 Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
833 for( sal_Int32 nCooSysIndex = 0; nCooSysIndex < aCooSysList.getLength(); ++nCooSysIndex )
835 xCooSys = aCooSysList[nCooSysIndex];
836 std::vector< Reference< XAxis > > aAllAxis( AxisHelper::getAllAxesOfCoordinateSystem( xCooSys ) );
838 ::std::vector< Reference< XAxis > >::iterator aFound =
839 ::std::find( aAllAxis.begin(), aAllAxis.end(), xAxis );
840 if( aFound != aAllAxis.end())
842 xRet.set( xCooSys );
843 break;
847 return xRet;
850 Reference< XChartType > AxisHelper::getChartTypeByIndex( const Reference< XCoordinateSystem >& xCooSys, sal_Int32 nIndex )
852 Reference< XChartType > xChartType;
854 Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
855 if( xChartTypeContainer.is() )
857 Sequence< Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
858 if( nIndex >= 0 && nIndex < aChartTypeList.getLength() )
859 xChartType.set( aChartTypeList[nIndex] );
862 return xChartType;
865 void AxisHelper::setRTLAxisLayout( const Reference< XCoordinateSystem >& xCooSys )
867 if( xCooSys.is() )
869 bool bCartesian = xCooSys->getViewServiceName().equals( CHART2_COOSYSTEM_CARTESIAN_VIEW_SERVICE_NAME );
870 if( bCartesian )
872 bool bVertical = false;
873 Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY );
874 if( xCooSysProp.is() )
875 xCooSysProp->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bVertical;
877 sal_Int32 nHorizontalAxisDimension = bVertical ? 1 : 0;
878 sal_Int32 nVerticalAxisDimension = bVertical ? 0 : 1;
882 //reverse direction for horizontal main axis
883 Reference< chart2::XAxis > xHorizontalMainAxis( AxisHelper::getAxis( nHorizontalAxisDimension, MAIN_AXIS_INDEX, xCooSys ) );
884 if( xHorizontalMainAxis.is() )
886 chart2::ScaleData aScale = xHorizontalMainAxis->getScaleData();
887 aScale.Orientation = chart2::AxisOrientation_REVERSE;
888 xHorizontalMainAxis->setScaleData(aScale);
891 //mathematical direction for vertical main axis
892 Reference< chart2::XAxis > xVerticalMainAxis( AxisHelper::getAxis( nVerticalAxisDimension, MAIN_AXIS_INDEX, xCooSys ) );
893 if( xVerticalMainAxis.is() )
895 chart2::ScaleData aScale = xVerticalMainAxis->getScaleData();
896 aScale.Orientation = chart2::AxisOrientation_MATHEMATICAL;
897 xVerticalMainAxis->setScaleData(aScale);
900 catch( uno::Exception & ex )
902 ASSERT_EXCEPTION( ex );
907 //reverse direction for horizontal secondary axis
908 Reference< chart2::XAxis > xHorizontalSecondaryAxis( AxisHelper::getAxis( nHorizontalAxisDimension, SECONDARY_AXIS_INDEX, xCooSys ) );
909 if( xHorizontalSecondaryAxis.is() )
911 chart2::ScaleData aScale = xHorizontalSecondaryAxis->getScaleData();
912 aScale.Orientation = chart2::AxisOrientation_REVERSE;
913 xHorizontalSecondaryAxis->setScaleData(aScale);
916 //mathematical direction for vertical secondary axis
917 Reference< chart2::XAxis > xVerticalSecondaryAxis( AxisHelper::getAxis( nVerticalAxisDimension, SECONDARY_AXIS_INDEX, xCooSys ) );
918 if( xVerticalSecondaryAxis.is() )
920 chart2::ScaleData aScale = xVerticalSecondaryAxis->getScaleData();
921 aScale.Orientation = chart2::AxisOrientation_MATHEMATICAL;
922 xVerticalSecondaryAxis->setScaleData(aScale);
925 catch( uno::Exception & ex )
927 ASSERT_EXCEPTION( ex );
933 Reference< XChartType > AxisHelper::getFirstChartTypeWithSeriesAttachedToAxisIndex( const Reference< chart2::XDiagram >& xDiagram, const sal_Int32 nAttachedAxisIndex )
935 Reference< XChartType > xChartType;
936 ::std::vector< Reference< XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
937 ::std::vector< Reference< XDataSeries > >::const_iterator aIter = aSeriesVector.begin();
938 for( ; aIter != aSeriesVector.end(); aIter++ )
940 sal_Int32 nCurrentIndex = DataSeriesHelper::getAttachedAxisIndex( *aIter );
941 if( nAttachedAxisIndex == nCurrentIndex )
943 xChartType = DiagramHelper::getChartTypeOfSeries( xDiagram, *aIter );
944 if(xChartType.is())
945 break;
948 return xChartType;
951 bool AxisHelper::isAxisPositioningEnabled()
953 const SvtSaveOptions::ODFDefaultVersion nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() );
954 return nCurrentVersion >= SvtSaveOptions::ODFVER_012;
957 //.............................................................................
958 } //namespace chart
959 //.............................................................................