LCOV - code coverage report
Current view: top level - chart2/source/tools - ExplicitCategoriesProvider.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 219 297 73.7 %
Date: 2014-04-11 Functions: 17 28 60.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 "ExplicitCategoriesProvider.hxx"
      21             : #include "DiagramHelper.hxx"
      22             : #include "ChartTypeHelper.hxx"
      23             : #include "AxisHelper.hxx"
      24             : #include "CommonConverters.hxx"
      25             : #include "DataSourceHelper.hxx"
      26             : #include "ChartModelHelper.hxx"
      27             : #include "ContainerHelper.hxx"
      28             : #include "macros.hxx"
      29             : #include "NumberFormatterWrapper.hxx"
      30             : 
      31             : #include <com/sun/star/chart2/AxisType.hpp>
      32             : #include <com/sun/star/util/NumberFormat.hpp>
      33             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      34             : #include <com/sun/star/frame/XModel.hpp>
      35             : 
      36             : namespace chart
      37             : {
      38             : 
      39             : using namespace ::com::sun::star;
      40             : using namespace ::com::sun::star::chart2;
      41             : using ::com::sun::star::uno::Reference;
      42             : using ::com::sun::star::uno::Sequence;
      43             : using ::std::vector;
      44             : 
      45        2198 : ExplicitCategoriesProvider::ExplicitCategoriesProvider( const Reference< chart2::XCoordinateSystem >& xCooSysModel
      46             :                                                        , ChartModel& rModel )
      47             :     : m_bDirty(true)
      48             :     , m_xCooSysModel( xCooSysModel )
      49             :     , mrModel(rModel)
      50             :     , m_xOriginalCategories()
      51             :     , m_bIsExplicitCategoriesInited(false)
      52             :     , m_bIsDateAxis(false)
      53        2198 :     , m_bIsAutoDate(false)
      54             : {
      55             :     try
      56             :     {
      57        2198 :         if( xCooSysModel.is() )
      58             :         {
      59        2198 :             uno::Reference< XAxis > xAxis( xCooSysModel->getAxisByDimension(0,0) );
      60        2198 :             if( xAxis.is() )
      61             :             {
      62        2198 :                 ScaleData aScale( xAxis->getScaleData() );
      63        2198 :                 m_xOriginalCategories = aScale.Categories;
      64        2198 :                 m_bIsAutoDate = (aScale.AutoDateAxis && aScale.AxisType==chart2::AxisType::CATEGORY);
      65        2198 :                 m_bIsDateAxis = (aScale.AxisType == chart2::AxisType::DATE || m_bIsAutoDate);
      66        2198 :             }
      67             :         }
      68             : 
      69        2198 :         if( m_xOriginalCategories.is() )
      70             :         {
      71        2137 :             uno::Reference< data::XDataProvider > xDataProvider( mrModel.getDataProvider() );
      72             : 
      73        4274 :             OUString aCategoriesRange( DataSourceHelper::getRangeFromValues( m_xOriginalCategories ) );
      74        2137 :             if( xDataProvider.is() && !aCategoriesRange.isEmpty() )
      75             :             {
      76        2136 :                 const bool bFirstCellAsLabel = false;
      77        2136 :                 const bool bHasCategories = false;
      78        2136 :                 const uno::Sequence< sal_Int32 > aSequenceMapping;
      79             : 
      80        2136 :                 uno::Reference< data::XDataSource > xColumnCategoriesSource( xDataProvider->createDataSource(
      81             :                             DataSourceHelper::createArguments( aCategoriesRange, aSequenceMapping, true /*bUseColumns*/
      82        4272 :                                 , bFirstCellAsLabel, bHasCategories ) ) );
      83             : 
      84        2136 :                 uno::Reference< data::XDataSource > xRowCategoriesSource( xDataProvider->createDataSource(
      85             :                             DataSourceHelper::createArguments( aCategoriesRange, aSequenceMapping, false /*bUseColumns*/
      86        4272 :                                 , bFirstCellAsLabel, bHasCategories ) ) );
      87             : 
      88        2136 :                 if( xColumnCategoriesSource.is() &&  xRowCategoriesSource.is() )
      89             :                 {
      90        2136 :                     Sequence< Reference< data::XLabeledDataSequence> > aColumns = xColumnCategoriesSource->getDataSequences();
      91        4272 :                     Sequence< Reference< data::XLabeledDataSequence> > aRows = xRowCategoriesSource->getDataSequences();
      92             : 
      93        2136 :                     sal_Int32 nColumnCount = aColumns.getLength();
      94        2136 :                     sal_Int32 nRowCount = aRows.getLength();
      95        2136 :                     if( nColumnCount>1 && nRowCount>1 )
      96             :                     {
      97             :                         //we have complex categories
      98             :                         //->split them in the direction of the first series
      99             :                         //detect whether the first series is a row or a column
     100           0 :                         bool bSeriesUsesColumns = true;
     101           0 :                         ::std::vector< Reference< XDataSeries > > aSeries( ChartModelHelper::getDataSeries( mrModel ) );
     102           0 :                         if( !aSeries.empty() )
     103             :                         {
     104           0 :                             uno::Reference< data::XDataSource > xSeriesSource( aSeries.front(), uno::UNO_QUERY );
     105           0 :                             OUString aStringDummy;
     106             :                             bool bDummy;
     107           0 :                             uno::Sequence< sal_Int32 > aSeqDummy;
     108           0 :                             DataSourceHelper::readArguments( xDataProvider->detectArguments( xSeriesSource),
     109           0 :                                     aStringDummy, aSeqDummy, bSeriesUsesColumns, bDummy, bDummy );
     110             :                         }
     111           0 :                         if( bSeriesUsesColumns )
     112           0 :                             m_aSplitCategoriesList=aColumns;
     113             :                         else
     114           0 :                             m_aSplitCategoriesList=aRows;
     115        2136 :                     }
     116        2136 :                 }
     117             :             }
     118        2137 :             if( !m_aSplitCategoriesList.getLength() )
     119             :             {
     120        2137 :                 m_aSplitCategoriesList.realloc(1);
     121        2137 :                 m_aSplitCategoriesList[0]=m_xOriginalCategories;
     122        2137 :             }
     123             :         }
     124             :     }
     125           0 :     catch( const uno::Exception & ex )
     126             :     {
     127             :         ASSERT_EXCEPTION( ex );
     128             :     }
     129        2198 : }
     130             : 
     131        2602 : ExplicitCategoriesProvider::~ExplicitCategoriesProvider()
     132             : {
     133        2602 : }
     134             : 
     135          18 : Reference< chart2::data::XDataSequence > ExplicitCategoriesProvider::getOriginalCategories()
     136             : {
     137          18 :     if( m_xOriginalCategories.is() )
     138           0 :         return m_xOriginalCategories->getValues();
     139          18 :     return 0;
     140             : }
     141             : 
     142          24 : const Sequence< Reference< data::XLabeledDataSequence> >& ExplicitCategoriesProvider::getSplitCategoriesList()
     143             : {
     144          24 :     return m_aSplitCategoriesList;
     145             : }
     146             : 
     147        3340 : bool ExplicitCategoriesProvider::hasComplexCategories() const
     148             : {
     149        3340 :     return m_aSplitCategoriesList.getLength() > 1;
     150             : }
     151             : 
     152           0 : sal_Int32 ExplicitCategoriesProvider::getCategoryLevelCount() const
     153             : {
     154           0 :     sal_Int32 nCount = m_aSplitCategoriesList.getLength();
     155           0 :     if(!nCount)
     156           0 :         nCount = 1;
     157           0 :     return nCount;
     158             : }
     159             : 
     160           0 : std::vector<sal_Int32> lcl_getLimitingBorders( const std::vector< ComplexCategory >& rComplexCategories )
     161             : {
     162           0 :     std::vector<sal_Int32> aLimitingBorders;
     163           0 :     std::vector< ComplexCategory >::const_iterator aIt( rComplexCategories.begin() );
     164           0 :     std::vector< ComplexCategory >::const_iterator aEnd( rComplexCategories.end() );
     165           0 :     sal_Int32 nBorderIndex = 0; /*border below the index*/
     166           0 :     for( ; aIt != aEnd; ++aIt )
     167             :     {
     168           0 :         ComplexCategory aComplexCategory(*aIt);
     169           0 :         nBorderIndex += aComplexCategory.Count;
     170           0 :         aLimitingBorders.push_back(nBorderIndex);
     171           0 :     }
     172           0 :     return aLimitingBorders;
     173             : }
     174             : 
     175         577 : void ExplicitCategoriesProvider::convertCategoryAnysToText( uno::Sequence< OUString >& rOutTexts, const uno::Sequence< uno::Any >& rInAnys, ChartModel& rModel )
     176             : {
     177         577 :     sal_Int32 nCount = rInAnys.getLength();
     178         577 :     if(!nCount)
     179         577 :         return;
     180         577 :     rOutTexts.realloc(nCount);
     181         577 :     Reference< util::XNumberFormats > xNumberFormats;
     182         577 :     xNumberFormats = Reference< util::XNumberFormats >( rModel.getNumberFormats() );
     183             : 
     184         577 :     sal_Int32 nAxisNumberFormat = 0;
     185        1154 :     Reference< XCoordinateSystem > xCooSysModel( ChartModelHelper::getFirstCoordinateSystem( rModel ) );
     186         577 :     if( xCooSysModel.is() )
     187             :     {
     188         577 :         Reference< chart2::XAxis > xAxis( xCooSysModel->getAxisByDimension(0,0) );
     189             :         nAxisNumberFormat = AxisHelper::getExplicitNumberFormatKeyForAxis(
     190         577 :             xAxis, xCooSysModel, uno::Reference< util::XNumberFormatsSupplier> (static_cast< ::cppu::OWeakObject* >( &rModel ), uno::UNO_QUERY), false );
     191             :     }
     192             : 
     193             :     sal_Int32 nLabelColor;
     194         577 :     bool bColorChanged = false;
     195             : 
     196        1154 :     NumberFormatterWrapper aNumberFormatterWrapper( rModel.getNumberFormatsSupplier() );
     197             : 
     198        3053 :     for(sal_Int32 nN=0;nN<nCount;nN++)
     199             :     {
     200        2476 :         OUString aText;
     201        4952 :         uno::Any aAny = rInAnys[nN];
     202        2476 :         if( aAny.hasValue() )
     203             :         {
     204        2476 :             double fDouble = 0;
     205        2476 :             if( aAny>>=fDouble )
     206             :             {
     207           0 :                 if( !::rtl::math::isNan(fDouble) )
     208           0 :                     aText = aNumberFormatterWrapper.getFormattedString(
     209           0 :                         nAxisNumberFormat, fDouble, nLabelColor, bColorChanged );
     210             :             }
     211             :             else
     212             :             {
     213        2476 :                 aAny>>=aText;
     214             :             }
     215             :         }
     216        2476 :         rOutTexts[nN] = aText;
     217        3053 :     }
     218             : }
     219             : 
     220         191 : SplitCategoriesProvider::~SplitCategoriesProvider()
     221             : {
     222         191 : }
     223             : 
     224             : class SplitCategoriesProvider_ForLabeledDataSequences : public SplitCategoriesProvider
     225             : {
     226             : public:
     227             : 
     228           0 :     explicit SplitCategoriesProvider_ForLabeledDataSequences(
     229             :         const ::com::sun::star::uno::Sequence<
     230             :             ::com::sun::star::uno::Reference<
     231             :                 ::com::sun::star::chart2::data::XLabeledDataSequence> >& rSplitCategoriesList
     232             :         , ChartModel& rModel )
     233             :         : m_rSplitCategoriesList( rSplitCategoriesList )
     234           0 :         , mrModel( rModel )
     235           0 :     {}
     236           0 :     virtual ~SplitCategoriesProvider_ForLabeledDataSequences()
     237           0 :     {}
     238             : 
     239             :     virtual sal_Int32 getLevelCount() const SAL_OVERRIDE;
     240             :     virtual uno::Sequence< OUString > getStringsForLevel( sal_Int32 nIndex ) const SAL_OVERRIDE;
     241             : 
     242             : private:
     243             :     const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
     244             :         ::com::sun::star::chart2::data::XLabeledDataSequence> >& m_rSplitCategoriesList;
     245             : 
     246             :     ChartModel& mrModel;
     247             : };
     248             : 
     249           0 : sal_Int32 SplitCategoriesProvider_ForLabeledDataSequences::getLevelCount() const
     250             : {
     251           0 :     return m_rSplitCategoriesList.getLength();
     252             : }
     253           0 : uno::Sequence< OUString > SplitCategoriesProvider_ForLabeledDataSequences::getStringsForLevel( sal_Int32 nLevel ) const
     254             : {
     255           0 :     uno::Sequence< OUString > aRet;
     256           0 :     Reference< data::XLabeledDataSequence > xLabeledDataSequence( m_rSplitCategoriesList[nLevel] );
     257           0 :     if( xLabeledDataSequence.is() )
     258             :     {
     259           0 :         uno::Reference< data::XDataSequence > xDataSequence( xLabeledDataSequence->getValues() );
     260           0 :         if( xDataSequence.is() )
     261           0 :             ExplicitCategoriesProvider::convertCategoryAnysToText( aRet, xDataSequence->getData(), mrModel );
     262             :     }
     263           0 :     return aRet;
     264             : }
     265             : 
     266         191 : std::vector< ComplexCategory > lcl_DataSequenceToComplexCategoryVector(
     267             :     const uno::Sequence< OUString >& rStrings
     268             :     , const std::vector<sal_Int32>& rLimitingBorders, bool bCreateSingleCategories )
     269             : {
     270         191 :     std::vector< ComplexCategory > aResult;
     271             : 
     272         191 :     sal_Int32 nMaxCount = rStrings.getLength();
     273         382 :     OUString aPrevious;
     274         191 :     sal_Int32 nCurrentCount=0;
     275        1208 :     for( sal_Int32 nN=0; nN<nMaxCount; nN++ )
     276             :     {
     277        1017 :         const OUString& aCurrent = rStrings[nN];
     278        1017 :         if( bCreateSingleCategories || ::std::find( rLimitingBorders.begin(), rLimitingBorders.end(), nN ) != rLimitingBorders.end() )
     279             :         {
     280        1017 :             aResult.push_back( ComplexCategory(aPrevious,nCurrentCount) );
     281        1017 :             nCurrentCount=1;
     282        1017 :             aPrevious = aCurrent;
     283             :         }
     284             :         else
     285             :         {
     286             :             // Empty value is interpreted as a continuation of the previous
     287             :             // category. Note that having the same value as the previous one
     288             :             // does not equate to a continuation of the category.
     289             : 
     290           0 :             if (aCurrent.isEmpty())
     291           0 :                 ++nCurrentCount;
     292             :             else
     293             :             {
     294           0 :                 aResult.push_back( ComplexCategory(aPrevious,nCurrentCount) );
     295           0 :                 nCurrentCount=1;
     296           0 :                 aPrevious = aCurrent;
     297             :             }
     298             :         }
     299             :     }
     300         191 :     if( nCurrentCount )
     301         191 :         aResult.push_back( ComplexCategory(aPrevious,nCurrentCount) );
     302             : 
     303         382 :     return aResult;
     304             : }
     305             : 
     306         382 : sal_Int32 lcl_getCategoryCount( std::vector< ComplexCategory >& rComplexCategories )
     307             : {
     308         382 :     sal_Int32 nCount = 0;
     309         382 :     std::vector< ComplexCategory >::const_iterator aIt( rComplexCategories.begin() );
     310         382 :     std::vector< ComplexCategory >::const_iterator aEnd( rComplexCategories.end() );
     311        2798 :     for( ; aIt != aEnd; ++aIt )
     312        2416 :         nCount+=aIt->Count;
     313         382 :     return nCount;
     314             : }
     315             : 
     316         191 : Sequence< OUString > lcl_getExplicitSimpleCategories(
     317             :     const SplitCategoriesProvider& rSplitCategoriesProvider,
     318             :     ::std::vector< ::std::vector< ComplexCategory > >& rComplexCats )
     319             : {
     320         191 :     Sequence< OUString > aRet;
     321             : 
     322         191 :     rComplexCats.clear();
     323         191 :     sal_Int32 nLCount = rSplitCategoriesProvider.getLevelCount();
     324         382 :     for( sal_Int32 nL = 0; nL < nLCount; nL++ )
     325             :     {
     326         191 :         std::vector<sal_Int32> aLimitingBorders;
     327         191 :         if(nL>0)
     328           0 :             aLimitingBorders = lcl_getLimitingBorders( rComplexCats.back() );
     329             :         rComplexCats.push_back( lcl_DataSequenceToComplexCategoryVector(
     330         191 :             rSplitCategoriesProvider.getStringsForLevel(nL), aLimitingBorders, nL==(nLCount-1) ) );
     331         191 :     }
     332             : 
     333         191 :     std::vector< std::vector< ComplexCategory > >::iterator aOuterIt( rComplexCats.begin() );
     334         191 :     std::vector< std::vector< ComplexCategory > >::const_iterator aOuterEnd( rComplexCats.end() );
     335             : 
     336             :     //ensure that the category count is the same on each level
     337         191 :     sal_Int32 nMaxCategoryCount = 0;
     338             :     {
     339         382 :         for( aOuterIt=rComplexCats.begin(); aOuterIt != aOuterEnd; ++aOuterIt )
     340             :         {
     341         191 :             sal_Int32 nCurrentCount = lcl_getCategoryCount( *aOuterIt );
     342         191 :             nMaxCategoryCount = std::max( nCurrentCount, nMaxCategoryCount );
     343             :         }
     344         382 :         for( aOuterIt=rComplexCats.begin(); aOuterIt != aOuterEnd; ++aOuterIt )
     345             :         {
     346         191 :             if ( !aOuterIt->empty() )
     347             :             {
     348         191 :                 sal_Int32 nCurrentCount = lcl_getCategoryCount( *aOuterIt );
     349         191 :                 if( nCurrentCount< nMaxCategoryCount )
     350             :                 {
     351           0 :                     ComplexCategory& rComplexCategory = aOuterIt->back();
     352           0 :                     rComplexCategory.Count += (nMaxCategoryCount-nCurrentCount);
     353             :                 }
     354             :             }
     355             :         }
     356             :     }
     357             : 
     358             :     //create a list with an element for every index
     359         382 :     std::vector< std::vector< ComplexCategory > > aComplexCatsPerIndex;
     360         382 :     for( aOuterIt=rComplexCats.begin() ; aOuterIt != aOuterEnd; ++aOuterIt )
     361             :     {
     362         191 :         std::vector< ComplexCategory > aSingleLevel;
     363         191 :         std::vector< ComplexCategory >::iterator aIt( aOuterIt->begin() );
     364         191 :         std::vector< ComplexCategory >::const_iterator aEnd( aOuterIt->end() );
     365        1399 :         for( ; aIt != aEnd; ++aIt )
     366             :         {
     367        1208 :             ComplexCategory aComplexCategory( *aIt );
     368        1208 :             sal_Int32 nCount = aComplexCategory.Count;
     369        3433 :             while( nCount-- )
     370        1017 :                 aSingleLevel.push_back(aComplexCategory);
     371        1208 :         }
     372         191 :         aComplexCatsPerIndex.push_back( aSingleLevel );
     373         191 :     }
     374             : 
     375         191 :     if(nMaxCategoryCount)
     376             :     {
     377         191 :         aRet.realloc(nMaxCategoryCount);
     378         191 :         aOuterEnd = aComplexCatsPerIndex.end();
     379         191 :         OUString aSpace(" ");
     380        1208 :         for(sal_Int32 nN=0; nN<nMaxCategoryCount; nN++)
     381             :         {
     382        1017 :             OUString aText;
     383        2034 :             for( aOuterIt=aComplexCatsPerIndex.begin() ; aOuterIt != aOuterEnd; ++aOuterIt )
     384             :             {
     385        1017 :                 if ( static_cast<size_t>(nN) < aOuterIt->size() )
     386             :                 {
     387        1017 :                     OUString aAddText = (*aOuterIt)[nN].Text;
     388        1017 :                     if( !aAddText.isEmpty() )
     389             :                     {
     390        1016 :                         if(!aText.isEmpty())
     391           0 :                             aText += aSpace;
     392        1016 :                         aText += aAddText;
     393        1017 :                     }
     394             :                 }
     395             :             }
     396        1017 :             aRet[nN]=aText;
     397        1208 :         }
     398             :     }
     399         382 :     return aRet;
     400             : }
     401             : 
     402         191 : Sequence< OUString > ExplicitCategoriesProvider::getExplicitSimpleCategories(
     403             :     const SplitCategoriesProvider& rSplitCategoriesProvider )
     404             : {
     405         191 :     vector< vector< ComplexCategory > > aComplexCats;
     406         191 :     return lcl_getExplicitSimpleCategories( rSplitCategoriesProvider, aComplexCats );
     407             : }
     408             : 
     409             : struct DatePlusIndexComparator
     410             : {
     411       14418 :     inline bool operator() ( const DatePlusIndex& aFirst,
     412             :                              const DatePlusIndex& aSecond ) const
     413             :     {
     414       14418 :         return ( aFirst.fValue < aSecond.fValue );
     415             :     }
     416             : };
     417             : 
     418        2064 : bool lcl_fillDateCategories( const uno::Reference< data::XDataSequence >& xDataSequence, std::vector< DatePlusIndex >& rDateCategories, bool bIsAutoDate, ChartModel& rModel )
     419             : {
     420        2064 :     bool bOnlyDatesFound = true;
     421        2064 :     bool bAnyDataFound = false;
     422             : 
     423        2064 :     if( xDataSequence.is() )
     424             :     {
     425        2064 :         uno::Sequence< uno::Any > aValues = xDataSequence->getData();
     426        2064 :         sal_Int32 nCount = aValues.getLength();
     427        2064 :         rDateCategories.reserve(nCount);
     428        4128 :         Reference< util::XNumberFormats > xNumberFormats;
     429        2064 :         xNumberFormats = Reference< util::XNumberFormats >( rModel.getNumberFormats() );
     430             : 
     431        2064 :         bool bOwnData = false;
     432        2064 :         bool bOwnDataAnddAxisHasAnyFormat = false;
     433        2064 :         bool bOwnDataAnddAxisHasDateFormat = false;
     434        4128 :         Reference< XCoordinateSystem > xCooSysModel( ChartModelHelper::getFirstCoordinateSystem( rModel ) );
     435        2064 :         if( xCooSysModel.is() )
     436             :         {
     437        2064 :             if( rModel.hasInternalDataProvider() )
     438             :             {
     439        1940 :                 bOwnData = true;
     440        1940 :                 Reference< beans::XPropertySet > xAxisProps( xCooSysModel->getAxisByDimension(0,0), uno::UNO_QUERY );
     441        1940 :                 sal_Int32 nAxisNumberFormat = 0;
     442        1940 :                 if( xAxisProps.is() && (xAxisProps->getPropertyValue( "NumberFormat" ) >>= nAxisNumberFormat) )
     443             :                 {
     444          12 :                     bOwnDataAnddAxisHasAnyFormat = true;
     445          12 :                     bOwnDataAnddAxisHasDateFormat = DiagramHelper::isDateNumberFormat( nAxisNumberFormat, xNumberFormats );
     446        1940 :                 }
     447             :             }
     448             :         }
     449             : 
     450       11336 :         for(sal_Int32 nN=0;nN<nCount;nN++)
     451             :         {
     452        9272 :             bool bIsDate = false;
     453        9272 :             if( bIsAutoDate )
     454             :             {
     455        9272 :                 if( bOwnData )
     456        8303 :                     bIsDate = bOwnDataAnddAxisHasAnyFormat ? bOwnDataAnddAxisHasDateFormat : true;
     457             :                 else
     458         969 :                     bIsDate = DiagramHelper::isDateNumberFormat( xDataSequence->getNumberFormatKeyByIndex( nN ), xNumberFormats );
     459             :             }
     460             :             else
     461           0 :                 bIsDate = true;
     462             : 
     463        9272 :             bool bContainsEmptyString = false;
     464        9272 :             uno::Any aAny = aValues[nN];
     465        9272 :             if( aAny.hasValue() )
     466             :             {
     467        9272 :                 OUString aTest;
     468        9272 :                 double fTest = 0;
     469        9272 :                 bool bContainsNan = false;
     470        9272 :                 if( (aAny>>=aTest) && aTest.isEmpty() ) //empty String
     471           3 :                     bContainsEmptyString = true;
     472        9269 :                 else if( (aAny>>=fTest) &&  ::rtl::math::isNan(fTest) )
     473           0 :                     bContainsNan = true;
     474             : 
     475        9272 :                 if( !bContainsEmptyString && !bContainsNan )
     476        9269 :                     bAnyDataFound = true;
     477             :             }
     478        9272 :             DatePlusIndex aDatePlusIndex( 1.0, nN );
     479        9272 :             if( bIsDate && (aAny >>= aDatePlusIndex.fValue) )
     480           0 :                 rDateCategories.push_back( aDatePlusIndex );
     481             :             else
     482             :             {
     483        9272 :                 if( aAny.hasValue() && !bContainsEmptyString )//empty string does not count as non date value!
     484        9269 :                     bOnlyDatesFound=false;
     485        9272 :                 ::rtl::math::setNan( &aDatePlusIndex.fValue );
     486        9272 :                 rDateCategories.push_back( aDatePlusIndex );
     487             :             }
     488        9272 :         }
     489        4128 :         ::std::sort( rDateCategories.begin(), rDateCategories.end(), DatePlusIndexComparator() );
     490             :     }
     491             : 
     492        2064 :     return bAnyDataFound && bOnlyDatesFound;
     493             : }
     494             : 
     495        7645 : void ExplicitCategoriesProvider::init()
     496             : {
     497        7645 :     if( m_bDirty )
     498             :     {
     499        2188 :         m_aComplexCats.clear();//not one per index
     500        2188 :         m_aDateCategories.clear();
     501             : 
     502        2188 :         if( m_xOriginalCategories.is() )
     503             :         {
     504        2127 :             if( !hasComplexCategories() )
     505             :             {
     506        2127 :                 if(m_bIsDateAxis)
     507             :                 {
     508        2073 :                     if( ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( m_xCooSysModel, 0 ), 2, 0 ) )
     509        2064 :                         m_bIsDateAxis = lcl_fillDateCategories( m_xOriginalCategories->getValues(), m_aDateCategories, m_bIsAutoDate, mrModel );
     510             :                     else
     511           9 :                         m_bIsDateAxis = false;
     512             :                 }
     513             :             }
     514             :             else
     515             :             {
     516           0 :                 m_bIsDateAxis = false;
     517             :             }
     518             :         }
     519             :         else
     520          61 :             m_bIsDateAxis=false;
     521        2188 :         m_bDirty = false;
     522             :     }
     523        7645 : }
     524             : 
     525        1451 : Sequence< OUString > ExplicitCategoriesProvider::getSimpleCategories()
     526             : {
     527        1451 :     if( !m_bIsExplicitCategoriesInited )
     528             :     {
     529         609 :         init();
     530         609 :         m_aExplicitCategories.realloc(0);
     531         609 :         if( m_xOriginalCategories.is() )
     532             :         {
     533         577 :             if( !hasComplexCategories() )
     534             :             {
     535         577 :                 uno::Reference< data::XDataSequence > xDataSequence( m_xOriginalCategories->getValues() );
     536         577 :                 if( xDataSequence.is() )
     537         577 :                     ExplicitCategoriesProvider::convertCategoryAnysToText( m_aExplicitCategories, xDataSequence->getData(), mrModel );
     538             :             }
     539             :             else
     540             :             {
     541           0 :                 m_aExplicitCategories = lcl_getExplicitSimpleCategories(
     542           0 :                     SplitCategoriesProvider_ForLabeledDataSequences( m_aSplitCategoriesList, mrModel ), m_aComplexCats );
     543             :             }
     544             :         }
     545         609 :         if(!m_aExplicitCategories.getLength())
     546          32 :             m_aExplicitCategories = DiagramHelper::generateAutomaticCategoriesFromCooSys( m_xCooSysModel );
     547         609 :         m_bIsExplicitCategoriesInited = true;
     548             :     }
     549        1451 :     return m_aExplicitCategories;
     550             : }
     551             : 
     552           0 : const std::vector<ComplexCategory>* ExplicitCategoriesProvider::getCategoriesByLevel( sal_Int32 nLevel )
     553             : {
     554           0 :     init();
     555           0 :     sal_Int32 nMaxIndex = m_aComplexCats.size()-1;
     556           0 :     if (nLevel >= 0 && nLevel <= nMaxIndex)
     557           0 :         return &m_aComplexCats[nMaxIndex-nLevel];
     558           0 :     return NULL;
     559             : }
     560             : 
     561           0 : OUString ExplicitCategoriesProvider::getCategoryByIndex(
     562             :           const Reference< XCoordinateSystem >& xCooSysModel
     563             :         , ChartModel& rModel
     564             :         , sal_Int32 nIndex )
     565             : {
     566           0 :     if( xCooSysModel.is())
     567             :     {
     568           0 :         ExplicitCategoriesProvider aExplicitCategoriesProvider( xCooSysModel, rModel );
     569           0 :         Sequence< OUString > aCategories( aExplicitCategoriesProvider.getSimpleCategories());
     570           0 :         if( nIndex < aCategories.getLength())
     571           0 :             return aCategories[ nIndex ];
     572             :     }
     573           0 :     return OUString();
     574             : }
     575             : 
     576        7036 : bool ExplicitCategoriesProvider::isDateAxis()
     577             : {
     578        7036 :     init();
     579        7036 :     return m_bIsDateAxis;
     580             : }
     581             : 
     582           0 : const std::vector< DatePlusIndex >&  ExplicitCategoriesProvider::getDateCategories()
     583             : {
     584           0 :     init();
     585           0 :     return m_aDateCategories;
     586             : }
     587             : 
     588             : } //namespace chart
     589             : 
     590             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10