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 :
21 : #include "VAxisBase.hxx"
22 : #include "ShapeFactory.hxx"
23 : #include "CommonConverters.hxx"
24 : #include "Tickmarks.hxx"
25 : #include "macros.hxx"
26 :
27 : #include <memory>
28 : #include <boost/scoped_ptr.hpp>
29 :
30 : //.............................................................................
31 : namespace chart
32 : {
33 : //.............................................................................
34 : using namespace ::com::sun::star;
35 : using namespace ::com::sun::star::chart2;
36 : using ::com::sun::star::uno::Reference;
37 :
38 82 : VAxisBase::VAxisBase( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount
39 : , const AxisProperties& rAxisProperties
40 : , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier )
41 : : VAxisOrGridBase( nDimensionIndex, nDimensionCount )
42 : , m_xNumberFormatsSupplier( xNumberFormatsSupplier )
43 : , m_aAxisProperties( rAxisProperties )
44 : , m_bUseTextLabels( false )
45 : , m_bReCreateAllTickInfos( true )
46 : , m_bRecordMaximumTextSize(false)
47 : , m_nMaximumTextWidthSoFar(0)
48 82 : , m_nMaximumTextHeightSoFar(0)
49 : {
50 82 : }
51 :
52 82 : VAxisBase::~VAxisBase()
53 : {
54 82 : }
55 :
56 656 : sal_Int32 VAxisBase::getDimensionCount()
57 : {
58 656 : return m_nDimension;
59 : }
60 :
61 82 : void VAxisBase::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize
62 : , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels )
63 : {
64 82 : m_aAxisLabelProperties.m_aFontReferenceSize = rFontReferenceSize;
65 82 : m_aAxisLabelProperties.m_aMaximumSpaceForLabels = rMaximumSpaceForLabels;
66 :
67 82 : if( !m_aAxisProperties.m_bDisplayLabels )
68 0 : return;
69 :
70 82 : if( AxisType::SERIES==m_aAxisProperties.m_nAxisType )
71 : {
72 0 : if( m_aAxisProperties.m_xAxisTextProvider.is() )
73 0 : m_aTextLabels = m_aAxisProperties.m_xAxisTextProvider->getTextualData();
74 :
75 0 : m_bUseTextLabels = true;
76 0 : if( m_aTextLabels.getLength() == 1 )
77 : {
78 : //don't show a single series name
79 0 : m_aAxisProperties.m_bDisplayLabels = false;
80 0 : return;
81 : }
82 : }
83 82 : else if( AxisType::CATEGORY==m_aAxisProperties.m_nAxisType )
84 : {
85 41 : if( m_aAxisProperties.m_pExplicitCategoriesProvider )
86 41 : m_aTextLabels = m_aAxisProperties.m_pExplicitCategoriesProvider->getSimpleCategories();
87 :
88 41 : m_bUseTextLabels = true;
89 : }
90 :
91 82 : m_aAxisLabelProperties.nNumberFormatKey = m_aAxisProperties.m_nNumberFormatKey;
92 82 : m_aAxisLabelProperties.init(m_aAxisProperties.m_xAxisModel);
93 82 : if( m_aAxisProperties.m_bComplexCategories && AxisType::CATEGORY == m_aAxisProperties.m_nAxisType )
94 0 : m_aAxisLabelProperties.eStaggering = SIDE_BY_SIDE;
95 : }
96 :
97 205 : bool VAxisBase::isDateAxis() const
98 : {
99 205 : return AxisType::DATE == m_aScale.AxisType;
100 : }
101 861 : bool VAxisBase::isComplexCategoryAxis() const
102 : {
103 861 : return m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels;
104 : }
105 :
106 779 : void VAxisBase::recordMaximumTextSize( const Reference< drawing::XShape >& xShape, double fRotationAngleDegree )
107 : {
108 779 : if( m_bRecordMaximumTextSize && xShape.is() )
109 : {
110 : awt::Size aSize( ShapeFactory::getSizeAfterRotation(
111 328 : xShape, fRotationAngleDegree ) );
112 :
113 328 : m_nMaximumTextWidthSoFar = std::max( m_nMaximumTextWidthSoFar, aSize.Width );
114 328 : m_nMaximumTextHeightSoFar = std::max( m_nMaximumTextHeightSoFar, aSize.Height );
115 : }
116 779 : }
117 :
118 0 : sal_Int32 VAxisBase::estimateMaximumAutoMainIncrementCount()
119 : {
120 0 : return 10;
121 : }
122 :
123 41 : void VAxisBase::setExrtaLinePositionAtOtherAxis( const double& fCrossingAt )
124 : {
125 41 : if( m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis )
126 0 : delete m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis;
127 41 : m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis = new double(fCrossingAt);
128 41 : }
129 :
130 246 : sal_Bool VAxisBase::isAnythingToDraw()
131 : {
132 246 : if( !m_aAxisProperties.m_xAxisModel.is() )
133 0 : return false;
134 :
135 : OSL_ENSURE(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"Axis is not proper initialized");
136 246 : if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
137 0 : return false;
138 :
139 246 : uno::Reference< beans::XPropertySet > xProps( m_aAxisProperties.m_xAxisModel, uno::UNO_QUERY );
140 246 : if( xProps.is() )
141 : {
142 246 : sal_Bool bShow = sal_False;
143 246 : xProps->getPropertyValue( C2U( "Show" ) ) >>= bShow;
144 246 : if( !bShow )
145 0 : return false;
146 : }
147 246 : return true;
148 : }
149 :
150 164 : void VAxisBase::setExplicitScaleAndIncrement(
151 : const ExplicitScaleData& rScale
152 : , const ExplicitIncrementData& rIncrement )
153 : throw (uno::RuntimeException)
154 : {
155 164 : m_bReCreateAllTickInfos = true;
156 164 : m_aScale = rScale;
157 164 : m_aIncrement = rIncrement;
158 164 : }
159 :
160 164 : void VAxisBase::createAllTickInfos( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos )
161 : {
162 164 : boost::scoped_ptr< TickFactory > apTickFactory( this->createTickFactory() );
163 164 : if( m_aScale.ShiftedCategoryPosition )
164 82 : apTickFactory->getAllTicksShifted( rAllTickInfos );
165 : else
166 82 : apTickFactory->getAllTicks( rAllTickInfos );
167 164 : }
168 :
169 246 : bool VAxisBase::prepareShapeCreation()
170 : {
171 : //returns true if all is ready for further shape creation and any shapes need to be created
172 246 : if( !isAnythingToDraw() )
173 0 : return false;
174 :
175 246 : if( m_bReCreateAllTickInfos )
176 : {
177 : //-----------------------------------------
178 : //create all scaled tickmark values
179 164 : removeTextShapesFromTicks();
180 :
181 164 : createAllTickInfos(m_aAllTickInfos);
182 164 : m_bReCreateAllTickInfos = false;
183 : }
184 :
185 246 : if( m_xGroupShape_Shapes.is() )
186 164 : return true;
187 :
188 : //-----------------------------------------
189 : //create named group shape
190 82 : m_xGroupShape_Shapes = this->createGroupShape( m_xLogicTarget, m_nDimension==2 ? m_aCID : C2U(""));
191 :
192 82 : if( m_aAxisProperties.m_bDisplayLabels )
193 82 : m_xTextTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget, m_aCID );
194 :
195 82 : return true;
196 : }
197 :
198 41 : sal_Int32 VAxisBase::getIndexOfLongestLabel( const uno::Sequence< rtl::OUString >& rLabels )
199 : {
200 41 : sal_Int32 nRet = 0;
201 41 : sal_Int32 nLength = 0;
202 41 : sal_Int32 nN = 0;
203 205 : for( nN=0; nN<rLabels.getLength(); nN++ )
204 : {
205 : //todo: get real text width (without creating shape) instead of character count
206 164 : if( rLabels[nN].getLength() > nLength )
207 : {
208 41 : nLength = rLabels[nN].getLength();
209 41 : nRet = nN;
210 : }
211 : }
212 41 : return nRet;
213 : }
214 :
215 246 : void VAxisBase::removeTextShapesFromTicks()
216 : {
217 246 : if( m_xTextTarget.is() )
218 : {
219 164 : ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = m_aAllTickInfos.begin();
220 164 : const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd = m_aAllTickInfos.end();
221 492 : for( ; aDepthIter != aDepthEnd; ++aDepthIter )
222 : {
223 328 : ::std::vector< TickInfo >::iterator aTickIter = (*aDepthIter).begin();
224 328 : const ::std::vector< TickInfo >::const_iterator aTickEnd = (*aDepthIter).end();
225 2132 : for( ; aTickIter != aTickEnd; ++aTickIter )
226 : {
227 1804 : TickInfo& rTickInfo = (*aTickIter);
228 1804 : if(rTickInfo.xTextShape.is())
229 : {
230 328 : m_xTextTarget->remove(rTickInfo.xTextShape);
231 328 : rTickInfo.xTextShape = NULL;
232 : }
233 : }
234 : }
235 : }
236 246 : }
237 :
238 0 : void VAxisBase::updateUnscaledValuesAtTicks( TickIter& rIter )
239 : {
240 0 : Reference< XScaling > xInverseScaling( NULL );
241 0 : if( m_aScale.Scaling.is() )
242 0 : xInverseScaling = m_aScale.Scaling->getInverseScaling();
243 :
244 0 : for( TickInfo* pTickInfo = rIter.firstInfo()
245 0 : ; pTickInfo; pTickInfo = rIter.nextInfo() )
246 : {
247 : //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
248 0 : }
249 0 : }
250 :
251 : //.............................................................................
252 : } //namespace chart
253 : //.............................................................................
254 :
255 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|