1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "VAxisBase.hxx"
21 #include "ShapeFactory.hxx"
22 #include "CommonConverters.hxx"
23 #include "Tickmarks.hxx"
26 #include <boost/scoped_ptr.hpp>
30 using namespace ::com::sun::star
;
31 using namespace ::com::sun::star::chart2
;
32 using ::com::sun::star::uno::Reference
;
34 VAxisBase::VAxisBase( sal_Int32 nDimensionIndex
, sal_Int32 nDimensionCount
35 , const AxisProperties
& rAxisProperties
36 , const uno::Reference
< util::XNumberFormatsSupplier
>& xNumberFormatsSupplier
)
37 : VAxisOrGridBase( nDimensionIndex
, nDimensionCount
)
38 , m_xNumberFormatsSupplier( xNumberFormatsSupplier
)
39 , m_aAxisProperties( rAxisProperties
)
40 , m_bUseTextLabels( false )
41 , m_bReCreateAllTickInfos( true )
42 , m_bRecordMaximumTextSize(false)
43 , m_nMaximumTextWidthSoFar(0)
44 , m_nMaximumTextHeightSoFar(0)
48 VAxisBase::~VAxisBase()
52 void VAxisBase::initAxisLabelProperties( const ::com::sun::star::awt::Size
& rFontReferenceSize
53 , const ::com::sun::star::awt::Rectangle
& rMaximumSpaceForLabels
)
55 m_aAxisLabelProperties
.m_aFontReferenceSize
= rFontReferenceSize
;
56 m_aAxisLabelProperties
.m_aMaximumSpaceForLabels
= rMaximumSpaceForLabels
;
58 if( !m_aAxisProperties
.m_bDisplayLabels
)
61 if( AxisType::SERIES
==m_aAxisProperties
.m_nAxisType
)
63 if( m_aAxisProperties
.m_xAxisTextProvider
.is() )
64 m_aTextLabels
= m_aAxisProperties
.m_xAxisTextProvider
->getTextualData();
66 m_bUseTextLabels
= true;
67 if( m_aTextLabels
.getLength() == 1 )
69 //don't show a single series name
70 m_aAxisProperties
.m_bDisplayLabels
= false;
74 else if( AxisType::CATEGORY
==m_aAxisProperties
.m_nAxisType
)
76 if( m_aAxisProperties
.m_pExplicitCategoriesProvider
)
77 m_aTextLabels
= m_aAxisProperties
.m_pExplicitCategoriesProvider
->getSimpleCategories();
79 m_bUseTextLabels
= true;
82 m_aAxisLabelProperties
.nNumberFormatKey
= m_aAxisProperties
.m_nNumberFormatKey
;
83 m_aAxisLabelProperties
.init(m_aAxisProperties
.m_xAxisModel
);
84 if( m_aAxisProperties
.m_bComplexCategories
&& AxisType::CATEGORY
== m_aAxisProperties
.m_nAxisType
)
85 m_aAxisLabelProperties
.eStaggering
= SIDE_BY_SIDE
;
88 bool VAxisBase::isDateAxis() const
90 return AxisType::DATE
== m_aScale
.AxisType
;
92 bool VAxisBase::isComplexCategoryAxis() const
94 return m_aAxisProperties
.m_bComplexCategories
&& m_bUseTextLabels
;
97 void VAxisBase::recordMaximumTextSize( const Reference
< drawing::XShape
>& xShape
, double fRotationAngleDegree
)
99 if( m_bRecordMaximumTextSize
&& xShape
.is() )
101 awt::Size
aSize( ShapeFactory::getSizeAfterRotation(
102 xShape
, fRotationAngleDegree
) );
104 m_nMaximumTextWidthSoFar
= std::max( m_nMaximumTextWidthSoFar
, aSize
.Width
);
105 m_nMaximumTextHeightSoFar
= std::max( m_nMaximumTextHeightSoFar
, aSize
.Height
);
109 sal_Int32
VAxisBase::estimateMaximumAutoMainIncrementCount()
114 void VAxisBase::setExtraLinePositionAtOtherAxis( double fCrossingAt
)
116 m_aAxisProperties
.m_pfExrtaLinePositionAtOtherAxis
.reset(fCrossingAt
);
119 sal_Int32
VAxisBase::getDimensionCount() const
124 bool VAxisBase::isAnythingToDraw()
126 if( !m_aAxisProperties
.m_xAxisModel
.is() )
129 OSL_ENSURE(m_pShapeFactory
&&m_xLogicTarget
.is()&&m_xFinalTarget
.is(),"Axis is not proper initialized");
130 if(!(m_pShapeFactory
&&m_xLogicTarget
.is()&&m_xFinalTarget
.is()))
133 uno::Reference
< beans::XPropertySet
> xProps( m_aAxisProperties
.m_xAxisModel
, uno::UNO_QUERY
);
137 xProps
->getPropertyValue( "Show" ) >>= bShow
;
144 void VAxisBase::setExplicitScaleAndIncrement(
145 const ExplicitScaleData
& rScale
146 , const ExplicitIncrementData
& rIncrement
)
147 throw (uno::RuntimeException
)
149 m_bReCreateAllTickInfos
= true;
151 m_aIncrement
= rIncrement
;
154 void VAxisBase::createAllTickInfos( TickInfoArraysType
& rAllTickInfos
)
156 boost::scoped_ptr
< TickFactory
> apTickFactory( this->createTickFactory() );
157 if( m_aScale
.ShiftedCategoryPosition
)
158 apTickFactory
->getAllTicksShifted( rAllTickInfos
);
160 apTickFactory
->getAllTicks( rAllTickInfos
);
163 bool VAxisBase::prepareShapeCreation()
165 //returns true if all is ready for further shape creation and any shapes need to be created
166 if( !isAnythingToDraw() )
169 if( m_bReCreateAllTickInfos
)
171 //create all scaled tickmark values
172 removeTextShapesFromTicks();
174 createAllTickInfos(m_aAllTickInfos
);
175 m_bReCreateAllTickInfos
= false;
178 if( m_xGroupShape_Shapes
.is() )
181 //create named group shape
182 m_xGroupShape_Shapes
= this->createGroupShape( m_xLogicTarget
, m_nDimension
==2 ? m_aCID
: "");
184 if( m_aAxisProperties
.m_bDisplayLabels
)
185 m_xTextTarget
= m_pShapeFactory
->createGroup2D( m_xFinalTarget
, m_aCID
);
190 size_t VAxisBase::getIndexOfLongestLabel( const uno::Sequence
<OUString
>& rLabels
)
193 sal_Int32 nLength
= 0;
195 for( nN
=0; nN
<rLabels
.getLength(); nN
++ )
197 //todo: get real text width (without creating shape) instead of character count
198 if( rLabels
[nN
].getLength() > nLength
)
200 nLength
= rLabels
[nN
].getLength();
209 void VAxisBase::removeTextShapesFromTicks()
211 if( m_xTextTarget
.is() )
213 TickInfoArraysType::iterator aDepthIter
= m_aAllTickInfos
.begin();
214 const TickInfoArraysType::const_iterator aDepthEnd
= m_aAllTickInfos
.end();
215 for( ; aDepthIter
!= aDepthEnd
; ++aDepthIter
)
217 TickInfoArrayType::iterator aTickIter
= (*aDepthIter
).begin();
218 const TickInfoArrayType::const_iterator aTickEnd
= (*aDepthIter
).end();
219 for( ; aTickIter
!= aTickEnd
; ++aTickIter
)
221 TickInfo
& rTickInfo
= (*aTickIter
);
222 if(rTickInfo
.xTextShape
.is())
224 m_xTextTarget
->remove(rTickInfo
.xTextShape
);
225 rTickInfo
.xTextShape
= NULL
;
232 void VAxisBase::updateUnscaledValuesAtTicks( TickIter
& rIter
)
234 Reference
< XScaling
> xInverseScaling( NULL
);
235 if( m_aScale
.Scaling
.is() )
236 xInverseScaling
= m_aScale
.Scaling
->getInverseScaling();
238 for( TickInfo
* pTickInfo
= rIter
.firstInfo()
239 ; pTickInfo
; pTickInfo
= rIter
.nextInfo() )
241 //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */