xref: /trunk/main/chart2/source/view/axes/VAxisBase.cxx (revision cde9e8dc)
1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cde9e8dcSAndrew Rist  * distributed with this work for additional information
6*cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist  *
11*cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist  *
13*cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist  * under the License.
19*cde9e8dcSAndrew Rist  *
20*cde9e8dcSAndrew Rist  *************************************************************/
21*cde9e8dcSAndrew Rist 
22*cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "VAxisBase.hxx"
28cdf0e10cSrcweir #include "ShapeFactory.hxx"
29cdf0e10cSrcweir #include "CommonConverters.hxx"
30cdf0e10cSrcweir #include "Tickmarks.hxx"
31cdf0e10cSrcweir #include "macros.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // header for define DBG_ASSERT
34cdf0e10cSrcweir #include <tools/debug.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <memory>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //.............................................................................
39cdf0e10cSrcweir namespace chart
40cdf0e10cSrcweir {
41cdf0e10cSrcweir //.............................................................................
42cdf0e10cSrcweir using namespace ::com::sun::star;
43cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
44cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
45cdf0e10cSrcweir 
VAxisBase(sal_Int32 nDimensionIndex,sal_Int32 nDimensionCount,const AxisProperties & rAxisProperties,const uno::Reference<util::XNumberFormatsSupplier> & xNumberFormatsSupplier)46cdf0e10cSrcweir VAxisBase::VAxisBase( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount
47cdf0e10cSrcweir                      , const AxisProperties& rAxisProperties
48cdf0e10cSrcweir                      , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier )
49cdf0e10cSrcweir             : VAxisOrGridBase( nDimensionIndex, nDimensionCount )
50cdf0e10cSrcweir             , m_xNumberFormatsSupplier( xNumberFormatsSupplier )
51cdf0e10cSrcweir             , m_aAxisProperties( rAxisProperties )
52cdf0e10cSrcweir             , m_bUseTextLabels( false )
53cdf0e10cSrcweir             , m_bReCreateAllTickInfos( true )
54cdf0e10cSrcweir             , m_bRecordMaximumTextSize(false)
55cdf0e10cSrcweir             , m_nMaximumTextWidthSoFar(0)
56cdf0e10cSrcweir             , m_nMaximumTextHeightSoFar(0)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
~VAxisBase()60cdf0e10cSrcweir VAxisBase::~VAxisBase()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
getDimensionCount()64cdf0e10cSrcweir sal_Int32 VAxisBase::getDimensionCount()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     return m_nDimension;
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
initAxisLabelProperties(const::com::sun::star::awt::Size & rFontReferenceSize,const::com::sun::star::awt::Rectangle & rMaximumSpaceForLabels)69cdf0e10cSrcweir void VAxisBase::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize
70cdf0e10cSrcweir                   , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     m_aAxisLabelProperties.m_aFontReferenceSize = rFontReferenceSize;
73cdf0e10cSrcweir     m_aAxisLabelProperties.m_aMaximumSpaceForLabels = rMaximumSpaceForLabels;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     if( !m_aAxisProperties.m_bDisplayLabels )
76cdf0e10cSrcweir         return;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     if( AxisType::SERIES==m_aAxisProperties.m_nAxisType )
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir         if( m_aAxisProperties.m_xAxisTextProvider.is() )
81cdf0e10cSrcweir             m_aTextLabels = m_aAxisProperties.m_xAxisTextProvider->getTextualData();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         m_bUseTextLabels = true;
84cdf0e10cSrcweir         if( m_aTextLabels.getLength() == 1 )
85cdf0e10cSrcweir         {
86cdf0e10cSrcweir             //don't show a single series name
87cdf0e10cSrcweir             m_aAxisProperties.m_bDisplayLabels = false;
88cdf0e10cSrcweir             return;
89cdf0e10cSrcweir         }
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir     else if( AxisType::CATEGORY==m_aAxisProperties.m_nAxisType )
92cdf0e10cSrcweir     {
93cdf0e10cSrcweir         if( m_aAxisProperties.m_pExplicitCategoriesProvider )
94cdf0e10cSrcweir             m_aTextLabels = m_aAxisProperties.m_pExplicitCategoriesProvider->getSimpleCategories();
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         m_bUseTextLabels = true;
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     m_aAxisLabelProperties.nNumberFormatKey = m_aAxisProperties.m_nNumberFormatKey;
100cdf0e10cSrcweir     m_aAxisLabelProperties.init(m_aAxisProperties.m_xAxisModel);
101cdf0e10cSrcweir     if( m_aAxisProperties.m_bComplexCategories && AxisType::CATEGORY == m_aAxisProperties.m_nAxisType )
102cdf0e10cSrcweir         m_aAxisLabelProperties.eStaggering = SIDE_BY_SIDE;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
isDateAxis() const105cdf0e10cSrcweir bool VAxisBase::isDateAxis() const
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     return AxisType::DATE == m_aScale.AxisType;
108cdf0e10cSrcweir }
isComplexCategoryAxis() const109cdf0e10cSrcweir bool VAxisBase::isComplexCategoryAxis() const
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     return m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
recordMaximumTextSize(const Reference<drawing::XShape> & xShape,double fRotationAngleDegree)114cdf0e10cSrcweir void VAxisBase::recordMaximumTextSize( const Reference< drawing::XShape >& xShape, double fRotationAngleDegree )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     if( m_bRecordMaximumTextSize && xShape.is() )
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         awt::Size aSize( ShapeFactory::getSizeAfterRotation(
119cdf0e10cSrcweir                             xShape, fRotationAngleDegree ) );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         m_nMaximumTextWidthSoFar = std::max( m_nMaximumTextWidthSoFar, aSize.Width );
122cdf0e10cSrcweir         m_nMaximumTextHeightSoFar = std::max( m_nMaximumTextHeightSoFar, aSize.Height );
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
estimateMaximumAutoMainIncrementCount()126cdf0e10cSrcweir sal_Int32 VAxisBase::estimateMaximumAutoMainIncrementCount()
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     return 10;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
setExrtaLinePositionAtOtherAxis(const double & fCrossingAt)131cdf0e10cSrcweir void VAxisBase::setExrtaLinePositionAtOtherAxis( const double& fCrossingAt )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     if( m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis )
134cdf0e10cSrcweir         delete m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis;
135cdf0e10cSrcweir     m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis = new double(fCrossingAt);
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
isAnythingToDraw()138cdf0e10cSrcweir sal_Bool VAxisBase::isAnythingToDraw()
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     if( !m_aAxisProperties.m_xAxisModel.is() )
141cdf0e10cSrcweir         return false;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     DBG_ASSERT(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"Axis is not proper initialized");
144cdf0e10cSrcweir     if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
145cdf0e10cSrcweir         return false;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps( m_aAxisProperties.m_xAxisModel, uno::UNO_QUERY );
148cdf0e10cSrcweir     if( xProps.is() )
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         sal_Bool bShow = sal_False;
151cdf0e10cSrcweir         xProps->getPropertyValue( C2U( "Show" ) ) >>= bShow;
152cdf0e10cSrcweir         if( !bShow )
153cdf0e10cSrcweir             return false;
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir     return true;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
setExplicitScaleAndIncrement(const ExplicitScaleData & rScale,const ExplicitIncrementData & rIncrement)158cdf0e10cSrcweir void VAxisBase::setExplicitScaleAndIncrement(
159cdf0e10cSrcweir               const ExplicitScaleData& rScale
160cdf0e10cSrcweir             , const ExplicitIncrementData& rIncrement )
161cdf0e10cSrcweir             throw (uno::RuntimeException)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     m_bReCreateAllTickInfos = true;
164cdf0e10cSrcweir     m_aScale = rScale;
165cdf0e10cSrcweir     m_aIncrement = rIncrement;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
createAllTickInfos(::std::vector<::std::vector<TickInfo>> & rAllTickInfos)168cdf0e10cSrcweir void VAxisBase::createAllTickInfos( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     std::auto_ptr< TickFactory > apTickFactory( this->createTickFactory() );
171cdf0e10cSrcweir     if( m_aScale.ShiftedCategoryPosition )
172cdf0e10cSrcweir         apTickFactory->getAllTicksShifted( rAllTickInfos );
173cdf0e10cSrcweir     else
174cdf0e10cSrcweir         apTickFactory->getAllTicks( rAllTickInfos );
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
prepareShapeCreation()177cdf0e10cSrcweir bool VAxisBase::prepareShapeCreation()
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     //returns true if all is ready for further shape creation and any shapes need to be created
180cdf0e10cSrcweir     if( !isAnythingToDraw() )
181cdf0e10cSrcweir         return false;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     if( m_bReCreateAllTickInfos )
184cdf0e10cSrcweir     {
185cdf0e10cSrcweir         //-----------------------------------------
186cdf0e10cSrcweir         //create all scaled tickmark values
187cdf0e10cSrcweir         removeTextShapesFromTicks();
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         createAllTickInfos(m_aAllTickInfos);
190cdf0e10cSrcweir         m_bReCreateAllTickInfos = false;
191cdf0e10cSrcweir     }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     if( m_xGroupShape_Shapes.is() )
194cdf0e10cSrcweir         return true;
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     //-----------------------------------------
197cdf0e10cSrcweir     //create named group shape
198cdf0e10cSrcweir     m_xGroupShape_Shapes = this->createGroupShape( m_xLogicTarget, m_nDimension==2 ? m_aCID : C2U(""));
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     if( m_aAxisProperties.m_bDisplayLabels )
201cdf0e10cSrcweir         m_xTextTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget, m_aCID );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     return true;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
getIndexOfLongestLabel(const uno::Sequence<rtl::OUString> & rLabels)206cdf0e10cSrcweir sal_Int32 VAxisBase::getIndexOfLongestLabel( const uno::Sequence< rtl::OUString >& rLabels )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     sal_Int32 nRet = 0;
209cdf0e10cSrcweir     sal_Int32 nLength = 0;
210cdf0e10cSrcweir     sal_Int32 nN = 0;
211cdf0e10cSrcweir     for( nN=0; nN<rLabels.getLength(); nN++ )
212cdf0e10cSrcweir     {
213cdf0e10cSrcweir         //todo: get real text width (without creating shape) instead of character count
214cdf0e10cSrcweir         if( rLabels[nN].getLength() > nLength )
215cdf0e10cSrcweir         {
216cdf0e10cSrcweir             nLength = rLabels[nN].getLength();
217cdf0e10cSrcweir             nRet = nN;
218cdf0e10cSrcweir         }
219cdf0e10cSrcweir     }
220cdf0e10cSrcweir     return nRet;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
removeTextShapesFromTicks()223cdf0e10cSrcweir void VAxisBase::removeTextShapesFromTicks()
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     if( m_xTextTarget.is() )
226cdf0e10cSrcweir     {
227cdf0e10cSrcweir        ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = m_aAllTickInfos.begin();
228cdf0e10cSrcweir         const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd  = m_aAllTickInfos.end();
229cdf0e10cSrcweir         for( ; aDepthIter != aDepthEnd; aDepthIter++ )
230cdf0e10cSrcweir         {
231cdf0e10cSrcweir             ::std::vector< TickInfo >::iterator       aTickIter = (*aDepthIter).begin();
232cdf0e10cSrcweir             const ::std::vector< TickInfo >::const_iterator aTickEnd  = (*aDepthIter).end();
233cdf0e10cSrcweir             for( ; aTickIter != aTickEnd; aTickIter++ )
234cdf0e10cSrcweir             {
235cdf0e10cSrcweir                 TickInfo& rTickInfo = (*aTickIter);
236cdf0e10cSrcweir                 if(rTickInfo.xTextShape.is())
237cdf0e10cSrcweir                 {
238cdf0e10cSrcweir                     m_xTextTarget->remove(rTickInfo.xTextShape);
239cdf0e10cSrcweir                     rTickInfo.xTextShape = NULL;
240cdf0e10cSrcweir                 }
241cdf0e10cSrcweir             }
242cdf0e10cSrcweir         }
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
updateUnscaledValuesAtTicks(TickIter & rIter)246cdf0e10cSrcweir void VAxisBase::updateUnscaledValuesAtTicks( TickIter& rIter )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir     Reference< XScaling > xInverseScaling( NULL );
249cdf0e10cSrcweir     if( m_aScale.Scaling.is() )
250cdf0e10cSrcweir         xInverseScaling = m_aScale.Scaling->getInverseScaling();
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     for( TickInfo* pTickInfo = rIter.firstInfo()
253cdf0e10cSrcweir         ; pTickInfo; pTickInfo = rIter.nextInfo() )
254cdf0e10cSrcweir     {
255cdf0e10cSrcweir         //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
256cdf0e10cSrcweir     }
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir //.............................................................................
260cdf0e10cSrcweir } //namespace chart
261cdf0e10cSrcweir //.............................................................................
262