merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / tools / AxisHelper.cxx
blob8cdd24e4dc05ccc24985ac487d73b32b600a970d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "AxisHelper.hxx"
32 #include "DiagramHelper.hxx"
33 #include "ChartTypeHelper.hxx"
34 #include "macros.hxx"
35 #include "AxisIndexDefines.hxx"
36 #include "LineProperties.hxx"
37 #include "ContainerHelper.hxx"
38 #include "servicenames_coosystems.hxx"
39 #include "DataSeriesHelper.hxx"
40 #include "Scaling.hxx"
42 #include <unotools/saveopt.hxx>
44 #include <com/sun/star/chart/ChartAxisPosition.hpp>
46 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
47 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
48 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
49 #include <com/sun/star/chart2/data/XDataSource.hpp>
51 // header for class OUStringBuffer
52 #include <rtl/ustrbuf.hxx>
53 #include <com/sun/star/util/XCloneable.hpp>
54 #include <com/sun/star/lang/XServiceName.hpp>
56 #include <map>
58 //.............................................................................
59 namespace chart
61 //.............................................................................
62 using namespace ::com::sun::star;
63 using namespace ::com::sun::star::chart2;
64 using ::com::sun::star::uno::Reference;
65 using ::com::sun::star::uno::Sequence;
67 //static
68 Reference< chart2::XScaling > AxisHelper::createLinearScaling()
70 return new LinearScaling( 1.0, 0.0 );
73 //static
74 Reference< chart2::XScaling > AxisHelper::createLogarithmicScaling( double fBase )
76 return new LogarithmicScaling( fBase );
79 //static
80 ScaleData AxisHelper::createDefaultScale()
82 ScaleData aScaleData;
83 aScaleData.AxisType = chart2::AxisType::REALNUMBER;
84 Sequence< SubIncrement > aSubIncrements(1);
85 aSubIncrements[0] = SubIncrement();
86 aScaleData.IncrementData.SubIncrements = aSubIncrements;
87 return aScaleData;
90 //static
91 void AxisHelper::removeExplicitScaling( ScaleData& rScaleData )
93 uno::Any aEmpty;
94 rScaleData.Minimum = rScaleData.Maximum = rScaleData.Origin = aEmpty;
95 rScaleData.Scaling = 0;
98 //static
99 bool AxisHelper::isLogarithmic( const Reference< XScaling >& xScaling )
101 bool bReturn = false;
102 Reference< lang::XServiceName > xServiceName( xScaling, uno::UNO_QUERY );
103 bReturn =( xServiceName.is() && (xServiceName->getServiceName()).equals(
104 C2U( "com.sun.star.chart2.LogarithmicScaling" )));
105 return bReturn;
108 //static
109 Reference< XAxis > AxisHelper::createAxis(
110 sal_Int32 nDimensionIndex
111 , sal_Int32 nAxisIndex // 0==main or 1==secondary axis
112 , const Reference< XCoordinateSystem >& xCooSys
113 , const Reference< uno::XComponentContext > & xContext
114 , ReferenceSizeProvider * pRefSizeProvider )
116 if( !xContext.is() || !xCooSys.is() )
117 return NULL;
118 if( nDimensionIndex >= xCooSys->getDimension() )
119 return NULL;
121 Reference< XAxis > xAxis( xContext->getServiceManager()->createInstanceWithContext(
122 C2U( "com.sun.star.chart2.Axis" ), xContext ), uno::UNO_QUERY );
124 OSL_ASSERT( xAxis.is());
125 if( xAxis.is())
127 xCooSys->setAxisByDimension( nDimensionIndex, xAxis, nAxisIndex );
129 if( nAxisIndex>0 )//when inserting secondary axes copy some things from the main axis
131 ::com::sun::star::chart::ChartAxisPosition eNewAxisPos( ::com::sun::star::chart::ChartAxisPosition_END );
133 Reference< XAxis > xMainAxis( xCooSys->getAxisByDimension( nDimensionIndex, 0 ) );
134 if( xMainAxis.is() )
136 ScaleData aScale = xAxis->getScaleData();
137 ScaleData aMainScale = xMainAxis->getScaleData();
139 aScale.AxisType = aMainScale.AxisType;
140 aScale.Categories = aMainScale.Categories;
141 aScale.Orientation = aMainScale.Orientation;
143 xAxis->setScaleData( aScale );
145 //ensure that the second axis is not placed on the main axis
146 Reference< beans::XPropertySet > xMainProp( xMainAxis, uno::UNO_QUERY );
147 if( xMainProp.is() )
149 ::com::sun::star::chart::ChartAxisPosition eMainAxisPos( ::com::sun::star::chart::ChartAxisPosition_ZERO );
150 xMainProp->getPropertyValue(C2U( "CrossoverPosition" )) >>= eMainAxisPos;
151 if( ::com::sun::star::chart::ChartAxisPosition_END == eMainAxisPos )
152 eNewAxisPos = ::com::sun::star::chart::ChartAxisPosition_START;
156 Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY );
157 if( xProp.is() )
158 xProp->setPropertyValue(C2U( "CrossoverPosition" ), uno::makeAny(eNewAxisPos) );
161 Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY );
162 if( xProp.is() ) try
164 // set correct initial AutoScale
165 if( pRefSizeProvider )
166 pRefSizeProvider->setValuesAtPropertySet( xProp );
168 catch( uno::Exception& e )
170 ASSERT_EXCEPTION( e );
173 return xAxis;
176 //static
177 Reference< XAxis > AxisHelper::createAxis( sal_Int32 nDimensionIndex, bool bMainAxis
178 , const Reference< chart2::XDiagram >& xDiagram
179 , const Reference< uno::XComponentContext >& xContext
180 , ReferenceSizeProvider * pRefSizeProvider )
182 OSL_ENSURE( xContext.is(), "need a context to create an axis" );
183 if( !xContext.is() )
184 return NULL;
186 sal_Int32 nAxisIndex = bMainAxis ? MAIN_AXIS_INDEX : SECONDARY_AXIS_INDEX;
187 sal_Int32 nCooSysIndex = 0;
188 Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
190 // create axis
191 return AxisHelper::createAxis(
192 nDimensionIndex, nAxisIndex, xCooSys, xContext, pRefSizeProvider );
195 //static
196 void AxisHelper::showAxis( sal_Int32 nDimensionIndex, bool bMainAxis
197 , const Reference< chart2::XDiagram >& xDiagram
198 , const Reference< uno::XComponentContext >& xContext
199 , ReferenceSizeProvider * pRefSizeProvider )
201 if( !xDiagram.is() )
202 return;
204 bool bNewAxisCreated = false;
205 Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
206 if( !xAxis.is() && xContext.is() )
208 // create axis
209 bNewAxisCreated = true;
210 xAxis.set( AxisHelper::createAxis( nDimensionIndex, bMainAxis, xDiagram, xContext, pRefSizeProvider ) );
213 OSL_ASSERT( xAxis.is());
214 if( !bNewAxisCreated ) //default is true already if created
215 AxisHelper::makeAxisVisible( xAxis );
218 //static
219 void AxisHelper::showGrid( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
220 , const Reference< XDiagram >& xDiagram
221 , const Reference< uno::XComponentContext >& /*xContext*/ )
223 if( !xDiagram.is() )
224 return;
226 Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
227 if(!xCooSys.is())
228 return;
230 Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
231 if(!xAxis.is())
233 //hhhh todo create axis without axis visibility
235 if(!xAxis.is())
236 return;
238 if( bMainGrid )
239 AxisHelper::makeGridVisible( xAxis->getGridProperties() );
240 else
242 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
243 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
244 AxisHelper::makeGridVisible( aSubGrids[nN] );
248 //static
249 void AxisHelper::makeAxisVisible( const Reference< XAxis >& xAxis )
251 Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
252 if( xProps.is() )
254 xProps->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_True ) );
255 LineProperties::SetLineVisible( xProps );
256 xProps->setPropertyValue( C2U( "DisplayLabels" ), uno::makeAny( sal_True ) );
260 //static
261 void AxisHelper::makeGridVisible( const Reference< beans::XPropertySet >& xGridProperties )
263 if( xGridProperties.is() )
265 xGridProperties->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_True ) );
266 LineProperties::SetLineVisible( xGridProperties );
270 //static
271 void AxisHelper::hideAxis( sal_Int32 nDimensionIndex, bool bMainAxis
272 , const Reference< XDiagram >& xDiagram )
274 AxisHelper::makeAxisInvisible( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
277 //static
278 void AxisHelper::makeAxisInvisible( const Reference< XAxis >& xAxis )
280 Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
281 if( xProps.is() )
283 xProps->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) );
287 //static
288 void AxisHelper::hideAxisIfNoDataIsAttached( const Reference< XAxis >& xAxis, const Reference< XDiagram >& xDiagram )
290 //axis is hidden if no data is attached anymore but data is available
291 bool bOtherSeriesAttachedToThisAxis = false;
292 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
293 ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt = aSeriesVector.begin();
294 for( ; aIt != aSeriesVector.end(); ++aIt)
296 uno::Reference< chart2::XAxis > xCurrentAxis( DiagramHelper::getAttachedAxis( *aIt, xDiagram ), uno::UNO_QUERY );
297 if( xCurrentAxis==xAxis )
299 bOtherSeriesAttachedToThisAxis = true;
300 break;
303 if(!bOtherSeriesAttachedToThisAxis && !aSeriesVector.empty() )
304 AxisHelper::makeAxisInvisible( xAxis );
307 void AxisHelper::hideGrid( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
308 , const Reference< XDiagram >& xDiagram )
310 if( !xDiagram.is() )
311 return;
313 Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
314 if(!xCooSys.is())
315 return;
317 Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
318 if(!xAxis.is())
319 return;
321 if( bMainGrid )
322 AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
323 else
325 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
326 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
327 AxisHelper::makeGridInvisible( aSubGrids[nN] );
331 //static
332 void AxisHelper::makeGridInvisible( const Reference< beans::XPropertySet >& xGridProperties )
334 if( xGridProperties.is() )
336 xGridProperties->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) );
340 sal_Bool AxisHelper::isGridShown( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
341 , const Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
343 sal_Bool bRet = false;
345 Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
346 if(!xCooSys.is())
347 return bRet;
349 Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
350 if(!xAxis.is())
351 return bRet;
353 if( bMainGrid )
354 bRet = AxisHelper::isGridVisible( xAxis->getGridProperties() );
355 else
357 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
358 if( aSubGrids.getLength() )
359 bRet = AxisHelper::isGridVisible( aSubGrids[0] );
362 return bRet;
365 //static
366 Reference< XCoordinateSystem > AxisHelper::getCoordinateSystemByIndex(
367 const Reference< XDiagram >& xDiagram, sal_Int32 nIndex )
369 Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
370 if(!xCooSysContainer.is())
371 return NULL;
372 Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
373 if(0<=nIndex && nIndex<aCooSysList.getLength())
374 return aCooSysList[nIndex];
375 return NULL;
378 //static
379 Reference< XAxis > AxisHelper::getAxis( sal_Int32 nDimensionIndex, bool bMainAxis
380 , const Reference< XDiagram >& xDiagram )
382 Reference< XAxis > xRet;
385 Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 );
386 xRet.set( AxisHelper::getAxis( nDimensionIndex, bMainAxis ? 0 : 1, xCooSys ) );
388 catch( const uno::Exception & )
391 return xRet;
394 //static
395 Reference< XAxis > AxisHelper::getAxis( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex
396 , const Reference< XCoordinateSystem >& xCooSys )
398 Reference< XAxis > xRet;
401 if( xCooSys.is() )
402 xRet.set( xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) );
404 catch( const uno::Exception & )
407 return xRet;
410 //static
411 Reference< XAxis > AxisHelper::getCrossingMainAxis( const Reference< XAxis >& xAxis
412 , const Reference< XCoordinateSystem >& xCooSys )
414 sal_Int32 nDimensionIndex = 0;
415 sal_Int32 nAxisIndex = 0;
416 AxisHelper::getIndicesForAxis( xAxis, xCooSys, nDimensionIndex, nAxisIndex );
417 if( 2==nDimensionIndex )
419 nDimensionIndex=1;
420 bool bSwapXY = false;
421 Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY );
422 if( xCooSysProp.is() && (xCooSysProp->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bSwapXY) && bSwapXY )
423 nDimensionIndex=0;
425 else if( 1==nDimensionIndex )
426 nDimensionIndex=0;
427 else
428 nDimensionIndex=1;
429 return AxisHelper::getAxis( nDimensionIndex, 0, xCooSys );
432 //static
433 Reference< XAxis > AxisHelper::getParallelAxis( const Reference< XAxis >& xAxis
434 , const Reference< XDiagram >& xDiagram )
438 sal_Int32 nCooSysIndex=-1;
439 sal_Int32 nDimensionIndex=-1;
440 sal_Int32 nAxisIndex=-1;
441 if( getIndicesForAxis( xAxis, xDiagram, nCooSysIndex, nDimensionIndex, nAxisIndex ) )
443 sal_Int32 nParallelAxisIndex = (nAxisIndex==1) ?0 :1;
444 return getAxis( nDimensionIndex, nParallelAxisIndex, getCoordinateSystemByIndex( xDiagram, nCooSysIndex ) );
447 catch( uno::RuntimeException& )
450 return 0;
453 sal_Bool AxisHelper::isAxisShown( sal_Int32 nDimensionIndex, bool bMainAxis
454 , const Reference< XDiagram >& xDiagram )
456 return AxisHelper::isAxisVisible( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
459 //static
460 sal_Bool AxisHelper::isAxisVisible( const Reference< XAxis >& xAxis )
462 sal_Bool bRet = false;
464 Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
465 if( xProps.is() )
467 xProps->getPropertyValue( C2U( "Show" ) ) >>= bRet;
468 bRet = bRet && ( LineProperties::IsLineVisible( xProps )
469 || areAxisLabelsVisible( xProps ) );
472 return bRet;
475 sal_Bool AxisHelper::areAxisLabelsVisible( const Reference< beans::XPropertySet >& xAxisProperties )
477 sal_Bool bRet = false;
478 if( xAxisProperties.is() )
480 xAxisProperties->getPropertyValue( C2U( "DisplayLabels" ) ) >>= bRet;
482 return bRet;
485 //static
486 sal_Bool AxisHelper::isGridVisible( const Reference< beans::XPropertySet >& xGridProperies )
488 sal_Bool bRet = false;
490 if( xGridProperies.is() )
492 xGridProperies->getPropertyValue( C2U( "Show" ) ) >>= bRet;
493 bRet = bRet && LineProperties::IsLineVisible( xGridProperies );
496 return bRet;
499 //static
500 Reference< beans::XPropertySet > AxisHelper::getGridProperties(
501 const Reference< XCoordinateSystem >& xCooSys
502 , sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex, sal_Int32 nSubGridIndex )
504 Reference< beans::XPropertySet > xRet;
506 Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, nAxisIndex, xCooSys ) );
507 if( xAxis.is() )
509 if( nSubGridIndex<0 )
510 xRet.set( xAxis->getGridProperties() );
511 else
513 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
514 if( nSubGridIndex >= 0 && nSubGridIndex < aSubGrids.getLength() )
515 xRet.set( aSubGrids[nSubGridIndex] );
519 return xRet;
522 //static
523 sal_Int32 AxisHelper::getDimensionIndexOfAxis(
524 const Reference< XAxis >& xAxis
525 , const Reference< XDiagram >& xDiagram )
527 sal_Int32 nDimensionIndex = -1;
528 sal_Int32 nCooSysIndex = -1;
529 sal_Int32 nAxisIndex = -1;
530 AxisHelper::getIndicesForAxis( xAxis, xDiagram, nCooSysIndex , nDimensionIndex, nAxisIndex );
531 return nDimensionIndex;
534 //static
535 bool AxisHelper::getIndicesForAxis(
536 const Reference< XAxis >& xAxis
537 , const Reference< XCoordinateSystem >& xCooSys
538 , sal_Int32& rOutDimensionIndex, sal_Int32& rOutAxisIndex )
540 //returns true if indices are found
542 rOutDimensionIndex = -1;
543 rOutAxisIndex = -1;
545 if( xCooSys.is() && xAxis.is() )
547 Reference< XAxis > xCurrentAxis;
548 sal_Int32 nDimensionCount( xCooSys->getDimension() );
549 for( sal_Int32 nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
551 sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
552 for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
554 xCurrentAxis = xCooSys->getAxisByDimension(nDimensionIndex,nAxisIndex);
555 if( xCurrentAxis == xAxis )
557 rOutDimensionIndex = nDimensionIndex;
558 rOutAxisIndex = nAxisIndex;
559 return true;
564 return false;
567 //static
568 bool AxisHelper::getIndicesForAxis( const Reference< XAxis >& xAxis, const Reference< XDiagram >& xDiagram
569 , sal_Int32& rOutCooSysIndex, sal_Int32& rOutDimensionIndex, sal_Int32& rOutAxisIndex )
571 //returns true if indices are found
573 rOutCooSysIndex = -1;
574 rOutDimensionIndex = -1;
575 rOutAxisIndex = -1;
577 Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
578 if(xCooSysContainer.is())
580 Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
581 for( sal_Int32 nC=0; nC<aCooSysList.getLength(); ++nC )
583 if( AxisHelper::getIndicesForAxis( xAxis, aCooSysList[nC], rOutDimensionIndex, rOutAxisIndex ) )
585 rOutCooSysIndex = nC;
586 return true;
591 return false;
594 //static
595 std::vector< Reference< XAxis > > AxisHelper::getAllAxesOfCoordinateSystem(
596 const Reference< XCoordinateSystem >& xCooSys
597 , bool bOnlyVisible /* = false */ )
599 std::vector< Reference< XAxis > > aAxisVector;
601 if(xCooSys.is())
603 sal_Int32 nDimensionIndex = 0;
604 sal_Int32 nMaxDimensionIndex = xCooSys->getDimension() -1;
605 if( nMaxDimensionIndex>=0 )
607 for(nDimensionIndex=0; nDimensionIndex<=nMaxDimensionIndex; ++nDimensionIndex)
609 const sal_Int32 nMaximumAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
610 for(sal_Int32 nAxisIndex=0; nAxisIndex<=nMaximumAxisIndex; ++nAxisIndex)
614 Reference< XAxis > xAxis( xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) );
615 bool bAddAxis = true;
616 if( xAxis.is() )
618 if( bOnlyVisible )
620 Reference< beans::XPropertySet > xAxisProp( xAxis, uno::UNO_QUERY );
621 if( !xAxisProp.is() ||
622 !(xAxisProp->getPropertyValue( C2U("Show")) >>= bAddAxis) )
623 bAddAxis = false;
625 if( bAddAxis )
626 aAxisVector.push_back( xAxis );
629 catch( const uno::Exception & ex )
631 ASSERT_EXCEPTION( ex );
638 return aAxisVector;
641 //static
642 Sequence< Reference< XAxis > > AxisHelper::getAllAxesOfDiagram(
643 const Reference< XDiagram >& xDiagram
644 , bool bOnlyVisible )
646 std::vector< Reference< XAxis > > aAxisVector;
648 Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
649 if(xCooSysContainer.is())
651 Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
652 sal_Int32 nC = 0;
653 for( nC=0; nC<aCooSysList.getLength(); ++nC )
655 std::vector< Reference< XAxis > > aAxesPerCooSys( AxisHelper::getAllAxesOfCoordinateSystem( aCooSysList[nC], bOnlyVisible ) );
656 aAxisVector.insert( aAxisVector.end(), aAxesPerCooSys.begin(), aAxesPerCooSys.end() );
660 return ContainerHelper::ContainerToSequence( aAxisVector );
663 //static
664 Sequence< Reference< beans::XPropertySet > > AxisHelper::getAllGrids( const Reference< XDiagram >& xDiagram )
666 Sequence< Reference< XAxis > > aAllAxes( AxisHelper::getAllAxesOfDiagram( xDiagram ) );
667 std::vector< Reference< beans::XPropertySet > > aGridVector;
669 sal_Int32 nA = 0;
670 for( nA=0; nA<aAllAxes.getLength(); ++nA )
672 Reference< XAxis > xAxis( aAllAxes[nA] );
673 if(!xAxis.is())
674 continue;
675 Reference< beans::XPropertySet > xGridProperties( xAxis->getGridProperties() );
676 if( xGridProperties.is() )
677 aGridVector.push_back( xGridProperties );
679 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );;
680 sal_Int32 nSubGrid = 0;
681 for( nSubGrid = 0; nSubGrid < aSubGrids.getLength(); ++nSubGrid )
683 Reference< beans::XPropertySet > xSubGrid( aSubGrids[nSubGrid] );
684 if( xSubGrid.is() )
685 aGridVector.push_back( xSubGrid );
689 return ContainerHelper::ContainerToSequence( aGridVector );
692 //static
693 void AxisHelper::getAxisOrGridPossibilities( Sequence< sal_Bool >& rPossibilityList
694 , const Reference< XDiagram>& xDiagram, sal_Bool bAxis )
696 rPossibilityList.realloc(6);
698 sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
700 //set possibilities:
701 sal_Int32 nIndex=0;
702 Reference< XChartType > xChartType = DiagramHelper::getChartTypeByIndex( xDiagram, 0 );
703 for(nIndex=0;nIndex<3;nIndex++)
704 rPossibilityList[nIndex]=ChartTypeHelper::isSupportingMainAxis(xChartType,nDimensionCount,nIndex);
705 for(nIndex=3;nIndex<6;nIndex++)
706 if( bAxis )
707 rPossibilityList[nIndex]=ChartTypeHelper::isSupportingSecondaryAxis(xChartType,nDimensionCount,nIndex-3);
708 else
709 rPossibilityList[nIndex] = rPossibilityList[nIndex-3];
712 //static
713 bool AxisHelper::isSecondaryYAxisNeeded( const Reference< XCoordinateSystem >& xCooSys )
715 Reference< chart2::XChartTypeContainer > xCTCnt( xCooSys, uno::UNO_QUERY );
716 if( xCTCnt.is() )
718 Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes() );
719 for( sal_Int32 i=0; i<aChartTypes.getLength(); ++i )
721 Reference< XDataSeriesContainer > xSeriesContainer( aChartTypes[i] , uno::UNO_QUERY );
722 if( !xSeriesContainer.is() )
723 continue;
725 Sequence< Reference< XDataSeries > > aSeriesList( xSeriesContainer->getDataSeries() );
726 for( sal_Int32 nS = aSeriesList.getLength(); nS-- ; )
728 Reference< beans::XPropertySet > xProp( aSeriesList[nS], uno::UNO_QUERY );
729 if(xProp.is())
731 sal_Int32 nAttachedAxisIndex = 0;
732 if( ( xProp->getPropertyValue( C2U( "AttachedAxisIndex" ) ) >>= nAttachedAxisIndex ) && nAttachedAxisIndex>0 )
733 return true;
738 return false;
741 //static
742 bool AxisHelper::shouldAxisBeDisplayed( const Reference< XAxis >& xAxis
743 , const Reference< XCoordinateSystem >& xCooSys )
745 bool bRet = false;
747 if( xAxis.is() && xCooSys.is() )
749 sal_Int32 nDimensionIndex=-1;
750 sal_Int32 nAxisIndex=-1;
751 if( AxisHelper::getIndicesForAxis( xAxis, xCooSys, nDimensionIndex, nAxisIndex ) )
753 sal_Int32 nDimensionCount = xCooSys->getDimension();
754 Reference< XChartType > xChartType( AxisHelper::getChartTypeByIndex( xCooSys, 0 ) );
756 bool bMainAxis = (nAxisIndex==MAIN_AXIS_INDEX);
757 if( bMainAxis )
758 bRet = ChartTypeHelper::isSupportingMainAxis(xChartType,nDimensionCount,nDimensionIndex);
759 else
760 bRet = ChartTypeHelper::isSupportingSecondaryAxis(xChartType,nDimensionCount,nDimensionIndex);
764 return bRet;
767 //static
768 void AxisHelper::getAxisOrGridExcistence( Sequence< sal_Bool >& rExistenceList
769 , const Reference< XDiagram>& xDiagram, sal_Bool bAxis )
771 rExistenceList.realloc(6);
773 if(bAxis)
775 sal_Int32 nN;
776 Reference< XAxis > xAxis;
777 for(nN=0;nN<3;nN++)
778 rExistenceList[nN] = AxisHelper::isAxisShown( nN, true, xDiagram );
779 for(nN=3;nN<6;nN++)
780 rExistenceList[nN] = AxisHelper::isAxisShown( nN%3, false, xDiagram );
782 else
784 sal_Int32 nN;
786 for(nN=0;nN<3;nN++)
787 rExistenceList[nN] = AxisHelper::isGridShown( nN, 0, true, xDiagram );
788 for(nN=3;nN<6;nN++)
789 rExistenceList[nN] = AxisHelper::isGridShown( nN%3, 0, false, xDiagram );
793 //static
794 bool AxisHelper::changeVisibilityOfAxes( const Reference< XDiagram >& xDiagram
795 , const Sequence< sal_Bool >& rOldExistenceList
796 , const Sequence< sal_Bool >& rNewExistenceList
797 , const Reference< uno::XComponentContext >& xContext
798 , ReferenceSizeProvider * pRefSizeProvider )
800 bool bChanged = false;
801 for(sal_Int32 nN=0;nN<6;nN++)
803 if(rOldExistenceList[nN]!=rNewExistenceList[nN])
805 bChanged = true;
806 if(rNewExistenceList[nN])
808 AxisHelper::showAxis( nN%3, nN<3, xDiagram, xContext, pRefSizeProvider );
810 else
811 AxisHelper::hideAxis( nN%3, nN<3, xDiagram );
814 return bChanged;
817 //static
818 bool AxisHelper::changeVisibilityOfGrids( const Reference< XDiagram >& xDiagram
819 , const Sequence< sal_Bool >& rOldExistenceList
820 , const Sequence< sal_Bool >& rNewExistenceList
821 , const Reference< uno::XComponentContext >& xContext )
823 bool bChanged = false;
824 for(sal_Int32 nN=0;nN<6;nN++)
826 if(rOldExistenceList[nN]!=rNewExistenceList[nN])
828 bChanged = true;
829 if(rNewExistenceList[nN])
830 AxisHelper::showGrid( nN%3, 0, nN<3, xDiagram, xContext );
831 else
832 AxisHelper::hideGrid( nN%3, 0, nN<3, xDiagram );
835 return bChanged;
838 //static
839 Reference< XCoordinateSystem > AxisHelper::getCoordinateSystemOfAxis(
840 const Reference< XAxis >& xAxis
841 , const Reference< XDiagram >& xDiagram )
843 Reference< XCoordinateSystem > xRet;
845 Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
846 if( xCooSysContainer.is() )
848 Reference< XCoordinateSystem > xCooSys;
849 Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
850 for( sal_Int32 nCooSysIndex = 0; nCooSysIndex < aCooSysList.getLength(); ++nCooSysIndex )
852 xCooSys = aCooSysList[nCooSysIndex];
853 std::vector< Reference< XAxis > > aAllAxis( AxisHelper::getAllAxesOfCoordinateSystem( xCooSys ) );
855 ::std::vector< Reference< XAxis > >::iterator aFound =
856 ::std::find( aAllAxis.begin(), aAllAxis.end(), xAxis );
857 if( aFound != aAllAxis.end())
859 xRet.set( xCooSys );
860 break;
864 return xRet;
867 Reference< XChartType > AxisHelper::getChartTypeByIndex( const Reference< XCoordinateSystem >& xCooSys, sal_Int32 nIndex )
869 Reference< XChartType > xChartType;
871 Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
872 if( xChartTypeContainer.is() )
874 Sequence< Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
875 if( nIndex >= 0 && nIndex < aChartTypeList.getLength() )
876 xChartType.set( aChartTypeList[nIndex] );
879 return xChartType;
882 void AxisHelper::setRTLAxisLayout( const Reference< XCoordinateSystem >& xCooSys )
884 if( xCooSys.is() )
886 bool bCartesian = xCooSys->getViewServiceName().equals( CHART2_COOSYSTEM_CARTESIAN_VIEW_SERVICE_NAME );
887 if( bCartesian )
889 bool bVertical = false;
890 Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY );
891 if( xCooSysProp.is() )
892 xCooSysProp->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bVertical;
894 sal_Int32 nHorizontalAxisDimension = bVertical ? 1 : 0;
895 sal_Int32 nVerticalAxisDimension = bVertical ? 0 : 1;
899 //reverse direction for horizontal main axis
900 Reference< chart2::XAxis > xHorizontalMainAxis( AxisHelper::getAxis( nHorizontalAxisDimension, MAIN_AXIS_INDEX, xCooSys ) );
901 if( xHorizontalMainAxis.is() )
903 chart2::ScaleData aScale = xHorizontalMainAxis->getScaleData();
904 aScale.Orientation = chart2::AxisOrientation_REVERSE;
905 xHorizontalMainAxis->setScaleData(aScale);
908 //mathematical direction for vertical main axis
909 Reference< chart2::XAxis > xVerticalMainAxis( AxisHelper::getAxis( nVerticalAxisDimension, MAIN_AXIS_INDEX, xCooSys ) );
910 if( xVerticalMainAxis.is() )
912 chart2::ScaleData aScale = xVerticalMainAxis->getScaleData();
913 aScale.Orientation = chart2::AxisOrientation_MATHEMATICAL;
914 xVerticalMainAxis->setScaleData(aScale);
917 catch( uno::Exception & ex )
919 ASSERT_EXCEPTION( ex );
924 //reverse direction for horizontal secondary axis
925 Reference< chart2::XAxis > xHorizontalSecondaryAxis( AxisHelper::getAxis( nHorizontalAxisDimension, SECONDARY_AXIS_INDEX, xCooSys ) );
926 if( xHorizontalSecondaryAxis.is() )
928 chart2::ScaleData aScale = xHorizontalSecondaryAxis->getScaleData();
929 aScale.Orientation = chart2::AxisOrientation_REVERSE;
930 xHorizontalSecondaryAxis->setScaleData(aScale);
933 //mathematical direction for vertical secondary axis
934 Reference< chart2::XAxis > xVerticalSecondaryAxis( AxisHelper::getAxis( nVerticalAxisDimension, SECONDARY_AXIS_INDEX, xCooSys ) );
935 if( xVerticalSecondaryAxis.is() )
937 chart2::ScaleData aScale = xVerticalSecondaryAxis->getScaleData();
938 aScale.Orientation = chart2::AxisOrientation_MATHEMATICAL;
939 xVerticalSecondaryAxis->setScaleData(aScale);
942 catch( uno::Exception & ex )
944 ASSERT_EXCEPTION( ex );
950 Reference< XChartType > AxisHelper::getFirstChartTypeWithSeriesAttachedToAxisIndex( const Reference< chart2::XDiagram >& xDiagram, const sal_Int32 nAttachedAxisIndex )
952 Reference< XChartType > xChartType;
953 ::std::vector< Reference< XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
954 ::std::vector< Reference< XDataSeries > >::const_iterator aIter = aSeriesVector.begin();
955 for( ; aIter != aSeriesVector.end(); aIter++ )
957 sal_Int32 nCurrentIndex = DataSeriesHelper::getAttachedAxisIndex( *aIter );
958 if( nAttachedAxisIndex == nCurrentIndex )
960 xChartType = DiagramHelper::getChartTypeOfSeries( xDiagram, *aIter );
961 if(xChartType.is())
962 break;
965 return xChartType;
968 bool AxisHelper::isAxisPositioningEnabled()
970 const SvtSaveOptions::ODFDefaultVersion nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() );
971 return nCurrentVersion >= SvtSaveOptions::ODFVER_012;
974 //.............................................................................
975 } //namespace chart
976 //.............................................................................