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 "VAxisProperties.hxx"
21 : #include "macros.hxx"
22 : #include "ViewDefines.hxx"
23 : #include "CommonConverters.hxx"
24 : #include "AxisHelper.hxx"
25 : #include "DiagramHelper.hxx"
26 : #include "ChartModelHelper.hxx"
27 :
28 : #include <com/sun/star/beans/XPropertySet.hpp>
29 : #include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp>
30 : #include <com/sun/star/drawing/LineStyle.hpp>
31 : #include <com/sun/star/text/WritingMode2.hpp>
32 :
33 : //.............................................................................
34 : namespace chart
35 : {
36 : //.............................................................................
37 : using namespace ::com::sun::star;
38 : using namespace ::com::sun::star::chart2;
39 :
40 1447 : sal_Int32 lcl_calcTickLengthForDepth(sal_Int32 nDepth,sal_Int32 nTickmarkStyle)
41 : {
42 1447 : sal_Int32 nWidth = AXIS2D_TICKLENGTH; //@maybefuturetodo this length could be offered by the model
43 1447 : double fPercent = 1.0;
44 1447 : switch(nDepth)
45 : {
46 : case 0:
47 1325 : fPercent = 1.0;
48 1325 : break;
49 : case 1:
50 122 : fPercent = 0.75;//percentage like in the old chart
51 122 : break;
52 : case 2:
53 0 : fPercent = 0.5;
54 0 : break;
55 : default:
56 0 : fPercent = 0.3;
57 0 : break;
58 : }
59 1447 : if(nTickmarkStyle==3)//inner and outer tickmarks
60 281 : fPercent*=2.0;
61 1447 : return static_cast<sal_Int32>(nWidth*fPercent);
62 : }
63 :
64 1447 : double lcl_getTickOffset(sal_Int32 nLength,sal_Int32 nTickmarkStyle)
65 : {
66 1447 : double fPercent = 0.0; //0<=fPercent<=1
67 : //0.0: completely inner
68 : //1.0: completely outer
69 : //0.5: half and half
70 :
71 : /*
72 : nTickmarkStyle:
73 : 1: inner tickmarks
74 : 2: outer tickmarks
75 : 3: inner and outer tickmarks
76 : */
77 1447 : switch(nTickmarkStyle)
78 : {
79 : case 1:
80 0 : fPercent = 0.0;
81 0 : break;
82 : case 2:
83 920 : fPercent = 1.0;
84 920 : break;
85 : default:
86 527 : fPercent = 0.5;
87 527 : break;
88 : }
89 1447 : return fPercent*nLength;
90 : }
91 :
92 1166 : VLineProperties AxisProperties::makeLinePropertiesForDepth( sal_Int32 /* nDepth */ ) const
93 : {
94 : //@todo get this from somewhere; maybe for each subincrement
95 : //so far the model does not offer different settings for each tick depth
96 1166 : return m_aLineProperties;
97 : }
98 :
99 1166 : TickmarkProperties AxisProperties::makeTickmarkProperties(
100 : sal_Int32 nDepth ) const
101 : {
102 : /*
103 : nTickmarkStyle:
104 : 1: inner tickmarks
105 : 2: outer tickmarks
106 : 3: inner and outer tickmarks
107 : */
108 1166 : sal_Int32 nTickmarkStyle = 1;
109 1166 : if(nDepth==0)
110 : {
111 1044 : nTickmarkStyle = m_nMajorTickmarks;
112 1044 : if(!nTickmarkStyle)
113 : {
114 : //create major tickmarks as if they were minor tickmarks
115 0 : nDepth = 1;
116 0 : nTickmarkStyle = m_nMinorTickmarks;
117 : }
118 : }
119 122 : else if( nDepth==1)
120 : {
121 122 : nTickmarkStyle = m_nMinorTickmarks;
122 : }
123 :
124 1166 : if( m_fInnerDirectionSign == 0.0 )
125 : {
126 0 : if( nTickmarkStyle != 0 )
127 0 : nTickmarkStyle = 3; //inner and outer tickmarks
128 : }
129 :
130 1166 : TickmarkProperties aTickmarkProperties;
131 1166 : aTickmarkProperties.Length = lcl_calcTickLengthForDepth(nDepth,nTickmarkStyle);
132 1166 : aTickmarkProperties.RelativePos = static_cast<sal_Int32>(lcl_getTickOffset(aTickmarkProperties.Length,nTickmarkStyle));
133 1166 : aTickmarkProperties.aLineProperties = this->makeLinePropertiesForDepth( nDepth );
134 1166 : return aTickmarkProperties;
135 : }
136 :
137 0 : TickmarkProperties AxisProperties::makeTickmarkPropertiesForComplexCategories(
138 : sal_Int32 nTickLength, sal_Int32 nTickStartDistanceToAxis, sal_Int32 /*nTextLevel*/ ) const
139 : {
140 0 : sal_Int32 nTickmarkStyle = (m_fLabelDirectionSign==m_fInnerDirectionSign) ? 2/*outside*/ : 1/*inside*/;
141 :
142 0 : TickmarkProperties aTickmarkProperties;
143 0 : aTickmarkProperties.Length = nTickLength;// + nTextLevel*( lcl_calcTickLengthForDepth(0,nTickmarkStyle) );
144 0 : aTickmarkProperties.RelativePos = static_cast<sal_Int32>(lcl_getTickOffset(aTickmarkProperties.Length+nTickStartDistanceToAxis,nTickmarkStyle));
145 0 : aTickmarkProperties.aLineProperties = this->makeLinePropertiesForDepth( 0 );
146 0 : return aTickmarkProperties;
147 : }
148 :
149 281 : TickmarkProperties AxisProperties::getBiggestTickmarkProperties()
150 : {
151 281 : TickmarkProperties aTickmarkProperties;
152 281 : sal_Int32 nDepth = 0;
153 281 : sal_Int32 nTickmarkStyle = 3;//inner and outer tickmarks
154 281 : aTickmarkProperties.Length = lcl_calcTickLengthForDepth( nDepth,nTickmarkStyle );
155 281 : aTickmarkProperties.RelativePos = static_cast<sal_Int32>( lcl_getTickOffset( aTickmarkProperties.Length, nTickmarkStyle ) );
156 281 : return aTickmarkProperties;
157 : }
158 :
159 : //--------------------------------------------------------------------------
160 :
161 1044 : AxisProperties::AxisProperties( const uno::Reference< XAxis >& xAxisModel
162 : , ExplicitCategoriesProvider* pExplicitCategoriesProvider )
163 : : m_xAxisModel(xAxisModel)
164 : , m_nDimensionIndex(0)
165 : , m_bIsMainAxis(true)
166 : , m_bSwapXAndY(false)
167 : , m_eCrossoverType( ::com::sun::star::chart::ChartAxisPosition_ZERO )
168 : , m_eLabelPos( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS )
169 : , m_eTickmarkPos( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS )
170 : , m_pfMainLinePositionAtOtherAxis(NULL)
171 : , m_pfExrtaLinePositionAtOtherAxis(NULL)
172 : , m_bCrossingAxisHasReverseDirection(false)
173 : , m_bCrossingAxisIsCategoryAxes(false)
174 : , m_fLabelDirectionSign(1.0)
175 : , m_fInnerDirectionSign(1.0)
176 : , m_aLabelAlignment(LABEL_ALIGN_RIGHT_TOP)
177 : , m_bDisplayLabels( true )
178 : , m_nNumberFormatKey(0)
179 : , m_nMajorTickmarks(1)
180 : , m_nMinorTickmarks(1)
181 : , m_aTickmarkPropertiesList()
182 : , m_aLineProperties()
183 : //for category axes
184 : , m_nAxisType(AxisType::REALNUMBER)
185 : , m_bComplexCategories(false)
186 : , m_pExplicitCategoriesProvider(pExplicitCategoriesProvider)
187 1044 : , m_xAxisTextProvider(0)
188 : {
189 1044 : }
190 :
191 1044 : AxisProperties::AxisProperties( const AxisProperties& rAxisProperties )
192 : : m_xAxisModel( rAxisProperties.m_xAxisModel )
193 : , m_nDimensionIndex( rAxisProperties.m_nDimensionIndex )
194 : , m_bIsMainAxis( rAxisProperties.m_bIsMainAxis )
195 : , m_bSwapXAndY( rAxisProperties.m_bSwapXAndY )
196 : , m_eCrossoverType( rAxisProperties.m_eCrossoverType )
197 : , m_eLabelPos( rAxisProperties.m_eLabelPos )
198 : , m_eTickmarkPos( rAxisProperties.m_eTickmarkPos )
199 : , m_pfMainLinePositionAtOtherAxis( NULL )
200 : , m_pfExrtaLinePositionAtOtherAxis( NULL )
201 : , m_bCrossingAxisHasReverseDirection( rAxisProperties.m_bCrossingAxisHasReverseDirection )
202 : , m_bCrossingAxisIsCategoryAxes( rAxisProperties.m_bCrossingAxisIsCategoryAxes )
203 : , m_fLabelDirectionSign( rAxisProperties.m_fLabelDirectionSign )
204 : , m_fInnerDirectionSign( rAxisProperties.m_fInnerDirectionSign )
205 : , m_aLabelAlignment( rAxisProperties.m_aLabelAlignment )
206 : , m_bDisplayLabels( rAxisProperties.m_bDisplayLabels )
207 : , m_nNumberFormatKey( rAxisProperties.m_nNumberFormatKey )
208 : , m_nMajorTickmarks( rAxisProperties.m_nMajorTickmarks )
209 : , m_nMinorTickmarks( rAxisProperties.m_nMinorTickmarks )
210 : , m_aTickmarkPropertiesList( rAxisProperties.m_aTickmarkPropertiesList )
211 : , m_aLineProperties( rAxisProperties.m_aLineProperties )
212 : //for category axes
213 : , m_nAxisType( rAxisProperties.m_nAxisType )
214 : , m_bComplexCategories( rAxisProperties.m_bComplexCategories )
215 : , m_pExplicitCategoriesProvider( rAxisProperties.m_pExplicitCategoriesProvider )
216 1044 : , m_xAxisTextProvider( rAxisProperties.m_xAxisTextProvider )
217 : {
218 1044 : if( rAxisProperties.m_pfMainLinePositionAtOtherAxis )
219 978 : m_pfMainLinePositionAtOtherAxis = new double(*rAxisProperties.m_pfMainLinePositionAtOtherAxis);
220 1044 : if( rAxisProperties.m_pfExrtaLinePositionAtOtherAxis )
221 0 : m_pfExrtaLinePositionAtOtherAxis = new double (*rAxisProperties.m_pfExrtaLinePositionAtOtherAxis);
222 1044 : }
223 :
224 4176 : AxisProperties::~AxisProperties()
225 : {
226 2088 : delete m_pfMainLinePositionAtOtherAxis;
227 2088 : delete m_pfExrtaLinePositionAtOtherAxis;
228 2088 : }
229 :
230 8 : LabelAlignment lcl_getLabelAlignmentForZAxis( const AxisProperties& rAxisProperties )
231 : {
232 8 : LabelAlignment aRet( LABEL_ALIGN_RIGHT );
233 8 : if( rAxisProperties.m_fLabelDirectionSign<0 )
234 0 : aRet = LABEL_ALIGN_LEFT;
235 8 : return aRet;
236 : }
237 :
238 518 : LabelAlignment lcl_getLabelAlignmentForYAxis( const AxisProperties& rAxisProperties )
239 : {
240 518 : LabelAlignment aRet( LABEL_ALIGN_RIGHT );
241 518 : if( rAxisProperties.m_fLabelDirectionSign<0 )
242 498 : aRet = LABEL_ALIGN_LEFT;
243 518 : return aRet;
244 : }
245 :
246 518 : LabelAlignment lcl_getLabelAlignmentForXAxis( const AxisProperties& rAxisProperties )
247 : {
248 518 : LabelAlignment aRet( LABEL_ALIGN_BOTTOM );
249 518 : if( rAxisProperties.m_fLabelDirectionSign<0 )
250 23 : aRet = LABEL_ALIGN_TOP;
251 518 : return aRet;
252 : }
253 :
254 1044 : void AxisProperties::initAxisPositioning( const uno::Reference< beans::XPropertySet >& xAxisProp )
255 : {
256 1044 : if( !xAxisProp.is() )
257 1044 : return;
258 : try
259 : {
260 1044 : if( AxisHelper::isAxisPositioningEnabled() )
261 : {
262 1044 : xAxisProp->getPropertyValue("CrossoverPosition") >>= m_eCrossoverType;
263 1044 : if( ::com::sun::star::chart::ChartAxisPosition_VALUE == m_eCrossoverType )
264 : {
265 64 : double fValue = 0.0;
266 64 : xAxisProp->getPropertyValue("CrossoverValue") >>= fValue;
267 :
268 64 : if( m_bCrossingAxisIsCategoryAxes )
269 0 : fValue = ::rtl::math::round(fValue);
270 64 : m_pfMainLinePositionAtOtherAxis = new double(fValue);
271 : }
272 980 : else if( ::com::sun::star::chart::ChartAxisPosition_ZERO == m_eCrossoverType )
273 914 : m_pfMainLinePositionAtOtherAxis = new double(0.0);
274 :
275 1044 : xAxisProp->getPropertyValue("LabelPosition") >>= m_eLabelPos;
276 1044 : xAxisProp->getPropertyValue("MarkPosition") >>= m_eTickmarkPos;
277 : }
278 : else
279 : {
280 0 : m_eCrossoverType = ::com::sun::star::chart::ChartAxisPosition_START;
281 0 : if( m_bIsMainAxis == m_bCrossingAxisHasReverseDirection )
282 0 : m_eCrossoverType = ::com::sun::star::chart::ChartAxisPosition_END;
283 0 : m_eLabelPos = ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS;
284 0 : m_eTickmarkPos = ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS;
285 : }
286 : }
287 0 : catch( const uno::Exception& e )
288 : {
289 : ASSERT_EXCEPTION( e );
290 : }
291 : }
292 :
293 1044 : void AxisProperties::init( bool bCartesian )
294 : {
295 : uno::Reference< beans::XPropertySet > xProp =
296 1044 : uno::Reference<beans::XPropertySet>::query( this->m_xAxisModel );
297 1044 : if( !xProp.is() )
298 1044 : return;
299 :
300 1044 : if( m_nDimensionIndex<2 )
301 1036 : initAxisPositioning( xProp );
302 :
303 2088 : ScaleData aScaleData = m_xAxisModel->getScaleData();
304 1044 : if( m_nDimensionIndex==0 )
305 518 : AxisHelper::checkDateAxis( aScaleData, m_pExplicitCategoriesProvider, bCartesian );
306 1044 : m_nAxisType = aScaleData.AxisType;
307 :
308 1044 : if( bCartesian )
309 : {
310 2606 : if( m_nDimensionIndex == 0 && m_nAxisType == AxisType::CATEGORY
311 1551 : && m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->hasComplexCategories() )
312 0 : m_bComplexCategories = true;
313 :
314 1044 : if( ::com::sun::star::chart::ChartAxisPosition_END == m_eCrossoverType )
315 0 : m_fInnerDirectionSign = m_bCrossingAxisHasReverseDirection ? 1 : -1;
316 : else
317 1044 : m_fInnerDirectionSign = m_bCrossingAxisHasReverseDirection ? -1 : 1;
318 :
319 1044 : if( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS == m_eLabelPos )
320 978 : m_fLabelDirectionSign = m_fInnerDirectionSign;
321 66 : else if( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS_OTHER_SIDE == m_eLabelPos )
322 20 : m_fLabelDirectionSign = -m_fInnerDirectionSign;
323 46 : else if( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START == m_eLabelPos )
324 46 : m_fLabelDirectionSign = m_bCrossingAxisHasReverseDirection ? -1 : 1;
325 0 : else if( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END == m_eLabelPos )
326 0 : m_fLabelDirectionSign = m_bCrossingAxisHasReverseDirection ? 1 : -1;
327 :
328 1044 : if( m_nDimensionIndex==2 )
329 8 : m_aLabelAlignment = lcl_getLabelAlignmentForZAxis(*this);
330 : else
331 : {
332 1554 : bool bIsYAxisPosition = (m_nDimensionIndex==1 && !m_bSwapXAndY)
333 1558 : || (m_nDimensionIndex==0 && m_bSwapXAndY);
334 1036 : if( bIsYAxisPosition )
335 : {
336 518 : m_fLabelDirectionSign*=-1;
337 518 : m_fInnerDirectionSign*=-1;
338 : }
339 :
340 1036 : if( bIsYAxisPosition )
341 518 : m_aLabelAlignment = lcl_getLabelAlignmentForYAxis(*this);
342 : else
343 518 : m_aLabelAlignment = lcl_getLabelAlignmentForXAxis(*this);
344 : }
345 : }
346 :
347 : try
348 : {
349 : //init LineProperties
350 1044 : m_aLineProperties.initFromPropertySet( xProp );
351 :
352 : //init display labels
353 1044 : xProp->getPropertyValue( "DisplayLabels" ) >>= m_bDisplayLabels;
354 :
355 : //init TickmarkProperties
356 1044 : xProp->getPropertyValue( "MajorTickmarks" ) >>= m_nMajorTickmarks;
357 1044 : xProp->getPropertyValue( "MinorTickmarks" ) >>= m_nMinorTickmarks;
358 :
359 1044 : sal_Int32 nMaxDepth = 0;
360 1044 : if(m_nMinorTickmarks!=0)
361 122 : nMaxDepth=2;
362 922 : else if(m_nMajorTickmarks!=0)
363 922 : nMaxDepth=1;
364 :
365 1044 : this->m_aTickmarkPropertiesList.clear();
366 2210 : for( sal_Int32 nDepth=0; nDepth<nMaxDepth; nDepth++ )
367 : {
368 1166 : TickmarkProperties aTickmarkProperties = this->makeTickmarkProperties( nDepth );
369 1166 : this->m_aTickmarkPropertiesList.push_back( aTickmarkProperties );
370 1166 : }
371 : }
372 0 : catch( const uno::Exception& e )
373 : {
374 : ASSERT_EXCEPTION( e );
375 1044 : }
376 : }
377 :
378 : //-----------------------------------------------------------------------------
379 :
380 1044 : AxisLabelProperties::AxisLabelProperties()
381 : : m_aFontReferenceSize( ChartModelHelper::getDefaultPageSize() )
382 : , m_aMaximumSpaceForLabels( 0 , 0, m_aFontReferenceSize.Width, m_aFontReferenceSize.Height )
383 : , nNumberFormatKey(0)
384 : , eStaggering( SIDE_BY_SIDE )
385 : , bLineBreakAllowed( false )
386 : , bOverlapAllowed( false )
387 : , bStackCharacters( false )
388 : , fRotationAngleDegree( 0.0 )
389 : , nRhythm( 1 )
390 1044 : , bRhythmIsFix(false)
391 : {
392 :
393 1044 : }
394 :
395 958 : void AxisLabelProperties::init( const uno::Reference< XAxis >& xAxisModel )
396 : {
397 : uno::Reference< beans::XPropertySet > xProp =
398 958 : uno::Reference<beans::XPropertySet>::query( xAxisModel );
399 958 : if(xProp.is())
400 : {
401 : try
402 : {
403 958 : xProp->getPropertyValue( "TextBreak" ) >>= this->bLineBreakAllowed;
404 958 : xProp->getPropertyValue( "TextOverlap" ) >>= this->bOverlapAllowed;
405 958 : xProp->getPropertyValue( "StackCharacters" ) >>= this->bStackCharacters;
406 958 : xProp->getPropertyValue( "TextRotation" ) >>= this->fRotationAngleDegree;
407 :
408 : ::com::sun::star::chart::ChartAxisArrangeOrderType eArrangeOrder;
409 958 : xProp->getPropertyValue( "ArrangeOrder" ) >>= eArrangeOrder;
410 958 : switch(eArrangeOrder)
411 : {
412 : case ::com::sun::star::chart::ChartAxisArrangeOrderType_SIDE_BY_SIDE:
413 107 : this->eStaggering = SIDE_BY_SIDE;
414 107 : break;
415 : case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_EVEN:
416 4 : this->eStaggering = STAGGER_EVEN;
417 4 : break;
418 : case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_ODD:
419 16 : this->eStaggering = STAGGER_ODD;
420 16 : break;
421 : default:
422 831 : this->eStaggering = STAGGER_AUTO;
423 831 : break;
424 : }
425 : }
426 0 : catch( const uno::Exception& e )
427 : {
428 : ASSERT_EXCEPTION( e );
429 : }
430 958 : }
431 958 : }
432 :
433 4698 : bool AxisLabelProperties::getIsStaggered() const
434 : {
435 4698 : return ( STAGGER_ODD == eStaggering || STAGGER_EVEN == eStaggering );
436 : }
437 :
438 : //.............................................................................
439 : } //namespace chart
440 : //.............................................................................
441 :
442 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|