Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "VCartesianCoordinateSystem.hxx"
21 : #include "VCartesianGrid.hxx"
22 : #include "VCartesianAxis.hxx"
23 : #include "macros.hxx"
24 : #include "AxisIndexDefines.hxx"
25 : #include "AxisHelper.hxx"
26 : #include "ChartTypeHelper.hxx"
27 :
28 : namespace chart
29 : {
30 : using namespace ::com::sun::star;
31 : using namespace ::com::sun::star::chart2;
32 : using ::com::sun::star::uno::Reference;
33 :
34 : class TextualDataProvider : public ::cppu::WeakImplHelper1<
35 : ::com::sun::star::chart2::data::XTextualDataSequence
36 : >
37 : {
38 : public:
39 49 : explicit TextualDataProvider( const uno::Sequence< OUString >& rTextSequence )
40 49 : : m_aTextSequence( rTextSequence )
41 : {
42 49 : }
43 98 : virtual ~TextualDataProvider()
44 49 : {
45 98 : }
46 :
47 : //XTextualDataSequence
48 49 : virtual uno::Sequence< OUString > SAL_CALL getTextualData()
49 : throw ( uno::RuntimeException, std::exception) SAL_OVERRIDE
50 : {
51 49 : return m_aTextSequence;
52 : }
53 :
54 : private: //member
55 : uno::Sequence< OUString > m_aTextSequence;
56 : };
57 :
58 1014 : VCartesianCoordinateSystem::VCartesianCoordinateSystem( const Reference< XCoordinateSystem >& xCooSys )
59 1014 : : VCoordinateSystem(xCooSys)
60 : {
61 1014 : }
62 :
63 2000 : VCartesianCoordinateSystem::~VCartesianCoordinateSystem()
64 : {
65 2000 : }
66 :
67 1014 : void VCartesianCoordinateSystem::createGridShapes()
68 : {
69 1014 : if(!m_xLogicTargetForGrids.is() || !m_xFinalTarget.is() )
70 1014 : return;
71 :
72 1014 : sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
73 1014 : bool bSwapXAndY = this->getPropertySwapXAndYAxis();
74 :
75 4056 : for( sal_Int32 nDimensionIndex=0; nDimensionIndex<3; nDimensionIndex++)
76 : {
77 3042 : sal_Int32 nAxisIndex = MAIN_AXIS_INDEX;
78 3042 : Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, nAxisIndex, m_xCooSysModel ) );
79 3042 : if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
80 965 : continue;
81 :
82 4154 : VCartesianGrid aGrid(nDimensionIndex,nDimensionCount, getGridListFromAxis( xAxis ));
83 : aGrid.setExplicitScaleAndIncrement( this->getExplicitScale(nDimensionIndex,nAxisIndex)
84 2077 : , this->getExplicitIncrement(nDimensionIndex,nAxisIndex) );
85 2077 : aGrid.set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
86 :
87 : aGrid.initPlotter(m_xLogicTargetForGrids,m_xFinalTarget,m_xShapeFactory
88 2077 : , this->createCIDForGrid( xAxis,nDimensionIndex,nAxisIndex ) );
89 2077 : if(2==nDimensionCount)
90 1930 : aGrid.setTransformationSceneToScreen( m_aMatrixSceneToScreen );
91 2077 : aGrid.setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
92 2077 : aGrid.createShapes();
93 2077 : }
94 : }
95 :
96 1014 : void VCartesianCoordinateSystem::createVAxisList(
97 : const uno::Reference<chart2::XChartDocument> & xChartDoc
98 : , const awt::Size& rFontReferenceSize
99 : , const awt::Rectangle& rMaximumSpaceForLabels
100 : )
101 : {
102 : // note: using xChartDoc itself as XNumberFormatsSupplier would cause
103 : // a leak from VCartesianAxis due to cyclic reference
104 : uno::Reference<util::XNumberFormatsSupplier> const xNumberFormatsSupplier(
105 1014 : dynamic_cast<ChartModel&>(*xChartDoc.get()).getNumberFormatsSupplier());
106 :
107 1014 : m_aAxisMap.clear();
108 :
109 1014 : sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
110 1014 : bool bSwapXAndY = this->getPropertySwapXAndYAxis();
111 :
112 1014 : if(nDimensionCount<=0)
113 1014 : return;
114 :
115 1014 : sal_Int32 nDimensionIndex = 0;
116 :
117 : // dimension index -> x, y or z axis.
118 3091 : for( nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
119 : {
120 : // axis index -> primary or secondary axis.
121 2077 : sal_Int32 nMaxAxisIndex = m_xCooSysModel->getMaximumAxisIndexByDimension(nDimensionIndex);
122 4202 : for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
123 : {
124 2125 : Reference< XAxis > xAxis = this->getAxisByDimension(nDimensionIndex,nAxisIndex);
125 2125 : if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
126 6 : continue;
127 :
128 4238 : AxisProperties aAxisProperties(xAxis,this->getExplicitCategoriesProvider());
129 2119 : aAxisProperties.m_nDimensionIndex = nDimensionIndex;
130 2119 : aAxisProperties.m_bSwapXAndY = bSwapXAndY;
131 2119 : aAxisProperties.m_bIsMainAxis = (nAxisIndex==0);
132 4238 : Reference< XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( xAxis, m_xCooSysModel ) );
133 2119 : if( xCrossingMainAxis.is() )
134 : {
135 2119 : ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
136 2119 : aAxisProperties.m_bCrossingAxisHasReverseDirection = (AxisOrientation_REVERSE==aCrossingScale.Orientation);
137 :
138 2119 : if( aCrossingScale.AxisType == AxisType::CATEGORY )
139 992 : aAxisProperties.m_bCrossingAxisIsCategoryAxes = true;
140 : }
141 :
142 2119 : if( nDimensionIndex == 2 )
143 : {
144 49 : aAxisProperties.m_xAxisTextProvider = new TextualDataProvider( m_aSeriesNamesForZAxis );
145 :
146 : //for the z axis copy the positioning properties from the x axis (or from the y axis for swapped coordinate systems)
147 49 : Reference< XAxis > xSisterAxis( AxisHelper::getCrossingMainAxis( xCrossingMainAxis, m_xCooSysModel ) );
148 49 : aAxisProperties.initAxisPositioning( Reference< beans::XPropertySet >( xSisterAxis, uno::UNO_QUERY) );
149 : }
150 2119 : aAxisProperties.init(true);
151 2119 : if(aAxisProperties.m_bDisplayLabels)
152 1975 : aAxisProperties.m_nNumberFormatKey = this->getNumberFormatKeyForAxis(xAxis, xChartDoc);
153 :
154 4238 : ::boost::shared_ptr< VAxisBase > apVAxis( new VCartesianAxis(aAxisProperties,xNumberFormatsSupplier,nDimensionIndex,nDimensionCount) );
155 2119 : tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex );
156 2119 : m_aAxisMap[aFullAxisIndex] = apVAxis;
157 2119 : apVAxis->set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
158 :
159 2119 : apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels);
160 2119 : }
161 1014 : }
162 : }
163 :
164 1014 : void VCartesianCoordinateSystem::initVAxisInList()
165 : {
166 1014 : if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
167 1014 : return;
168 :
169 1014 : sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
170 1014 : bool bSwapXAndY = this->getPropertySwapXAndYAxis();
171 :
172 1014 : tVAxisMap::iterator aIt( m_aAxisMap.begin() );
173 1014 : tVAxisMap::const_iterator aEnd( m_aAxisMap.end() );
174 3133 : for( ; aIt != aEnd; ++aIt )
175 : {
176 2119 : VAxisBase* pVAxis = aIt->second.get();
177 2119 : if( pVAxis )
178 : {
179 2119 : sal_Int32 nDimensionIndex = aIt->first.first;
180 2119 : sal_Int32 nAxisIndex = aIt->first.second;
181 2119 : pVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
182 : pVAxis->initPlotter(m_xLogicTargetForAxes,m_xFinalTarget,m_xShapeFactory
183 2119 : , this->createCIDForAxis( getAxisByDimension( nDimensionIndex, nAxisIndex ), nDimensionIndex, nAxisIndex ) );
184 2119 : if(2==nDimensionCount)
185 1972 : pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
186 2119 : pVAxis->setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
187 : }
188 : }
189 : }
190 :
191 1014 : void VCartesianCoordinateSystem::updateScalesAndIncrementsOnAxes()
192 : {
193 1014 : if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
194 1014 : return;
195 :
196 1014 : sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
197 1014 : bool bSwapXAndY = this->getPropertySwapXAndYAxis();
198 :
199 1014 : tVAxisMap::iterator aIt( m_aAxisMap.begin() );
200 1014 : tVAxisMap::const_iterator aEnd( m_aAxisMap.end() );
201 3133 : for( ; aIt != aEnd; ++aIt )
202 : {
203 2119 : VAxisBase* pVAxis = aIt->second.get();
204 2119 : if( pVAxis )
205 : {
206 2119 : sal_Int32 nDimensionIndex = aIt->first.first;
207 2119 : sal_Int32 nAxisIndex = aIt->first.second;
208 2119 : pVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
209 2119 : if(2==nDimensionCount)
210 1972 : pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
211 2119 : pVAxis->setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
212 : }
213 : }
214 : }
215 :
216 : } //namespace chart
217 :
218 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|