LCOV - code coverage report
Current view: top level - chart2/source/view/axes - VAxisProperties.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 151 181 83.4 %
Date: 2014-11-03 Functions: 17 18 94.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 "VAxisProperties.hxx"
      21             : #include "macros.hxx"
      22             : #include "ViewDefines.hxx"
      23             : #include "CommonConverters.hxx"
      24             : #include "AxisHelper.hxx"
      25             : #include "DiagramHelper.hxx"
      26             : #include "ChartModelHelper.hxx"
      27             : 
      28             : #include <com/sun/star/beans/XPropertySet.hpp>
      29             : #include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp>
      30             : #include <com/sun/star/drawing/LineStyle.hpp>
      31             : #include <com/sun/star/text/WritingMode2.hpp>
      32             : 
      33             : using namespace ::com::sun::star;
      34             : using namespace ::com::sun::star::chart2;
      35             : 
      36             : namespace chart {
      37             : 
      38        1095 : AxisLabelAlignment::AxisLabelAlignment() :
      39             :     mfLabelDirection(1.0),
      40             :     mfInnerTickDirection(1.0),
      41        1095 :     meAlignment(LABEL_ALIGN_RIGHT_TOP) {}
      42             : 
      43        1384 : sal_Int32 lcl_calcTickLengthForDepth(sal_Int32 nDepth,sal_Int32 nTickmarkStyle)
      44             : {
      45        1384 :     sal_Int32 nWidth = AXIS2D_TICKLENGTH; //@maybefuturetodo this length could be offered by the model
      46        1384 :     double fPercent = 1.0;
      47        1384 :     switch(nDepth)
      48             :     {
      49             :         case 0:
      50        1297 :             fPercent = 1.0;
      51        1297 :             break;
      52             :         case 1:
      53          87 :             fPercent = 0.75;//percentage like in the old chart
      54          87 :             break;
      55             :         case 2:
      56           0 :             fPercent = 0.5;
      57           0 :             break;
      58             :         default:
      59           0 :             fPercent = 0.3;
      60           0 :             break;
      61             :     }
      62        1384 :     if(nTickmarkStyle==3)//inner and outer tickmarks
      63         246 :         fPercent*=2.0;
      64        1384 :     return static_cast<sal_Int32>(nWidth*fPercent);
      65             : }
      66             : 
      67        1384 : double lcl_getTickOffset(sal_Int32 nLength,sal_Int32 nTickmarkStyle)
      68             : {
      69        1384 :     double fPercent = 0.0; //0<=fPercent<=1
      70             :     //0.0: completely inner
      71             :     //1.0: completely outer
      72             :     //0.5: half and half
      73             : 
      74             :     /*
      75             :     nTickmarkStyle:
      76             :     1: inner tickmarks
      77             :     2: outer tickmarks
      78             :     3: inner and outer tickmarks
      79             :     */
      80        1384 :     switch(nTickmarkStyle)
      81             :     {
      82             :         case 1:
      83           0 :             fPercent = 0.0;
      84           0 :             break;
      85             :         case 2:
      86         964 :             fPercent = 1.0;
      87         964 :             break;
      88             :         default:
      89         420 :             fPercent = 0.5;
      90         420 :             break;
      91             :     }
      92        1384 :     return fPercent*nLength;
      93             : }
      94             : 
      95        1138 : TickmarkProperties AxisProperties::makeTickmarkProperties(
      96             :                         sal_Int32 nDepth ) const
      97             : {
      98             :     /*
      99             :     nTickmarkStyle:
     100             :     1: inner tickmarks
     101             :     2: outer tickmarks
     102             :     3: inner and outer tickmarks
     103             :     */
     104        1138 :     sal_Int32 nTickmarkStyle = 1;
     105        1138 :     if(nDepth==0)
     106             :     {
     107        1051 :         nTickmarkStyle = m_nMajorTickmarks;
     108        1051 :         if(!nTickmarkStyle)
     109             :         {
     110             :             //create major tickmarks as if they were minor tickmarks
     111           0 :             nDepth = 1;
     112           0 :             nTickmarkStyle = m_nMinorTickmarks;
     113             :         }
     114             :     }
     115          87 :     else if( nDepth==1)
     116             :     {
     117          87 :         nTickmarkStyle = m_nMinorTickmarks;
     118             :     }
     119             : 
     120        1138 :     if (maLabelAlignment.mfInnerTickDirection == 0.0)
     121             :     {
     122           0 :         if( nTickmarkStyle != 0 )
     123           0 :             nTickmarkStyle = 3; //inner and outer tickmarks
     124             :     }
     125             : 
     126        1138 :     TickmarkProperties aTickmarkProperties;
     127        1138 :     aTickmarkProperties.Length = lcl_calcTickLengthForDepth(nDepth,nTickmarkStyle);
     128        1138 :     aTickmarkProperties.RelativePos = static_cast<sal_Int32>(lcl_getTickOffset(aTickmarkProperties.Length,nTickmarkStyle));
     129        1138 :     aTickmarkProperties.aLineProperties = this->makeLinePropertiesForDepth( nDepth );
     130        1138 :     return aTickmarkProperties;
     131             : }
     132             : 
     133           0 : TickmarkProperties AxisProperties::makeTickmarkPropertiesForComplexCategories(
     134             :     sal_Int32 nTickLength, sal_Int32 nTickStartDistanceToAxis, sal_Int32 /*nTextLevel*/ ) const
     135             : {
     136           0 :     sal_Int32 nTickmarkStyle = (maLabelAlignment.mfLabelDirection == maLabelAlignment.mfInnerTickDirection) ? 2/*outside*/ : 1/*inside*/;
     137             : 
     138           0 :     TickmarkProperties aTickmarkProperties;
     139           0 :     aTickmarkProperties.Length = nTickLength;// + nTextLevel*( lcl_calcTickLengthForDepth(0,nTickmarkStyle) );
     140           0 :     aTickmarkProperties.RelativePos = static_cast<sal_Int32>(lcl_getTickOffset(aTickmarkProperties.Length+nTickStartDistanceToAxis,nTickmarkStyle));
     141           0 :     aTickmarkProperties.aLineProperties = this->makeLinePropertiesForDepth( 0 );
     142           0 :     return aTickmarkProperties;
     143             : }
     144             : 
     145         246 : TickmarkProperties AxisProperties::getBiggestTickmarkProperties()
     146             : {
     147         246 :     TickmarkProperties aTickmarkProperties;
     148         246 :     sal_Int32 nDepth = 0;
     149         246 :     sal_Int32 nTickmarkStyle = 3;//inner and outer tickmarks
     150         246 :     aTickmarkProperties.Length = lcl_calcTickLengthForDepth( nDepth,nTickmarkStyle );
     151         246 :     aTickmarkProperties.RelativePos = static_cast<sal_Int32>( lcl_getTickOffset( aTickmarkProperties.Length, nTickmarkStyle ) );
     152         246 :     return aTickmarkProperties;
     153             : }
     154             : 
     155        1095 : AxisProperties::AxisProperties( const uno::Reference< XAxis >& xAxisModel
     156             :                               , ExplicitCategoriesProvider* pExplicitCategoriesProvider )
     157             :     : m_xAxisModel(xAxisModel)
     158             :     , m_nDimensionIndex(0)
     159             :     , m_bIsMainAxis(true)
     160             :     , m_bSwapXAndY(false)
     161             :     , m_eCrossoverType( ::com::sun::star::chart::ChartAxisPosition_ZERO )
     162             :     , m_eLabelPos( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS )
     163             :     , m_eTickmarkPos( ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS )
     164             :     , m_bCrossingAxisHasReverseDirection(false)
     165             :     , m_bCrossingAxisIsCategoryAxes(false)
     166             :     , m_bDisplayLabels( true )
     167             :     , m_nNumberFormatKey(0)
     168             :     , m_nMajorTickmarks(1)
     169             :     , m_nMinorTickmarks(1)
     170             :     , m_aTickmarkPropertiesList()
     171             :     , m_aLineProperties()
     172             :     //for category axes
     173             :     , m_nAxisType(AxisType::REALNUMBER)
     174             :     , m_bComplexCategories(false)
     175             :     , m_pExplicitCategoriesProvider(pExplicitCategoriesProvider)
     176        1095 :     , m_xAxisTextProvider(0)
     177             : {
     178        1095 : }
     179             : 
     180        1095 : AxisProperties::AxisProperties( const AxisProperties& rAxisProperties )
     181             :     : m_xAxisModel( rAxisProperties.m_xAxisModel )
     182             :     , m_nDimensionIndex( rAxisProperties.m_nDimensionIndex )
     183             :     , m_bIsMainAxis( rAxisProperties.m_bIsMainAxis )
     184             :     , m_bSwapXAndY( rAxisProperties.m_bSwapXAndY )
     185             :     , m_eCrossoverType( rAxisProperties.m_eCrossoverType )
     186             :     , m_eLabelPos( rAxisProperties.m_eLabelPos )
     187             :     , m_eTickmarkPos( rAxisProperties.m_eTickmarkPos )
     188             :     , m_bCrossingAxisHasReverseDirection( rAxisProperties.m_bCrossingAxisHasReverseDirection )
     189             :     , m_bCrossingAxisIsCategoryAxes( rAxisProperties.m_bCrossingAxisIsCategoryAxes )
     190             :     , maLabelAlignment( rAxisProperties.maLabelAlignment )
     191             :     , m_bDisplayLabels( rAxisProperties.m_bDisplayLabels )
     192             :     , m_nNumberFormatKey( rAxisProperties.m_nNumberFormatKey )
     193             :     , m_nMajorTickmarks( rAxisProperties.m_nMajorTickmarks )
     194             :     , m_nMinorTickmarks( rAxisProperties.m_nMinorTickmarks )
     195             :     , m_aTickmarkPropertiesList( rAxisProperties.m_aTickmarkPropertiesList )
     196             :     , m_aLineProperties( rAxisProperties.m_aLineProperties )
     197             :     //for category axes
     198             :     , m_nAxisType( rAxisProperties.m_nAxisType )
     199             :     , m_bComplexCategories( rAxisProperties.m_bComplexCategories )
     200             :     , m_pExplicitCategoriesProvider( rAxisProperties.m_pExplicitCategoriesProvider )
     201        1095 :     , m_xAxisTextProvider( rAxisProperties.m_xAxisTextProvider )
     202             : {
     203        1095 :     if( rAxisProperties.m_pfMainLinePositionAtOtherAxis )
     204        1032 :         m_pfMainLinePositionAtOtherAxis.reset(*rAxisProperties.m_pfMainLinePositionAtOtherAxis);
     205        1095 :     if( rAxisProperties.m_pfExrtaLinePositionAtOtherAxis )
     206           0 :         m_pfExrtaLinePositionAtOtherAxis.reset(*rAxisProperties.m_pfExrtaLinePositionAtOtherAxis);
     207        1095 : }
     208             : 
     209          35 : LabelAlignment lcl_getLabelAlignmentForZAxis( const AxisProperties& rAxisProperties )
     210             : {
     211          35 :     LabelAlignment aRet( LABEL_ALIGN_RIGHT );
     212          35 :     if (rAxisProperties.maLabelAlignment.mfLabelDirection < 0)
     213           0 :         aRet = LABEL_ALIGN_LEFT;
     214          35 :     return aRet;
     215             : }
     216             : 
     217         530 : LabelAlignment lcl_getLabelAlignmentForYAxis( const AxisProperties& rAxisProperties )
     218             : {
     219         530 :     LabelAlignment aRet( LABEL_ALIGN_RIGHT );
     220         530 :     if (rAxisProperties.maLabelAlignment.mfLabelDirection < 0)
     221         509 :         aRet = LABEL_ALIGN_LEFT;
     222         530 :     return aRet;
     223             : }
     224             : 
     225         530 : LabelAlignment lcl_getLabelAlignmentForXAxis( const AxisProperties& rAxisProperties )
     226             : {
     227         530 :     LabelAlignment aRet( LABEL_ALIGN_BOTTOM );
     228         530 :     if (rAxisProperties.maLabelAlignment.mfLabelDirection < 0)
     229          14 :         aRet = LABEL_ALIGN_TOP;
     230         530 :     return aRet;
     231             : }
     232             : 
     233        1095 : void AxisProperties::initAxisPositioning( const uno::Reference< beans::XPropertySet >& xAxisProp )
     234             : {
     235        1095 :     if( !xAxisProp.is() )
     236        1095 :         return;
     237             :     try
     238             :     {
     239        1095 :         if( AxisHelper::isAxisPositioningEnabled() )
     240             :         {
     241        1095 :             xAxisProp->getPropertyValue("CrossoverPosition") >>= m_eCrossoverType;
     242        1095 :             if( ::com::sun::star::chart::ChartAxisPosition_VALUE == m_eCrossoverType )
     243             :             {
     244          47 :                 double fValue = 0.0;
     245          47 :                 xAxisProp->getPropertyValue("CrossoverValue") >>= fValue;
     246             : 
     247          47 :                 if( m_bCrossingAxisIsCategoryAxes )
     248           4 :                     fValue = ::rtl::math::round(fValue);
     249          47 :                 m_pfMainLinePositionAtOtherAxis.reset(fValue);
     250             :             }
     251        1048 :             else if( ::com::sun::star::chart::ChartAxisPosition_ZERO == m_eCrossoverType )
     252         985 :                 m_pfMainLinePositionAtOtherAxis.reset(0.0);
     253             : 
     254        1095 :             xAxisProp->getPropertyValue("LabelPosition") >>= m_eLabelPos;
     255        1095 :             xAxisProp->getPropertyValue("MarkPosition") >>= m_eTickmarkPos;
     256             :         }
     257             :         else
     258             :         {
     259           0 :             m_eCrossoverType = ::com::sun::star::chart::ChartAxisPosition_START;
     260           0 :             if( m_bIsMainAxis == m_bCrossingAxisHasReverseDirection )
     261           0 :                 m_eCrossoverType = ::com::sun::star::chart::ChartAxisPosition_END;
     262           0 :             m_eLabelPos = ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS;
     263           0 :             m_eTickmarkPos = ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS;
     264             :         }
     265             :     }
     266           0 :     catch( const uno::Exception& e )
     267             :     {
     268             :         ASSERT_EXCEPTION( e );
     269             :     }
     270             : }
     271             : 
     272        1095 : void AxisProperties::init( bool bCartesian )
     273             : {
     274             :     uno::Reference< beans::XPropertySet > xProp =
     275        1095 :         uno::Reference<beans::XPropertySet>::query( this->m_xAxisModel );
     276        1095 :     if( !xProp.is() )
     277        1095 :         return;
     278             : 
     279        1095 :     if( m_nDimensionIndex<2 )
     280        1060 :         initAxisPositioning( xProp );
     281             : 
     282        2190 :     ScaleData aScaleData = m_xAxisModel->getScaleData();
     283        1095 :     if( m_nDimensionIndex==0 )
     284         530 :         AxisHelper::checkDateAxis( aScaleData, m_pExplicitCategoriesProvider, bCartesian );
     285        1095 :     m_nAxisType = aScaleData.AxisType;
     286             : 
     287        1095 :     if( bCartesian )
     288             :     {
     289        2720 :         if( m_nDimensionIndex == 0 && m_nAxisType == AxisType::CATEGORY
     290        1575 :                 && m_pExplicitCategoriesProvider && m_pExplicitCategoriesProvider->hasComplexCategories() )
     291           0 :             m_bComplexCategories = true;
     292             : 
     293        1095 :         if( ::com::sun::star::chart::ChartAxisPosition_END == m_eCrossoverType )
     294           6 :             maLabelAlignment.mfInnerTickDirection = m_bCrossingAxisHasReverseDirection ? 1.0 : -1.0;
     295             :         else
     296        1089 :             maLabelAlignment.mfInnerTickDirection = m_bCrossingAxisHasReverseDirection ? -1.0 : 1.0;
     297             : 
     298        1095 :         if( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS == m_eLabelPos )
     299        1039 :             maLabelAlignment.mfLabelDirection = maLabelAlignment.mfInnerTickDirection;
     300          56 :         else if( ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS_OTHER_SIDE == m_eLabelPos )
     301          15 :             maLabelAlignment.mfLabelDirection = -maLabelAlignment.mfInnerTickDirection;
     302          41 :         else if( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_START == m_eLabelPos )
     303          41 :             maLabelAlignment.mfLabelDirection = m_bCrossingAxisHasReverseDirection ? -1 : 1;
     304           0 :         else if( ::com::sun::star::chart::ChartAxisLabelPosition_OUTSIDE_END == m_eLabelPos )
     305           0 :             maLabelAlignment.mfLabelDirection = m_bCrossingAxisHasReverseDirection ? 1 : -1;
     306             : 
     307        1095 :         if( m_nDimensionIndex==2 )
     308          35 :             maLabelAlignment.meAlignment = lcl_getLabelAlignmentForZAxis(*this);
     309             :         else
     310             :         {
     311        1590 :             bool bIsYAxisPosition = (m_nDimensionIndex==1 && !m_bSwapXAndY)
     312        1609 :                 || (m_nDimensionIndex==0 && m_bSwapXAndY);
     313        1060 :             if( bIsYAxisPosition )
     314             :             {
     315         530 :                 maLabelAlignment.mfLabelDirection *= -1.0;
     316         530 :                 maLabelAlignment.mfInnerTickDirection *= -1.0;
     317             :             }
     318             : 
     319        1060 :             if( bIsYAxisPosition )
     320         530 :                 maLabelAlignment.meAlignment = lcl_getLabelAlignmentForYAxis(*this);
     321             :             else
     322         530 :                 maLabelAlignment.meAlignment = lcl_getLabelAlignmentForXAxis(*this);
     323             :         }
     324             :     }
     325             : 
     326             :     try
     327             :     {
     328             :         //init LineProperties
     329        1095 :         m_aLineProperties.initFromPropertySet( xProp );
     330             : 
     331             :         //init display labels
     332        1095 :         xProp->getPropertyValue( "DisplayLabels" ) >>= m_bDisplayLabels;
     333             : 
     334             :         //init TickmarkProperties
     335        1095 :         xProp->getPropertyValue( "MajorTickmarks" ) >>= m_nMajorTickmarks;
     336        1095 :         xProp->getPropertyValue( "MinorTickmarks" ) >>= m_nMinorTickmarks;
     337             : 
     338        1095 :         sal_Int32 nMaxDepth = 0;
     339        1095 :         if(m_nMinorTickmarks!=0)
     340          87 :             nMaxDepth=2;
     341        1008 :         else if(m_nMajorTickmarks!=0)
     342         964 :             nMaxDepth=1;
     343             : 
     344        1095 :         this->m_aTickmarkPropertiesList.clear();
     345        2233 :         for( sal_Int32 nDepth=0; nDepth<nMaxDepth; nDepth++ )
     346             :         {
     347        1138 :             TickmarkProperties aTickmarkProperties = this->makeTickmarkProperties( nDepth );
     348        1138 :             this->m_aTickmarkPropertiesList.push_back( aTickmarkProperties );
     349        1138 :         }
     350             :     }
     351           0 :     catch( const uno::Exception& e )
     352             :     {
     353             :         ASSERT_EXCEPTION( e );
     354        1095 :     }
     355             : }
     356             : 
     357        1095 : AxisLabelProperties::AxisLabelProperties()
     358             :                         : m_aFontReferenceSize( ChartModelHelper::getDefaultPageSize() )
     359             :                         , m_aMaximumSpaceForLabels( 0 , 0, m_aFontReferenceSize.Width, m_aFontReferenceSize.Height )
     360             :                         , nNumberFormatKey(0)
     361             :                         , eStaggering( SIDE_BY_SIDE )
     362             :                         , bLineBreakAllowed( false )
     363             :                         , bOverlapAllowed( false )
     364             :                         , bStackCharacters( false )
     365             :                         , fRotationAngleDegree( 0.0 )
     366             :                         , nRhythm( 1 )
     367        1095 :                         , bRhythmIsFix(false)
     368             : {
     369             : 
     370        1095 : }
     371             : 
     372        1008 : void AxisLabelProperties::init( const uno::Reference< XAxis >& xAxisModel )
     373             : {
     374             :     uno::Reference< beans::XPropertySet > xProp =
     375        1008 :         uno::Reference<beans::XPropertySet>::query( xAxisModel );
     376        1008 :     if(xProp.is())
     377             :     {
     378             :         try
     379             :         {
     380        1008 :             xProp->getPropertyValue( "TextBreak" ) >>= this->bLineBreakAllowed;
     381        1008 :             xProp->getPropertyValue( "TextOverlap" ) >>= this->bOverlapAllowed;
     382        1008 :             xProp->getPropertyValue( "StackCharacters" ) >>= this->bStackCharacters;
     383        1008 :             xProp->getPropertyValue( "TextRotation" ) >>= this->fRotationAngleDegree;
     384             : 
     385             :             ::com::sun::star::chart::ChartAxisArrangeOrderType eArrangeOrder;
     386        1008 :             xProp->getPropertyValue( "ArrangeOrder" ) >>= eArrangeOrder;
     387        1008 :             switch(eArrangeOrder)
     388             :             {
     389             :                 case ::com::sun::star::chart::ChartAxisArrangeOrderType_SIDE_BY_SIDE:
     390         157 :                     this->eStaggering = SIDE_BY_SIDE;
     391         157 :                     break;
     392             :                 case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_EVEN:
     393           7 :                     this->eStaggering = STAGGER_EVEN;
     394           7 :                     break;
     395             :                 case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_ODD:
     396           9 :                     this->eStaggering = STAGGER_ODD;
     397           9 :                     break;
     398             :                 default:
     399         835 :                     this->eStaggering = STAGGER_AUTO;
     400         835 :                     break;
     401             :             }
     402             :         }
     403           0 :         catch( const uno::Exception& e )
     404             :         {
     405             :             ASSERT_EXCEPTION( e );
     406             :         }
     407        1008 :     }
     408        1008 : }
     409             : 
     410        4986 : bool AxisLabelProperties::getIsStaggered() const
     411             : {
     412        4986 :     return ( STAGGER_ODD == eStaggering || STAGGER_EVEN == eStaggering );
     413             : }
     414             : 
     415         108 : } //namespace chart
     416             : 
     417             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10