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 35 : TextualDataProvider( const uno::Sequence< OUString >& rTextSequence )
40 35 : : m_aTextSequence( rTextSequence )
41 : {
42 35 : }
43 70 : virtual ~TextualDataProvider()
44 35 : {
45 70 : }
46 :
47 : //XTextualDataSequence
48 35 : virtual uno::Sequence< OUString > SAL_CALL getTextualData()
49 : throw ( uno::RuntimeException, std::exception) SAL_OVERRIDE
50 : {
51 35 : return m_aTextSequence;
52 : }
53 :
54 : private: //member
55 : uno::Sequence< OUString > m_aTextSequence;
56 : };
57 :
58 524 : VCartesianCoordinateSystem::VCartesianCoordinateSystem( const Reference< XCoordinateSystem >& xCooSys )
59 524 : : VCoordinateSystem(xCooSys)
60 : {
61 524 : }
62 :
63 1000 : VCartesianCoordinateSystem::~VCartesianCoordinateSystem()
64 : {
65 1000 : }
66 :
67 524 : void VCartesianCoordinateSystem::createGridShapes()
68 : {
69 524 : if(!m_xLogicTargetForGrids.is() || !m_xFinalTarget.is() )
70 524 : return;
71 :
72 524 : sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
73 524 : bool bSwapXAndY = this->getPropertySwapXAndYAxis();
74 :
75 2096 : for( sal_Int32 nDimensionIndex=0; nDimensionIndex<3; nDimensionIndex++)
76 : {
77 1572 : sal_Int32 nAxisIndex = MAIN_AXIS_INDEX;
78 1572 : Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, nAxisIndex, m_xCooSysModel ) );
79 1572 : if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
80 489 : continue;
81 :
82 2166 : VCartesianGrid aGrid(nDimensionIndex,nDimensionCount,this->getGridListFromAxis( xAxis ));
83 : aGrid.setExplicitScaleAndIncrement( this->getExplicitScale(nDimensionIndex,nAxisIndex)
84 1083 : , this->getExplicitIncrement(nDimensionIndex,nAxisIndex) );
85 1083 : aGrid.set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
86 :
87 : aGrid.initPlotter(m_xLogicTargetForGrids,m_xFinalTarget,m_xShapeFactory
88 1083 : , this->createCIDForGrid( xAxis,nDimensionIndex,nAxisIndex ) );
89 1083 : if(2==nDimensionCount)
90 978 : aGrid.setTransformationSceneToScreen( m_aMatrixSceneToScreen );
91 1083 : aGrid.setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
92 1083 : aGrid.createShapes();
93 1083 : }
94 : }
95 :
96 524 : 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 524 : dynamic_cast<ChartModel&>(*xChartDoc.get()).getNumberFormatsSupplier());
106 :
107 524 : m_aAxisMap.clear();
108 :
109 524 : sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
110 524 : bool bSwapXAndY = this->getPropertySwapXAndYAxis();
111 :
112 524 : if(nDimensionCount<=0)
113 524 : return;
114 :
115 524 : sal_Int32 nDimensionIndex = 0;
116 :
117 : // dimension index -> x, y or z axis.
118 1607 : for( nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
119 : {
120 : // axis index -> primary or secondary axis.
121 1083 : sal_Int32 nMaxAxisIndex = m_xCooSysModel->getMaximumAxisIndexByDimension(nDimensionIndex);
122 2192 : for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
123 : {
124 1109 : Reference< XAxis > xAxis = this->getAxisByDimension(nDimensionIndex,nAxisIndex);
125 1109 : if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
126 14 : continue;
127 :
128 2190 : AxisProperties aAxisProperties(xAxis,this->getExplicitCategoriesProvider());
129 1095 : aAxisProperties.m_nDimensionIndex = nDimensionIndex;
130 1095 : aAxisProperties.m_bSwapXAndY = bSwapXAndY;
131 1095 : aAxisProperties.m_bIsMainAxis = (nAxisIndex==0);
132 2190 : Reference< XAxis > xCrossingMainAxis( AxisHelper::getCrossingMainAxis( xAxis, m_xCooSysModel ) );
133 1095 : if( xCrossingMainAxis.is() )
134 : {
135 1095 : ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
136 1095 : aAxisProperties.m_bCrossingAxisHasReverseDirection = (AxisOrientation_REVERSE==aCrossingScale.Orientation);
137 :
138 1095 : if( aCrossingScale.AxisType == AxisType::CATEGORY )
139 491 : aAxisProperties.m_bCrossingAxisIsCategoryAxes = true;
140 : }
141 :
142 1095 : if( nDimensionIndex == 2 )
143 : {
144 35 : 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 35 : Reference< XAxis > xSisterAxis( AxisHelper::getCrossingMainAxis( xCrossingMainAxis, m_xCooSysModel ) );
148 35 : aAxisProperties.initAxisPositioning( Reference< beans::XPropertySet >( xSisterAxis, uno::UNO_QUERY) );
149 : }
150 1095 : aAxisProperties.init(true);
151 1095 : if(aAxisProperties.m_bDisplayLabels)
152 1029 : aAxisProperties.m_nNumberFormatKey = this->getNumberFormatKeyForAxis(xAxis, xChartDoc);
153 :
154 2190 : ::boost::shared_ptr< VAxisBase > apVAxis( new VCartesianAxis(aAxisProperties,xNumberFormatsSupplier,nDimensionIndex,nDimensionCount) );
155 1095 : tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex );
156 1095 : m_aAxisMap[aFullAxisIndex] = apVAxis;
157 1095 : apVAxis->set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
158 :
159 1095 : apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels);
160 1095 : }
161 524 : }
162 : }
163 :
164 524 : void VCartesianCoordinateSystem::initVAxisInList()
165 : {
166 524 : if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
167 524 : return;
168 :
169 524 : sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
170 524 : bool bSwapXAndY = this->getPropertySwapXAndYAxis();
171 :
172 524 : tVAxisMap::iterator aIt( m_aAxisMap.begin() );
173 524 : tVAxisMap::const_iterator aEnd( m_aAxisMap.end() );
174 1619 : for( ; aIt != aEnd; ++aIt )
175 : {
176 1095 : VAxisBase* pVAxis = aIt->second.get();
177 1095 : if( pVAxis )
178 : {
179 1095 : sal_Int32 nDimensionIndex = aIt->first.first;
180 1095 : sal_Int32 nAxisIndex = aIt->first.second;
181 1095 : pVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
182 : pVAxis->initPlotter(m_xLogicTargetForAxes,m_xFinalTarget,m_xShapeFactory
183 1095 : , this->createCIDForAxis( getAxisByDimension( nDimensionIndex, nAxisIndex ), nDimensionIndex, nAxisIndex ) );
184 1095 : if(2==nDimensionCount)
185 990 : pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
186 1095 : pVAxis->setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
187 : }
188 : }
189 : }
190 :
191 524 : void VCartesianCoordinateSystem::updateScalesAndIncrementsOnAxes()
192 : {
193 524 : if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
194 524 : return;
195 :
196 524 : sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
197 524 : bool bSwapXAndY = this->getPropertySwapXAndYAxis();
198 :
199 524 : tVAxisMap::iterator aIt( m_aAxisMap.begin() );
200 524 : tVAxisMap::const_iterator aEnd( m_aAxisMap.end() );
201 1619 : for( ; aIt != aEnd; ++aIt )
202 : {
203 1095 : VAxisBase* pVAxis = aIt->second.get();
204 1095 : if( pVAxis )
205 : {
206 1095 : sal_Int32 nDimensionIndex = aIt->first.first;
207 1095 : sal_Int32 nAxisIndex = aIt->first.second;
208 1095 : pVAxis->setExplicitScaleAndIncrement( this->getExplicitScale( nDimensionIndex, nAxisIndex ), this->getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
209 1095 : if(2==nDimensionCount)
210 990 : pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
211 1095 : pVAxis->setScales( this->getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
212 : }
213 : }
214 : }
215 :
216 108 : } //namespace chart
217 :
218 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|