LCOV - code coverage report
Current view: top level - chart2/source/tools - AxisHelper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 424 604 70.2 %
Date: 2014-04-11 Functions: 37 47 78.7 %
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 "AxisHelper.hxx"
      21             : #include "DiagramHelper.hxx"
      22             : #include "ChartTypeHelper.hxx"
      23             : #include "macros.hxx"
      24             : #include "AxisIndexDefines.hxx"
      25             : #include "LinePropertiesHelper.hxx"
      26             : #include "ContainerHelper.hxx"
      27             : #include "servicenames_coosystems.hxx"
      28             : #include "DataSeriesHelper.hxx"
      29             : #include "Scaling.hxx"
      30             : #include "ChartModelHelper.hxx"
      31             : #include "DataSourceHelper.hxx"
      32             : 
      33             : #include <unotools/saveopt.hxx>
      34             : 
      35             : #include <com/sun/star/chart/ChartAxisPosition.hpp>
      36             : 
      37             : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
      38             : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
      39             : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
      40             : #include <com/sun/star/chart2/data/XDataSource.hpp>
      41             : 
      42             : // header for class OUStringBuffer
      43             : #include <rtl/ustrbuf.hxx>
      44             : #include <rtl/math.hxx>
      45             : 
      46             : #include <com/sun/star/util/XCloneable.hpp>
      47             : #include <com/sun/star/lang/XServiceName.hpp>
      48             : 
      49             : #include <map>
      50             : 
      51             : namespace chart
      52             : {
      53             : using namespace ::com::sun::star;
      54             : using namespace ::com::sun::star::chart2;
      55             : using ::com::sun::star::uno::Reference;
      56             : using ::com::sun::star::uno::Sequence;
      57             : 
      58         560 : Reference< chart2::XScaling > AxisHelper::createLinearScaling()
      59             : {
      60         560 :     return new LinearScaling( 1.0, 0.0 );
      61             : }
      62             : 
      63           4 : Reference< chart2::XScaling > AxisHelper::createLogarithmicScaling( double fBase )
      64             : {
      65           4 :     return new LogarithmicScaling( fBase );
      66             : }
      67             : 
      68        4476 : ScaleData AxisHelper::createDefaultScale()
      69             : {
      70        4476 :     ScaleData aScaleData;
      71        4476 :     aScaleData.AxisType = chart2::AxisType::REALNUMBER;
      72        4476 :     aScaleData.AutoDateAxis = true;
      73        4476 :     aScaleData.ShiftedCategoryPosition = false;//this is adapted in the view code currently
      74        8952 :     Sequence< SubIncrement > aSubIncrements(1);
      75        4476 :     aSubIncrements[0] = SubIncrement();
      76        4476 :     aScaleData.IncrementData.SubIncrements = aSubIncrements;
      77        8952 :     return aScaleData;
      78             : }
      79             : 
      80        2167 : void AxisHelper::removeExplicitScaling( ScaleData& rScaleData )
      81             : {
      82        2167 :     uno::Any aEmpty;
      83        2167 :     rScaleData.Minimum = rScaleData.Maximum = rScaleData.Origin = aEmpty;
      84        2167 :     rScaleData.Scaling = 0;
      85        4334 :     ScaleData aDefaultScale( createDefaultScale() );
      86        2167 :     rScaleData.IncrementData = aDefaultScale.IncrementData;
      87        4334 :     rScaleData.TimeIncrement = aDefaultScale.TimeIncrement;
      88        2167 : }
      89             : 
      90        4586 : bool AxisHelper::isLogarithmic( const Reference< XScaling >& xScaling )
      91             : {
      92        4586 :     bool bReturn = false;
      93        4586 :     Reference< lang::XServiceName > xServiceName( xScaling, uno::UNO_QUERY );
      94       14915 :     bReturn =( xServiceName.is() && (xServiceName->getServiceName()).equals(
      95       14915 :               "com.sun.star.chart2.LogarithmicScaling"));
      96        4586 :     return bReturn;
      97             : }
      98             : 
      99        2973 : chart2::ScaleData AxisHelper::getDateCheckedScale( const Reference< chart2::XAxis >& xAxis, ChartModel& rModel )
     100             : {
     101        2973 :     ScaleData aScale = xAxis->getScaleData();
     102        5946 :     Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( rModel ) );
     103        2973 :     if( aScale.AutoDateAxis && aScale.AxisType == AxisType::CATEGORY )
     104             :     {
     105        1563 :         sal_Int32 nDimensionIndex=0; sal_Int32 nAxisIndex=0;
     106        1563 :         AxisHelper::getIndicesForAxis(xAxis, xCooSys, nDimensionIndex, nAxisIndex );
     107        1563 :         bool bChartTypeAllowsDateAxis = ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys, 0 ), 2, nDimensionIndex );
     108        1563 :         if( bChartTypeAllowsDateAxis )
     109        1556 :             aScale.AxisType = AxisType::DATE;
     110             :     }
     111        2973 :     if( aScale.AxisType == AxisType::DATE )
     112             :     {
     113        1556 :         ExplicitCategoriesProvider aExplicitCategoriesProvider( xCooSys, rModel );
     114        1556 :         if( !aExplicitCategoriesProvider.isDateAxis() )
     115        1556 :             aScale.AxisType = AxisType::CATEGORY;
     116             :     }
     117        5946 :     return aScale;
     118             : }
     119             : 
     120        1226 : void AxisHelper::checkDateAxis( chart2::ScaleData& rScale, ExplicitCategoriesProvider* pExplicitCategoriesProvider, bool bChartTypeAllowsDateAxis )
     121             : {
     122        1226 :     if( rScale.AutoDateAxis && rScale.AxisType == AxisType::CATEGORY && bChartTypeAllowsDateAxis )
     123             :     {
     124        1055 :         rScale.AxisType = AxisType::DATE;
     125        1055 :         removeExplicitScaling( rScale );
     126             :     }
     127        1226 :     if( rScale.AxisType == AxisType::DATE && (!pExplicitCategoriesProvider || !pExplicitCategoriesProvider->isDateAxis()) )
     128             :     {
     129        1055 :         rScale.AxisType = AxisType::CATEGORY;
     130        1055 :         removeExplicitScaling( rScale );
     131             :     }
     132        1226 : }
     133             : 
     134        3246 : sal_Int32 AxisHelper::getExplicitNumberFormatKeyForAxis(
     135             :                   const Reference< chart2::XAxis >& xAxis
     136             :                 , const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem
     137             :                 , const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier
     138             :                 , bool bSearchForParallelAxisIfNothingIsFound )
     139             : {
     140        3246 :     sal_Int32 nNumberFormatKey(0);
     141        3246 :     bool bNumberFormatKeyFoundViaAttachedData = false;
     142        3246 :     sal_Int32 nAxisIndex = 0;
     143        3246 :     sal_Int32 nDimensionIndex = 1;
     144        3246 :     AxisHelper::getIndicesForAxis( xAxis, xCorrespondingCoordinateSystem, nDimensionIndex, nAxisIndex );
     145        3246 :     Reference< chart2::XChartDocument > xChartDoc( xNumberFormatsSupplier, uno::UNO_QUERY );
     146             : 
     147        6492 :     Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY );
     148        3246 :     if( xProp.is() && !( xProp->getPropertyValue( "NumberFormat" ) >>= nNumberFormatKey ) )
     149             :     {
     150        2973 :         bool bFormatSet = false;
     151             :         //check whether we have a percent scale -> use percent format
     152        2973 :         if( xNumberFormatsSupplier.is() )
     153             :         {
     154        2973 :             ChartModel* pModel = dynamic_cast<ChartModel*>( xChartDoc.get() );
     155             :             assert(pModel);
     156        2973 :             ScaleData aData = AxisHelper::getDateCheckedScale( xAxis, *pModel );
     157        2973 :             if( aData.AxisType==AxisType::PERCENT )
     158             :             {
     159          73 :                 sal_Int32 nPercentFormat = DiagramHelper::getPercentNumberFormat( xNumberFormatsSupplier );
     160          73 :                 if( nPercentFormat != -1 )
     161             :                 {
     162          73 :                     nNumberFormatKey = nPercentFormat;
     163          73 :                     bFormatSet = true;
     164             :                 }
     165             :             }
     166        2900 :             else if( aData.AxisType==AxisType::DATE )
     167             :             {
     168           0 :                 if( aData.Categories.is() )
     169             :                 {
     170           0 :                     Reference< data::XDataSequence > xSeq( aData.Categories->getValues());
     171           0 :                     if( xSeq.is() && !( xChartDoc.is() && xChartDoc->hasInternalDataProvider()) )
     172           0 :                         nNumberFormatKey = xSeq->getNumberFormatKeyByIndex( -1 );
     173             :                     else
     174           0 :                         nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier );
     175           0 :                     bFormatSet = true;
     176             :                 }
     177             :             }
     178        2900 :             else if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() && nDimensionIndex == 0 ) //maybe date axis
     179             :             {
     180        1642 :                 Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram() );
     181        1642 :                 if( DiagramHelper::isSupportingDateAxis( xDiagram ) )
     182             :                 {
     183        1467 :                     nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier );
     184             :                 }
     185             :                 else
     186             :                 {
     187         175 :                     Reference< data::XDataSource > xSource( DataSourceHelper::getUsedData( xChartDoc ) );
     188         175 :                     if( xSource.is() )
     189             :                     {
     190             :                         ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aXValues(
     191         175 :                             DataSeriesHelper::getAllDataSequencesByRole( xSource->getDataSequences(), "values-x", true ) );
     192         175 :                         if( aXValues.empty() )
     193             :                         {
     194         151 :                             Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
     195         151 :                             if( xCategories.is() )
     196             :                             {
     197         151 :                                 Reference< data::XDataSequence > xSeq( xCategories->getValues());
     198         151 :                                 if( xSeq.is() )
     199             :                                 {
     200         151 :                                     bool bHasValidDoubles = false;
     201         151 :                                     double fTest=0.0;
     202         151 :                                     Sequence< uno::Any > aCats( xSeq->getData() );
     203         151 :                                     sal_Int32 nCount = aCats.getLength();
     204        1019 :                                     for( sal_Int32 i = 0; i < nCount; ++i )
     205             :                                     {
     206         868 :                                         if( (aCats[i]>>=fTest) && !::rtl::math::isNan(fTest) )
     207             :                                         {
     208           0 :                                             bHasValidDoubles=true;
     209           0 :                                             break;
     210             :                                         }
     211             :                                     }
     212         151 :                                     if( bHasValidDoubles )
     213           0 :                                         nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier );
     214         151 :                                 }
     215         151 :                             }
     216         175 :                         }
     217         175 :                     }
     218             :                 }
     219        1642 :                 bFormatSet = true;
     220        2973 :             }
     221             :         }
     222             : 
     223        2973 :         if( !bFormatSet )
     224             :         {
     225             :             typedef ::std::map< sal_Int32, sal_Int32 > tNumberformatFrequency;
     226        1258 :             tNumberformatFrequency aKeyMap;
     227             : 
     228             :             try
     229             :             {
     230        1258 :                 Reference< XChartTypeContainer > xCTCnt( xCorrespondingCoordinateSystem, uno::UNO_QUERY_THROW );
     231        1258 :                 if( xCTCnt.is() )
     232             :                 {
     233        1258 :                     OUString aRoleToMatch;
     234        1258 :                     if( nDimensionIndex == 0 )
     235         128 :                         aRoleToMatch = "values-x";
     236        2516 :                     Sequence< Reference< XChartType > > aChartTypes( xCTCnt->getChartTypes());
     237        2564 :                     for( sal_Int32 nCTIdx=0; nCTIdx<aChartTypes.getLength(); ++nCTIdx )
     238             :                     {
     239        1306 :                         if( nDimensionIndex != 0 )
     240        1178 :                             aRoleToMatch = ChartTypeHelper::getRoleOfSequenceForYAxisNumberFormatDetection( aChartTypes[nCTIdx] );
     241        1306 :                         Reference< XDataSeriesContainer > xDSCnt( aChartTypes[nCTIdx], uno::UNO_QUERY_THROW );
     242        2612 :                         Sequence< Reference< XDataSeries > > aDataSeriesSeq( xDSCnt->getDataSeries());
     243        5074 :                         for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aDataSeriesSeq.getLength(); ++nSeriesIdx )
     244             :                         {
     245        3768 :                             Reference< chart2::XDataSeries > xDataSeries(aDataSeriesSeq[nSeriesIdx]);
     246        7488 :                             Reference< data::XDataSource > xSource( xDataSeries, uno::UNO_QUERY_THROW );
     247             : 
     248        3768 :                             if( nDimensionIndex == 1 )
     249             :                             {
     250             :                                 //only take those series into accoutn that are attached to this axis
     251        2089 :                                 sal_Int32 nAttachedAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries);
     252        2089 :                                 if( nAttachedAxisIndex != nAxisIndex )
     253          48 :                                     continue;
     254             :                             }
     255             : 
     256             :                             Reference< data::XLabeledDataSequence > xLabeledSeq(
     257        7440 :                                 DataSeriesHelper::getDataSequenceByRole( xSource, aRoleToMatch ) );
     258             : 
     259        3720 :                             if( !xLabeledSeq.is() && nDimensionIndex==0 )
     260             :                             {
     261         690 :                                 ScaleData aData = xAxis->getScaleData();
     262         690 :                                 xLabeledSeq = aData.Categories;
     263             :                             }
     264             : 
     265        3720 :                             if( xLabeledSeq.is() )
     266             :                             {
     267        3658 :                                 Reference< data::XDataSequence > xSeq( xLabeledSeq->getValues());
     268        3658 :                                 if( xSeq.is() )
     269             :                                 {
     270        3658 :                                     sal_Int32 nKey = xSeq->getNumberFormatKeyByIndex( -1 );
     271             :                                     // initialize the value
     272        3658 :                                     if( aKeyMap.find( nKey ) == aKeyMap.end())
     273        1218 :                                         aKeyMap[ nKey ] = 0;
     274             :                                     // increase frequency
     275        3658 :                                     aKeyMap[ nKey ] = (aKeyMap[ nKey ] + 1);
     276        3658 :                                 }
     277             :                             }
     278        3720 :                         }
     279        2564 :                     }
     280        1258 :                 }
     281             :             }
     282           0 :             catch( const uno::Exception & ex )
     283             :             {
     284             :                 ASSERT_EXCEPTION( ex );
     285             :             }
     286             : 
     287        1258 :             if( ! aKeyMap.empty())
     288             :             {
     289        1218 :                 sal_Int32 nMaxFreq = 0;
     290             :                 // find most frequent key
     291        7308 :                 for( tNumberformatFrequency::const_iterator aIt = aKeyMap.begin();
     292        4872 :                     aIt != aKeyMap.end(); ++aIt )
     293             :                 {
     294             :                     OSL_TRACE( "NumberFormatKey %d appears %d times", (*aIt).first, (*aIt).second );
     295             :                     // all values must at least be 1
     296        1218 :                     if( (*aIt).second > nMaxFreq )
     297             :                     {
     298        1218 :                         nNumberFormatKey = (*aIt).first;
     299        1218 :                         bNumberFormatKeyFoundViaAttachedData = true;
     300        1218 :                         nMaxFreq = (*aIt).second;
     301             :                     }
     302             :                 }
     303             :             }
     304             : 
     305        1258 :             if( bSearchForParallelAxisIfNothingIsFound )
     306             :             {
     307             :                 //no format is set to this axis and no data is set to this axis
     308             :                 //--> try to obtain the format from the parallel y-axis
     309        1218 :                 if( !bNumberFormatKeyFoundViaAttachedData && nDimensionIndex == 1 )
     310             :                 {
     311          22 :                     sal_Int32 nParallelAxisIndex = (nAxisIndex==1) ?0 :1;
     312          22 :                     Reference< XAxis > xParallelAxis( AxisHelper::getAxis( 1, nParallelAxisIndex, xCorrespondingCoordinateSystem ) );
     313          22 :                     nNumberFormatKey = AxisHelper::getExplicitNumberFormatKeyForAxis( xParallelAxis, xCorrespondingCoordinateSystem, xNumberFormatsSupplier, false );
     314             :                 }
     315        1258 :             }
     316             :         }
     317             :     }
     318        6492 :     return nNumberFormatKey;
     319             : }
     320             : 
     321          10 : Reference< XAxis > AxisHelper::createAxis(
     322             :           sal_Int32 nDimensionIndex
     323             :         , sal_Int32 nAxisIndex // 0==main or 1==secondary axis
     324             :         , const Reference< XCoordinateSystem >& xCooSys
     325             :         , const Reference< uno::XComponentContext > & xContext
     326             :         , ReferenceSizeProvider * pRefSizeProvider )
     327             : {
     328          10 :     if( !xContext.is() || !xCooSys.is() )
     329           0 :         return NULL;
     330          10 :     if( nDimensionIndex >= xCooSys->getDimension() )
     331           0 :         return NULL;
     332             : 
     333          20 :     Reference< XAxis > xAxis( xContext->getServiceManager()->createInstanceWithContext(
     334          10 :                     "com.sun.star.chart2.Axis", xContext ), uno::UNO_QUERY );
     335             : 
     336             :     OSL_ASSERT( xAxis.is());
     337          10 :     if( xAxis.is())
     338             :     {
     339          10 :         xCooSys->setAxisByDimension( nDimensionIndex, xAxis, nAxisIndex );
     340             : 
     341          10 :         if( nAxisIndex>0 )//when inserting secondary axes copy some things from the main axis
     342             :         {
     343          10 :             ::com::sun::star::chart::ChartAxisPosition eNewAxisPos( ::com::sun::star::chart::ChartAxisPosition_END );
     344             : 
     345          10 :             Reference< XAxis > xMainAxis( xCooSys->getAxisByDimension( nDimensionIndex, 0 ) );
     346          10 :             if( xMainAxis.is() )
     347             :             {
     348          10 :                 ScaleData aScale = xAxis->getScaleData();
     349          20 :                 ScaleData aMainScale = xMainAxis->getScaleData();
     350             : 
     351          10 :                 aScale.AxisType = aMainScale.AxisType;
     352          10 :                 aScale.AutoDateAxis = aMainScale.AutoDateAxis;
     353          10 :                 aScale.Categories = aMainScale.Categories;
     354          10 :                 aScale.Orientation = aMainScale.Orientation;
     355             : 
     356          10 :                 xAxis->setScaleData( aScale );
     357             : 
     358             :                 //ensure that the second axis is not placed on the main axis
     359          20 :                 Reference< beans::XPropertySet > xMainProp( xMainAxis, uno::UNO_QUERY );
     360          10 :                 if( xMainProp.is() )
     361             :                 {
     362          10 :                     ::com::sun::star::chart::ChartAxisPosition eMainAxisPos( ::com::sun::star::chart::ChartAxisPosition_ZERO );
     363          10 :                     xMainProp->getPropertyValue("CrossoverPosition") >>= eMainAxisPos;
     364          10 :                     if( ::com::sun::star::chart::ChartAxisPosition_END == eMainAxisPos )
     365           0 :                         eNewAxisPos = ::com::sun::star::chart::ChartAxisPosition_START;
     366          10 :                 }
     367             :             }
     368             : 
     369          20 :             Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY );
     370          10 :             if( xProp.is() )
     371          20 :                 xProp->setPropertyValue("CrossoverPosition", uno::makeAny(eNewAxisPos) );
     372             :         }
     373             : 
     374          10 :         Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY );
     375          10 :         if( xProp.is() ) try
     376             :         {
     377             :             // set correct initial AutoScale
     378          10 :             if( pRefSizeProvider )
     379           0 :                 pRefSizeProvider->setValuesAtPropertySet( xProp );
     380             :         }
     381           0 :         catch( const uno::Exception& e )
     382             :         {
     383             :             ASSERT_EXCEPTION( e );
     384          10 :         }
     385             :     }
     386          10 :     return xAxis;
     387             : }
     388             : 
     389          10 : Reference< XAxis > AxisHelper::createAxis( sal_Int32 nDimensionIndex, bool bMainAxis
     390             :                 , const Reference< chart2::XDiagram >& xDiagram
     391             :                 , const Reference< uno::XComponentContext >& xContext
     392             :                 , ReferenceSizeProvider * pRefSizeProvider )
     393             : {
     394             :     OSL_ENSURE( xContext.is(), "need a context to create an axis" );
     395          10 :     if( !xContext.is() )
     396           0 :         return NULL;
     397             : 
     398          10 :     sal_Int32 nAxisIndex = bMainAxis ? MAIN_AXIS_INDEX : SECONDARY_AXIS_INDEX;
     399          10 :     sal_Int32 nCooSysIndex = 0;
     400          10 :     Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
     401             : 
     402             :     // create axis
     403             :     return AxisHelper::createAxis(
     404          10 :         nDimensionIndex, nAxisIndex, xCooSys, xContext, pRefSizeProvider );
     405             : }
     406             : 
     407         126 : void AxisHelper::showAxis( sal_Int32 nDimensionIndex, bool bMainAxis
     408             :                 , const Reference< chart2::XDiagram >& xDiagram
     409             :                 , const Reference< uno::XComponentContext >& xContext
     410             :                 , ReferenceSizeProvider * pRefSizeProvider )
     411             : {
     412         126 :     if( !xDiagram.is() )
     413         126 :         return;
     414             : 
     415         126 :     bool bNewAxisCreated = false;
     416         126 :     Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
     417         126 :     if( !xAxis.is() && xContext.is() )
     418             :     {
     419             :         // create axis
     420          10 :         bNewAxisCreated = true;
     421          10 :         xAxis.set( AxisHelper::createAxis( nDimensionIndex, bMainAxis, xDiagram, xContext, pRefSizeProvider ) );
     422             :     }
     423             : 
     424             :     OSL_ASSERT( xAxis.is());
     425         126 :     if( !bNewAxisCreated ) //default is true already if created
     426         116 :         AxisHelper::makeAxisVisible( xAxis );
     427             : }
     428             : 
     429          94 : void AxisHelper::showGrid( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
     430             :                 , const Reference< XDiagram >& xDiagram
     431             :                 , const Reference< uno::XComponentContext >& /*xContext*/ )
     432             : {
     433          94 :     if( !xDiagram.is() )
     434           0 :         return;
     435             : 
     436          94 :     Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
     437          94 :     if(!xCooSys.is())
     438           0 :         return;
     439             : 
     440         188 :     Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
     441          94 :     if(!xAxis.is())
     442             :     {
     443             :         //hhhh todo create axis without axis visibility
     444             :     }
     445          94 :     if(!xAxis.is())
     446           0 :         return;
     447             : 
     448          94 :     if( bMainGrid )
     449          82 :         AxisHelper::makeGridVisible( xAxis->getGridProperties() );
     450             :     else
     451             :     {
     452          12 :         Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
     453          24 :         for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
     454          24 :             AxisHelper::makeGridVisible( aSubGrids[nN] );
     455          94 :     }
     456             : }
     457             : 
     458         116 : void AxisHelper::makeAxisVisible( const Reference< XAxis >& xAxis )
     459             : {
     460         116 :     Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
     461         116 :     if( xProps.is() )
     462             :     {
     463         116 :         xProps->setPropertyValue( "Show", uno::makeAny( sal_True ) );
     464         116 :         LinePropertiesHelper::SetLineVisible( xProps );
     465         116 :         xProps->setPropertyValue( "DisplayLabels", uno::makeAny( sal_True ) );
     466         116 :     }
     467         116 : }
     468             : 
     469         326 : void AxisHelper::makeGridVisible( const Reference< beans::XPropertySet >& xGridProperties )
     470             : {
     471         326 :     if( xGridProperties.is() )
     472             :     {
     473         326 :         xGridProperties->setPropertyValue( "Show", uno::makeAny( sal_True ) );
     474         326 :         LinePropertiesHelper::SetLineVisible( xGridProperties );
     475             :     }
     476         326 : }
     477             : 
     478         166 : void AxisHelper::hideAxis( sal_Int32 nDimensionIndex, bool bMainAxis
     479             :                 , const Reference< XDiagram >& xDiagram )
     480             : {
     481         166 :     AxisHelper::makeAxisInvisible( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
     482         166 : }
     483             : 
     484         166 : void AxisHelper::makeAxisInvisible( const Reference< XAxis >& xAxis )
     485             : {
     486         166 :     Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
     487         166 :     if( xProps.is() )
     488             :     {
     489         166 :         xProps->setPropertyValue( "Show", uno::makeAny( sal_False ) );
     490         166 :     }
     491         166 : }
     492             : 
     493           0 : void AxisHelper::hideAxisIfNoDataIsAttached( const Reference< XAxis >& xAxis, const Reference< XDiagram >& xDiagram )
     494             : {
     495             :     //axis is hidden if no data is attached anymore but data is available
     496           0 :     bool bOtherSeriesAttachedToThisAxis = false;
     497           0 :     ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
     498           0 :     ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt = aSeriesVector.begin();
     499           0 :     for( ; aIt != aSeriesVector.end(); ++aIt)
     500             :     {
     501           0 :         uno::Reference< chart2::XAxis > xCurrentAxis( DiagramHelper::getAttachedAxis( *aIt, xDiagram ), uno::UNO_QUERY );
     502           0 :         if( xCurrentAxis==xAxis )
     503             :         {
     504           0 :             bOtherSeriesAttachedToThisAxis = true;
     505           0 :             break;
     506             :         }
     507           0 :     }
     508           0 :     if(!bOtherSeriesAttachedToThisAxis && !aSeriesVector.empty() )
     509           0 :         AxisHelper::makeAxisInvisible( xAxis );
     510           0 : }
     511             : 
     512          83 : void AxisHelper::hideGrid( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
     513             :                 , const Reference< XDiagram >& xDiagram )
     514             : {
     515          83 :     if( !xDiagram.is() )
     516           0 :         return;
     517             : 
     518          83 :     Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
     519          83 :     if(!xCooSys.is())
     520           0 :         return;
     521             : 
     522         166 :     Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
     523          83 :     if(!xAxis.is())
     524           0 :         return;
     525             : 
     526          83 :     if( bMainGrid )
     527          83 :         AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
     528             :     else
     529             :     {
     530           0 :         Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
     531           0 :         for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
     532           0 :             AxisHelper::makeGridInvisible( aSubGrids[nN] );
     533          83 :     }
     534             : }
     535             : 
     536          83 : void AxisHelper::makeGridInvisible( const Reference< beans::XPropertySet >& xGridProperties )
     537             : {
     538          83 :     if( xGridProperties.is() )
     539             :     {
     540          83 :         xGridProperties->setPropertyValue( "Show", uno::makeAny( sal_False ) );
     541             :     }
     542          83 : }
     543             : 
     544        7256 : sal_Bool AxisHelper::isGridShown( sal_Int32 nDimensionIndex, sal_Int32 nCooSysIndex, bool bMainGrid
     545             :                 , const Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
     546             : {
     547        7256 :     sal_Bool bRet = false;
     548             : 
     549        7256 :     Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, nCooSysIndex );
     550        7256 :     if(!xCooSys.is())
     551         108 :         return bRet;
     552             : 
     553       14296 :     Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, MAIN_AXIS_INDEX, xCooSys ) );
     554        7148 :     if(!xAxis.is())
     555        1902 :         return bRet;
     556             : 
     557        5246 :     if( bMainGrid )
     558        2741 :         bRet = AxisHelper::isGridVisible( xAxis->getGridProperties() );
     559             :     else
     560             :     {
     561        2505 :         Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
     562        2505 :         if( aSubGrids.getLength() )
     563        2505 :             bRet = AxisHelper::isGridVisible( aSubGrids[0] );
     564             :     }
     565             : 
     566       12502 :     return bRet;
     567             : }
     568             : 
     569      151462 : Reference< XCoordinateSystem > AxisHelper::getCoordinateSystemByIndex(
     570             :     const Reference< XDiagram >& xDiagram, sal_Int32 nIndex )
     571             : {
     572      151462 :     Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
     573      151462 :     if(!xCooSysContainer.is())
     574         176 :         return NULL;
     575      302572 :     Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
     576      151286 :     if(0<=nIndex && nIndex<aCooSysList.getLength())
     577      151254 :         return aCooSysList[nIndex];
     578      151494 :     return NULL;
     579             : }
     580             : 
     581      139959 : Reference< XAxis > AxisHelper::getAxis( sal_Int32 nDimensionIndex, bool bMainAxis
     582             :             , const Reference< XDiagram >& xDiagram )
     583             : {
     584      139959 :     Reference< XAxis > xRet;
     585             :     try
     586             :     {
     587      139959 :         Reference< XCoordinateSystem > xCooSys = AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 );
     588      139959 :         xRet.set( AxisHelper::getAxis( nDimensionIndex, bMainAxis ? 0 : 1, xCooSys ) );
     589             :     }
     590           0 :     catch( const uno::Exception & )
     591             :     {
     592             :     }
     593      139959 :     return xRet;
     594             : }
     595             : 
     596      158507 : Reference< XAxis > AxisHelper::getAxis( sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex
     597             :             , const Reference< XCoordinateSystem >& xCooSys )
     598             : {
     599      158507 :     Reference< XAxis > xRet;
     600      158507 :     if(!xCooSys.is())
     601         100 :         return xRet;
     602             : 
     603      158407 :     if(nDimensionIndex >= xCooSys->getDimension())
     604        4577 :         return xRet;
     605             : 
     606      153830 :     if(nAxisIndex > xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex))
     607        5964 :         return xRet;
     608             : 
     609             :     assert(nAxisIndex >= 0);
     610             :     assert(nDimensionIndex >= 0);
     611      147866 :     xRet.set( xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) );
     612      147866 :     return xRet;
     613             : }
     614             : 
     615        2449 : Reference< XAxis > AxisHelper::getCrossingMainAxis( const Reference< XAxis >& xAxis
     616             :             , const Reference< XCoordinateSystem >& xCooSys )
     617             : {
     618        2449 :     sal_Int32 nDimensionIndex = 0;
     619        2449 :     sal_Int32 nAxisIndex = 0;
     620        2449 :     AxisHelper::getIndicesForAxis( xAxis, xCooSys, nDimensionIndex, nAxisIndex );
     621        2449 :     if( 2==nDimensionIndex )
     622             :     {
     623          11 :         nDimensionIndex=1;
     624          11 :         bool bSwapXY = false;
     625          11 :         Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY );
     626          11 :         if( xCooSysProp.is() && (xCooSysProp->getPropertyValue( "SwapXAndYAxis" ) >>= bSwapXY) && bSwapXY )
     627           2 :             nDimensionIndex=0;
     628             :     }
     629        2438 :     else if( 1==nDimensionIndex )
     630        1832 :         nDimensionIndex=0;
     631             :     else
     632         606 :         nDimensionIndex=1;
     633        2449 :     return AxisHelper::getAxis( nDimensionIndex, 0, xCooSys );
     634             : }
     635             : 
     636           0 : Reference< XAxis > AxisHelper::getParallelAxis( const Reference< XAxis >& xAxis
     637             :             , const Reference< XDiagram >& xDiagram )
     638             : {
     639             :     try
     640             :     {
     641           0 :         sal_Int32 nCooSysIndex=-1;
     642           0 :         sal_Int32 nDimensionIndex=-1;
     643           0 :         sal_Int32 nAxisIndex=-1;
     644           0 :         if( getIndicesForAxis( xAxis, xDiagram, nCooSysIndex, nDimensionIndex, nAxisIndex ) )
     645             :         {
     646           0 :             sal_Int32 nParallelAxisIndex = (nAxisIndex==1) ?0 :1;
     647           0 :             return getAxis( nDimensionIndex, nParallelAxisIndex, getCoordinateSystemByIndex( xDiagram, nCooSysIndex ) );
     648             :         }
     649             :     }
     650           0 :     catch( const uno::RuntimeException& )
     651             :     {
     652             :     }
     653           0 :     return 0;
     654             : }
     655             : 
     656        2385 : sal_Bool AxisHelper::isAxisShown( sal_Int32 nDimensionIndex, bool bMainAxis
     657             :             , const Reference< XDiagram >& xDiagram )
     658             : {
     659        2385 :     return AxisHelper::isAxisVisible( AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ) );
     660             : }
     661             : 
     662        3912 : sal_Bool AxisHelper::isAxisVisible( const Reference< XAxis >& xAxis )
     663             : {
     664        3912 :     sal_Bool bRet = false;
     665             : 
     666        3912 :     Reference< beans::XPropertySet > xProps( xAxis, uno::UNO_QUERY );
     667        3912 :     if( xProps.is() )
     668             :     {
     669        2832 :         xProps->getPropertyValue( "Show" ) >>= bRet;
     670        5185 :         bRet = bRet && ( LinePropertiesHelper::IsLineVisible( xProps )
     671        3040 :             || areAxisLabelsVisible( xProps ) );
     672             :     }
     673             : 
     674        3912 :     return bRet;
     675             : }
     676             : 
     677         208 : sal_Bool AxisHelper::areAxisLabelsVisible( const Reference< beans::XPropertySet >& xAxisProperties )
     678             : {
     679         208 :     sal_Bool bRet = false;
     680         208 :     if( xAxisProperties.is() )
     681             :     {
     682         208 :         xAxisProperties->getPropertyValue( "DisplayLabels" ) >>= bRet;
     683             :     }
     684         208 :     return bRet;
     685             : }
     686             : 
     687       10730 : sal_Bool AxisHelper::isGridVisible( const Reference< beans::XPropertySet >& xGridProperies )
     688             : {
     689       10730 :     sal_Bool bRet = false;
     690             : 
     691       10730 :     if( xGridProperies.is() )
     692             :     {
     693       10730 :         xGridProperies->getPropertyValue( "Show" ) >>= bRet;
     694       10730 :         bRet = bRet && LinePropertiesHelper::IsLineVisible( xGridProperies );
     695             :     }
     696             : 
     697       10730 :     return bRet;
     698             : }
     699             : 
     700        4060 : Reference< beans::XPropertySet > AxisHelper::getGridProperties(
     701             :             const Reference< XCoordinateSystem >& xCooSys
     702             :         , sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex, sal_Int32 nSubGridIndex )
     703             : {
     704        4060 :     Reference< beans::XPropertySet > xRet;
     705             : 
     706        8120 :     Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, nAxisIndex, xCooSys ) );
     707        4060 :     if( xAxis.is() )
     708             :     {
     709        4060 :         if( nSubGridIndex<0 )
     710        3264 :             xRet.set( xAxis->getGridProperties() );
     711             :         else
     712             :         {
     713         796 :             Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
     714         796 :             if( nSubGridIndex >= 0 && nSubGridIndex < aSubGrids.getLength() )
     715         796 :                 xRet.set( aSubGrids[nSubGridIndex] );
     716             :         }
     717             :     }
     718             : 
     719        8120 :     return xRet;
     720             : }
     721             : 
     722           0 : sal_Int32 AxisHelper::getDimensionIndexOfAxis(
     723             :               const Reference< XAxis >& xAxis
     724             :             , const Reference< XDiagram >& xDiagram )
     725             : {
     726           0 :     sal_Int32 nDimensionIndex = -1;
     727           0 :     sal_Int32 nCooSysIndex = -1;
     728           0 :     sal_Int32 nAxisIndex = -1;
     729           0 :     AxisHelper::getIndicesForAxis( xAxis, xDiagram, nCooSysIndex , nDimensionIndex, nAxisIndex );
     730           0 :     return nDimensionIndex;
     731             : }
     732             : 
     733       15650 : bool AxisHelper::getIndicesForAxis(
     734             :               const Reference< XAxis >& xAxis
     735             :             , const Reference< XCoordinateSystem >& xCooSys
     736             :             , sal_Int32& rOutDimensionIndex, sal_Int32& rOutAxisIndex )
     737             : {
     738             :     //returns true if indices are found
     739             : 
     740       15650 :     rOutDimensionIndex = -1;
     741       15650 :     rOutAxisIndex = -1;
     742             : 
     743       15650 :     if( xCooSys.is() && xAxis.is() )
     744             :     {
     745       15630 :         Reference< XAxis > xCurrentAxis;
     746       15630 :         sal_Int32 nDimensionCount( xCooSys->getDimension() );
     747       23705 :         for( sal_Int32 nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
     748             :         {
     749       23705 :             sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
     750       32033 :             for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
     751             :             {
     752       23958 :                  xCurrentAxis = xCooSys->getAxisByDimension(nDimensionIndex,nAxisIndex);
     753       23958 :                  if( xCurrentAxis == xAxis )
     754             :                  {
     755       15630 :                      rOutDimensionIndex = nDimensionIndex;
     756       15630 :                      rOutAxisIndex = nAxisIndex;
     757       15630 :                      return true;
     758             :                  }
     759             :             }
     760           0 :         }
     761             :     }
     762          20 :     return false;
     763             : }
     764             : 
     765        3462 : bool AxisHelper::getIndicesForAxis( const Reference< XAxis >& xAxis, const Reference< XDiagram >& xDiagram
     766             :             , sal_Int32& rOutCooSysIndex, sal_Int32& rOutDimensionIndex, sal_Int32& rOutAxisIndex )
     767             : {
     768             :     //returns true if indices are found
     769             : 
     770        3462 :     rOutCooSysIndex = -1;
     771        3462 :     rOutDimensionIndex = -1;
     772        3462 :     rOutAxisIndex = -1;
     773             : 
     774        3462 :     Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
     775        3462 :     if(xCooSysContainer.is())
     776             :     {
     777        3462 :         Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
     778        3462 :         for( sal_Int32 nC=0; nC<aCooSysList.getLength(); ++nC )
     779             :         {
     780        3462 :             if( AxisHelper::getIndicesForAxis( xAxis, aCooSysList[nC], rOutDimensionIndex, rOutAxisIndex ) )
     781             :             {
     782        3462 :                 rOutCooSysIndex = nC;
     783        3462 :                 return true;
     784             :             }
     785           0 :         }
     786             :     }
     787             : 
     788           0 :     return false;
     789             : }
     790             : 
     791       14819 : std::vector< Reference< XAxis > > AxisHelper::getAllAxesOfCoordinateSystem(
     792             :       const Reference< XCoordinateSystem >& xCooSys
     793             :     , bool bOnlyVisible /* = false */ )
     794             : {
     795       14819 :     std::vector< Reference< XAxis > > aAxisVector;
     796             : 
     797       14819 :     if(xCooSys.is())
     798             :     {
     799       14819 :         sal_Int32 nMaxDimensionIndex = xCooSys->getDimension() -1;
     800       14819 :         if( nMaxDimensionIndex>=0 )
     801             :         {
     802       14819 :             sal_Int32 nDimensionIndex = 0;
     803       50619 :             for(; nDimensionIndex<=nMaxDimensionIndex; ++nDimensionIndex)
     804             :             {
     805       35800 :                 const sal_Int32 nMaximumAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
     806       73814 :                 for(sal_Int32 nAxisIndex=0; nAxisIndex<=nMaximumAxisIndex; ++nAxisIndex)
     807             :                 {
     808             :                     try
     809             :                     {
     810       38014 :                         Reference< XAxis > xAxis( xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) );
     811       38014 :                         bool bAddAxis = true;
     812       38014 :                         if( xAxis.is() )
     813             :                         {
     814       38014 :                             if( bOnlyVisible )
     815             :                             {
     816        1527 :                                 Reference< beans::XPropertySet > xAxisProp( xAxis, uno::UNO_QUERY );
     817        6108 :                                 if( !xAxisProp.is() ||
     818        6108 :                                     !(xAxisProp->getPropertyValue( "Show") >>= bAddAxis) )
     819           0 :                                     bAddAxis = false;
     820             :                             }
     821       38014 :                             if( bAddAxis )
     822       37911 :                                 aAxisVector.push_back( xAxis );
     823       38014 :                         }
     824             :                     }
     825           0 :                     catch( const uno::Exception & ex )
     826             :                     {
     827             :                         ASSERT_EXCEPTION( ex );
     828             :                     }
     829             :                 }
     830             :             }
     831             :         }
     832             :     }
     833             : 
     834       14819 :     return aAxisVector;
     835             : }
     836             : 
     837        2300 : Sequence< Reference< XAxis > > AxisHelper::getAllAxesOfDiagram(
     838             :       const Reference< XDiagram >& xDiagram
     839             :     , bool bOnlyVisible )
     840             : {
     841        2300 :     std::vector< Reference< XAxis > > aAxisVector;
     842             : 
     843        4600 :     Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
     844        2300 :     if(xCooSysContainer.is())
     845             :     {
     846        2300 :         Sequence< Reference< XCoordinateSystem > > aCooSysList = xCooSysContainer->getCoordinateSystems();
     847        2300 :         sal_Int32 nC = 0;
     848        4594 :         for( nC=0; nC<aCooSysList.getLength(); ++nC )
     849             :         {
     850        2294 :             std::vector< Reference< XAxis > > aAxesPerCooSys( AxisHelper::getAllAxesOfCoordinateSystem( aCooSysList[nC], bOnlyVisible ) );
     851        2294 :             aAxisVector.insert( aAxisVector.end(), aAxesPerCooSys.begin(), aAxesPerCooSys.end() );
     852        4594 :         }
     853             :     }
     854             : 
     855        4600 :     return ContainerHelper::ContainerToSequence( aAxisVector );
     856             : }
     857             : 
     858           0 : Sequence< Reference< beans::XPropertySet > > AxisHelper::getAllGrids( const Reference< XDiagram >& xDiagram )
     859             : {
     860           0 :     Sequence< Reference< XAxis > > aAllAxes( AxisHelper::getAllAxesOfDiagram( xDiagram ) );
     861           0 :     std::vector< Reference< beans::XPropertySet > > aGridVector;
     862             : 
     863           0 :     sal_Int32 nA = 0;
     864           0 :     for( nA=0; nA<aAllAxes.getLength(); ++nA )
     865             :     {
     866           0 :         Reference< XAxis > xAxis( aAllAxes[nA] );
     867           0 :         if(!xAxis.is())
     868           0 :             continue;
     869           0 :         Reference< beans::XPropertySet > xGridProperties( xAxis->getGridProperties() );
     870           0 :         if( xGridProperties.is() )
     871           0 :             aGridVector.push_back( xGridProperties );
     872             : 
     873           0 :         Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );;
     874           0 :         sal_Int32 nSubGrid = 0;
     875           0 :         for( nSubGrid = 0; nSubGrid < aSubGrids.getLength(); ++nSubGrid )
     876             :         {
     877           0 :             Reference< beans::XPropertySet > xSubGrid( aSubGrids[nSubGrid] );
     878           0 :             if( xSubGrid.is() )
     879           0 :                 aGridVector.push_back( xSubGrid );
     880           0 :         }
     881           0 :     }
     882             : 
     883           0 :     return ContainerHelper::ContainerToSequence( aGridVector );
     884             : }
     885             : 
     886           0 : void AxisHelper::getAxisOrGridPossibilities( Sequence< sal_Bool >& rPossibilityList
     887             :         , const Reference< XDiagram>& xDiagram, sal_Bool bAxis )
     888             : {
     889           0 :     rPossibilityList.realloc(6);
     890             : 
     891           0 :     sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
     892             : 
     893             :     //set possibilities:
     894           0 :     sal_Int32 nIndex=0;
     895           0 :     Reference< XChartType > xChartType = DiagramHelper::getChartTypeByIndex( xDiagram, 0 );
     896           0 :     for(nIndex=0;nIndex<3;nIndex++)
     897           0 :         rPossibilityList[nIndex]=ChartTypeHelper::isSupportingMainAxis(xChartType,nDimensionCount,nIndex);
     898           0 :     for(nIndex=3;nIndex<6;nIndex++)
     899           0 :         if( bAxis )
     900           0 :             rPossibilityList[nIndex]=ChartTypeHelper::isSupportingSecondaryAxis(xChartType,nDimensionCount,nIndex-3);
     901             :         else
     902           0 :             rPossibilityList[nIndex] = rPossibilityList[nIndex-3];
     903           0 : }
     904             : 
     905         232 : bool AxisHelper::isSecondaryYAxisNeeded( const Reference< XCoordinateSystem >& xCooSys )
     906             : {
     907         232 :     Reference< chart2::XChartTypeContainer > xCTCnt( xCooSys, uno::UNO_QUERY );
     908         232 :     if( xCTCnt.is() )
     909             :     {
     910         232 :         Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes() );
     911         232 :         for( sal_Int32 i=0; i<aChartTypes.getLength(); ++i )
     912             :         {
     913           0 :             Reference< XDataSeriesContainer > xSeriesContainer( aChartTypes[i] , uno::UNO_QUERY );
     914           0 :             if( !xSeriesContainer.is() )
     915           0 :                     continue;
     916             : 
     917           0 :             Sequence< Reference< XDataSeries > > aSeriesList( xSeriesContainer->getDataSeries() );
     918           0 :             for( sal_Int32 nS = aSeriesList.getLength(); nS-- ; )
     919             :             {
     920           0 :                 Reference< beans::XPropertySet > xProp( aSeriesList[nS], uno::UNO_QUERY );
     921           0 :                 if(xProp.is())
     922             :                 {
     923           0 :                     sal_Int32 nAttachedAxisIndex = 0;
     924           0 :                     if( ( xProp->getPropertyValue( "AttachedAxisIndex" ) >>= nAttachedAxisIndex ) && nAttachedAxisIndex>0 )
     925           0 :                         return true;
     926             :                 }
     927           0 :             }
     928         232 :         }
     929             :     }
     930         232 :     return false;
     931             : }
     932             : 
     933        2501 : bool AxisHelper::shouldAxisBeDisplayed( const Reference< XAxis >& xAxis
     934             :                                        , const Reference< XCoordinateSystem >& xCooSys )
     935             : {
     936        2501 :     bool bRet = false;
     937             : 
     938        2501 :     if( xAxis.is() && xCooSys.is() )
     939             :     {
     940        2501 :         sal_Int32 nDimensionIndex=-1;
     941        2501 :         sal_Int32 nAxisIndex=-1;
     942        2501 :         if( AxisHelper::getIndicesForAxis( xAxis, xCooSys, nDimensionIndex, nAxisIndex ) )
     943             :         {
     944        2501 :             sal_Int32 nDimensionCount = xCooSys->getDimension();
     945        2501 :             Reference< XChartType > xChartType( AxisHelper::getChartTypeByIndex( xCooSys, 0 ) );
     946             : 
     947        2501 :             bool bMainAxis = (nAxisIndex==MAIN_AXIS_INDEX);
     948        2501 :             if( bMainAxis )
     949        2492 :                 bRet = ChartTypeHelper::isSupportingMainAxis(xChartType,nDimensionCount,nDimensionIndex);
     950             :             else
     951           9 :                 bRet = ChartTypeHelper::isSupportingSecondaryAxis(xChartType,nDimensionCount,nDimensionIndex);
     952             :         }
     953             :     }
     954             : 
     955        2501 :     return bRet;
     956             : }
     957             : 
     958           0 : void AxisHelper::getAxisOrGridExcistence( Sequence< sal_Bool >& rExistenceList
     959             :         , const Reference< XDiagram>& xDiagram, sal_Bool bAxis )
     960             : {
     961           0 :     rExistenceList.realloc(6);
     962             : 
     963           0 :     if(bAxis)
     964             :     {
     965             :         sal_Int32 nN;
     966           0 :         Reference< XAxis > xAxis;
     967           0 :         for(nN=0;nN<3;nN++)
     968           0 :             rExistenceList[nN] = AxisHelper::isAxisShown( nN, true, xDiagram );
     969           0 :         for(nN=3;nN<6;nN++)
     970           0 :             rExistenceList[nN] = AxisHelper::isAxisShown( nN%3, false, xDiagram );
     971             :     }
     972             :     else
     973             :     {
     974             :         sal_Int32 nN;
     975             : 
     976           0 :         for(nN=0;nN<3;nN++)
     977           0 :             rExistenceList[nN] = AxisHelper::isGridShown( nN, 0, true, xDiagram );
     978           0 :         for(nN=3;nN<6;nN++)
     979           0 :             rExistenceList[nN] = AxisHelper::isGridShown( nN%3, 0, false, xDiagram );
     980             :     }
     981           0 : }
     982             : 
     983           0 : bool AxisHelper::changeVisibilityOfAxes( const Reference< XDiagram >& xDiagram
     984             :                         , const Sequence< sal_Bool >& rOldExistenceList
     985             :                         , const Sequence< sal_Bool >& rNewExistenceList
     986             :                         , const Reference< uno::XComponentContext >& xContext
     987             :                         , ReferenceSizeProvider * pRefSizeProvider )
     988             : {
     989           0 :     bool bChanged = false;
     990           0 :     for(sal_Int32 nN=0;nN<6;nN++)
     991             :     {
     992           0 :         if(rOldExistenceList[nN]!=rNewExistenceList[nN])
     993             :         {
     994           0 :             bChanged = true;
     995           0 :             if(rNewExistenceList[nN])
     996             :             {
     997           0 :                 AxisHelper::showAxis( nN%3, nN<3, xDiagram, xContext, pRefSizeProvider );
     998             :             }
     999             :             else
    1000           0 :                 AxisHelper::hideAxis( nN%3, nN<3, xDiagram );
    1001             :         }
    1002             :     }
    1003           0 :     return bChanged;
    1004             : }
    1005             : 
    1006           0 : bool AxisHelper::changeVisibilityOfGrids( const Reference< XDiagram >& xDiagram
    1007             :                         , const Sequence< sal_Bool >& rOldExistenceList
    1008             :                         , const Sequence< sal_Bool >& rNewExistenceList
    1009             :                         , const Reference< uno::XComponentContext >& xContext )
    1010             : {
    1011           0 :     bool bChanged = false;
    1012           0 :     for(sal_Int32 nN=0;nN<6;nN++)
    1013             :     {
    1014           0 :         if(rOldExistenceList[nN]!=rNewExistenceList[nN])
    1015             :         {
    1016           0 :             bChanged = true;
    1017           0 :             if(rNewExistenceList[nN])
    1018           0 :                 AxisHelper::showGrid( nN%3, 0, nN<3, xDiagram, xContext );
    1019             :             else
    1020           0 :                 AxisHelper::hideGrid( nN%3, 0, nN<3, xDiagram );
    1021             :         }
    1022             :     }
    1023           0 :     return bChanged;
    1024             : }
    1025             : 
    1026       12525 : Reference< XCoordinateSystem > AxisHelper::getCoordinateSystemOfAxis(
    1027             :               const Reference< XAxis >& xAxis
    1028             :             , const Reference< XDiagram >& xDiagram )
    1029             : {
    1030       12525 :     Reference< XCoordinateSystem > xRet;
    1031             : 
    1032       25050 :     Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
    1033       12525 :     if( xCooSysContainer.is() )
    1034             :     {
    1035       12525 :         Reference< XCoordinateSystem > xCooSys;
    1036       25050 :         Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
    1037       12525 :         for( sal_Int32 nCooSysIndex = 0; nCooSysIndex < aCooSysList.getLength(); ++nCooSysIndex )
    1038             :         {
    1039       12525 :             xCooSys = aCooSysList[nCooSysIndex];
    1040       12525 :             std::vector< Reference< XAxis > > aAllAxis( AxisHelper::getAllAxesOfCoordinateSystem( xCooSys ) );
    1041             : 
    1042             :             ::std::vector< Reference< XAxis > >::iterator aFound =
    1043       12525 :                   ::std::find( aAllAxis.begin(), aAllAxis.end(), xAxis );
    1044       12525 :             if( aFound != aAllAxis.end())
    1045             :             {
    1046       12525 :                 xRet.set( xCooSys );
    1047       12525 :                 break;
    1048             :             }
    1049       12525 :         }
    1050             :     }
    1051       25050 :     return xRet;
    1052             : }
    1053             : 
    1054        7383 : Reference< XChartType > AxisHelper::getChartTypeByIndex( const Reference< XCoordinateSystem >& xCooSys, sal_Int32 nIndex )
    1055             : {
    1056        7383 :     Reference< XChartType > xChartType;
    1057             : 
    1058       14766 :     Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
    1059        7383 :     if( xChartTypeContainer.is() )
    1060             :     {
    1061        7383 :         Sequence< Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
    1062        7383 :         if( nIndex >= 0 && nIndex < aChartTypeList.getLength() )
    1063        7383 :             xChartType.set( aChartTypeList[nIndex] );
    1064             :     }
    1065             : 
    1066       14766 :     return xChartType;
    1067             : }
    1068             : 
    1069           0 : void AxisHelper::setRTLAxisLayout( const Reference< XCoordinateSystem >& xCooSys )
    1070             : {
    1071           0 :     if( xCooSys.is() )
    1072             :     {
    1073           0 :         bool bCartesian = xCooSys->getViewServiceName().equals( CHART2_COOSYSTEM_CARTESIAN_VIEW_SERVICE_NAME );
    1074           0 :         if( bCartesian )
    1075             :         {
    1076           0 :             bool bVertical = false;
    1077           0 :             Reference< beans::XPropertySet > xCooSysProp( xCooSys, uno::UNO_QUERY );
    1078           0 :             if( xCooSysProp.is() )
    1079           0 :                 xCooSysProp->getPropertyValue( "SwapXAndYAxis" ) >>= bVertical;
    1080             : 
    1081           0 :             sal_Int32 nHorizontalAxisDimension = bVertical ? 1 : 0;
    1082           0 :             sal_Int32 nVerticalAxisDimension = bVertical ? 0 : 1;
    1083             : 
    1084             :             try
    1085             :             {
    1086             :                 //reverse direction for horizontal main axis
    1087           0 :                 Reference< chart2::XAxis > xHorizontalMainAxis( AxisHelper::getAxis( nHorizontalAxisDimension, MAIN_AXIS_INDEX, xCooSys ) );
    1088           0 :                 if( xHorizontalMainAxis.is() )
    1089             :                 {
    1090           0 :                     chart2::ScaleData aScale = xHorizontalMainAxis->getScaleData();
    1091           0 :                     aScale.Orientation = chart2::AxisOrientation_REVERSE;
    1092           0 :                     xHorizontalMainAxis->setScaleData(aScale);
    1093             :                 }
    1094             : 
    1095             :                 //mathematical direction for vertical main axis
    1096           0 :                 Reference< chart2::XAxis > xVerticalMainAxis( AxisHelper::getAxis( nVerticalAxisDimension, MAIN_AXIS_INDEX, xCooSys ) );
    1097           0 :                 if( xVerticalMainAxis.is() )
    1098             :                 {
    1099           0 :                     chart2::ScaleData aScale = xVerticalMainAxis->getScaleData();
    1100           0 :                     aScale.Orientation = chart2::AxisOrientation_MATHEMATICAL;
    1101           0 :                     xVerticalMainAxis->setScaleData(aScale);
    1102           0 :                 }
    1103             :             }
    1104           0 :             catch( const uno::Exception & ex )
    1105             :             {
    1106             :                 ASSERT_EXCEPTION( ex );
    1107             :             }
    1108             : 
    1109             :             try
    1110             :             {
    1111             :                 //reverse direction for horizontal secondary axis
    1112           0 :                 Reference< chart2::XAxis > xHorizontalSecondaryAxis( AxisHelper::getAxis( nHorizontalAxisDimension, SECONDARY_AXIS_INDEX, xCooSys ) );
    1113           0 :                 if( xHorizontalSecondaryAxis.is() )
    1114             :                 {
    1115           0 :                     chart2::ScaleData aScale = xHorizontalSecondaryAxis->getScaleData();
    1116           0 :                     aScale.Orientation = chart2::AxisOrientation_REVERSE;
    1117           0 :                     xHorizontalSecondaryAxis->setScaleData(aScale);
    1118             :                 }
    1119             : 
    1120             :                 //mathematical direction for vertical secondary axis
    1121           0 :                 Reference< chart2::XAxis > xVerticalSecondaryAxis( AxisHelper::getAxis( nVerticalAxisDimension, SECONDARY_AXIS_INDEX, xCooSys ) );
    1122           0 :                 if( xVerticalSecondaryAxis.is() )
    1123             :                 {
    1124           0 :                     chart2::ScaleData aScale = xVerticalSecondaryAxis->getScaleData();
    1125           0 :                     aScale.Orientation = chart2::AxisOrientation_MATHEMATICAL;
    1126           0 :                     xVerticalSecondaryAxis->setScaleData(aScale);
    1127           0 :                 }
    1128             :             }
    1129           0 :             catch( const uno::Exception & ex )
    1130             :             {
    1131             :                 ASSERT_EXCEPTION( ex );
    1132           0 :             }
    1133             :         }
    1134             :     }
    1135           0 : }
    1136             : 
    1137           0 : Reference< XChartType > AxisHelper::getFirstChartTypeWithSeriesAttachedToAxisIndex( const Reference< chart2::XDiagram >& xDiagram, const sal_Int32 nAttachedAxisIndex )
    1138             : {
    1139           0 :     Reference< XChartType > xChartType;
    1140           0 :     ::std::vector< Reference< XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
    1141           0 :     ::std::vector< Reference< XDataSeries > >::const_iterator aIter = aSeriesVector.begin();
    1142           0 :     for( ; aIter != aSeriesVector.end(); ++aIter )
    1143             :     {
    1144           0 :         sal_Int32 nCurrentIndex = DataSeriesHelper::getAttachedAxisIndex( *aIter );
    1145           0 :         if( nAttachedAxisIndex == nCurrentIndex )
    1146             :         {
    1147           0 :             xChartType = DiagramHelper::getChartTypeOfSeries( xDiagram, *aIter );
    1148           0 :             if(xChartType.is())
    1149           0 :                 break;
    1150             :         }
    1151             :     }
    1152           0 :     return xChartType;
    1153             : }
    1154             : 
    1155        4666 : bool AxisHelper::isAxisPositioningEnabled()
    1156             : {
    1157        4666 :     const SvtSaveOptions::ODFDefaultVersion nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() );
    1158        4666 :     return nCurrentVersion >= SvtSaveOptions::ODFVER_012;
    1159             : }
    1160             : 
    1161             : } //namespace chart
    1162             : 
    1163             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10