1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
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>
61 //.............................................................................
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
;
71 Reference
< chart2::XScaling
> AxisHelper::createLinearScaling()
73 return new LinearScaling( 1.0, 0.0 );
77 Reference
< chart2::XScaling
> AxisHelper::createLogarithmicScaling( double fBase
)
79 return new LogarithmicScaling( fBase
);
83 ScaleData
AxisHelper::createDefaultScale()
86 aScaleData
.AxisType
= chart2::AxisType::REALNUMBER
;
87 Sequence
< SubIncrement
> aSubIncrements(1);
88 aSubIncrements
[0] = SubIncrement();
89 aScaleData
.IncrementData
.SubIncrements
= aSubIncrements
;
94 void AxisHelper::removeExplicitScaling( ScaleData
& rScaleData
)
97 rScaleData
.Minimum
= rScaleData
.Maximum
= rScaleData
.Origin
= aEmpty
;
98 rScaleData
.Scaling
= 0;
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" )));
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() )
121 if( nDimensionIndex
>= xCooSys
->getDimension() )
124 Reference
< XAxis
> xAxis( xContext
->getServiceManager()->createInstanceWithContext(
125 C2U( "com.sun.star.chart2.Axis" ), xContext
), uno::UNO_QUERY
);
127 OSL_ASSERT( 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 ) );
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
);
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
);
161 xProp
->setPropertyValue(C2U( "CrossoverPosition" ), uno::makeAny(eNewAxisPos
) );
164 Reference
< beans::XPropertySet
> xProp( xAxis
, uno::UNO_QUERY
);
167 // set correct initial AutoScale
168 if( pRefSizeProvider
)
169 pRefSizeProvider
->setValuesAtPropertySet( xProp
);
171 catch( uno::Exception
& e
)
173 ASSERT_EXCEPTION( e
);
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" );
189 sal_Int32 nAxisIndex
= bMainAxis
? MAIN_AXIS_INDEX
: SECONDARY_AXIS_INDEX
;
190 sal_Int32 nCooSysIndex
= 0;
191 Reference
< XCoordinateSystem
> xCooSys
= AxisHelper::getCoordinateSystemByIndex( xDiagram
, nCooSysIndex
);
194 return AxisHelper::createAxis(
195 nDimensionIndex
, nAxisIndex
, xCooSys
, xContext
, pRefSizeProvider
);
199 void AxisHelper::showAxis( sal_Int32 nDimensionIndex
, bool bMainAxis
200 , const Reference
< chart2::XDiagram
>& xDiagram
201 , const Reference
< uno::XComponentContext
>& xContext
202 , ReferenceSizeProvider
* pRefSizeProvider
)
207 bool bNewAxisCreated
= false;
208 Reference
< XAxis
> xAxis( AxisHelper::getAxis( nDimensionIndex
, bMainAxis
, xDiagram
) );
209 if( !xAxis
.is() && xContext
.is() )
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
);
222 void AxisHelper::showGrid( sal_Int32 nDimensionIndex
, sal_Int32 nCooSysIndex
, bool bMainGrid
223 , const Reference
< XDiagram
>& xDiagram
224 , const Reference
< uno::XComponentContext
>& /*xContext*/ )
229 Reference
< XCoordinateSystem
> xCooSys
= AxisHelper::getCoordinateSystemByIndex( xDiagram
, nCooSysIndex
);
233 Reference
< XAxis
> xAxis( AxisHelper::getAxis( nDimensionIndex
, MAIN_AXIS_INDEX
, xCooSys
) );
236 //hhhh todo create axis without axis visibility
242 AxisHelper::makeGridVisible( xAxis
->getGridProperties() );
245 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
246 for( sal_Int32 nN
=0; nN
<aSubGrids
.getLength(); nN
++)
247 AxisHelper::makeGridVisible( aSubGrids
[nN
] );
252 void AxisHelper::makeAxisVisible( const Reference
< XAxis
>& xAxis
)
254 Reference
< beans::XPropertySet
> xProps( xAxis
, uno::UNO_QUERY
);
257 xProps
->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_True
) );
258 LineProperties::SetLineVisible( xProps
);
259 xProps
->setPropertyValue( C2U( "DisplayLabels" ), uno::makeAny( sal_True
) );
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
);
274 void AxisHelper::hideAxis( sal_Int32 nDimensionIndex
, bool bMainAxis
275 , const Reference
< XDiagram
>& xDiagram
)
277 AxisHelper::makeAxisInvisible( AxisHelper::getAxis( nDimensionIndex
, bMainAxis
, xDiagram
) );
281 void AxisHelper::makeAxisInvisible( const Reference
< XAxis
>& xAxis
)
283 Reference
< beans::XPropertySet
> xProps( xAxis
, uno::UNO_QUERY
);
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
)
296 Reference
< XCoordinateSystem
> xCooSys
= AxisHelper::getCoordinateSystemByIndex( xDiagram
, nCooSysIndex
);
300 Reference
< XAxis
> xAxis( AxisHelper::getAxis( nDimensionIndex
, MAIN_AXIS_INDEX
, xCooSys
) );
305 AxisHelper::makeGridInvisible( xAxis
->getGridProperties() );
308 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
309 for( sal_Int32 nN
=0; nN
<aSubGrids
.getLength(); nN
++)
310 AxisHelper::makeGridInvisible( aSubGrids
[nN
] );
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
);
332 Reference
< XAxis
> xAxis( AxisHelper::getAxis( nDimensionIndex
, MAIN_AXIS_INDEX
, xCooSys
) );
337 bRet
= AxisHelper::isGridVisible( xAxis
->getGridProperties() );
340 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
341 if( aSubGrids
.getLength() )
342 bRet
= AxisHelper::isGridVisible( aSubGrids
[0] );
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())
355 Sequence
< Reference
< XCoordinateSystem
> > aCooSysList
= xCooSysContainer
->getCoordinateSystems();
356 if(0<=nIndex
&& nIndex
<aCooSysList
.getLength())
357 return aCooSysList
[nIndex
];
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
& )
378 Reference
< XAxis
> AxisHelper::getAxis( sal_Int32 nDimensionIndex
, sal_Int32 nAxisIndex
379 , const Reference
< XCoordinateSystem
>& xCooSys
)
381 Reference
< XAxis
> xRet
;
385 xRet
.set( xCooSys
->getAxisByDimension( nDimensionIndex
, nAxisIndex
) );
387 catch( const uno::Exception
& )
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
)
403 bool bSwapXY
= false;
404 Reference
< beans::XPropertySet
> xCooSysProp( xCooSys
, uno::UNO_QUERY
);
405 if( xCooSysProp
.is() && (xCooSysProp
->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bSwapXY
) && bSwapXY
)
408 else if( 1==nDimensionIndex
)
412 return AxisHelper::getAxis( nDimensionIndex
, 0, xCooSys
);
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
& )
436 sal_Bool
AxisHelper::isAxisShown( sal_Int32 nDimensionIndex
, bool bMainAxis
437 , const Reference
< XDiagram
>& xDiagram
)
439 return AxisHelper::isAxisVisible( AxisHelper::getAxis( nDimensionIndex
, bMainAxis
, xDiagram
) );
443 sal_Bool
AxisHelper::isAxisVisible( const Reference
< XAxis
>& xAxis
)
445 sal_Bool bRet
= false;
447 Reference
< beans::XPropertySet
> xProps( xAxis
, uno::UNO_QUERY
);
450 xProps
->getPropertyValue( C2U( "Show" ) ) >>= bRet
;
451 bRet
= bRet
&& ( LineProperties::IsLineVisible( xProps
)
452 || areAxisLabelsVisible( xProps
) );
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
;
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
);
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
) );
492 if( nSubGridIndex
<0 )
493 xRet
.set( xAxis
->getGridProperties() );
496 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
497 if( nSubGridIndex
>= 0 && nSubGridIndex
< aSubGrids
.getLength() )
498 xRet
.set( aSubGrids
[nSubGridIndex
] );
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
;
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;
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
;
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;
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
;
578 std::vector
< Reference
< XAxis
> > AxisHelper::getAllAxesOfCoordinateSystem(
579 const Reference
< XCoordinateSystem
>& xCooSys
580 , bool bOnlyVisible
/* = false */ )
582 std::vector
< Reference
< XAxis
> > aAxisVector
;
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;
603 Reference
< beans::XPropertySet
> xAxisProp( xAxis
, uno::UNO_QUERY
);
604 if( !xAxisProp
.is() ||
605 !(xAxisProp
->getPropertyValue( C2U("Show")) >>= bAddAxis
) )
609 aAxisVector
.push_back( xAxis
);
612 catch( const uno::Exception
& ex
)
614 ASSERT_EXCEPTION( ex
);
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();
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
);
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
;
653 for( nA
=0; nA
<aAllAxes
.getLength(); ++nA
)
655 Reference
< XAxis
> xAxis( aAllAxes
[nA
] );
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
] );
668 aGridVector
.push_back( xSubGrid
);
672 return ContainerHelper::ContainerToSequence( aGridVector
);
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
);
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
++)
690 rPossibilityList
[nIndex
]=ChartTypeHelper::isSupportingSecondaryAxis(xChartType
,nDimensionCount
,nIndex
-3);
692 rPossibilityList
[nIndex
] = rPossibilityList
[nIndex
-3];
696 bool AxisHelper::isSecondaryYAxisNeeded( const Reference
< XCoordinateSystem
>& xCooSys
)
698 Reference
< chart2::XChartTypeContainer
> xCTCnt( xCooSys
, uno::UNO_QUERY
);
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() )
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
);
714 sal_Int32 nAttachedAxisIndex
= 0;
715 if( ( xProp
->getPropertyValue( C2U( "AttachedAxisIndex" ) ) >>= nAttachedAxisIndex
) && nAttachedAxisIndex
>0 )
725 bool AxisHelper::shouldAxisBeDisplayed( const Reference
< XAxis
>& xAxis
726 , const Reference
< XCoordinateSystem
>& xCooSys
)
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
);
741 bRet
= ChartTypeHelper::isSupportingMainAxis(xChartType
,nDimensionCount
,nDimensionIndex
);
743 bRet
= ChartTypeHelper::isSupportingSecondaryAxis(xChartType
,nDimensionCount
,nDimensionIndex
);
751 void AxisHelper::getAxisOrGridExcistence( Sequence
< sal_Bool
>& rExistenceList
752 , const Reference
< XDiagram
>& xDiagram
, sal_Bool bAxis
)
754 rExistenceList
.realloc(6);
759 Reference
< XAxis
> xAxis
;
761 rExistenceList
[nN
] = AxisHelper::isAxisShown( nN
, true, xDiagram
);
763 rExistenceList
[nN
] = AxisHelper::isAxisShown( nN
%3, false, xDiagram
);
770 rExistenceList
[nN
] = AxisHelper::isGridShown( nN
, 0, true, xDiagram
);
772 rExistenceList
[nN
] = AxisHelper::isGridShown( nN
%3, 0, false, xDiagram
);
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
])
789 if(rNewExistenceList
[nN
])
791 AxisHelper::showAxis( nN
%3, nN
<3, xDiagram
, xContext
, pRefSizeProvider
);
794 AxisHelper::hideAxis( nN
%3, nN
<3, xDiagram
);
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
])
812 if(rNewExistenceList
[nN
])
813 AxisHelper::showGrid( nN
%3, 0, nN
<3, xDiagram
, xContext
);
815 AxisHelper::hideGrid( nN
%3, 0, nN
<3, xDiagram
);
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())
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
] );
865 void AxisHelper::setRTLAxisLayout( const Reference
< XCoordinateSystem
>& xCooSys
)
869 bool bCartesian
= xCooSys
->getViewServiceName().equals( CHART2_COOSYSTEM_CARTESIAN_VIEW_SERVICE_NAME
);
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
);
951 bool AxisHelper::isAxisPositioningEnabled()
953 const SvtSaveOptions::ODFDefaultVersion
nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() );
954 return nCurrentVersion
>= SvtSaveOptions::ODFVER_012
;
957 //.............................................................................
959 //.............................................................................