1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "VPolarCoordinateSystem.hxx"
27 #include "VPolarGrid.hxx"
28 #include "VPolarAxis.hxx"
29 #include "AxisIndexDefines.hxx"
30 #include "AxisHelper.hxx"
31 
32 //.............................................................................
33 namespace chart
34 {
35 //.............................................................................
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::chart2;
38 using ::com::sun::star::uno::Reference;
39 
VPolarCoordinateSystem(const Reference<XCoordinateSystem> & xCooSys)40 VPolarCoordinateSystem::VPolarCoordinateSystem( const Reference< XCoordinateSystem >& xCooSys )
41     : VCoordinateSystem(xCooSys)
42 {
43 }
44 
~VPolarCoordinateSystem()45 VPolarCoordinateSystem::~VPolarCoordinateSystem()
46 {
47 }
48 
49 //better performance for big data
getCoordinateSystemResolution(const awt::Size & rPageSize,const awt::Size & rPageResolution)50 uno::Sequence< sal_Int32 > VPolarCoordinateSystem::getCoordinateSystemResolution(
51             const awt::Size& rPageSize, const awt::Size& rPageResolution )
52 {
53     uno::Sequence< sal_Int32 > aResolution( VCoordinateSystem::getCoordinateSystemResolution( rPageSize, rPageResolution) );
54 
55     if( aResolution.getLength() >= 2 )
56     {
57         if( this->getPropertySwapXAndYAxis() )
58         {
59             aResolution[0]/=2;//radius
60             aResolution[1]*=4;//outer circle resolution
61         }
62         else
63         {
64             aResolution[0]*=4;//outer circle resolution
65             aResolution[1]/=2;//radius
66         }
67     }
68 
69     return aResolution;
70 }
71 
createVAxisList(const uno::Reference<util::XNumberFormatsSupplier> & xNumberFormatsSupplier,const awt::Size & rFontReferenceSize,const awt::Rectangle & rMaximumSpaceForLabels)72 void VPolarCoordinateSystem::createVAxisList(
73               const uno::Reference< util::XNumberFormatsSupplier > & xNumberFormatsSupplier
74             , const awt::Size& rFontReferenceSize
75             , const awt::Rectangle& rMaximumSpaceForLabels
76             )
77 {
78     m_aAxisMap.clear();
79 
80     //if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
81     //    return;
82 
83     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
84 //     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
85 
86     sal_Int32 nDimensionIndex = 0;
87 
88     //create angle axis (dimension index 0)
89     for( nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
90     {
91         sal_Int32 nMaxAxisIndex = m_xCooSysModel->getMaximumAxisIndexByDimension(nDimensionIndex);
92         for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
93         {
94             Reference< XAxis > xAxis( this->getAxisByDimension(nDimensionIndex,nAxisIndex) );
95             if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
96                 continue;
97             AxisProperties aAxisProperties(xAxis,this->getExplicitCategoriesProvider());
98             aAxisProperties.init();
99             if(aAxisProperties.m_bDisplayLabels)
100                 aAxisProperties.m_nNumberFormatKey = this->getNumberFormatKeyForAxis( xAxis, xNumberFormatsSupplier );
101             //-------------------
102             ::boost::shared_ptr< VAxisBase > apVAxis( VPolarAxis::createAxis( aAxisProperties,xNumberFormatsSupplier,nDimensionIndex,nDimensionCount) );
103             tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex );
104             m_aAxisMap[aFullAxisIndex] = apVAxis;
105 
106             apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels);
107         }
108     }
109 }
110 
initVAxisInList()111 void VPolarCoordinateSystem::initVAxisInList()
112 {
113     if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
114         return;
115 
116     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
117     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
118 
119     tVAxisMap::iterator aIt( m_aAxisMap.begin() );
120     tVAxisMap::const_iterator aEnd( m_aAxisMap.end() );
121     for( ; aIt != aEnd; ++aIt )
122     {
123         VAxisBase* pVAxis = aIt->second.get();
124         if( pVAxis )
125         {
126             sal_Int32 nDimensionIndex = aIt->first.first;
127             sal_Int32 nAxisIndex = aIt->first.second;
128             pVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement(nDimensionIndex, nAxisIndex) );
129             pVAxis->initPlotter(m_xLogicTargetForAxes,m_xFinalTarget,m_xShapeFactory
130                 , this->createCIDForAxis( getAxisByDimension( nDimensionIndex, nAxisIndex ), nDimensionIndex, nAxisIndex ) );
131             VPolarAxis* pVPolarAxis = dynamic_cast< VPolarAxis* >( pVAxis );
132             if( pVPolarAxis )
133                 pVPolarAxis->setIncrements( this->getExplicitIncrements( nDimensionIndex, nAxisIndex ) );
134             if(2==nDimensionCount)
135                 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
136             pVAxis->setScales( this->getExplicitScales( nDimensionIndex, nAxisIndex ), bSwapXAndY );
137         }
138     }
139 }
140 
updateScalesAndIncrementsOnAxes()141 void VPolarCoordinateSystem::updateScalesAndIncrementsOnAxes()
142 {
143     if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
144         return;
145 
146     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
147     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
148 
149     tVAxisMap::iterator aIt( m_aAxisMap.begin() );
150     tVAxisMap::const_iterator aEnd( m_aAxisMap.end() );
151     for( ; aIt != aEnd; ++aIt )
152     {
153         VAxisBase* pVAxis = aIt->second.get();
154         if( pVAxis )
155         {
156             sal_Int32 nDimensionIndex = aIt->first.first;
157             sal_Int32 nAxisIndex = aIt->first.second;
158             pVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement(nDimensionIndex, nAxisIndex) );
159             VPolarAxis* pVPolarAxis = dynamic_cast< VPolarAxis* >( pVAxis );
160             if( pVPolarAxis )
161                 pVPolarAxis->setIncrements( this->getExplicitIncrements( nDimensionIndex, nAxisIndex ) );
162             if(2==nDimensionCount)
163                 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
164             pVAxis->setScales( this->getExplicitScales( nDimensionIndex, nAxisIndex ), bSwapXAndY );
165         }
166     }
167 }
168 
createGridShapes()169 void VPolarCoordinateSystem::createGridShapes()
170 {
171     if(!m_xLogicTargetForGrids.is() || !m_xFinalTarget.is() )
172         return;
173 
174     sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
175     bool bSwapXAndY = this->getPropertySwapXAndYAxis();
176 
177     for( sal_Int32 nDimensionIndex=0; nDimensionIndex<3; nDimensionIndex++)
178     {
179         sal_Int32 nAxisIndex = MAIN_AXIS_INDEX;
180 
181         Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, nAxisIndex, m_xCooSysModel ) );
182         if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
183             continue;
184 
185         VPolarGrid aGrid(nDimensionIndex,nDimensionCount,this->getGridListFromAxis( xAxis ));
186         aGrid.setIncrements( this->getExplicitIncrements( nDimensionIndex, nAxisIndex ) );
187         aGrid.initPlotter(m_xLogicTargetForGrids,m_xFinalTarget,m_xShapeFactory
188             , this->createCIDForGrid( xAxis, nDimensionIndex, nAxisIndex ) );
189         if(2==nDimensionCount)
190             aGrid.setTransformationSceneToScreen( m_aMatrixSceneToScreen );
191         aGrid.setScales( this->getExplicitScales( nDimensionIndex, nAxisIndex), bSwapXAndY );
192         aGrid.createShapes();
193     }
194 }
195 
196 //.............................................................................
197 } //namespace chart
198 //.............................................................................
199