LCOV - code coverage report
Current view: top level - chart2/source/view/axes - Tickmarks.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 159 0.0 %
Date: 2014-04-14 Functions: 0 25 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.hxx"
      21             : #include "Tickmarks_Equidistant.hxx"
      22             : #include "Tickmarks_Dates.hxx"
      23             : #include "ViewDefines.hxx"
      24             : #include <rtl/math.hxx>
      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           0 : TickInfo::TickInfo( const ::com::sun::star::uno::Reference<
      34             :                     ::com::sun::star::chart2::XScaling >& xInverse )
      35             : : fScaledTickValue( 0.0 )
      36             : , xInverseScaling( xInverse )
      37             : , aTickScreenPosition(0.0,0.0)
      38             : , bPaintIt( true )
      39             : , xTextShape( NULL )
      40           0 : , nFactorForLimitedTextWidth(1)
      41             : {
      42           0 : }
      43             : 
      44           0 : double TickInfo::getUnscaledTickValue() const
      45             : {
      46           0 :     if( xInverseScaling.is() )
      47           0 :         return xInverseScaling->doScaling( fScaledTickValue );
      48             :     else
      49           0 :         return fScaledTickValue;
      50             : }
      51             : 
      52           0 : sal_Int32 TickInfo::getScreenDistanceBetweenTicks( const TickInfo& rOherTickInfo ) const
      53             : {
      54             :     //return the positive distance between the two first tickmarks in screen values
      55             : 
      56           0 :     B2DVector aDistance = rOherTickInfo.aTickScreenPosition - aTickScreenPosition;
      57           0 :     sal_Int32 nRet = static_cast<sal_Int32>(aDistance.getLength());
      58           0 :     if(nRet<0)
      59           0 :         nRet *= -1;
      60           0 :     return nRet;
      61             : }
      62             : 
      63           0 : PureTickIter::PureTickIter( ::std::vector< TickInfo >& rTickInfoVector )
      64             :             : m_rTickVector(rTickInfoVector)
      65           0 :             , m_aTickIter(m_rTickVector.begin())
      66             : {
      67           0 : }
      68           0 : PureTickIter::~PureTickIter()
      69             : {
      70           0 : }
      71           0 : TickInfo* PureTickIter::firstInfo()
      72             : {
      73           0 :     m_aTickIter = m_rTickVector.begin();
      74           0 :     if(m_aTickIter!=m_rTickVector.end())
      75           0 :         return &*m_aTickIter;
      76           0 :     return 0;
      77             : }
      78           0 : TickInfo* PureTickIter::nextInfo()
      79             : {
      80           0 :     if(m_aTickIter!=m_rTickVector.end())
      81             :     {
      82           0 :         ++m_aTickIter;
      83           0 :         if(m_aTickIter!=m_rTickVector.end())
      84           0 :             return &*m_aTickIter;
      85             :     }
      86           0 :     return 0;
      87             : }
      88             : 
      89           0 : TickFactory::TickFactory(
      90             :           const ExplicitScaleData& rScale, const ExplicitIncrementData& rIncrement )
      91             :             : m_rScale( rScale )
      92             :             , m_rIncrement( rIncrement )
      93           0 :             , m_xInverseScaling(NULL)
      94             : {
      95             :     //@todo: make sure that the scale is valid for the scaling
      96             : 
      97           0 :     if( m_rScale.Scaling.is() )
      98             :     {
      99           0 :         m_xInverseScaling = m_rScale.Scaling->getInverseScaling();
     100             :         OSL_ENSURE( m_xInverseScaling.is(), "each Scaling needs to return a inverse Scaling" );
     101             :     }
     102             : 
     103           0 :     m_fScaledVisibleMin = m_rScale.Minimum;
     104           0 :     if( m_xInverseScaling.is() )
     105           0 :         m_fScaledVisibleMin = m_rScale.Scaling->doScaling(m_fScaledVisibleMin);
     106             : 
     107           0 :     m_fScaledVisibleMax = m_rScale.Maximum;
     108           0 :     if( m_xInverseScaling.is() )
     109           0 :         m_fScaledVisibleMax = m_rScale.Scaling->doScaling(m_fScaledVisibleMax);
     110           0 : }
     111             : 
     112           0 : TickFactory::~TickFactory()
     113             : {
     114           0 : }
     115             : 
     116           0 : bool TickFactory::isDateAxis() const
     117             : {
     118           0 :     return m_rScale.AxisType == AxisType::DATE;
     119             : }
     120             : 
     121           0 : void TickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const
     122             : {
     123           0 :     if( isDateAxis() )
     124           0 :         DateTickFactory( m_rScale, m_rIncrement ).getAllTicks( rAllTickInfos );
     125             :     else
     126           0 :         EquidistantTickFactory( m_rScale, m_rIncrement ).getAllTicks( rAllTickInfos );
     127           0 : }
     128             : 
     129           0 : void TickFactory::getAllTicksShifted( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const
     130             : {
     131           0 :     if( isDateAxis() )
     132           0 :         DateTickFactory( m_rScale, m_rIncrement ).getAllTicksShifted( rAllTickInfos );
     133             :     else
     134           0 :         EquidistantTickFactory( m_rScale, m_rIncrement ).getAllTicksShifted( rAllTickInfos );
     135           0 : }
     136             : 
     137             : // ___TickFactory_2D___
     138           0 : TickFactory_2D::TickFactory_2D(
     139             :           const ExplicitScaleData& rScale, const ExplicitIncrementData& rIncrement
     140             :           //, double fStrech_SceneToScreen, double fOffset_SceneToScreen )
     141             :           , const B2DVector& rStartScreenPos, const B2DVector& rEndScreenPos
     142             :           , const B2DVector& rAxisLineToLabelLineShift )
     143             :           : TickFactory( rScale, rIncrement )
     144             :           , m_aAxisStartScreenPosition2D(rStartScreenPos)
     145             :           , m_aAxisEndScreenPosition2D(rEndScreenPos)
     146             :           , m_aAxisLineToLabelLineShift(rAxisLineToLabelLineShift)
     147             :           , m_fStrech_LogicToScreen(1.0)
     148           0 :           , m_fOffset_LogicToScreen(0.0)
     149             : {
     150           0 :     double fWidthY = m_fScaledVisibleMax - m_fScaledVisibleMin;
     151           0 :     if( AxisOrientation_MATHEMATICAL==m_rScale.Orientation )
     152             :     {
     153           0 :         m_fStrech_LogicToScreen = 1.0/fWidthY;
     154           0 :         m_fOffset_LogicToScreen = -m_fScaledVisibleMin;
     155             :     }
     156             :     else
     157             :     {
     158           0 :         B2DVector aSwap(m_aAxisStartScreenPosition2D);
     159           0 :         m_aAxisStartScreenPosition2D = m_aAxisEndScreenPosition2D;
     160           0 :         m_aAxisEndScreenPosition2D = aSwap;
     161             : 
     162           0 :         m_fStrech_LogicToScreen = -1.0/fWidthY;
     163           0 :         m_fOffset_LogicToScreen = -m_fScaledVisibleMax;
     164             :     }
     165           0 : }
     166             : 
     167           0 : TickFactory_2D::~TickFactory_2D()
     168             : {
     169           0 : }
     170             : 
     171           0 : bool TickFactory_2D::isHorizontalAxis() const
     172             : {
     173           0 :     return ( m_aAxisStartScreenPosition2D.getY() == m_aAxisEndScreenPosition2D.getY() );
     174             : }
     175           0 : bool TickFactory_2D::isVerticalAxis() const
     176             : {
     177           0 :     return ( m_aAxisStartScreenPosition2D.getX() == m_aAxisEndScreenPosition2D.getX() );
     178             : }
     179             : 
     180             : //static
     181           0 : sal_Int32 TickFactory_2D::getTickScreenDistance( TickIter& rIter )
     182             : {
     183             :     //return the positive distance between the two first tickmarks in screen values
     184             :     //if there are less than two tickmarks -1 is returned
     185             : 
     186           0 :     const TickInfo* pFirstTickInfo = rIter.firstInfo();
     187           0 :     const TickInfo* pSecondTickInfo = rIter.nextInfo();
     188           0 :     if(!pSecondTickInfo  || !pFirstTickInfo)
     189           0 :         return -1;
     190             : 
     191           0 :     return pFirstTickInfo->getScreenDistanceBetweenTicks( *pSecondTickInfo );
     192             : }
     193             : 
     194           0 : B2DVector TickFactory_2D::getTickScreenPosition2D( double fScaledLogicTickValue ) const
     195             : {
     196           0 :     B2DVector aRet(m_aAxisStartScreenPosition2D);
     197           0 :     aRet += (m_aAxisEndScreenPosition2D-m_aAxisStartScreenPosition2D)
     198           0 :                 *((fScaledLogicTickValue+m_fOffset_LogicToScreen)*m_fStrech_LogicToScreen);
     199           0 :     return aRet;
     200             : }
     201             : 
     202           0 : void TickFactory_2D::addPointSequenceForTickLine( drawing::PointSequenceSequence& rPoints
     203             :                                 , sal_Int32 nSequenceIndex
     204             :                                 , double fScaledLogicTickValue, double fInnerDirectionSign
     205             :                                 , const TickmarkProperties& rTickmarkProperties
     206             :                                 , bool bPlaceAtLabels ) const
     207             : {
     208           0 :     if( fInnerDirectionSign==0.0 )
     209           0 :         fInnerDirectionSign = 1.0;
     210             : 
     211           0 :     B2DVector aTickScreenPosition = this->getTickScreenPosition2D(fScaledLogicTickValue);
     212           0 :     if( bPlaceAtLabels )
     213           0 :         aTickScreenPosition += m_aAxisLineToLabelLineShift;
     214             : 
     215           0 :     B2DVector aMainDirection = m_aAxisEndScreenPosition2D-m_aAxisStartScreenPosition2D;
     216           0 :     aMainDirection.normalize();
     217           0 :     B2DVector aOrthoDirection(-aMainDirection.getY(),aMainDirection.getX());
     218           0 :     aOrthoDirection *= fInnerDirectionSign;
     219           0 :     aOrthoDirection.normalize();
     220             : 
     221           0 :     B2DVector aStart = aTickScreenPosition + aOrthoDirection*rTickmarkProperties.RelativePos;
     222           0 :     B2DVector aEnd = aStart - aOrthoDirection*rTickmarkProperties.Length;
     223             : 
     224           0 :     rPoints[nSequenceIndex].realloc(2);
     225           0 :     rPoints[nSequenceIndex][0].X = static_cast<sal_Int32>(aStart.getX());
     226           0 :     rPoints[nSequenceIndex][0].Y = static_cast<sal_Int32>(aStart.getY());
     227           0 :     rPoints[nSequenceIndex][1].X = static_cast<sal_Int32>(aEnd.getX());
     228           0 :     rPoints[nSequenceIndex][1].Y = static_cast<sal_Int32>(aEnd.getY());
     229           0 : }
     230             : 
     231           0 : B2DVector TickFactory_2D::getDistanceAxisTickToText( const AxisProperties& rAxisProperties, bool bIncludeFarAwayDistanceIfSo, bool bIncludeSpaceBetweenTickAndText ) const
     232             : {
     233           0 :     bool bFarAwayLabels = false;
     234           0 :     if( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START == rAxisProperties.m_eLabelPos
     235           0 :         || ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END == rAxisProperties.m_eLabelPos )
     236           0 :         bFarAwayLabels = true;
     237             : 
     238           0 :     double fInnerDirectionSign = rAxisProperties.m_fInnerDirectionSign;
     239           0 :     if( fInnerDirectionSign==0.0 )
     240           0 :         fInnerDirectionSign = 1.0;
     241             : 
     242           0 :     B2DVector aMainDirection = m_aAxisEndScreenPosition2D-m_aAxisStartScreenPosition2D;
     243           0 :     aMainDirection.normalize();
     244           0 :     B2DVector aOrthoDirection(-aMainDirection.getY(),aMainDirection.getX());
     245           0 :     aOrthoDirection *= fInnerDirectionSign;
     246           0 :     aOrthoDirection.normalize();
     247             : 
     248           0 :     B2DVector aStart(0,0), aEnd(0,0);
     249           0 :     if( bFarAwayLabels )
     250             :     {
     251           0 :         TickmarkProperties aProps( AxisProperties::getBiggestTickmarkProperties() );
     252           0 :         aStart = aOrthoDirection*aProps.RelativePos;
     253           0 :         aEnd = aStart - aOrthoDirection*aProps.Length;
     254             :     }
     255             :     else
     256             :     {
     257           0 :         for( sal_Int32 nN=rAxisProperties.m_aTickmarkPropertiesList.size();nN--;)
     258             :         {
     259           0 :             const TickmarkProperties& rProps = rAxisProperties.m_aTickmarkPropertiesList[nN];
     260           0 :             B2DVector aNewStart = aOrthoDirection*rProps.RelativePos;
     261           0 :             B2DVector aNewEnd = aNewStart - aOrthoDirection*rProps.Length;
     262           0 :             if(aNewStart.getLength()>aStart.getLength())
     263           0 :                 aStart=aNewStart;
     264           0 :             if(aNewEnd.getLength()>aEnd.getLength())
     265           0 :                 aEnd=aNewEnd;
     266           0 :         }
     267             :     }
     268             : 
     269           0 :     B2DVector aLabelDirection(aStart);
     270           0 :     if( rAxisProperties.m_fInnerDirectionSign != rAxisProperties.m_fLabelDirectionSign )
     271           0 :         aLabelDirection = aEnd;
     272             : 
     273           0 :     B2DVector aOrthoLabelDirection(aOrthoDirection);
     274           0 :     if( rAxisProperties.m_fInnerDirectionSign != rAxisProperties.m_fLabelDirectionSign )
     275           0 :         aOrthoLabelDirection*=-1.0;
     276           0 :     aOrthoLabelDirection.normalize();
     277           0 :     if( bIncludeSpaceBetweenTickAndText )
     278           0 :         aLabelDirection += aOrthoLabelDirection*AXIS2D_TICKLABELSPACING;
     279           0 :     if( bFarAwayLabels && bIncludeFarAwayDistanceIfSo )
     280           0 :         aLabelDirection += m_aAxisLineToLabelLineShift;
     281           0 :     return aLabelDirection;
     282             : }
     283             : 
     284           0 : void TickFactory_2D::createPointSequenceForAxisMainLine( drawing::PointSequenceSequence& rPoints ) const
     285             : {
     286           0 :     rPoints[0].realloc(2);
     287           0 :     rPoints[0][0].X = static_cast<sal_Int32>(m_aAxisStartScreenPosition2D.getX());
     288           0 :     rPoints[0][0].Y = static_cast<sal_Int32>(m_aAxisStartScreenPosition2D.getY());
     289           0 :     rPoints[0][1].X = static_cast<sal_Int32>(m_aAxisEndScreenPosition2D.getX());
     290           0 :     rPoints[0][1].Y = static_cast<sal_Int32>(m_aAxisEndScreenPosition2D.getY());
     291           0 : }
     292             : 
     293           0 : void TickFactory_2D::updateScreenValues( ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const
     294             : {
     295             :     //get the transformed screen values for all tickmarks in rAllTickInfos
     296           0 :     ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter       = rAllTickInfos.begin();
     297           0 :     const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd  = rAllTickInfos.end();
     298           0 :     for( ; aDepthIter != aDepthEnd; ++aDepthIter )
     299             :     {
     300           0 :         ::std::vector< TickInfo >::iterator       aTickIter = (*aDepthIter).begin();
     301           0 :         const ::std::vector< TickInfo >::const_iterator aTickEnd  = (*aDepthIter).end();
     302           0 :         for( ; aTickIter != aTickEnd; ++aTickIter )
     303             :         {
     304           0 :             TickInfo& rTickInfo = (*aTickIter);
     305           0 :             rTickInfo.aTickScreenPosition =
     306           0 :                 this->getTickScreenPosition2D( rTickInfo.fScaledTickValue );
     307             :         }
     308             :     }
     309           0 : }
     310             : 
     311             : } //namespace chart
     312             : 
     313             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10