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

Generated by: LCOV version 1.10