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"
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>
58 //.............................................................................
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
;
68 Reference
< chart2::XScaling
> AxisHelper::createLinearScaling()
70 return new LinearScaling( 1.0, 0.0 );
74 Reference
< chart2::XScaling
> AxisHelper::createLogarithmicScaling( double fBase
)
76 return new LogarithmicScaling( fBase
);
80 ScaleData
AxisHelper::createDefaultScale()
83 aScaleData
.AxisType
= chart2::AxisType::REALNUMBER
;
84 Sequence
< SubIncrement
> aSubIncrements(1);
85 aSubIncrements
[0] = SubIncrement();
86 aScaleData
.IncrementData
.SubIncrements
= aSubIncrements
;
91 void AxisHelper::removeExplicitScaling( ScaleData
& rScaleData
)
94 rScaleData
.Minimum
= rScaleData
.Maximum
= rScaleData
.Origin
= aEmpty
;
95 rScaleData
.Scaling
= 0;
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" )));
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() )
118 if( nDimensionIndex
>= xCooSys
->getDimension() )
121 Reference
< XAxis
> xAxis( xContext
->getServiceManager()->createInstanceWithContext(
122 C2U( "com.sun.star.chart2.Axis" ), xContext
), uno::UNO_QUERY
);
124 OSL_ASSERT( 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 ) );
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
);
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
);
158 xProp
->setPropertyValue(C2U( "CrossoverPosition" ), uno::makeAny(eNewAxisPos
) );
161 Reference
< beans::XPropertySet
> xProp( xAxis
, uno::UNO_QUERY
);
164 // set correct initial AutoScale
165 if( pRefSizeProvider
)
166 pRefSizeProvider
->setValuesAtPropertySet( xProp
);
168 catch( uno::Exception
& e
)
170 ASSERT_EXCEPTION( e
);
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" );
186 sal_Int32 nAxisIndex
= bMainAxis
? MAIN_AXIS_INDEX
: SECONDARY_AXIS_INDEX
;
187 sal_Int32 nCooSysIndex
= 0;
188 Reference
< XCoordinateSystem
> xCooSys
= AxisHelper::getCoordinateSystemByIndex( xDiagram
, nCooSysIndex
);
191 return AxisHelper::createAxis(
192 nDimensionIndex
, nAxisIndex
, xCooSys
, xContext
, pRefSizeProvider
);
196 void AxisHelper::showAxis( sal_Int32 nDimensionIndex
, bool bMainAxis
197 , const Reference
< chart2::XDiagram
>& xDiagram
198 , const Reference
< uno::XComponentContext
>& xContext
199 , ReferenceSizeProvider
* pRefSizeProvider
)
204 bool bNewAxisCreated
= false;
205 Reference
< XAxis
> xAxis( AxisHelper::getAxis( nDimensionIndex
, bMainAxis
, xDiagram
) );
206 if( !xAxis
.is() && xContext
.is() )
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
);
219 void AxisHelper::showGrid( sal_Int32 nDimensionIndex
, sal_Int32 nCooSysIndex
, bool bMainGrid
220 , const Reference
< XDiagram
>& xDiagram
221 , const Reference
< uno::XComponentContext
>& /*xContext*/ )
226 Reference
< XCoordinateSystem
> xCooSys
= AxisHelper::getCoordinateSystemByIndex( xDiagram
, nCooSysIndex
);
230 Reference
< XAxis
> xAxis( AxisHelper::getAxis( nDimensionIndex
, MAIN_AXIS_INDEX
, xCooSys
) );
233 //hhhh todo create axis without axis visibility
239 AxisHelper::makeGridVisible( xAxis
->getGridProperties() );
242 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
243 for( sal_Int32 nN
=0; nN
<aSubGrids
.getLength(); nN
++)
244 AxisHelper::makeGridVisible( aSubGrids
[nN
] );
249 void AxisHelper::makeAxisVisible( const Reference
< XAxis
>& xAxis
)
251 Reference
< beans::XPropertySet
> xProps( xAxis
, uno::UNO_QUERY
);
254 xProps
->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_True
) );
255 LineProperties::SetLineVisible( xProps
);
256 xProps
->setPropertyValue( C2U( "DisplayLabels" ), uno::makeAny( sal_True
) );
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
);
271 void AxisHelper::hideAxis( sal_Int32 nDimensionIndex
, bool bMainAxis
272 , const Reference
< XDiagram
>& xDiagram
)
274 AxisHelper::makeAxisInvisible( AxisHelper::getAxis( nDimensionIndex
, bMainAxis
, xDiagram
) );
278 void AxisHelper::makeAxisInvisible( const Reference
< XAxis
>& xAxis
)
280 Reference
< beans::XPropertySet
> xProps( xAxis
, uno::UNO_QUERY
);
283 xProps
->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False
) );
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;
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
)
313 Reference
< XCoordinateSystem
> xCooSys
= AxisHelper::getCoordinateSystemByIndex( xDiagram
, nCooSysIndex
);
317 Reference
< XAxis
> xAxis( AxisHelper::getAxis( nDimensionIndex
, MAIN_AXIS_INDEX
, xCooSys
) );
322 AxisHelper::makeGridInvisible( xAxis
->getGridProperties() );
325 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
326 for( sal_Int32 nN
=0; nN
<aSubGrids
.getLength(); nN
++)
327 AxisHelper::makeGridInvisible( aSubGrids
[nN
] );
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
);
349 Reference
< XAxis
> xAxis( AxisHelper::getAxis( nDimensionIndex
, MAIN_AXIS_INDEX
, xCooSys
) );
354 bRet
= AxisHelper::isGridVisible( xAxis
->getGridProperties() );
357 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
358 if( aSubGrids
.getLength() )
359 bRet
= AxisHelper::isGridVisible( aSubGrids
[0] );
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())
372 Sequence
< Reference
< XCoordinateSystem
> > aCooSysList
= xCooSysContainer
->getCoordinateSystems();
373 if(0<=nIndex
&& nIndex
<aCooSysList
.getLength())
374 return aCooSysList
[nIndex
];
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
& )
395 Reference
< XAxis
> AxisHelper::getAxis( sal_Int32 nDimensionIndex
, sal_Int32 nAxisIndex
396 , const Reference
< XCoordinateSystem
>& xCooSys
)
398 Reference
< XAxis
> xRet
;
402 xRet
.set( xCooSys
->getAxisByDimension( nDimensionIndex
, nAxisIndex
) );
404 catch( const uno::Exception
& )
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
)
420 bool bSwapXY
= false;
421 Reference
< beans::XPropertySet
> xCooSysProp( xCooSys
, uno::UNO_QUERY
);
422 if( xCooSysProp
.is() && (xCooSysProp
->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bSwapXY
) && bSwapXY
)
425 else if( 1==nDimensionIndex
)
429 return AxisHelper::getAxis( nDimensionIndex
, 0, xCooSys
);
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
& )
453 sal_Bool
AxisHelper::isAxisShown( sal_Int32 nDimensionIndex
, bool bMainAxis
454 , const Reference
< XDiagram
>& xDiagram
)
456 return AxisHelper::isAxisVisible( AxisHelper::getAxis( nDimensionIndex
, bMainAxis
, xDiagram
) );
460 sal_Bool
AxisHelper::isAxisVisible( const Reference
< XAxis
>& xAxis
)
462 sal_Bool bRet
= false;
464 Reference
< beans::XPropertySet
> xProps( xAxis
, uno::UNO_QUERY
);
467 xProps
->getPropertyValue( C2U( "Show" ) ) >>= bRet
;
468 bRet
= bRet
&& ( LineProperties::IsLineVisible( xProps
)
469 || areAxisLabelsVisible( xProps
) );
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
;
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
);
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
) );
509 if( nSubGridIndex
<0 )
510 xRet
.set( xAxis
->getGridProperties() );
513 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
514 if( nSubGridIndex
>= 0 && nSubGridIndex
< aSubGrids
.getLength() )
515 xRet
.set( aSubGrids
[nSubGridIndex
] );
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
;
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;
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
;
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;
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
;
595 std::vector
< Reference
< XAxis
> > AxisHelper::getAllAxesOfCoordinateSystem(
596 const Reference
< XCoordinateSystem
>& xCooSys
597 , bool bOnlyVisible
/* = false */ )
599 std::vector
< Reference
< XAxis
> > aAxisVector
;
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;
620 Reference
< beans::XPropertySet
> xAxisProp( xAxis
, uno::UNO_QUERY
);
621 if( !xAxisProp
.is() ||
622 !(xAxisProp
->getPropertyValue( C2U("Show")) >>= bAddAxis
) )
626 aAxisVector
.push_back( xAxis
);
629 catch( const uno::Exception
& ex
)
631 ASSERT_EXCEPTION( ex
);
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();
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
);
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
;
670 for( nA
=0; nA
<aAllAxes
.getLength(); ++nA
)
672 Reference
< XAxis
> xAxis( aAllAxes
[nA
] );
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
] );
685 aGridVector
.push_back( xSubGrid
);
689 return ContainerHelper::ContainerToSequence( aGridVector
);
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
);
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
++)
707 rPossibilityList
[nIndex
]=ChartTypeHelper::isSupportingSecondaryAxis(xChartType
,nDimensionCount
,nIndex
-3);
709 rPossibilityList
[nIndex
] = rPossibilityList
[nIndex
-3];
713 bool AxisHelper::isSecondaryYAxisNeeded( const Reference
< XCoordinateSystem
>& xCooSys
)
715 Reference
< chart2::XChartTypeContainer
> xCTCnt( xCooSys
, uno::UNO_QUERY
);
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() )
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
);
731 sal_Int32 nAttachedAxisIndex
= 0;
732 if( ( xProp
->getPropertyValue( C2U( "AttachedAxisIndex" ) ) >>= nAttachedAxisIndex
) && nAttachedAxisIndex
>0 )
742 bool AxisHelper::shouldAxisBeDisplayed( const Reference
< XAxis
>& xAxis
743 , const Reference
< XCoordinateSystem
>& xCooSys
)
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
);
758 bRet
= ChartTypeHelper::isSupportingMainAxis(xChartType
,nDimensionCount
,nDimensionIndex
);
760 bRet
= ChartTypeHelper::isSupportingSecondaryAxis(xChartType
,nDimensionCount
,nDimensionIndex
);
768 void AxisHelper::getAxisOrGridExcistence( Sequence
< sal_Bool
>& rExistenceList
769 , const Reference
< XDiagram
>& xDiagram
, sal_Bool bAxis
)
771 rExistenceList
.realloc(6);
776 Reference
< XAxis
> xAxis
;
778 rExistenceList
[nN
] = AxisHelper::isAxisShown( nN
, true, xDiagram
);
780 rExistenceList
[nN
] = AxisHelper::isAxisShown( nN
%3, false, xDiagram
);
787 rExistenceList
[nN
] = AxisHelper::isGridShown( nN
, 0, true, xDiagram
);
789 rExistenceList
[nN
] = AxisHelper::isGridShown( nN
%3, 0, false, xDiagram
);
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
])
806 if(rNewExistenceList
[nN
])
808 AxisHelper::showAxis( nN
%3, nN
<3, xDiagram
, xContext
, pRefSizeProvider
);
811 AxisHelper::hideAxis( nN
%3, nN
<3, xDiagram
);
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
])
829 if(rNewExistenceList
[nN
])
830 AxisHelper::showGrid( nN
%3, 0, nN
<3, xDiagram
, xContext
);
832 AxisHelper::hideGrid( nN
%3, 0, nN
<3, xDiagram
);
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())
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
] );
882 void AxisHelper::setRTLAxisLayout( const Reference
< XCoordinateSystem
>& xCooSys
)
886 bool bCartesian
= xCooSys
->getViewServiceName().equals( CHART2_COOSYSTEM_CARTESIAN_VIEW_SERVICE_NAME
);
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
);
968 bool AxisHelper::isAxisPositioningEnabled()
970 const SvtSaveOptions::ODFDefaultVersion
nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() );
971 return nCurrentVersion
>= SvtSaveOptions::ODFVER_012
;
974 //.............................................................................
976 //.............................................................................