LCOV - code coverage report
Current view: top level - chart2/source/view/axes - VAxisBase.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 96 109 88.1 %
Date: 2014-11-03 Functions: 16 19 84.2 %
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        1095 : 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        1095 :             , m_nMaximumTextHeightSoFar(0)
      45             : {
      46        1095 : }
      47             : 
      48        1047 : VAxisBase::~VAxisBase()
      49             : {
      50        1047 : }
      51             : 
      52        1095 : void VAxisBase::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize
      53             :                   , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels )
      54             : {
      55        1095 :     m_aAxisLabelProperties.m_aFontReferenceSize = rFontReferenceSize;
      56        1095 :     m_aAxisLabelProperties.m_aMaximumSpaceForLabels = rMaximumSpaceForLabels;
      57             : 
      58        1095 :     if( !m_aAxisProperties.m_bDisplayLabels )
      59          66 :         return;
      60             : 
      61        1029 :     if( AxisType::SERIES==m_aAxisProperties.m_nAxisType )
      62             :     {
      63          35 :         if( m_aAxisProperties.m_xAxisTextProvider.is() )
      64          35 :             m_aTextLabels = m_aAxisProperties.m_xAxisTextProvider->getTextualData();
      65             : 
      66          35 :         m_bUseTextLabels = true;
      67          35 :         if( m_aTextLabels.getLength() == 1 )
      68             :         {
      69             :             //don't show a single series name
      70          21 :             m_aAxisProperties.m_bDisplayLabels = false;
      71          21 :             return;
      72             :         }
      73             :     }
      74         994 :     else if( AxisType::CATEGORY==m_aAxisProperties.m_nAxisType )
      75             :     {
      76         476 :         if( m_aAxisProperties.m_pExplicitCategoriesProvider )
      77         476 :             m_aTextLabels = m_aAxisProperties.m_pExplicitCategoriesProvider->getSimpleCategories();
      78             : 
      79         476 :         m_bUseTextLabels = true;
      80             :     }
      81             : 
      82        1008 :     m_aAxisLabelProperties.nNumberFormatKey = m_aAxisProperties.m_nNumberFormatKey;
      83        1008 :     m_aAxisLabelProperties.init(m_aAxisProperties.m_xAxisModel);
      84        1008 :     if( m_aAxisProperties.m_bComplexCategories && AxisType::CATEGORY == m_aAxisProperties.m_nAxisType )
      85           0 :         m_aAxisLabelProperties.eStaggering = SIDE_BY_SIDE;
      86             : }
      87             : 
      88        2357 : bool VAxisBase::isDateAxis() const
      89             : {
      90        2357 :     return AxisType::DATE == m_aScale.AxisType;
      91             : }
      92       10402 : bool VAxisBase::isComplexCategoryAxis() const
      93             : {
      94       10402 :     return m_aAxisProperties.m_bComplexCategories && m_bUseTextLabels;
      95             : }
      96             : 
      97       10193 : void VAxisBase::recordMaximumTextSize( const Reference< drawing::XShape >& xShape, double fRotationAngleDegree )
      98             : {
      99       10193 :     if( m_bRecordMaximumTextSize && xShape.is() )
     100             :     {
     101             :         awt::Size aSize( ShapeFactory::getSizeAfterRotation(
     102        3845 :                             xShape, fRotationAngleDegree ) );
     103             : 
     104        3845 :         m_nMaximumTextWidthSoFar = std::max( m_nMaximumTextWidthSoFar, aSize.Width );
     105        3845 :         m_nMaximumTextHeightSoFar = std::max( m_nMaximumTextHeightSoFar, aSize.Height );
     106             :     }
     107       10193 : }
     108             : 
     109           0 : sal_Int32 VAxisBase::estimateMaximumAutoMainIncrementCount()
     110             : {
     111           0 :     return 10;
     112             : }
     113             : 
     114         574 : void VAxisBase::setExrtaLinePositionAtOtherAxis( double fCrossingAt )
     115             : {
     116         574 :     m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis.reset(fCrossingAt);
     117         574 : }
     118             : 
     119        8752 : sal_Int32 VAxisBase::getDimensionCount() const
     120             : {
     121        8752 :     return m_nDimension;
     122             : }
     123             : 
     124        3285 : bool VAxisBase::isAnythingToDraw()
     125             : {
     126        3285 :     if( !m_aAxisProperties.m_xAxisModel.is() )
     127           0 :         return false;
     128             : 
     129             :     OSL_ENSURE(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"Axis is not proper initialized");
     130        3285 :     if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
     131           0 :         return false;
     132             : 
     133        3285 :     uno::Reference< beans::XPropertySet > xProps( m_aAxisProperties.m_xAxisModel, uno::UNO_QUERY );
     134        3285 :     if( xProps.is() )
     135             :     {
     136        3285 :         bool bShow = false;
     137        3285 :         xProps->getPropertyValue( "Show" ) >>= bShow;
     138        3285 :         if( !bShow )
     139          87 :             return false;
     140             :     }
     141        3198 :     return true;
     142             : }
     143             : 
     144        2190 : void VAxisBase::setExplicitScaleAndIncrement(
     145             :               const ExplicitScaleData& rScale
     146             :             , const ExplicitIncrementData& rIncrement )
     147             :             throw (uno::RuntimeException)
     148             : {
     149        2190 :     m_bReCreateAllTickInfos = true;
     150        2190 :     m_aScale = rScale;
     151        2190 :     m_aIncrement = rIncrement;
     152        2190 : }
     153             : 
     154        2132 : void VAxisBase::createAllTickInfos( TickInfoArraysType& rAllTickInfos )
     155             : {
     156        2132 :     boost::scoped_ptr< TickFactory > apTickFactory( this->createTickFactory() );
     157        2132 :     if( m_aScale.ShiftedCategoryPosition )
     158         876 :         apTickFactory->getAllTicksShifted( rAllTickInfos );
     159             :     else
     160        1256 :         apTickFactory->getAllTicks( rAllTickInfos );
     161        2132 : }
     162             : 
     163        3285 : bool VAxisBase::prepareShapeCreation()
     164             : {
     165             :     //returns true if all is ready for further shape creation and any shapes need to be created
     166        3285 :     if( !isAnythingToDraw() )
     167          87 :         return false;
     168             : 
     169        3198 :     if( m_bReCreateAllTickInfos )
     170             :     {
     171             :         //create all scaled tickmark values
     172        2132 :         removeTextShapesFromTicks();
     173             : 
     174        2132 :         createAllTickInfos(m_aAllTickInfos);
     175        2132 :         m_bReCreateAllTickInfos = false;
     176             :     }
     177             : 
     178        3198 :     if( m_xGroupShape_Shapes.is() )
     179        2132 :         return true;
     180             : 
     181             :     //create named group shape
     182        1066 :     m_xGroupShape_Shapes = this->createGroupShape( m_xLogicTarget, m_nDimension==2 ? m_aCID : "");
     183             : 
     184        1066 :     if( m_aAxisProperties.m_bDisplayLabels )
     185         986 :         m_xTextTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget, m_aCID );
     186             : 
     187        1066 :     return true;
     188             : }
     189             : 
     190         486 : sal_Int32 VAxisBase::getIndexOfLongestLabel( const uno::Sequence< OUString >& rLabels )
     191             : {
     192         486 :     sal_Int32 nRet = 0;
     193         486 :     sal_Int32 nLength = 0;
     194         486 :     sal_Int32 nN = 0;
     195        2848 :     for( nN=0; nN<rLabels.getLength(); nN++ )
     196             :     {
     197             :         //todo: get real text width (without creating shape) instead of character count
     198        2362 :         if( rLabels[nN].getLength() > nLength )
     199             :         {
     200         486 :             nLength = rLabels[nN].getLength();
     201         486 :             nRet = nN;
     202             :         }
     203             :     }
     204         486 :     return nRet;
     205             : }
     206             : 
     207        3127 : void VAxisBase::removeTextShapesFromTicks()
     208             : {
     209        3127 :     if( m_xTextTarget.is() )
     210             :     {
     211        1981 :         TickInfoArraysType::iterator aDepthIter = m_aAllTickInfos.begin();
     212        1981 :         const TickInfoArraysType::const_iterator aDepthEnd  = m_aAllTickInfos.end();
     213        5943 :         for( ; aDepthIter != aDepthEnd; ++aDepthIter )
     214             :         {
     215        3962 :             TickInfoArrayType::iterator aTickIter = (*aDepthIter).begin();
     216        3962 :             const TickInfoArrayType::const_iterator aTickEnd  = (*aDepthIter).end();
     217       29713 :             for( ; aTickIter != aTickEnd; ++aTickIter )
     218             :             {
     219       25751 :                 TickInfo& rTickInfo = (*aTickIter);
     220       25751 :                 if(rTickInfo.xTextShape.is())
     221             :                 {
     222        3863 :                     m_xTextTarget->remove(rTickInfo.xTextShape);
     223        3863 :                     rTickInfo.xTextShape = NULL;
     224             :                 }
     225             :             }
     226             :         }
     227             :     }
     228        3127 : }
     229             : 
     230           0 : void VAxisBase::updateUnscaledValuesAtTicks( TickIter& rIter )
     231             : {
     232           0 :     Reference< XScaling > xInverseScaling( NULL );
     233           0 :     if( m_aScale.Scaling.is() )
     234           0 :         xInverseScaling = m_aScale.Scaling->getInverseScaling();
     235             : 
     236           0 :     for( TickInfo* pTickInfo = rIter.firstInfo()
     237           0 :         ; pTickInfo; pTickInfo = rIter.nextInfo() )
     238             :     {
     239             :         //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
     240           0 :     }
     241           0 : }
     242             : 
     243         108 : } //namespace chart
     244             : 
     245             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10