1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VAxisProperties.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "VAxisProperties.hxx"
35 #include "ViewDefines.hxx"
36 #include "CommonConverters.hxx"
37 #include "AxisHelper.hxx"
38 #include "DiagramHelper.hxx"
40 #include <tools/color.hxx>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp>
43 #include <com/sun/star/drawing/LineStyle.hpp>
44 #include <com/sun/star/text/WritingMode2.hpp>
46 //.............................................................................
49 //.............................................................................
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::chart2
;
53 sal_Int32
lcl_calcTickLengthForDepth(sal_Int32 nDepth
,sal_Int32 nTickmarkStyle
)
55 sal_Int32 nWidth
= AXIS2D_TICKLENGTH
; //@maybefuturetodo this length could be offered by the model
56 double fPercent
= 1.0;
63 fPercent
= 0.75;//percentage like in the old chart
72 if(nTickmarkStyle
==3)//inner and outer tickmarks
74 return static_cast<sal_Int32
>(nWidth
*fPercent
);
77 double lcl_getTickOffset(sal_Int32 nLength
,sal_Int32 nTickmarkStyle
)
79 double fPercent
= 0.0; //0<=fPercent<=1
80 //0.0: completly inner
81 //1.0: completly outer
88 3: inner and outer tickmarks
90 switch(nTickmarkStyle
)
102 return fPercent
*nLength
;
105 VLineProperties
AxisProperties::makeLinePropertiesForDepth( sal_Int32
/* nDepth */ ) const
107 //@todo get this from somewhere; maybe for each subincrement
108 //so far the model does not offer different settings for each tick depth
109 return m_aLineProperties
;
112 TickmarkProperties
AxisProperties::makeTickmarkProperties(
113 sal_Int32 nDepth
) const
119 3: inner and outer tickmarks
121 sal_Int32 nTickmarkStyle
= 1;
124 nTickmarkStyle
= m_nMajorTickmarks
;
127 //create major tickmarks as if they were minor tickmarks
129 nTickmarkStyle
= m_nMinorTickmarks
;
134 nTickmarkStyle
= m_nMinorTickmarks
;
137 if( m_fInnerDirectionSign
== 0.0 )
139 if( nTickmarkStyle
!= 0 )
140 nTickmarkStyle
= 3; //inner and outer tickmarks
143 TickmarkProperties aTickmarkProperties
;
144 aTickmarkProperties
.Length
= lcl_calcTickLengthForDepth(nDepth
,nTickmarkStyle
);
145 aTickmarkProperties
.RelativePos
= static_cast<sal_Int32
>(lcl_getTickOffset(aTickmarkProperties
.Length
,nTickmarkStyle
));
146 aTickmarkProperties
.aLineProperties
= this->makeLinePropertiesForDepth( nDepth
);
147 return aTickmarkProperties
;
151 TickmarkProperties
AxisProperties::getBiggestTickmarkProperties()
153 TickmarkProperties aTickmarkProperties
;
154 sal_Int32 nDepth
= 0;
155 sal_Int32 nTickmarkStyle
= 3;//inner and outer tickmarks
156 aTickmarkProperties
.Length
= lcl_calcTickLengthForDepth( nDepth
,nTickmarkStyle
);
157 aTickmarkProperties
.RelativePos
= static_cast<sal_Int32
>( lcl_getTickOffset( aTickmarkProperties
.Length
, nTickmarkStyle
) );
158 return aTickmarkProperties
;
161 //--------------------------------------------------------------------------
163 AxisProperties::AxisProperties( const uno::Reference
< XAxis
>& xAxisModel
164 , const uno::Reference
< data::XTextualDataSequence
>& xAxisTextProvider
)
165 : m_xAxisModel(xAxisModel
)
166 , m_nDimensionIndex(0)
167 , m_bIsMainAxis(true)
168 , m_bSwapXAndY(false)
169 , m_eCrossoverType( ::com::sun::star::chart::ChartAxisPosition_ZERO
)
170 , m_eLabelPos( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS
)
171 , m_eTickmarkPos( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS
)
172 , m_pfMainLinePositionAtOtherAxis(NULL
)
173 , m_pfExrtaLinePositionAtOtherAxis(NULL
)
174 , m_bCrossingAxisHasReverseDirection(false)
175 , m_bCrossingAxisIsCategoryAxes(false)
176 , m_bAxisBetweenCategories(false)
177 , m_fLabelDirectionSign(1.0)
178 , m_fInnerDirectionSign(1.0)
179 , m_bLabelsOutside(true)
180 , m_aLabelAlignment(LABEL_ALIGN_RIGHT_TOP
)
181 , m_bDisplayLabels( true )
182 , m_nNumberFormatKey(0)
183 , m_nMajorTickmarks(1)
184 , m_nMinorTickmarks(1)
185 , m_aTickmarkPropertiesList()
186 , m_aLineProperties()
188 , m_nAxisType(AxisType::REALNUMBER
)
189 , m_xAxisTextProvider(xAxisTextProvider
)
190 , m_bTickmarksAtIndicatedValue(false)
194 AxisProperties::AxisProperties( const AxisProperties
& rAxisProperties
)
195 : m_xAxisModel( rAxisProperties
.m_xAxisModel
)
196 , m_nDimensionIndex( m_nDimensionIndex
)
197 , m_bIsMainAxis( rAxisProperties
.m_bIsMainAxis
)
198 , m_bSwapXAndY( rAxisProperties
.m_bSwapXAndY
)
199 , m_eCrossoverType( rAxisProperties
.m_eCrossoverType
)
200 , m_eLabelPos( rAxisProperties
.m_eLabelPos
)
201 , m_eTickmarkPos( rAxisProperties
.m_eTickmarkPos
)
202 , m_pfMainLinePositionAtOtherAxis( NULL
)
203 , m_pfExrtaLinePositionAtOtherAxis( NULL
)
204 , m_bCrossingAxisHasReverseDirection( rAxisProperties
.m_bCrossingAxisHasReverseDirection
)
205 , m_bCrossingAxisIsCategoryAxes( rAxisProperties
.m_bCrossingAxisIsCategoryAxes
)
206 , m_bAxisBetweenCategories( rAxisProperties
.m_bAxisBetweenCategories
)
207 , m_fLabelDirectionSign( rAxisProperties
.m_fLabelDirectionSign
)
208 , m_fInnerDirectionSign( rAxisProperties
.m_fInnerDirectionSign
)
209 , m_bLabelsOutside( rAxisProperties
.m_bLabelsOutside
)
210 , m_aLabelAlignment( rAxisProperties
.m_aLabelAlignment
)
211 , m_bDisplayLabels( rAxisProperties
.m_bDisplayLabels
)
212 , m_nNumberFormatKey( rAxisProperties
.m_nNumberFormatKey
)
213 , m_nMajorTickmarks( rAxisProperties
.m_nMajorTickmarks
)
214 , m_nMinorTickmarks( rAxisProperties
.m_nMinorTickmarks
)
215 , m_aTickmarkPropertiesList( rAxisProperties
.m_aTickmarkPropertiesList
)
216 , m_aLineProperties( rAxisProperties
.m_aLineProperties
)
218 , m_nAxisType( rAxisProperties
.m_nAxisType
)
219 , m_xAxisTextProvider( rAxisProperties
.m_xAxisTextProvider
)
220 , m_bTickmarksAtIndicatedValue( rAxisProperties
.m_bTickmarksAtIndicatedValue
)
222 if( rAxisProperties
.m_pfMainLinePositionAtOtherAxis
)
223 m_pfMainLinePositionAtOtherAxis
= new double(*rAxisProperties
.m_pfMainLinePositionAtOtherAxis
);
224 if( rAxisProperties
.m_pfExrtaLinePositionAtOtherAxis
)
225 m_pfExrtaLinePositionAtOtherAxis
= new double (*rAxisProperties
.m_pfExrtaLinePositionAtOtherAxis
);
228 AxisProperties::~AxisProperties()
230 delete m_pfMainLinePositionAtOtherAxis
;
231 delete m_pfExrtaLinePositionAtOtherAxis
;
234 LabelAlignment
lcl_getLabelAlignmentForZAxis( const AxisProperties
& rAxisProperties
)
236 LabelAlignment
aRet( LABEL_ALIGN_RIGHT
);
237 if( rAxisProperties
.m_fLabelDirectionSign
<0 )
238 aRet
= LABEL_ALIGN_LEFT
;
242 LabelAlignment
lcl_getLabelAlignmentForYAxis( const AxisProperties
& rAxisProperties
)
244 LabelAlignment
aRet( LABEL_ALIGN_RIGHT
);
245 if( rAxisProperties
.m_fLabelDirectionSign
<0 )
246 aRet
= LABEL_ALIGN_LEFT
;
250 LabelAlignment
lcl_getLabelAlignmentForXAxis( const AxisProperties
& rAxisProperties
)
252 LabelAlignment
aRet( LABEL_ALIGN_BOTTOM
);
253 if( rAxisProperties
.m_fLabelDirectionSign
<0 )
254 aRet
= LABEL_ALIGN_TOP
;
258 void AxisProperties::initAxisPositioning( const uno::Reference
< beans::XPropertySet
>& xAxisProp
)
260 if( !xAxisProp
.is() )
264 if( AxisHelper::isAxisPositioningEnabled() )
266 xAxisProp
->getPropertyValue(C2U( "CrossoverPosition" )) >>= m_eCrossoverType
;
267 if( ::com::sun::star::chart::ChartAxisPosition_VALUE
== m_eCrossoverType
)
270 xAxisProp
->getPropertyValue(C2U( "CrossoverValue" )) >>= fValue
;
272 if( m_bCrossingAxisIsCategoryAxes
)
274 fValue
= ::rtl::math::round(fValue
);
275 if( m_bAxisBetweenCategories
)
278 m_pfMainLinePositionAtOtherAxis
= new double(fValue
);
280 else if( ::com::sun::star::chart::ChartAxisPosition_ZERO
== m_eCrossoverType
)
281 m_pfMainLinePositionAtOtherAxis
= new double(0.0);
283 xAxisProp
->getPropertyValue(C2U( "LabelPosition" )) >>= m_eLabelPos
;
284 xAxisProp
->getPropertyValue(C2U( "MarkPosition" )) >>= m_eTickmarkPos
;
288 m_eCrossoverType
= ::com::sun::star::chart::ChartAxisPosition_START
;
289 if( m_bIsMainAxis
== m_bCrossingAxisHasReverseDirection
)
290 m_eCrossoverType
= ::com::sun::star::chart::ChartAxisPosition_END
;
291 m_eLabelPos
= ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS
;
292 m_eTickmarkPos
= ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS
;
295 catch( uno::Exception
& e
)
297 ASSERT_EXCEPTION( e
);
301 void AxisProperties::init( bool bCartesian
)
303 uno::Reference
< beans::XPropertySet
> xProp
=
304 uno::Reference
<beans::XPropertySet
>::query( this->m_xAxisModel
);
308 if( m_nDimensionIndex
<2 )
309 initAxisPositioning( xProp
);
313 if( ::com::sun::star::chart::ChartAxisPosition_END
== m_eCrossoverType
)
314 m_fInnerDirectionSign
= m_bCrossingAxisHasReverseDirection
? 1 : -1;
316 m_fInnerDirectionSign
= m_bCrossingAxisHasReverseDirection
? -1 : 1;
318 if( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS
== m_eLabelPos
)
319 m_fLabelDirectionSign
= m_fInnerDirectionSign
;
320 else if( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS_OTHER_SIDE
== m_eLabelPos
)
321 m_fLabelDirectionSign
= -m_fInnerDirectionSign
;
322 else if( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START
== m_eLabelPos
)
323 m_fLabelDirectionSign
= m_bCrossingAxisHasReverseDirection
? -1 : 1;
324 else if( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END
== m_eLabelPos
)
325 m_fLabelDirectionSign
= m_bCrossingAxisHasReverseDirection
? 1 : -1;
327 if( m_nDimensionIndex
==2 )
328 m_aLabelAlignment
= lcl_getLabelAlignmentForZAxis(*this);
331 bool bIsYAxisPosition
= (m_nDimensionIndex
==1 && !m_bSwapXAndY
)
332 || (m_nDimensionIndex
==0 && m_bSwapXAndY
);
333 if( bIsYAxisPosition
)
335 m_fLabelDirectionSign
*=-1;
336 m_fInnerDirectionSign
*=-1;
339 if( bIsYAxisPosition
)
340 m_aLabelAlignment
= lcl_getLabelAlignmentForYAxis(*this);
342 m_aLabelAlignment
= lcl_getLabelAlignmentForXAxis(*this);
348 //init LineProperties
349 m_aLineProperties
.initFromPropertySet( xProp
);
351 //init display labels
352 xProp
->getPropertyValue( C2U( "DisplayLabels" ) ) >>= m_bDisplayLabels
;
355 ScaleData aScaleData
= m_xAxisModel
->getScaleData();
356 m_nAxisType
= aScaleData
.AxisType
;
358 //init TickmarkProperties
359 xProp
->getPropertyValue( C2U( "MajorTickmarks" ) ) >>= m_nMajorTickmarks
;
360 xProp
->getPropertyValue( C2U( "MinorTickmarks" ) ) >>= m_nMinorTickmarks
;
362 sal_Int32 nMaxDepth
= 0;
363 if(m_nMinorTickmarks
!=0)
365 else if(m_nMajorTickmarks
!=0)
368 this->m_aTickmarkPropertiesList
.clear();
369 for( sal_Int32 nDepth
=0; nDepth
<nMaxDepth
; nDepth
++ )
371 TickmarkProperties aTickmarkProperties
= this->makeTickmarkProperties( nDepth
);
372 this->m_aTickmarkPropertiesList
.push_back( aTickmarkProperties
);
375 catch( uno::Exception
& e
)
377 ASSERT_EXCEPTION( e
);
381 //-----------------------------------------------------------------------------
383 AxisLabelProperties::AxisLabelProperties()
384 : m_aFontReferenceSize( 8000, 7000 )
385 , m_aMaximumSpaceForLabels( 0 , 0, 8000, 7000 )
386 , nNumberFormatKey(0)
387 , eStaggering( SIDE_BY_SIDE
)
388 , bLineBreakAllowed( false )
389 , bOverlapAllowed( false )
390 , bStackCharacters( false )
391 , fRotationAngleDegree( 0.0 )
393 , bRhythmIsFix(false)
396 aLocale.Language = C2U( "en" );
397 aLocale.Country = C2U( "US" );
399 //aLocale.Language = C2U( "ar" );
400 //aLocale.Country = C2U( "IR" );
402 //aLocale.Language = C2U( "ja" );
403 //aLocale.Country = C2U( "JP" );
407 void AxisLabelProperties::init( const uno::Reference
< XAxis
>& xAxisModel
)
409 uno::Reference
< beans::XPropertySet
> xProp
=
410 uno::Reference
<beans::XPropertySet
>::query( xAxisModel
);
415 xProp
->getPropertyValue( C2U( "TextBreak" ) ) >>= this->bLineBreakAllowed
;
416 xProp
->getPropertyValue( C2U( "TextOverlap" ) ) >>= this->bOverlapAllowed
;
417 xProp
->getPropertyValue( C2U( "StackCharacters" ) ) >>= this->bStackCharacters
;
418 xProp
->getPropertyValue( C2U( "TextRotation" ) ) >>= this->fRotationAngleDegree
;
420 ::com::sun::star::chart::ChartAxisArrangeOrderType eArrangeOrder
;
421 xProp
->getPropertyValue( C2U( "ArrangeOrder" ) ) >>= eArrangeOrder
;
422 switch(eArrangeOrder
)
424 case ::com::sun::star::chart::ChartAxisArrangeOrderType_SIDE_BY_SIDE
:
425 this->eStaggering
= SIDE_BY_SIDE
;
427 case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_EVEN
:
428 this->eStaggering
= STAGGER_EVEN
;
430 case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_ODD
:
431 this->eStaggering
= STAGGER_ODD
;
434 this->eStaggering
= STAGGER_AUTO
;
438 catch( uno::Exception
& e
)
440 ASSERT_EXCEPTION( e
);
446 sal_Int16 getSwappedWritingMode( sal_Int16 nWritingMode )
449 //RL_TB == RT (Arabic, Hebrew)
450 //TB_RL == TR (Japanese, Chinese, Korean)
451 // ?? TL (Mongolian) see also text::WritingMode2
455 case text::WritingMode2::RL_TB:
456 return text::WritingMode2::TB_RL;
457 case text::WritingMode2::TB_RL:
458 return text::WritingMode2::RL_TB;
459 case text::WritingMode2::LR_TB:
460 return text::WritingMode2::TB_LR;
462 return text::WritingMode2::LR_TB;
467 sal_Bool
AxisLabelProperties::getIsStaggered() const
469 if( STAGGER_ODD
== eStaggering
|| STAGGER_EVEN
== eStaggering
)
474 //.............................................................................
476 //.............................................................................