LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/view/axes - Tickmarks_Equidistant.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 288 335 86.0 %
Date: 2012-12-27 Functions: 26 27 96.3 %
Legend: Lines: hit not hit

          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         611 : 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         611 :     if(rIncrement.Distance<=0.0)
      41           0 :         return fMin;
      42             : 
      43             :     double fRet = rIncrement.BaseValue +
      44         611 :         floor( approxSub( fMin, rIncrement.BaseValue )
      45         611 :                     / rIncrement.Distance)
      46        1222 :             *rIncrement.Distance;
      47             : 
      48         611 :     if( fRet > fMin )
      49             :     {
      50           0 :         if( !approxEqual(fRet, fMin) )
      51           0 :             fRet -= rIncrement.Distance;
      52             :     }
      53         611 :     return fRet;
      54             : }
      55             : //static
      56         611 : 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         611 :     if(rIncrement.Distance<=0.0)
      60           0 :         return fMax;
      61             : 
      62             :     double fRet = rIncrement.BaseValue +
      63         611 :         floor( approxSub( fMax, rIncrement.BaseValue )
      64         611 :                     / rIncrement.Distance)
      65        1222 :             *rIncrement.Distance;
      66             : 
      67         611 :     if( fRet < fMax )
      68             :     {
      69         324 :         if( !approxEqual(fRet, fMax) )
      70         324 :             fRet += rIncrement.Distance;
      71             :     }
      72         611 :     return fRet;
      73             : }
      74             : 
      75         369 : EquidistantTickFactory::EquidistantTickFactory(
      76             :           const ExplicitScaleData& rScale, const ExplicitIncrementData& rIncrement )
      77             :             : m_rScale( rScale )
      78             :             , m_rIncrement( rIncrement )
      79             :             , m_xInverseScaling(NULL)
      80         369 :             , m_pfCurrentValues(NULL)
      81             : {
      82             :     //@todo: make sure that the scale is valid for the scaling
      83             : 
      84         369 :     m_pfCurrentValues = new double[getTickDepth()];
      85             : 
      86         369 :     if( m_rScale.Scaling.is() )
      87             :     {
      88         123 :         m_xInverseScaling = m_rScale.Scaling->getInverseScaling();
      89             :         OSL_ENSURE( m_xInverseScaling.is(), "each Scaling needs to return a inverse Scaling" );
      90             :     }
      91             : 
      92         369 :     double fMin = m_fScaledVisibleMin = m_rScale.Minimum;
      93         369 :     if( m_xInverseScaling.is() )
      94             :     {
      95         123 :         m_fScaledVisibleMin = m_rScale.Scaling->doScaling(m_fScaledVisibleMin);
      96         123 :         if(m_rIncrement.PostEquidistant )
      97         123 :             fMin = m_fScaledVisibleMin;
      98             :     }
      99             : 
     100         369 :     double fMax = m_fScaledVisibleMax = m_rScale.Maximum;
     101         369 :     if( m_xInverseScaling.is() )
     102             :     {
     103         123 :         m_fScaledVisibleMax = m_rScale.Scaling->doScaling(m_fScaledVisibleMax);
     104         123 :         if(m_rIncrement.PostEquidistant )
     105         123 :             fMax = m_fScaledVisibleMax;
     106             :     }
     107             : 
     108             :     //--
     109         369 :     m_fOuterMajorTickBorderMin = EquidistantTickFactory::getMinimumAtIncrement( fMin, m_rIncrement );
     110         369 :     m_fOuterMajorTickBorderMax = EquidistantTickFactory::getMaximumAtIncrement( fMax, m_rIncrement );
     111             :     //--
     112             : 
     113         369 :     m_fOuterMajorTickBorderMin_Scaled = m_fOuterMajorTickBorderMin;
     114         369 :     m_fOuterMajorTickBorderMax_Scaled = m_fOuterMajorTickBorderMax;
     115         369 :     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         369 : }
     134             : 
     135         738 : EquidistantTickFactory::~EquidistantTickFactory()
     136             : {
     137         369 :     delete[] m_pfCurrentValues;
     138         369 : }
     139             : 
     140        1230 : sal_Int32 EquidistantTickFactory::getTickDepth() const
     141             : {
     142        1230 :     return static_cast<sal_Int32>(m_rIncrement.SubIncrements.size()) + 1;
     143             : }
     144             : 
     145         287 : void EquidistantTickFactory::addSubTicks( sal_Int32 nDepth, uno::Sequence< uno::Sequence< double > >& rParentTicks ) const
     146             : {
     147         287 :     EquidistantTickIter aIter( rParentTicks, m_rIncrement, 0, nDepth-1 );
     148         287 :     double* pfNextParentTick = aIter.firstValue();
     149         287 :     if(!pfNextParentTick)
     150             :         return;
     151         287 :     double fLastParentTick = *pfNextParentTick;
     152         287 :     pfNextParentTick = aIter.nextValue();
     153         287 :     if(!pfNextParentTick)
     154             :         return;
     155             : 
     156         287 :     sal_Int32 nMaxSubTickCount = this->getMaxTickCount( nDepth );
     157         287 :     if(!nMaxSubTickCount)
     158             :         return;
     159             : 
     160         287 :     uno::Sequence< double > aSubTicks(nMaxSubTickCount);
     161         287 :     sal_Int32 nRealSubTickCount = 0;
     162         287 :     sal_Int32 nIntervalCount = m_rIncrement.SubIncrements[nDepth-1].IntervalCount;
     163             : 
     164         287 :     double* pValue = NULL;
     165        1763 :     for(; pfNextParentTick; fLastParentTick=*pfNextParentTick, pfNextParentTick = aIter.nextValue())
     166             :     {
     167        2952 :         for( sal_Int32 nPartTick = 1; nPartTick<nIntervalCount; nPartTick++ )
     168             :         {
     169             :             pValue = this->getMinorTick( nPartTick, nDepth
     170        1476 :                         , fLastParentTick, *pfNextParentTick );
     171        1476 :             if(!pValue)
     172           0 :                 continue;
     173             : 
     174        1476 :             aSubTicks[nRealSubTickCount] = *pValue;
     175        1476 :             nRealSubTickCount++;
     176             :         }
     177             :     }
     178             : 
     179         287 :     aSubTicks.realloc(nRealSubTickCount);
     180         287 :     rParentTicks[nDepth] = aSubTicks;
     181         287 :     if(static_cast<sal_Int32>(m_rIncrement.SubIncrements.size())>nDepth)
     182           0 :         addSubTicks( nDepth+1, rParentTicks );
     183             : }
     184             : 
     185             : 
     186         574 : 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         574 :     if( nDepth >= getTickDepth() )
     193           0 :         return 0;
     194         574 :     if( m_fOuterMajorTickBorderMax < m_fOuterMajorTickBorderMin )
     195           0 :         return 0;
     196         574 :     if( m_rIncrement.Distance<=0.0)
     197           0 :         return 0;
     198             : 
     199             :     double fSub;
     200         574 :     if(m_rIncrement.PostEquidistant  )
     201         574 :         fSub = approxSub( m_fScaledVisibleMax, m_fScaledVisibleMin );
     202             :     else
     203           0 :         fSub = approxSub( m_rScale.Maximum, m_rScale.Minimum );
     204             : 
     205         574 :     if (!isFinite(fSub))
     206           0 :         return 0;
     207             : 
     208         574 :     double fIntervalCount = fSub / m_rIncrement.Distance;
     209         574 :     if (fIntervalCount > std::numeric_limits<sal_Int32>::max())
     210             :         // Interval count too high!  Bail out.
     211           0 :         return 0;
     212             : 
     213         574 :     sal_Int32 nIntervalCount = static_cast<sal_Int32>(fIntervalCount);
     214             : 
     215         574 :     nIntervalCount+=3;
     216         574 :     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         574 :     sal_Int32 nTickCount = nIntervalCount;
     223         574 :     if(nDepth>0 && m_rIncrement.SubIncrements[nDepth-1].IntervalCount>1)
     224         287 :         nTickCount = nIntervalCount * (m_rIncrement.SubIncrements[nDepth-1].IntervalCount-1);
     225             : 
     226         574 :     return nTickCount;
     227             : }
     228             : 
     229        2255 : double* EquidistantTickFactory::getMajorTick( sal_Int32 nTick ) const
     230             : {
     231        2255 :     m_pfCurrentValues[0] = m_fOuterMajorTickBorderMin + nTick*m_rIncrement.Distance;
     232             : 
     233        2255 :     if(m_pfCurrentValues[0]>m_fOuterMajorTickBorderMax)
     234             :     {
     235         492 :         if( !approxEqual(m_pfCurrentValues[0],m_fOuterMajorTickBorderMax) )
     236         492 :             return NULL;
     237             :     }
     238        1763 :     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        1763 :     if(!m_rIncrement.PostEquidistant && m_xInverseScaling.is() )
     246           0 :         m_pfCurrentValues[0] = m_rScale.Scaling->doScaling( m_pfCurrentValues[0] );
     247             : 
     248        1763 :     return &m_pfCurrentValues[0];
     249             : }
     250             : 
     251        1476 : 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        1476 :         if(fStartParentTick >= fNextParentTick)
     258           0 :             return NULL;
     259        1476 :         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        1476 :         if(nTick<=0)
     264           0 :             return NULL;
     265        1476 :         if(nTick>=m_rIncrement.SubIncrements[nDepth-1].IntervalCount)
     266           0 :             return NULL;
     267             :     }
     268             : 
     269        1476 :     bool    bPostEquidistant = m_rIncrement.SubIncrements[nDepth-1].PostEquidistant;
     270             : 
     271        1476 :     double fAdaptedStartParent = fStartParentTick;
     272        1476 :     double fAdaptedNextParent  = fNextParentTick;
     273             : 
     274        1476 :     if( !bPostEquidistant && m_xInverseScaling.is() )
     275             :     {
     276         738 :         fAdaptedStartParent = m_xInverseScaling->doScaling(fStartParentTick);
     277         738 :         fAdaptedNextParent  = m_xInverseScaling->doScaling(fNextParentTick);
     278             :     }
     279             : 
     280        1476 :     double fDistance = (fAdaptedNextParent - fAdaptedStartParent)/m_rIncrement.SubIncrements[nDepth-1].IntervalCount;
     281             : 
     282        1476 :     m_pfCurrentValues[nDepth] = fAdaptedStartParent + nTick*fDistance;
     283             : 
     284             :     //return always the value after scaling
     285        1476 :     if(!bPostEquidistant && m_xInverseScaling.is() )
     286         738 :         m_pfCurrentValues[nDepth] = m_rScale.Scaling->doScaling( m_pfCurrentValues[nDepth] );
     287             : 
     288        1476 :     if( !isWithinOuterBorder( m_pfCurrentValues[nDepth] ) )
     289           0 :         return NULL;
     290             : 
     291        1476 :     return &m_pfCurrentValues[nDepth];
     292             : }
     293             : 
     294        1476 : bool EquidistantTickFactory::isWithinOuterBorder( double fScaledValue ) const
     295             : {
     296        1476 :     if(fScaledValue>m_fOuterMajorTickBorderMax_Scaled)
     297           0 :         return false;
     298        1476 :     if(fScaledValue<m_fOuterMajorTickBorderMin_Scaled)
     299           0 :         return false;
     300             : 
     301        1476 :     return true;
     302             : }
     303             : 
     304        1722 : bool EquidistantTickFactory::isVisible( double fScaledValue ) const
     305             : {
     306        1722 :     if(fScaledValue>m_fScaledVisibleMax)
     307             :     {
     308          82 :         if( !approxEqual(fScaledValue,m_fScaledVisibleMax) )
     309          82 :             return false;
     310             :     }
     311        1640 :     if(fScaledValue<m_fScaledVisibleMin)
     312             :     {
     313          82 :         if( !approxEqual(fScaledValue,m_fScaledVisibleMin) )
     314          82 :             return false;
     315             :     }
     316        1558 :     return true;
     317             : }
     318             : 
     319         287 : void EquidistantTickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const
     320             : {
     321         287 :     uno::Sequence< uno::Sequence< double > > aAllTicks;
     322             : 
     323             :     //create point sequences for each tick depth
     324         287 :     sal_Int32 nDepthCount = this->getTickDepth();
     325         287 :     sal_Int32 nMaxMajorTickCount = this->getMaxTickCount( 0 );
     326             : 
     327         287 :     if (nDepthCount <= 0 || nMaxMajorTickCount <= 0)
     328             :         return;
     329             : 
     330         287 :     aAllTicks.realloc(nDepthCount);
     331         287 :     aAllTicks[0].realloc(nMaxMajorTickCount);
     332             : 
     333         287 :     sal_Int32 nRealMajorTickCount = 0;
     334         287 :     double* pValue = NULL;
     335        2542 :     for( sal_Int32 nMajorTick=0; nMajorTick<nMaxMajorTickCount; nMajorTick++ )
     336             :     {
     337        2255 :         pValue = this->getMajorTick( nMajorTick );
     338        2255 :         if(!pValue)
     339         492 :             continue;
     340        1763 :         aAllTicks[0][nRealMajorTickCount] = *pValue;
     341        1763 :         nRealMajorTickCount++;
     342             :     }
     343         287 :     if(!nRealMajorTickCount)
     344             :         return;
     345         287 :     aAllTicks[0].realloc(nRealMajorTickCount);
     346             : 
     347         287 :     if(nDepthCount>0)
     348         287 :         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         287 :     sal_Int32 nDepth = 0;
     354         287 :     sal_Int32 nTick = 0;
     355         861 :     for( nDepth = 0; nDepth < nDepthCount; nDepth++)
     356             :     {
     357         574 :         sal_Int32 nInvisibleAtLowerBorder = 0;
     358         574 :         sal_Int32 nInvisibleAtUpperBorder = 0;
     359             :         //we need only to check all ticks within the first major interval at each border
     360         574 :         sal_Int32 nCheckCount = 1;
     361         861 :         for(sal_Int32 nN=0; nN<nDepth; nN++)
     362             :         {
     363         287 :             if( m_rIncrement.SubIncrements[nN].IntervalCount>1 )
     364         287 :                 nCheckCount *= m_rIncrement.SubIncrements[nN].IntervalCount;
     365             :         }
     366         574 :         uno::Sequence< double >& rTicks = aAllTicks[nDepth];
     367         574 :         sal_Int32 nCount = rTicks.getLength();
     368             :         //check lower border
     369        1435 :         for( nTick=0; nTick<nCheckCount && nTick<nCount; nTick++)
     370             :         {
     371         861 :             if( !isVisible( rTicks[nTick] ) )
     372          82 :                 nInvisibleAtLowerBorder++;
     373             :         }
     374             :         //check upper border
     375        1435 :         for( nTick=nCount-1; nTick>nCount-1-nCheckCount && nTick>=0; nTick--)
     376             :         {
     377         861 :             if( !isVisible( rTicks[nTick] ) )
     378          82 :                 nInvisibleAtUpperBorder++;
     379             :         }
     380             :         //resize sequence
     381         574 :         if( !nInvisibleAtLowerBorder && !nInvisibleAtUpperBorder)
     382         492 :             continue;
     383          82 :         if( !nInvisibleAtLowerBorder )
     384           0 :             rTicks.realloc(nCount-nInvisibleAtUpperBorder);
     385             :         else
     386             :         {
     387          82 :             sal_Int32 nNewCount = nCount-nInvisibleAtUpperBorder-nInvisibleAtLowerBorder;
     388          82 :             if(nNewCount<0)
     389           0 :                 nNewCount=0;
     390             : 
     391          82 :             uno::Sequence< double > aOldTicks(rTicks);
     392          82 :             rTicks.realloc(nNewCount);
     393         410 :             for(nTick = 0; nTick<nNewCount; nTick++)
     394         410 :                 rTicks[nTick] = aOldTicks[nInvisibleAtLowerBorder+nTick];
     395             :         }
     396             :     }
     397             : 
     398             :     //fill return value
     399         287 :     rAllTickInfos.resize(aAllTicks.getLength());
     400         861 :     for( nDepth=0 ;nDepth<aAllTicks.getLength(); nDepth++ )
     401             :     {
     402         574 :         sal_Int32 nCount = aAllTicks[nDepth].getLength();
     403             : 
     404         574 :         ::std::vector< TickInfo >& rTickInfoVector = rAllTickInfos[nDepth];
     405         574 :         rTickInfoVector.clear();
     406         574 :         rTickInfoVector.reserve( nCount );
     407        3649 :         for(sal_Int32 nN = 0; nN<nCount; nN++)
     408             :         {
     409        3075 :             TickInfo aTickInfo(m_xInverseScaling);
     410        3075 :             aTickInfo.fScaledTickValue = aAllTicks[nDepth][nN];
     411        3075 :             rTickInfoVector.push_back(aTickInfo);
     412        3075 :         }
     413         287 :     }
     414             : }
     415             : 
     416          82 : void EquidistantTickFactory::getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const
     417             : {
     418          82 :     ExplicitIncrementData aShiftedIncrement( m_rIncrement );
     419          82 :     aShiftedIncrement.BaseValue = m_rIncrement.BaseValue-m_rIncrement.Distance/2.0;
     420          82 :     EquidistantTickFactory( m_rScale, aShiftedIncrement ).getAllTicks(rAllTickInfos);
     421          82 : }
     422             : 
     423             : //-----------------------------------------------------------------------------
     424             : //-----------------------------------------------------------------------------
     425             : //-----------------------------------------------------------------------------
     426             : 
     427         287 : 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         287 :                 , m_nCurrentDepth(-1), m_nCurrentPos(-1), m_fCurrentValue( 0.0 )
     437             : {
     438         287 :     initIter( nMinDepth, nMaxDepth );
     439         287 : }
     440             : 
     441         123 : 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         123 :                 , m_nCurrentDepth(-1), m_nCurrentPos(-1), m_fCurrentValue( 0.0 )
     451             : {
     452         123 :     initIter( nMinDepth, nMaxDepth );
     453         123 : }
     454             : 
     455         410 : void EquidistantTickIter::initIter( sal_Int32 /*nMinDepth*/, sal_Int32 nMaxDepth )
     456             : {
     457         410 :     m_nMaxDepth = nMaxDepth;
     458         410 :     if(nMaxDepth<0 || m_nMaxDepth>getMaxDepth())
     459         123 :         m_nMaxDepth=getMaxDepth();
     460             : 
     461         410 :     sal_Int32 nDepth = 0;
     462         943 :     for( nDepth = 0; nDepth<=m_nMaxDepth ;nDepth++ )
     463         533 :         m_nTickCount += getTickCount(nDepth);
     464             : 
     465         410 :     if(!m_nTickCount)
     466         410 :         return;
     467             : 
     468         410 :     m_pnPositions      = new sal_Int32[m_nMaxDepth+1];
     469             : 
     470         410 :     m_pnPreParentCount = new sal_Int32[m_nMaxDepth+1];
     471         410 :     m_pbIntervalFinished = new bool[m_nMaxDepth+1];
     472         410 :     m_pnPreParentCount[0] = 0;
     473         410 :     m_pbIntervalFinished[0] = false;
     474         410 :     double fParentValue = getTickValue(0,0);
     475         533 :     for( nDepth = 1; nDepth<=m_nMaxDepth ;nDepth++ )
     476             :     {
     477         123 :         m_pbIntervalFinished[nDepth] = false;
     478             : 
     479         123 :         sal_Int32 nPreParentCount = 0;
     480         123 :         sal_Int32 nCount = getTickCount(nDepth);
     481         328 :         for(sal_Int32 nN = 0; nN<nCount; nN++)
     482             :         {
     483         164 :             if(getTickValue(nDepth,nN) < fParentValue)
     484          41 :                 nPreParentCount++;
     485             :             else
     486         123 :                 break;
     487             :         }
     488         123 :         m_pnPreParentCount[nDepth] = nPreParentCount;
     489         123 :         if(nCount)
     490             :         {
     491         123 :             double fNextParentValue = getTickValue(nDepth,0);
     492         123 :             if( fNextParentValue < fParentValue )
     493          41 :                 fParentValue = fNextParentValue;
     494             :         }
     495             :     }
     496             : }
     497             : 
     498         820 : EquidistantTickIter::~EquidistantTickIter()
     499             : {
     500         410 :     delete[] m_pnPositions;
     501         410 :     delete[] m_pnPreParentCount;
     502         410 :     delete[] m_pbIntervalFinished;
     503         410 : }
     504             : 
     505         410 : 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         410 :     sal_Int32 nReturnDepth=0;
     510         410 :     double fMinValue = DBL_MAX;
     511         943 :     for(sal_Int32 nDepth = 0; nDepth<=m_nMaxDepth ;nDepth++ )
     512             :     {
     513         533 :         sal_Int32 nCount = getTickCount(nDepth);
     514         533 :         if( !nCount )
     515           0 :             continue;
     516         533 :         double fThisValue = getTickValue(nDepth,0);
     517         533 :         if(fThisValue<fMinValue)
     518             :         {
     519         451 :             nReturnDepth = nDepth;
     520         451 :             fMinValue = fThisValue;
     521             :         }
     522             :     }
     523         410 :     return nReturnDepth;
     524             : }
     525             : 
     526         287 : double* EquidistantTickIter::firstValue()
     527             : {
     528         287 :     if( gotoFirst() )
     529             :     {
     530         287 :         m_fCurrentValue = getTickValue(m_nCurrentDepth, m_pnPositions[m_nCurrentDepth]);
     531         287 :         return &m_fCurrentValue;
     532             :     }
     533           0 :     return NULL;
     534             : }
     535             : 
     536         123 : TickInfo* EquidistantTickIter::firstInfo()
     537             : {
     538         123 :     if( m_pInfoTicks && gotoFirst() )
     539         123 :         return &(*m_pInfoTicks)[m_nCurrentDepth][m_pnPositions[m_nCurrentDepth]];
     540           0 :     return NULL;
     541             : }
     542             : 
     543         574 : sal_Int32 EquidistantTickIter::getIntervalCount( sal_Int32 nDepth )
     544             : {
     545         574 :     if(nDepth>static_cast<sal_Int32>(m_rIncrement.SubIncrements.size()) || nDepth<0)
     546           0 :         return 0;
     547             : 
     548         574 :     if(!nDepth)
     549           0 :         return m_nTickCount;
     550             : 
     551         574 :     return m_rIncrement.SubIncrements[nDepth-1].IntervalCount;
     552             : }
     553             : 
     554        2050 : bool EquidistantTickIter::isAtLastPartTick()
     555             : {
     556        2050 :     if(!m_nCurrentDepth)
     557        1476 :         return false;
     558         574 :     sal_Int32 nIntervalCount = getIntervalCount( m_nCurrentDepth );
     559         574 :     if(!nIntervalCount || nIntervalCount == 1)
     560           0 :         return true;
     561         574 :     if( m_pbIntervalFinished[m_nCurrentDepth] )
     562           0 :         return false;
     563         574 :     sal_Int32 nPos = m_pnPositions[m_nCurrentDepth]+1;
     564         574 :     if(m_pnPreParentCount[m_nCurrentDepth])
     565         164 :         nPos += nIntervalCount-1 - m_pnPreParentCount[m_nCurrentDepth];
     566         574 :     bool bRet = nPos && nPos % (nIntervalCount-1) == 0;
     567         574 :     if(!nPos && !m_pnPreParentCount[m_nCurrentDepth]
     568           0 :              && m_pnPositions[m_nCurrentDepth-1]==-1 )
     569           0 :          bRet = true;
     570         574 :     return bRet;
     571             : }
     572             : 
     573         410 : bool EquidistantTickIter::gotoFirst()
     574             : {
     575         410 :     if( m_nMaxDepth<0 )
     576           0 :         return false;
     577         410 :     if( !m_nTickCount )
     578           0 :         return false;
     579             : 
     580         943 :     for(sal_Int32 nDepth = 0; nDepth<=m_nMaxDepth ;nDepth++ )
     581         533 :         m_pnPositions[nDepth] = -1;
     582             : 
     583         410 :     m_nCurrentPos   = 0;
     584         410 :     m_nCurrentDepth = getStartDepth();
     585         410 :     m_pnPositions[m_nCurrentDepth] = 0;
     586         410 :     return true;
     587             : }
     588             : 
     589        3034 : bool EquidistantTickIter::gotoNext()
     590             : {
     591        3034 :     if( m_nCurrentPos < 0 )
     592           0 :         return false;
     593        3034 :     m_nCurrentPos++;
     594             : 
     595        3034 :     if( m_nCurrentPos >= m_nTickCount )
     596         410 :         return false;
     597             : 
     598        2624 :     if( m_nCurrentDepth==m_nMaxDepth && isAtLastPartTick() )
     599             :     {
     600         574 :         do
     601             :         {
     602         574 :             m_pbIntervalFinished[m_nCurrentDepth] = true;
     603         574 :             m_nCurrentDepth--;
     604             :         }
     605           0 :         while( m_nCurrentDepth && isAtLastPartTick() );
     606             :     }
     607        2050 :     else if( m_nCurrentDepth<m_nMaxDepth )
     608             :     {
     609         574 :         do
     610             :         {
     611         574 :             m_nCurrentDepth++;
     612             :         }
     613             :         while( m_nCurrentDepth<m_nMaxDepth );
     614             :     }
     615        2624 :     m_pbIntervalFinished[m_nCurrentDepth] = false;
     616        2624 :     m_pnPositions[m_nCurrentDepth] = m_pnPositions[m_nCurrentDepth]+1;
     617        2624 :     return true;
     618             : }
     619             : 
     620        1763 : double* EquidistantTickIter::nextValue()
     621             : {
     622        1763 :     if( gotoNext() )
     623             :     {
     624        1476 :         m_fCurrentValue = getTickValue(m_nCurrentDepth, m_pnPositions[m_nCurrentDepth]);
     625        1476 :         return &m_fCurrentValue;
     626             :     }
     627         287 :     return NULL;
     628             : }
     629             : 
     630        1271 : TickInfo* EquidistantTickIter::nextInfo()
     631             : {
     632        3567 :     if( m_pInfoTicks && gotoNext() &&
     633             :         static_cast< sal_Int32 >(
     634        2296 :             (*m_pInfoTicks)[m_nCurrentDepth].size()) > m_pnPositions[m_nCurrentDepth] )
     635             :     {
     636        1148 :         return &(*m_pInfoTicks)[m_nCurrentDepth][m_pnPositions[m_nCurrentDepth]];
     637             :     }
     638         123 :     return NULL;
     639             : }
     640             : 
     641             : //.............................................................................
     642             : } //namespace chart
     643             : //.............................................................................
     644             : 
     645             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10