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

Generated by: LCOV version 1.11