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

Generated by: LCOV version 1.10