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 "Tickmarks_Equidistant.hxx"
21 : #include "ViewDefines.hxx"
22 : #include <rtl/math.hxx>
23 :
24 : #include <limits>
25 : #include <memory>
26 :
27 : //.............................................................................
28 : namespace chart
29 : {
30 : //.............................................................................
31 : using namespace ::com::sun::star;
32 : using namespace ::com::sun::star::chart2;
33 : using namespace ::rtl::math;
34 : using ::basegfx::B2DVector;
35 :
36 : //static
37 1222 : double EquidistantTickFactory::getMinimumAtIncrement( double fMin, const ExplicitIncrementData& rIncrement )
38 : {
39 : //the returned value will be <= fMin and on a Major Tick given by rIncrement
40 1222 : if(rIncrement.Distance<=0.0)
41 0 : return fMin;
42 :
43 : double fRet = rIncrement.BaseValue +
44 1222 : floor( approxSub( fMin, rIncrement.BaseValue )
45 1222 : / rIncrement.Distance)
46 2444 : *rIncrement.Distance;
47 :
48 1222 : if( fRet > fMin )
49 : {
50 0 : if( !approxEqual(fRet, fMin) )
51 0 : fRet -= rIncrement.Distance;
52 : }
53 1222 : return fRet;
54 : }
55 : //static
56 1222 : double EquidistantTickFactory::getMaximumAtIncrement( double fMax, const ExplicitIncrementData& rIncrement )
57 : {
58 : //the returned value will be >= fMax and on a Major Tick given by rIncrement
59 1222 : if(rIncrement.Distance<=0.0)
60 0 : return fMax;
61 :
62 : double fRet = rIncrement.BaseValue +
63 1222 : floor( approxSub( fMax, rIncrement.BaseValue )
64 1222 : / rIncrement.Distance)
65 2444 : *rIncrement.Distance;
66 :
67 1222 : if( fRet < fMax )
68 : {
69 648 : if( !approxEqual(fRet, fMax) )
70 648 : fRet += rIncrement.Distance;
71 : }
72 1222 : return fRet;
73 : }
74 :
75 738 : EquidistantTickFactory::EquidistantTickFactory(
76 : const ExplicitScaleData& rScale, const ExplicitIncrementData& rIncrement )
77 : : m_rScale( rScale )
78 : , m_rIncrement( rIncrement )
79 : , m_xInverseScaling(NULL)
80 738 : , m_pfCurrentValues(NULL)
81 : {
82 : //@todo: make sure that the scale is valid for the scaling
83 :
84 738 : m_pfCurrentValues = new double[getTickDepth()];
85 :
86 738 : if( m_rScale.Scaling.is() )
87 : {
88 246 : m_xInverseScaling = m_rScale.Scaling->getInverseScaling();
89 : OSL_ENSURE( m_xInverseScaling.is(), "each Scaling needs to return a inverse Scaling" );
90 : }
91 :
92 738 : double fMin = m_fScaledVisibleMin = m_rScale.Minimum;
93 738 : if( m_xInverseScaling.is() )
94 : {
95 246 : m_fScaledVisibleMin = m_rScale.Scaling->doScaling(m_fScaledVisibleMin);
96 246 : if(m_rIncrement.PostEquidistant )
97 246 : fMin = m_fScaledVisibleMin;
98 : }
99 :
100 738 : double fMax = m_fScaledVisibleMax = m_rScale.Maximum;
101 738 : if( m_xInverseScaling.is() )
102 : {
103 246 : m_fScaledVisibleMax = m_rScale.Scaling->doScaling(m_fScaledVisibleMax);
104 246 : if(m_rIncrement.PostEquidistant )
105 246 : fMax = m_fScaledVisibleMax;
106 : }
107 :
108 : //--
109 738 : m_fOuterMajorTickBorderMin = EquidistantTickFactory::getMinimumAtIncrement( fMin, m_rIncrement );
110 738 : m_fOuterMajorTickBorderMax = EquidistantTickFactory::getMaximumAtIncrement( fMax, m_rIncrement );
111 : //--
112 :
113 738 : m_fOuterMajorTickBorderMin_Scaled = m_fOuterMajorTickBorderMin;
114 738 : m_fOuterMajorTickBorderMax_Scaled = m_fOuterMajorTickBorderMax;
115 738 : if(!m_rIncrement.PostEquidistant && m_xInverseScaling.is() )
116 : {
117 0 : m_fOuterMajorTickBorderMin_Scaled = m_rScale.Scaling->doScaling(m_fOuterMajorTickBorderMin);
118 0 : m_fOuterMajorTickBorderMax_Scaled = m_rScale.Scaling->doScaling(m_fOuterMajorTickBorderMax);
119 :
120 : //check validity of new range: m_fOuterMajorTickBorderMin <-> m_fOuterMajorTickBorderMax
121 : //it is assumed here, that the original range in the given Scale is valid
122 0 : if( !rtl::math::isFinite(m_fOuterMajorTickBorderMin_Scaled) )
123 : {
124 0 : m_fOuterMajorTickBorderMin += m_rIncrement.Distance;
125 0 : m_fOuterMajorTickBorderMin_Scaled = m_rScale.Scaling->doScaling(m_fOuterMajorTickBorderMin);
126 : }
127 0 : if( !rtl::math::isFinite(m_fOuterMajorTickBorderMax_Scaled) )
128 : {
129 0 : m_fOuterMajorTickBorderMax -= m_rIncrement.Distance;
130 0 : m_fOuterMajorTickBorderMax_Scaled = m_rScale.Scaling->doScaling(m_fOuterMajorTickBorderMax);
131 : }
132 : }
133 738 : }
134 :
135 1476 : EquidistantTickFactory::~EquidistantTickFactory()
136 : {
137 738 : delete[] m_pfCurrentValues;
138 738 : }
139 :
140 2460 : sal_Int32 EquidistantTickFactory::getTickDepth() const
141 : {
142 2460 : return static_cast<sal_Int32>(m_rIncrement.SubIncrements.size()) + 1;
143 : }
144 :
145 574 : void EquidistantTickFactory::addSubTicks( sal_Int32 nDepth, uno::Sequence< uno::Sequence< double > >& rParentTicks ) const
146 : {
147 574 : EquidistantTickIter aIter( rParentTicks, m_rIncrement, 0, nDepth-1 );
148 574 : double* pfNextParentTick = aIter.firstValue();
149 574 : if(!pfNextParentTick)
150 : return;
151 574 : double fLastParentTick = *pfNextParentTick;
152 574 : pfNextParentTick = aIter.nextValue();
153 574 : if(!pfNextParentTick)
154 : return;
155 :
156 574 : sal_Int32 nMaxSubTickCount = this->getMaxTickCount( nDepth );
157 574 : if(!nMaxSubTickCount)
158 : return;
159 :
160 574 : uno::Sequence< double > aSubTicks(nMaxSubTickCount);
161 574 : sal_Int32 nRealSubTickCount = 0;
162 574 : sal_Int32 nIntervalCount = m_rIncrement.SubIncrements[nDepth-1].IntervalCount;
163 :
164 574 : double* pValue = NULL;
165 3526 : for(; pfNextParentTick; fLastParentTick=*pfNextParentTick, pfNextParentTick = aIter.nextValue())
166 : {
167 5904 : for( sal_Int32 nPartTick = 1; nPartTick<nIntervalCount; nPartTick++ )
168 : {
169 : pValue = this->getMinorTick( nPartTick, nDepth
170 2952 : , fLastParentTick, *pfNextParentTick );
171 2952 : if(!pValue)
172 0 : continue;
173 :
174 2952 : aSubTicks[nRealSubTickCount] = *pValue;
175 2952 : nRealSubTickCount++;
176 : }
177 : }
178 :
179 574 : aSubTicks.realloc(nRealSubTickCount);
180 574 : rParentTicks[nDepth] = aSubTicks;
181 574 : if(static_cast<sal_Int32>(m_rIncrement.SubIncrements.size())>nDepth)
182 0 : addSubTicks( nDepth+1, rParentTicks );
183 : }
184 :
185 :
186 1148 : sal_Int32 EquidistantTickFactory::getMaxTickCount( sal_Int32 nDepth ) const
187 : {
188 : //return the maximum amount of ticks
189 : //possibly open intervals at the two ends of the region are handled as if they were completely visible
190 : //(this is necessary for calculating the sub ticks at the borders correctly)
191 :
192 1148 : if( nDepth >= getTickDepth() )
193 0 : return 0;
194 1148 : if( m_fOuterMajorTickBorderMax < m_fOuterMajorTickBorderMin )
195 0 : return 0;
196 1148 : if( m_rIncrement.Distance<=0.0)
197 0 : return 0;
198 :
199 : double fSub;
200 1148 : if(m_rIncrement.PostEquidistant )
201 1148 : fSub = approxSub( m_fScaledVisibleMax, m_fScaledVisibleMin );
202 : else
203 0 : fSub = approxSub( m_rScale.Maximum, m_rScale.Minimum );
204 :
205 1148 : if (!isFinite(fSub))
206 0 : return 0;
207 :
208 1148 : double fIntervalCount = fSub / m_rIncrement.Distance;
209 1148 : if (fIntervalCount > std::numeric_limits<sal_Int32>::max())
210 : // Interval count too high! Bail out.
211 0 : return 0;
212 :
213 1148 : sal_Int32 nIntervalCount = static_cast<sal_Int32>(fIntervalCount);
214 :
215 1148 : nIntervalCount+=3;
216 1148 : for(sal_Int32 nN=0; nN<nDepth-1; nN++)
217 : {
218 0 : if( m_rIncrement.SubIncrements[nN].IntervalCount>1 )
219 0 : nIntervalCount *= m_rIncrement.SubIncrements[nN].IntervalCount;
220 : }
221 :
222 1148 : sal_Int32 nTickCount = nIntervalCount;
223 1148 : if(nDepth>0 && m_rIncrement.SubIncrements[nDepth-1].IntervalCount>1)
224 574 : nTickCount = nIntervalCount * (m_rIncrement.SubIncrements[nDepth-1].IntervalCount-1);
225 :
226 1148 : return nTickCount;
227 : }
228 :
229 4510 : double* EquidistantTickFactory::getMajorTick( sal_Int32 nTick ) const
230 : {
231 4510 : m_pfCurrentValues[0] = m_fOuterMajorTickBorderMin + nTick*m_rIncrement.Distance;
232 :
233 4510 : if(m_pfCurrentValues[0]>m_fOuterMajorTickBorderMax)
234 : {
235 984 : if( !approxEqual(m_pfCurrentValues[0],m_fOuterMajorTickBorderMax) )
236 984 : return NULL;
237 : }
238 3526 : if(m_pfCurrentValues[0]<m_fOuterMajorTickBorderMin)
239 : {
240 0 : if( !approxEqual(m_pfCurrentValues[0],m_fOuterMajorTickBorderMin) )
241 0 : return NULL;
242 : }
243 :
244 : //return always the value after scaling
245 3526 : if(!m_rIncrement.PostEquidistant && m_xInverseScaling.is() )
246 0 : m_pfCurrentValues[0] = m_rScale.Scaling->doScaling( m_pfCurrentValues[0] );
247 :
248 3526 : return &m_pfCurrentValues[0];
249 : }
250 :
251 2952 : double* EquidistantTickFactory::getMinorTick( sal_Int32 nTick, sal_Int32 nDepth
252 : , double fStartParentTick, double fNextParentTick ) const
253 : {
254 : //check validity of arguments
255 : {
256 : //OSL_ENSURE( fStartParentTick < fNextParentTick, "fStartParentTick >= fNextParentTick");
257 2952 : if(fStartParentTick >= fNextParentTick)
258 0 : return NULL;
259 2952 : if(nDepth>static_cast<sal_Int32>(m_rIncrement.SubIncrements.size()) || nDepth<=0)
260 0 : return NULL;
261 :
262 : //subticks are only calculated if they are laying between parent ticks:
263 2952 : if(nTick<=0)
264 0 : return NULL;
265 2952 : if(nTick>=m_rIncrement.SubIncrements[nDepth-1].IntervalCount)
266 0 : return NULL;
267 : }
268 :
269 2952 : bool bPostEquidistant = m_rIncrement.SubIncrements[nDepth-1].PostEquidistant;
270 :
271 2952 : double fAdaptedStartParent = fStartParentTick;
272 2952 : double fAdaptedNextParent = fNextParentTick;
273 :
274 2952 : if( !bPostEquidistant && m_xInverseScaling.is() )
275 : {
276 1476 : fAdaptedStartParent = m_xInverseScaling->doScaling(fStartParentTick);
277 1476 : fAdaptedNextParent = m_xInverseScaling->doScaling(fNextParentTick);
278 : }
279 :
280 2952 : double fDistance = (fAdaptedNextParent - fAdaptedStartParent)/m_rIncrement.SubIncrements[nDepth-1].IntervalCount;
281 :
282 2952 : m_pfCurrentValues[nDepth] = fAdaptedStartParent + nTick*fDistance;
283 :
284 : //return always the value after scaling
285 2952 : if(!bPostEquidistant && m_xInverseScaling.is() )
286 1476 : m_pfCurrentValues[nDepth] = m_rScale.Scaling->doScaling( m_pfCurrentValues[nDepth] );
287 :
288 2952 : if( !isWithinOuterBorder( m_pfCurrentValues[nDepth] ) )
289 0 : return NULL;
290 :
291 2952 : return &m_pfCurrentValues[nDepth];
292 : }
293 :
294 2952 : bool EquidistantTickFactory::isWithinOuterBorder( double fScaledValue ) const
295 : {
296 2952 : if(fScaledValue>m_fOuterMajorTickBorderMax_Scaled)
297 0 : return false;
298 2952 : if(fScaledValue<m_fOuterMajorTickBorderMin_Scaled)
299 0 : return false;
300 :
301 2952 : return true;
302 : }
303 :
304 3444 : bool EquidistantTickFactory::isVisible( double fScaledValue ) const
305 : {
306 3444 : if(fScaledValue>m_fScaledVisibleMax)
307 : {
308 164 : if( !approxEqual(fScaledValue,m_fScaledVisibleMax) )
309 164 : return false;
310 : }
311 3280 : if(fScaledValue<m_fScaledVisibleMin)
312 : {
313 164 : if( !approxEqual(fScaledValue,m_fScaledVisibleMin) )
314 164 : return false;
315 : }
316 3116 : return true;
317 : }
318 :
319 574 : void EquidistantTickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const
320 : {
321 574 : uno::Sequence< uno::Sequence< double > > aAllTicks;
322 :
323 : //create point sequences for each tick depth
324 574 : sal_Int32 nDepthCount = this->getTickDepth();
325 574 : sal_Int32 nMaxMajorTickCount = this->getMaxTickCount( 0 );
326 :
327 574 : if (nDepthCount <= 0 || nMaxMajorTickCount <= 0)
328 : return;
329 :
330 574 : aAllTicks.realloc(nDepthCount);
331 574 : aAllTicks[0].realloc(nMaxMajorTickCount);
332 :
333 574 : sal_Int32 nRealMajorTickCount = 0;
334 574 : double* pValue = NULL;
335 5084 : for( sal_Int32 nMajorTick=0; nMajorTick<nMaxMajorTickCount; nMajorTick++ )
336 : {
337 4510 : pValue = this->getMajorTick( nMajorTick );
338 4510 : if(!pValue)
339 984 : continue;
340 3526 : aAllTicks[0][nRealMajorTickCount] = *pValue;
341 3526 : nRealMajorTickCount++;
342 : }
343 574 : if(!nRealMajorTickCount)
344 : return;
345 574 : aAllTicks[0].realloc(nRealMajorTickCount);
346 :
347 574 : if(nDepthCount>0)
348 574 : this->addSubTicks( 1, aAllTicks );
349 :
350 : //so far we have added all ticks between the outer major tick marks
351 : //this was necessary to create sub ticks correctly
352 : //now we reduce all ticks to the visible ones that lie between the real borders
353 574 : sal_Int32 nDepth = 0;
354 574 : sal_Int32 nTick = 0;
355 1722 : for( nDepth = 0; nDepth < nDepthCount; nDepth++)
356 : {
357 1148 : sal_Int32 nInvisibleAtLowerBorder = 0;
358 1148 : sal_Int32 nInvisibleAtUpperBorder = 0;
359 : //we need only to check all ticks within the first major interval at each border
360 1148 : sal_Int32 nCheckCount = 1;
361 1722 : for(sal_Int32 nN=0; nN<nDepth; nN++)
362 : {
363 574 : if( m_rIncrement.SubIncrements[nN].IntervalCount>1 )
364 574 : nCheckCount *= m_rIncrement.SubIncrements[nN].IntervalCount;
365 : }
366 1148 : uno::Sequence< double >& rTicks = aAllTicks[nDepth];
367 1148 : sal_Int32 nCount = rTicks.getLength();
368 : //check lower border
369 2870 : for( nTick=0; nTick<nCheckCount && nTick<nCount; nTick++)
370 : {
371 1722 : if( !isVisible( rTicks[nTick] ) )
372 164 : nInvisibleAtLowerBorder++;
373 : }
374 : //check upper border
375 2870 : for( nTick=nCount-1; nTick>nCount-1-nCheckCount && nTick>=0; nTick--)
376 : {
377 1722 : if( !isVisible( rTicks[nTick] ) )
378 164 : nInvisibleAtUpperBorder++;
379 : }
380 : //resize sequence
381 1148 : if( !nInvisibleAtLowerBorder && !nInvisibleAtUpperBorder)
382 984 : continue;
383 164 : if( !nInvisibleAtLowerBorder )
384 0 : rTicks.realloc(nCount-nInvisibleAtUpperBorder);
385 : else
386 : {
387 164 : sal_Int32 nNewCount = nCount-nInvisibleAtUpperBorder-nInvisibleAtLowerBorder;
388 164 : if(nNewCount<0)
389 0 : nNewCount=0;
390 :
391 164 : uno::Sequence< double > aOldTicks(rTicks);
392 164 : rTicks.realloc(nNewCount);
393 820 : for(nTick = 0; nTick<nNewCount; nTick++)
394 820 : rTicks[nTick] = aOldTicks[nInvisibleAtLowerBorder+nTick];
395 : }
396 : }
397 :
398 : //fill return value
399 574 : rAllTickInfos.resize(aAllTicks.getLength());
400 1722 : for( nDepth=0 ;nDepth<aAllTicks.getLength(); nDepth++ )
401 : {
402 1148 : sal_Int32 nCount = aAllTicks[nDepth].getLength();
403 :
404 1148 : ::std::vector< TickInfo >& rTickInfoVector = rAllTickInfos[nDepth];
405 1148 : rTickInfoVector.clear();
406 1148 : rTickInfoVector.reserve( nCount );
407 7298 : for(sal_Int32 nN = 0; nN<nCount; nN++)
408 : {
409 6150 : TickInfo aTickInfo(m_xInverseScaling);
410 6150 : aTickInfo.fScaledTickValue = aAllTicks[nDepth][nN];
411 6150 : rTickInfoVector.push_back(aTickInfo);
412 6150 : }
413 574 : }
414 : }
415 :
416 164 : void EquidistantTickFactory::getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const
417 : {
418 164 : ExplicitIncrementData aShiftedIncrement( m_rIncrement );
419 164 : aShiftedIncrement.BaseValue = m_rIncrement.BaseValue-m_rIncrement.Distance/2.0;
420 164 : EquidistantTickFactory( m_rScale, aShiftedIncrement ).getAllTicks(rAllTickInfos);
421 164 : }
422 :
423 : //-----------------------------------------------------------------------------
424 : //-----------------------------------------------------------------------------
425 : //-----------------------------------------------------------------------------
426 :
427 574 : EquidistantTickIter::EquidistantTickIter( const uno::Sequence< uno::Sequence< double > >& rTicks
428 : , const ExplicitIncrementData& rIncrement
429 : , sal_Int32 nMinDepth, sal_Int32 nMaxDepth )
430 : : m_pSimpleTicks(&rTicks)
431 : , m_pInfoTicks(0)
432 : , m_rIncrement(rIncrement)
433 : , m_nMaxDepth(0)
434 : , m_nTickCount(0), m_pnPositions(NULL)
435 : , m_pnPreParentCount(NULL), m_pbIntervalFinished(NULL)
436 574 : , m_nCurrentDepth(-1), m_nCurrentPos(-1), m_fCurrentValue( 0.0 )
437 : {
438 574 : initIter( nMinDepth, nMaxDepth );
439 574 : }
440 :
441 246 : EquidistantTickIter::EquidistantTickIter( ::std::vector< ::std::vector< TickInfo > >& rTicks
442 : , const ExplicitIncrementData& rIncrement
443 : , sal_Int32 nMinDepth, sal_Int32 nMaxDepth )
444 : : m_pSimpleTicks(NULL)
445 : , m_pInfoTicks(&rTicks)
446 : , m_rIncrement(rIncrement)
447 : , m_nMaxDepth(0)
448 : , m_nTickCount(0), m_pnPositions(NULL)
449 : , m_pnPreParentCount(NULL), m_pbIntervalFinished(NULL)
450 246 : , m_nCurrentDepth(-1), m_nCurrentPos(-1), m_fCurrentValue( 0.0 )
451 : {
452 246 : initIter( nMinDepth, nMaxDepth );
453 246 : }
454 :
455 820 : void EquidistantTickIter::initIter( sal_Int32 /*nMinDepth*/, sal_Int32 nMaxDepth )
456 : {
457 820 : m_nMaxDepth = nMaxDepth;
458 820 : if(nMaxDepth<0 || m_nMaxDepth>getMaxDepth())
459 246 : m_nMaxDepth=getMaxDepth();
460 :
461 820 : sal_Int32 nDepth = 0;
462 1886 : for( nDepth = 0; nDepth<=m_nMaxDepth ;nDepth++ )
463 1066 : m_nTickCount += getTickCount(nDepth);
464 :
465 820 : if(!m_nTickCount)
466 820 : return;
467 :
468 820 : m_pnPositions = new sal_Int32[m_nMaxDepth+1];
469 :
470 820 : m_pnPreParentCount = new sal_Int32[m_nMaxDepth+1];
471 820 : m_pbIntervalFinished = new bool[m_nMaxDepth+1];
472 820 : m_pnPreParentCount[0] = 0;
473 820 : m_pbIntervalFinished[0] = false;
474 820 : double fParentValue = getTickValue(0,0);
475 1066 : for( nDepth = 1; nDepth<=m_nMaxDepth ;nDepth++ )
476 : {
477 246 : m_pbIntervalFinished[nDepth] = false;
478 :
479 246 : sal_Int32 nPreParentCount = 0;
480 246 : sal_Int32 nCount = getTickCount(nDepth);
481 656 : for(sal_Int32 nN = 0; nN<nCount; nN++)
482 : {
483 328 : if(getTickValue(nDepth,nN) < fParentValue)
484 82 : nPreParentCount++;
485 : else
486 246 : break;
487 : }
488 246 : m_pnPreParentCount[nDepth] = nPreParentCount;
489 246 : if(nCount)
490 : {
491 246 : double fNextParentValue = getTickValue(nDepth,0);
492 246 : if( fNextParentValue < fParentValue )
493 82 : fParentValue = fNextParentValue;
494 : }
495 : }
496 : }
497 :
498 1640 : EquidistantTickIter::~EquidistantTickIter()
499 : {
500 820 : delete[] m_pnPositions;
501 820 : delete[] m_pnPreParentCount;
502 820 : delete[] m_pbIntervalFinished;
503 820 : }
504 :
505 820 : sal_Int32 EquidistantTickIter::getStartDepth() const
506 : {
507 : //find the depth of the first visible tickmark:
508 : //it is the depth of the smallest value
509 820 : sal_Int32 nReturnDepth=0;
510 820 : double fMinValue = DBL_MAX;
511 1886 : for(sal_Int32 nDepth = 0; nDepth<=m_nMaxDepth ;nDepth++ )
512 : {
513 1066 : sal_Int32 nCount = getTickCount(nDepth);
514 1066 : if( !nCount )
515 0 : continue;
516 1066 : double fThisValue = getTickValue(nDepth,0);
517 1066 : if(fThisValue<fMinValue)
518 : {
519 902 : nReturnDepth = nDepth;
520 902 : fMinValue = fThisValue;
521 : }
522 : }
523 820 : return nReturnDepth;
524 : }
525 :
526 574 : double* EquidistantTickIter::firstValue()
527 : {
528 574 : if( gotoFirst() )
529 : {
530 574 : m_fCurrentValue = getTickValue(m_nCurrentDepth, m_pnPositions[m_nCurrentDepth]);
531 574 : return &m_fCurrentValue;
532 : }
533 0 : return NULL;
534 : }
535 :
536 246 : TickInfo* EquidistantTickIter::firstInfo()
537 : {
538 246 : if( m_pInfoTicks && gotoFirst() )
539 246 : return &(*m_pInfoTicks)[m_nCurrentDepth][m_pnPositions[m_nCurrentDepth]];
540 0 : return NULL;
541 : }
542 :
543 1148 : sal_Int32 EquidistantTickIter::getIntervalCount( sal_Int32 nDepth )
544 : {
545 1148 : if(nDepth>static_cast<sal_Int32>(m_rIncrement.SubIncrements.size()) || nDepth<0)
546 0 : return 0;
547 :
548 1148 : if(!nDepth)
549 0 : return m_nTickCount;
550 :
551 1148 : return m_rIncrement.SubIncrements[nDepth-1].IntervalCount;
552 : }
553 :
554 4100 : bool EquidistantTickIter::isAtLastPartTick()
555 : {
556 4100 : if(!m_nCurrentDepth)
557 2952 : return false;
558 1148 : sal_Int32 nIntervalCount = getIntervalCount( m_nCurrentDepth );
559 1148 : if(!nIntervalCount || nIntervalCount == 1)
560 0 : return true;
561 1148 : if( m_pbIntervalFinished[m_nCurrentDepth] )
562 0 : return false;
563 1148 : sal_Int32 nPos = m_pnPositions[m_nCurrentDepth]+1;
564 1148 : if(m_pnPreParentCount[m_nCurrentDepth])
565 328 : nPos += nIntervalCount-1 - m_pnPreParentCount[m_nCurrentDepth];
566 1148 : bool bRet = nPos && nPos % (nIntervalCount-1) == 0;
567 1148 : if(!nPos && !m_pnPreParentCount[m_nCurrentDepth]
568 0 : && m_pnPositions[m_nCurrentDepth-1]==-1 )
569 0 : bRet = true;
570 1148 : return bRet;
571 : }
572 :
573 820 : bool EquidistantTickIter::gotoFirst()
574 : {
575 820 : if( m_nMaxDepth<0 )
576 0 : return false;
577 820 : if( !m_nTickCount )
578 0 : return false;
579 :
580 1886 : for(sal_Int32 nDepth = 0; nDepth<=m_nMaxDepth ;nDepth++ )
581 1066 : m_pnPositions[nDepth] = -1;
582 :
583 820 : m_nCurrentPos = 0;
584 820 : m_nCurrentDepth = getStartDepth();
585 820 : m_pnPositions[m_nCurrentDepth] = 0;
586 820 : return true;
587 : }
588 :
589 6068 : bool EquidistantTickIter::gotoNext()
590 : {
591 6068 : if( m_nCurrentPos < 0 )
592 0 : return false;
593 6068 : m_nCurrentPos++;
594 :
595 6068 : if( m_nCurrentPos >= m_nTickCount )
596 820 : return false;
597 :
598 5248 : if( m_nCurrentDepth==m_nMaxDepth && isAtLastPartTick() )
599 : {
600 1148 : do
601 : {
602 1148 : m_pbIntervalFinished[m_nCurrentDepth] = true;
603 1148 : m_nCurrentDepth--;
604 : }
605 0 : while( m_nCurrentDepth && isAtLastPartTick() );
606 : }
607 4100 : else if( m_nCurrentDepth<m_nMaxDepth )
608 : {
609 1148 : do
610 : {
611 1148 : m_nCurrentDepth++;
612 : }
613 : while( m_nCurrentDepth<m_nMaxDepth );
614 : }
615 5248 : m_pbIntervalFinished[m_nCurrentDepth] = false;
616 5248 : m_pnPositions[m_nCurrentDepth] = m_pnPositions[m_nCurrentDepth]+1;
617 5248 : return true;
618 : }
619 :
620 3526 : double* EquidistantTickIter::nextValue()
621 : {
622 3526 : if( gotoNext() )
623 : {
624 2952 : m_fCurrentValue = getTickValue(m_nCurrentDepth, m_pnPositions[m_nCurrentDepth]);
625 2952 : return &m_fCurrentValue;
626 : }
627 574 : return NULL;
628 : }
629 :
630 2542 : TickInfo* EquidistantTickIter::nextInfo()
631 : {
632 7134 : if( m_pInfoTicks && gotoNext() &&
633 : static_cast< sal_Int32 >(
634 4592 : (*m_pInfoTicks)[m_nCurrentDepth].size()) > m_pnPositions[m_nCurrentDepth] )
635 : {
636 2296 : return &(*m_pInfoTicks)[m_nCurrentDepth][m_pnPositions[m_nCurrentDepth]];
637 : }
638 246 : return NULL;
639 : }
640 :
641 : //.............................................................................
642 : } //namespace chart
643 : //.............................................................................
644 :
645 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|