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