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: VCartesianCoordinateSystem.cxx,v $
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"
33 #include "VCartesianCoordinateSystem.hxx"
34 #include "VCartesianGrid.hxx"
35 #include "VCartesianAxis.hxx"
37 #include "AxisIndexDefines.hxx"
38 #include "AxisHelper.hxx"
39 #include "ChartTypeHelper.hxx"
44 //.............................................................................
47 //.............................................................................
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::chart2
;
50 using ::com::sun::star::uno::Reference
;
52 //.............................................................................
54 class TextualDataProvider
: public ::cppu::WeakImplHelper1
<
55 ::com::sun::star::chart2::data::XTextualDataSequence
59 TextualDataProvider( const uno::Sequence
< ::rtl::OUString
>& rTextSequence
)
60 : m_aTextSequence( rTextSequence
)
63 virtual ~TextualDataProvider()
67 //XTextualDataSequence
68 virtual uno::Sequence
< ::rtl::OUString
> SAL_CALL
getTextualData()
69 throw ( uno::RuntimeException
)
71 return m_aTextSequence
;
75 uno::Sequence
< ::rtl::OUString
> m_aTextSequence
;
78 //.............................................................................
80 VCartesianCoordinateSystem::VCartesianCoordinateSystem( const Reference
< XCoordinateSystem
>& xCooSys
)
81 : VCoordinateSystem(xCooSys
)
85 VCartesianCoordinateSystem::~VCartesianCoordinateSystem()
89 void VCartesianCoordinateSystem::createGridShapes()
91 if(!m_xLogicTargetForGrids
.is() || !m_xFinalTarget
.is() )
94 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
95 bool bSwapXAndY
= this->getPropertySwapXAndYAxis();
97 for( sal_Int32 nDimensionIndex
=0; nDimensionIndex
<3; nDimensionIndex
++)
99 sal_Int32 nAxisIndex
= MAIN_AXIS_INDEX
;
100 Reference
< XAxis
> xAxis( AxisHelper::getAxis( nDimensionIndex
, nAxisIndex
, m_xCooSysModel
) );
101 if(!xAxis
.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis
, m_xCooSysModel
))
104 VCartesianGrid
aGrid(nDimensionIndex
,nDimensionCount
,this->getGridListFromAxis( xAxis
));
105 aGrid
.setExplicitScaleAndIncrement( this->getExplicitScale(nDimensionIndex
,nAxisIndex
)
106 , this->getExplicitIncrement(nDimensionIndex
,nAxisIndex
) );
107 aGrid
.set3DWallPositions( m_eLeftWallPos
, m_eBackWallPos
, m_eBottomPos
);
109 aGrid
.initPlotter(m_xLogicTargetForGrids
,m_xFinalTarget
,m_xShapeFactory
110 , this->createCIDForGrid( xAxis
,nDimensionIndex
,nAxisIndex
) );
111 if(2==nDimensionCount
)
112 aGrid
.setTransformationSceneToScreen( m_aMatrixSceneToScreen
);
113 aGrid
.setScales( this->getExplicitScales(nDimensionIndex
,nAxisIndex
), bSwapXAndY
);
114 aGrid
.createShapes();
118 void VCartesianCoordinateSystem::createVAxisList(
119 const uno::Reference
< util::XNumberFormatsSupplier
> & xNumberFormatsSupplier
120 , const awt::Size
& rFontReferenceSize
121 , const awt::Rectangle
& rMaximumSpaceForLabels
126 //if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
129 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
130 bool bSwapXAndY
= this->getPropertySwapXAndYAxis();
132 if(nDimensionCount
<=0)
135 sal_Int32 nDimensionIndex
= 0;
137 for( nDimensionIndex
= 0; nDimensionIndex
< nDimensionCount
; nDimensionIndex
++ )
139 sal_Int32 nMaxAxisIndex
= m_xCooSysModel
->getMaximumAxisIndexByDimension(nDimensionIndex
);
140 for( sal_Int32 nAxisIndex
= 0; nAxisIndex
<= nMaxAxisIndex
; nAxisIndex
++ )
142 Reference
< XAxis
> xAxis
= this->getAxisByDimension(nDimensionIndex
,nAxisIndex
);
143 if(!xAxis
.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis
, m_xCooSysModel
))
146 AxisProperties
aAxisProperties(xAxis
,this->getExplicitCategoriesProvider());
147 aAxisProperties
.m_nDimensionIndex
= nDimensionIndex
;
148 aAxisProperties
.m_bSwapXAndY
= bSwapXAndY
;
149 aAxisProperties
.m_bIsMainAxis
= (nAxisIndex
==0);
150 Reference
< XAxis
> xCrossingMainAxis( AxisHelper::getCrossingMainAxis( xAxis
, m_xCooSysModel
) );
151 if( xCrossingMainAxis
.is() )
153 ScaleData
aCrossingScale( xCrossingMainAxis
->getScaleData() );
154 aAxisProperties
.m_bCrossingAxisHasReverseDirection
= (AxisOrientation_REVERSE
==aCrossingScale
.Orientation
);
156 if( aCrossingScale
.AxisType
== AxisType::CATEGORY
)
158 aAxisProperties
.m_bCrossingAxisIsCategoryAxes
= true;
159 aAxisProperties
.m_bAxisBetweenCategories
= ChartTypeHelper::shiftTicksAtXAxisPerDefault( AxisHelper::getChartTypeByIndex( m_xCooSysModel
, 0 ) );
163 if( nDimensionIndex
== 2 )
165 aAxisProperties
.m_xAxisTextProvider
= new TextualDataProvider( m_aSeriesNamesForZAxis
);
167 //for the z axis copy the positioning properties from the x axis (or from the y axis for swapped coordinate systems)
168 Reference
< XAxis
> xSisterAxis( AxisHelper::getCrossingMainAxis( xCrossingMainAxis
, m_xCooSysModel
) );
169 aAxisProperties
.initAxisPositioning( Reference
< beans::XPropertySet
>( xSisterAxis
, uno::UNO_QUERY
) );
171 aAxisProperties
.init(true);
172 if(aAxisProperties
.m_bDisplayLabels
)
173 aAxisProperties
.m_nNumberFormatKey
= this->getNumberFormatKeyForAxis( xAxis
, xNumberFormatsSupplier
);
174 //-------------------
175 ::boost::shared_ptr
< VAxisBase
> apVAxis( new VCartesianAxis(aAxisProperties
,xNumberFormatsSupplier
,nDimensionIndex
,nDimensionCount
) );
176 tFullAxisIndex
aFullAxisIndex( nDimensionIndex
, nAxisIndex
);
177 m_aAxisMap
[aFullAxisIndex
] = apVAxis
;
178 apVAxis
->set3DWallPositions( m_eLeftWallPos
, m_eBackWallPos
, m_eBottomPos
);
180 //apVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
181 //apVAxis->initPlotter(m_xLogicTargetForAxes,m_xFinalTarget,m_xShapeFactory
182 // , this->createCIDForAxis( xAxis, nDimensionIndex, nAxisIndex ) );
183 //if(2==nDimensionCount)
184 // apVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
185 //apVAxis->setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
186 apVAxis
->initAxisLabelProperties(rFontReferenceSize
,rMaximumSpaceForLabels
);
191 void VCartesianCoordinateSystem::initVAxisInList()
193 if(!m_xLogicTargetForAxes
.is() || !m_xFinalTarget
.is() || !m_xCooSysModel
.is() )
196 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
197 bool bSwapXAndY
= this->getPropertySwapXAndYAxis();
199 tVAxisMap::iterator
aIt( m_aAxisMap
.begin() );
200 tVAxisMap::const_iterator
aEnd( m_aAxisMap
.end() );
201 for( ; aIt
!= aEnd
; ++aIt
)
203 VAxisBase
* pVAxis
= aIt
->second
.get();
206 sal_Int32 nDimensionIndex
= aIt
->first
.first
;
207 sal_Int32 nAxisIndex
= aIt
->first
.second
;
208 pVAxis
->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex
, nAxisIndex
), this->getExplicitIncrement( nDimensionIndex
, nAxisIndex
) );
209 pVAxis
->initPlotter(m_xLogicTargetForAxes
,m_xFinalTarget
,m_xShapeFactory
210 , this->createCIDForAxis( getAxisByDimension( nDimensionIndex
, nAxisIndex
), nDimensionIndex
, nAxisIndex
) );
211 if(2==nDimensionCount
)
212 pVAxis
->setTransformationSceneToScreen( m_aMatrixSceneToScreen
);
213 pVAxis
->setScales( this->getExplicitScales(nDimensionIndex
,nAxisIndex
), bSwapXAndY
);
218 void VCartesianCoordinateSystem::updateScalesAndIncrementsOnAxes()
220 if(!m_xLogicTargetForAxes
.is() || !m_xFinalTarget
.is() || !m_xCooSysModel
.is() )
223 sal_Int32 nDimensionCount
= m_xCooSysModel
->getDimension();
224 bool bSwapXAndY
= this->getPropertySwapXAndYAxis();
226 tVAxisMap::iterator
aIt( m_aAxisMap
.begin() );
227 tVAxisMap::const_iterator
aEnd( m_aAxisMap
.end() );
228 for( ; aIt
!= aEnd
; ++aIt
)
230 VAxisBase
* pVAxis
= aIt
->second
.get();
233 sal_Int32 nDimensionIndex
= aIt
->first
.first
;
234 sal_Int32 nAxisIndex
= aIt
->first
.second
;
235 pVAxis
->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex
, nAxisIndex
), this->getExplicitIncrement( nDimensionIndex
, nAxisIndex
) );
236 if(2==nDimensionCount
)
237 pVAxis
->setTransformationSceneToScreen( m_aMatrixSceneToScreen
);
238 pVAxis
->setScales( this->getExplicitScales(nDimensionIndex
,nAxisIndex
), bSwapXAndY
);
243 //.............................................................................
245 //.............................................................................