LCOV - code coverage report
Current view: top level - chart2/source/view/axes - VPolarAngleAxis.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 80 83 96.4 %
Date: 2015-06-13 12:38:46 Functions: 8 8 100.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 <basegfx/numeric/ftools.hxx>
      21             : 
      22             : #include "VPolarAngleAxis.hxx"
      23             : #include "VPolarGrid.hxx"
      24             : #include "AbstractShapeFactory.hxx"
      25             : #include "macros.hxx"
      26             : #include "NumberFormatterWrapper.hxx"
      27             : #include "PolarLabelPositionHelper.hxx"
      28             : #include <tools/color.hxx>
      29             : 
      30             : #include <boost/scoped_ptr.hpp>
      31             : 
      32             : namespace chart
      33             : {
      34             : using namespace ::com::sun::star;
      35             : using namespace ::com::sun::star::chart2;
      36             : using namespace ::rtl::math;
      37             : 
      38           2 : VPolarAngleAxis::VPolarAngleAxis( const AxisProperties& rAxisProperties
      39             :             , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier
      40             :             , sal_Int32 nDimensionCount )
      41           2 :             : VPolarAxis( rAxisProperties, xNumberFormatsSupplier, 0/*nDimensionIndex*/, nDimensionCount )
      42             : {
      43           2 : }
      44             : 
      45           6 : VPolarAngleAxis::~VPolarAngleAxis()
      46             : {
      47           2 :     delete m_pPosHelper;
      48           2 :     m_pPosHelper = NULL;
      49           4 : }
      50             : 
      51           8 : bool VPolarAngleAxis::createTextShapes_ForAngleAxis(
      52             :                        const uno::Reference< drawing::XShapes >& xTarget
      53             :                      , EquidistantTickIter& rTickIter
      54             :                      , AxisLabelProperties& rAxisLabelProperties
      55             :                      , double fLogicRadius
      56             :                      , double fLogicZ )
      57             : {
      58           8 :     sal_Int32 nDimensionCount = 2;
      59           8 :     AbstractShapeFactory* pShapeFactory = AbstractShapeFactory::getOrCreateShapeFactory(m_xShapeFactory);
      60             : 
      61             :     FixedNumberFormatter aFixedNumberFormatter(
      62           8 :         m_xNumberFormatsSupplier, rAxisLabelProperties.nNumberFormatKey );
      63             : 
      64             :     //prepare text properties for multipropertyset-interface of shape
      65          16 :     tNameSequence aPropNames;
      66          16 :     tAnySequence aPropValues;
      67             : 
      68          16 :     uno::Reference< beans::XPropertySet > xProps( m_aAxisProperties.m_xAxisModel, uno::UNO_QUERY );
      69           8 :     PropertyMapper::getTextLabelMultiPropertyLists( xProps, aPropNames, aPropValues, false );
      70             :     LabelPositionHelper::doDynamicFontResize( aPropValues, aPropNames, xProps
      71           8 :         , rAxisLabelProperties.m_aFontReferenceSize );
      72             : 
      73           8 :     uno::Any* pColorAny = PropertyMapper::getValuePointer(aPropValues,aPropNames,"CharColor");
      74           8 :     sal_Int32 nColor = Color( COL_AUTO ).GetColor();
      75           8 :     if(pColorAny)
      76           8 :         *pColorAny >>= nColor;
      77             : 
      78           8 :     const uno::Sequence< OUString >* pLabels = m_bUseTextLabels? &m_aTextLabels : 0;
      79             : 
      80             :     //TickInfo* pLastVisibleNeighbourTickInfo = NULL;
      81           8 :     sal_Int32 nTick = 0;
      82             : 
      83          56 :     for( TickInfo* pTickInfo = rTickIter.firstInfo()
      84             :         ; pTickInfo
      85          48 :         ; pTickInfo = rTickIter.nextInfo(), nTick++ )
      86             :     {
      87             :         //don't create labels which does not fit into the rhythm
      88          48 :         if( nTick%rAxisLabelProperties.nRhythm != 0)
      89           0 :             continue;
      90             : 
      91             :         //don't create labels for invisible ticks
      92          48 :         if( !pTickInfo->bPaintIt )
      93           0 :             continue;
      94             : 
      95             :         //if NO OVERLAP -> don't create labels where the
      96             :         //anchor position is the same as for the last label
      97             :         //@todo
      98             : 
      99          48 :         if(!pTickInfo->xTextShape.is())
     100             :         {
     101             :             //create single label
     102          48 :             bool bHasExtraColor=false;
     103          48 :             sal_Int32 nExtraColor=0;
     104             : 
     105          48 :             OUString aLabel;
     106          48 :             if(pLabels)
     107             :             {
     108          48 :                 sal_Int32 nIndex = static_cast< sal_Int32 >(pTickInfo->getUnscaledTickValue()) - 1; //first category (index 0) matches with real number 1.0
     109          48 :                 if( nIndex>=0 && nIndex<pLabels->getLength() )
     110          40 :                     aLabel = (*pLabels)[nIndex];
     111             :             }
     112             :             else
     113           0 :                 aLabel = aFixedNumberFormatter.getFormattedString( pTickInfo->getUnscaledTickValue(), nExtraColor, bHasExtraColor );
     114             : 
     115          48 :             if(pColorAny)
     116          48 :                 *pColorAny = uno::makeAny(bHasExtraColor?nExtraColor:nColor);
     117             : 
     118          48 :             double fLogicAngle = pTickInfo->getUnscaledTickValue();
     119             : 
     120          48 :             LabelAlignment eLabelAlignment(LABEL_ALIGN_CENTER);
     121          96 :             PolarLabelPositionHelper aPolarLabelPositionHelper(m_pPosHelper,nDimensionCount,xTarget, pShapeFactory);
     122          48 :             sal_Int32 nScreenValueOffsetInRadiusDirection = m_aAxisLabelProperties.m_aMaximumSpaceForLabels.Height/15;
     123             :             awt::Point aAnchorScreenPosition2D( aPolarLabelPositionHelper.getLabelScreenPositionAndAlignmentForLogicValues(
     124          48 :                     eLabelAlignment, fLogicAngle, fLogicRadius, fLogicZ, nScreenValueOffsetInRadiusDirection ));
     125          48 :             LabelPositionHelper::changeTextAdjustment( aPropValues, aPropNames, eLabelAlignment );
     126             : 
     127             :             // #i78696# use mathematically correct rotation now
     128          48 :             const double fRotationAnglePi(rAxisLabelProperties.fRotationAngleDegree * (F_PI / -180.0));
     129             : 
     130          96 :             uno::Any aATransformation = AbstractShapeFactory::makeTransformation( aAnchorScreenPosition2D, fRotationAnglePi );
     131          96 :             OUString aStackedLabel = AbstractShapeFactory::getStackedString( aLabel, rAxisLabelProperties.bStackCharacters );
     132             : 
     133          96 :             pTickInfo->xTextShape = pShapeFactory->createText( xTarget, aStackedLabel, aPropNames, aPropValues, aATransformation );
     134             :         }
     135             : 
     136             :         //if NO OVERLAP -> remove overlapping shapes
     137             :         //@todo
     138             :     }
     139          16 :     return true;
     140             : }
     141             : 
     142           2 : void VPolarAngleAxis::createMaximumLabels()
     143             : {
     144           2 :     if( !prepareShapeCreation() )
     145           2 :         return;
     146             : 
     147           2 :     createLabels();
     148             : }
     149             : 
     150           2 : void VPolarAngleAxis::updatePositions()
     151             : {
     152             :     //todo: really only update the positions
     153             : 
     154           2 :     if( !prepareShapeCreation() )
     155           2 :         return;
     156             : 
     157           2 :     createLabels();
     158             : }
     159             : 
     160           8 : void VPolarAngleAxis::createLabels()
     161             : {
     162           8 :     if( !prepareShapeCreation() )
     163           8 :         return;
     164             : 
     165           8 :     double fLogicRadius = m_pPosHelper->getOuterLogicRadius();
     166             : 
     167           8 :     if( m_aAxisProperties.m_bDisplayLabels )
     168             :     {
     169             :         //get the transformed screen values for all tickmarks in aAllTickInfos
     170           8 :         boost::scoped_ptr< TickFactory > apTickFactory( this->createTickFactory() );
     171             : 
     172             :         //create tick mark text shapes
     173             :         //@todo: iterate through all tick depth which should be labeled
     174             : 
     175          16 :         EquidistantTickIter aTickIter( m_aAllTickInfos, m_aIncrement, 0, 0 );
     176           8 :         this->updateUnscaledValuesAtTicks( aTickIter );
     177             : 
     178           8 :         removeTextShapesFromTicks();
     179             : 
     180           8 :         AxisLabelProperties aAxisLabelProperties( m_aAxisLabelProperties );
     181           8 :         aAxisLabelProperties.bOverlapAllowed = true;
     182           8 :         double fLogicZ      = 1.0;//as defined
     183          16 :         while( !createTextShapes_ForAngleAxis( m_xTextTarget, aTickIter
     184             :                         , aAxisLabelProperties
     185             :                         , fLogicRadius, fLogicZ
     186           8 :                         ) )
     187             :         {
     188           8 :         }
     189             : 
     190             :         //no staggering for polar angle axis
     191             :     }
     192             : }
     193             : 
     194           2 : void VPolarAngleAxis::createShapes()
     195             : {
     196           2 :     if( !prepareShapeCreation() )
     197           2 :         return;
     198             : 
     199           2 :     double fLogicRadius = m_pPosHelper->getOuterLogicRadius();
     200           2 :     double fLogicZ      = 1.0;//as defined
     201             : 
     202             :     //create axis main lines
     203           2 :     drawing::PointSequenceSequence aPoints(1);
     204           2 :     VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints, m_aAllTickInfos, m_aIncrement, m_aScale, m_pPosHelper, fLogicRadius, fLogicZ );
     205             :     uno::Reference< drawing::XShape > xShape = m_pShapeFactory->createLine2D(
     206           4 :             m_xGroupShape_Shapes, aPoints, &m_aAxisProperties.m_aLineProperties );
     207             :     //because of this name this line will be used for marking the axis
     208           2 :     ::chart::AbstractShapeFactory::setShapeName( xShape, "MarkHandles" );
     209             : 
     210             :     //create labels
     211           4 :     createLabels();
     212             : }
     213             : 
     214             : } //namespace chart
     215             : 
     216             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11