diff options
author | Mathias Bauer <mba@openoffice.org> | 2011-02-03 15:53:56 +0100 |
---|---|---|
committer | Mathias Bauer <mba@openoffice.org> | 2011-02-03 15:53:56 +0100 |
commit | 76f355864a8c03b64ebfc71139f525a1fc25836a (patch) | |
tree | 189737059bcece8ceacb7abf0c1e3834caa123c5 /chart2/source/view/main/ChartView.cxx | |
parent | 894985ff00c217013cc360a77108fc68cd8647e7 (diff) | |
parent | 0ceb085ea2b49234664765161095f2e5911e2b3b (diff) |
CWS gnumake3: resync to m99
Diffstat (limited to 'chart2/source/view/main/ChartView.cxx')
-rw-r--r-- | chart2/source/view/main/ChartView.cxx | 237 |
1 files changed, 66 insertions, 171 deletions
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 390c1890154e..72b40adfed88 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -31,6 +31,7 @@ #include "ChartView.hxx" #include "chartview/DrawModelWrapper.hxx" +#include "NumberFormatterWrapper.hxx" #include "ViewDefines.hxx" #include "VDiagram.hxx" #include "VTitle.hxx" @@ -56,6 +57,7 @@ #include "ControllerLockGuard.hxx" #include "BaseGFXHelper.hxx" #include "DataSeriesHelper.hxx" +#include "DateHelper.hxx" #include <comphelper/scopeguard.hxx> #include <boost/bind.hpp> @@ -78,7 +80,6 @@ #include <com/sun/star/chart/ChartAxisPosition.hpp> #include <com/sun/star/chart/DataLabelPlacement.hpp> #include <com/sun/star/chart/MissingValueTreatment.hpp> -#include <com/sun/star/chart2/ExplicitSubIncrement.hpp> #include <com/sun/star/chart2/StackingDirection.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> @@ -472,7 +473,7 @@ private: }; AxisUsage::AxisUsage() - : aScaleAutomatism(AxisHelper::createDefaultScale()) + : aScaleAutomatism(AxisHelper::createDefaultScale(),Date()) { } @@ -563,7 +564,7 @@ public: ~SeriesPlotterContainer(); void initializeCooSysAndSeriesPlotter( const uno::Reference< frame::XModel >& xChartModel ); - void initAxisUsageList(); + void initAxisUsageList(const Date& rNullDate); void doAutoScaling( const uno::Reference< frame::XModel >& xChartModel ); void updateScalesAndIncrementsOnAxes(); void setScalesFromCooSysToPlotter(); @@ -581,13 +582,15 @@ private: std::vector< VCoordinateSystem* >& m_rVCooSysList; ::std::map< uno::Reference< XAxis >, AxisUsage > m_aAxisUsageList; sal_Int32 m_nMaxAxisIndex; - bool m_bChartTypeUsesShiftedXAxisTicksPerDefault; + bool m_bChartTypeUsesShiftedCategoryPositionPerDefault; + sal_Int32 m_nDefaultDateNumberFormat; }; SeriesPlotterContainer::SeriesPlotterContainer( std::vector< VCoordinateSystem* >& rVCooSysList ) : m_rVCooSysList( rVCooSysList ) , m_nMaxAxisIndex(0) - , m_bChartTypeUsesShiftedXAxisTicksPerDefault(false) + , m_bChartTypeUsesShiftedCategoryPositionPerDefault(false) + , m_nDefaultDateNumberFormat(0) { } @@ -625,6 +628,10 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter( return; uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY ); + uno::Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY ); + if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() + && DiagramHelper::isSupportingDateAxis( xDiagram ) ) + m_nDefaultDateNumberFormat=DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier ); sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram ); if(!nDimensionCount) @@ -682,7 +689,7 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter( uno::Reference< XChartType > xChartType( aChartTypeList[nT] ); if(nT==0) - m_bChartTypeUsesShiftedXAxisTicksPerDefault = ChartTypeHelper::shiftTicksAtXAxisPerDefault( xChartType ); + m_bChartTypeUsesShiftedCategoryPositionPerDefault = ChartTypeHelper::shiftCategoryPosAtXAxisPerDefault( xChartType ); bool bExcludingPositioning = DiagramPositioningMode_EXCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ); VSeriesPlotter* pPlotter = VSeriesPlotter::createSeriesPlotter( xChartType, nDimensionCount, bExcludingPositioning ); @@ -793,7 +800,7 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter( } } -void SeriesPlotterContainer::initAxisUsageList() +void SeriesPlotterContainer::initAxisUsageList(const Date& rNullDate) { m_aAxisUsageList.clear(); size_t nC; @@ -803,8 +810,10 @@ void SeriesPlotterContainer::initAxisUsageList() for(sal_Int32 nDimensionIndex=0; nDimensionIndex<3; nDimensionIndex++) { uno::Reference< XCoordinateSystem > xCooSys = pVCooSys->getModel(); - if( nDimensionIndex >= xCooSys->getDimension() ) + sal_Int32 nDimensionCount = xCooSys->getDimension(); + if( nDimensionIndex >= nDimensionCount ) continue; + bool bChartTypeAllowsDateAxis = ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys, 0 ), nDimensionCount, nDimensionIndex ); const sal_Int32 nMaximumAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex); for(sal_Int32 nAxisIndex=0; nAxisIndex<=nMaximumAxisIndex; ++nAxisIndex) { @@ -813,7 +822,20 @@ void SeriesPlotterContainer::initAxisUsageList() if( xAxis.is()) { if(m_aAxisUsageList.find(xAxis)==m_aAxisUsageList.end()) - m_aAxisUsageList[xAxis].aScaleAutomatism = ScaleAutomatism(xAxis->getScaleData()); + { + chart2::ScaleData aSourceScale = xAxis->getScaleData(); + ExplicitCategoriesProvider* pExplicitCategoriesProvider = pVCooSys->getExplicitCategoriesProvider(); + if( nDimensionIndex==0 ) + AxisHelper::checkDateAxis( aSourceScale, pExplicitCategoriesProvider, bChartTypeAllowsDateAxis ); + if( (aSourceScale.AxisType == AxisType::CATEGORY && m_bChartTypeUsesShiftedCategoryPositionPerDefault) + || (aSourceScale.AxisType==AxisType::CATEGORY && pExplicitCategoriesProvider && pExplicitCategoriesProvider->hasComplexCategories() ) + || aSourceScale.AxisType == AxisType::DATE + || aSourceScale.AxisType == AxisType::SERIES ) + aSourceScale.ShiftedCategoryPosition = true; + else + aSourceScale.ShiftedCategoryPosition = false; + m_aAxisUsageList[xAxis].aScaleAutomatism = ScaleAutomatism(aSourceScale,rNullDate); + } AxisUsage& rAxisUsage = m_aAxisUsageList[xAxis]; rAxisUsage.addCoordinateSystem(pVCooSys,nDimensionIndex,nAxisIndex); } @@ -886,6 +908,11 @@ void SeriesPlotterContainer::setNumberFormatsFromAxes() { aAxesNumberFormats.setFormat( nNumberFormatKey, nDimensionIndex, nAxisIndex ); } + else if( nDimensionIndex==0 ) + { + //provide a default date format for date axis with own data + aAxesNumberFormats.setFormat( m_nDefaultDateNumberFormat, nDimensionIndex, nAxisIndex ); + } } } catch( lang::IndexOutOfBoundsException& e ) @@ -936,13 +963,7 @@ void SeriesPlotterContainer::doAutoScaling( const uno::Reference< frame::XModel rAxisUsage.aScaleAutomatism.calculateExplicitScaleAndIncrement( aExplicitScale, aExplicitIncrement ); for( nC=0; nC < aVCooSysList_X.size(); nC++) - { - ExplicitCategoriesProvider* pExplicitCategoriesProvider = aVCooSysList_X[nC]->getExplicitCategoriesProvider(); - - if( m_bChartTypeUsesShiftedXAxisTicksPerDefault || (aExplicitScale.AxisType==AxisType::CATEGORY && pExplicitCategoriesProvider && pExplicitCategoriesProvider->hasComplexCategories() ) ) - aExplicitIncrement.ShiftedPosition = true; aVCooSysList_X[nC]->setExplicitScaleAndIncrement( 0, nAxisIndex, aExplicitScale, aExplicitIncrement ); - } for( nC=0; nC < aVCooSysList_Z.size(); nC++) aVCooSysList_Z[nC]->setExplicitScaleAndIncrement( 2, nAxisIndex, aExplicitScale, aExplicitIncrement ); } @@ -1027,7 +1048,6 @@ void SeriesPlotterContainer::AdaptScaleOfYAxisWithoutAttachedSeries( const uno:: aExplicitScaleDest.Orientation = aExplicitScaleSource.Orientation; aExplicitScaleDest.Scaling = aExplicitScaleSource.Scaling; - aExplicitScaleDest.Breaks = aExplicitScaleSource.Breaks; aExplicitScaleDest.AxisType = aExplicitScaleSource.AxisType; aExplicitIncrementDest.BaseValue = aExplicitIncrementSource.BaseValue; @@ -1065,7 +1085,7 @@ void SeriesPlotterContainer::AdaptScaleOfYAxisWithoutAttachedSeries( const uno:: bAutoMinorInterval = !( aScale.IncrementData.SubIncrements[0].IntervalCount.hasValue() ); if( bAutoMinorInterval ) { - if( aExplicitIncrementDest.SubIncrements.getLength() && aExplicitIncrementSource.SubIncrements.getLength() ) + if( !aExplicitIncrementDest.SubIncrements.empty() && !aExplicitIncrementSource.SubIncrements.empty() ) aExplicitIncrementDest.SubIncrements[0].IntervalCount = aExplicitIncrementSource.SubIncrements[0].IntervalCount; } @@ -1380,7 +1400,8 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( SeriesPlotterContainer& // - prepare list of all axis and how they are used - rSeriesPlotterContainer.initAxisUsageList(); + Date aNullDate = NumberFormatterWrapper( uno::Reference< util::XNumberFormatsSupplier >( m_xChartModel, uno::UNO_QUERY ) ).getNullDate(); + rSeriesPlotterContainer.initAxisUsageList(aNullDate); rSeriesPlotterContainer.doAutoScaling( m_xChartModel ); rSeriesPlotterContainer.setScalesFromCooSysToPlotter(); rSeriesPlotterContainer.setNumberFormatsFromAxes(); @@ -1663,6 +1684,31 @@ sal_Bool ChartView::getExplicitValuesForAxis( { rExplicitScale = pVCooSys->getExplicitScale(nDimensionIndex,nAxisIndex); rExplicitIncrement = pVCooSys->getExplicitIncrement(nDimensionIndex,nAxisIndex); + if( rExplicitScale.ShiftedCategoryPosition ) + { + //remove 'one' from max + if( rExplicitScale.AxisType == ::com::sun::star::chart2::AxisType::DATE ) + { + Date aMaxDate(rExplicitScale.NullDate); aMaxDate += static_cast<long>(::rtl::math::approxFloor(rExplicitScale.Maximum)); + //for explicit scales with shifted categories we need one interval more + switch( rExplicitScale.TimeResolution ) + { + case ::com::sun::star::chart::TimeUnit::DAY: + aMaxDate--;break; + case ::com::sun::star::chart::TimeUnit::MONTH: + aMaxDate = DateHelper::GetDateSomeMonthsAway(aMaxDate,-1); + break; + case ::com::sun::star::chart::TimeUnit::YEAR: + aMaxDate = DateHelper::GetDateSomeYearsAway(aMaxDate,-1); + break; + } + rExplicitScale.Maximum = aMaxDate - rExplicitScale.NullDate; + } + else if( rExplicitScale.AxisType == ::com::sun::star::chart2::AxisType::CATEGORY ) + rExplicitScale.Maximum -= 1.0; + else if( rExplicitScale.AxisType == ::com::sun::star::chart2::AxisType::SERIES ) + rExplicitScale.Maximum -= 1.0; + } return sal_True; } return sal_False; @@ -1791,166 +1837,15 @@ bool lcl_getPropertySwapXAndYAxis( const uno::Reference< XDiagram >& xDiagram ) } -sal_Int32 lcl_getExplicitNumberFormatKeyForAxis( - const Reference< chart2::XAxis >& xAxis - , const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem - , const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier - , bool bSearchForParallelAxisIfNothingIsFound ) -{ - sal_Int32 nNumberFormatKey(0); - Reference< beans::XPropertySet > xProp( xAxis, uno::UNO_QUERY ); - if( xProp.is() && !( xProp->getPropertyValue( C2U( "NumberFormat" ) ) >>= nNumberFormatKey ) ) - { - bool bPercentFormatSet = false; - //check wether we have a percent scale -> use percent format - if( xNumberFormatsSupplier.is() ) - { - ScaleData aData = xAxis->getScaleData(); - if( aData.AxisType==AxisType::PERCENT ) - { - sal_Int32 nPercentFormat = ExplicitValueProvider::getPercentNumberFormat( xNumberFormatsSupplier ); - if( nPercentFormat != -1 ) - { - nNumberFormatKey = nPercentFormat; - bPercentFormatSet = true; - } - } - } - - if( !bPercentFormatSet ) - { - typedef ::std::map< sal_Int32, sal_Int32 > tNumberformatFrequency; - tNumberformatFrequency aKeyMap; - - bool bNumberFormatKeyFoundViaAttachedData = false; - sal_Int32 nAxisIndex = 0; - sal_Int32 nDimensionIndex = 1; - - try - { - Reference< XChartTypeContainer > xCTCnt( xCorrespondingCoordinateSystem, uno::UNO_QUERY_THROW ); - if( xCTCnt.is() ) - { - AxisHelper::getIndicesForAxis( xAxis, xCorrespondingCoordinateSystem, nDimensionIndex, nAxisIndex ); - ::rtl::OUString aRoleToMatch; - if( nDimensionIndex == 0 ) - aRoleToMatch = C2U("values-x"); - Sequence< Reference< XChartType > > aChartTypes( xCTCnt->getChartTypes()); - for( sal_Int32 nCTIdx=0; nCTIdx<aChartTypes.getLength(); ++nCTIdx ) - { - if( nDimensionIndex != 0 ) - aRoleToMatch = ChartTypeHelper::getRoleOfSequenceForYAxisNumberFormatDetection( aChartTypes[nCTIdx] ); - Reference< XDataSeriesContainer > xDSCnt( aChartTypes[nCTIdx], uno::UNO_QUERY_THROW ); - Sequence< Reference< XDataSeries > > aDataSeriesSeq( xDSCnt->getDataSeries()); - for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aDataSeriesSeq.getLength(); ++nSeriesIdx ) - { - Reference< chart2::XDataSeries > xDataSeries(aDataSeriesSeq[nSeriesIdx]); - Reference< data::XDataSource > xSource( xDataSeries, uno::UNO_QUERY_THROW ); - - if( nDimensionIndex == 1 ) - { - //only take those series into accoutn that are attached to this axis - sal_Int32 nAttachedAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries); - if( nAttachedAxisIndex != nAxisIndex ) - continue; - } - - Sequence< Reference< data::XLabeledDataSequence > > aLabeledSeq( xSource->getDataSequences()); - for( sal_Int32 nLSeqIdx=0; nLSeqIdx<aLabeledSeq.getLength(); ++nLSeqIdx ) - { - if(!aLabeledSeq[nLSeqIdx].is()) - continue; - Reference< data::XDataSequence > xSeq( aLabeledSeq[nLSeqIdx]->getValues()); - if(!xSeq.is()) - continue; - Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY ); - ::rtl::OUString aRole; - bool bTakeIntoAccount = - ( xSeqProp.is() && (aRoleToMatch.getLength() > 0) && - (xSeqProp->getPropertyValue(C2U("Role")) >>= aRole ) && - aRole.equals( aRoleToMatch )); - - if( bTakeIntoAccount ) - { - sal_Int32 nKey = xSeq->getNumberFormatKeyByIndex( -1 ); - // initialize the value - if( aKeyMap.find( nKey ) == aKeyMap.end()) - aKeyMap[ nKey ] = 0; - // increase frequency - aKeyMap[ nKey ] = (aKeyMap[ nKey ] + 1); - } - } - } - } - } - } - catch( const uno::Exception & ex ) - { - ASSERT_EXCEPTION( ex ); - } - - if( ! aKeyMap.empty()) - { - sal_Int32 nMaxFreq = 0; - // find most frequent key - for( tNumberformatFrequency::const_iterator aIt = aKeyMap.begin(); - aIt != aKeyMap.end(); ++aIt ) - { - OSL_TRACE( "NumberFormatKey %d appears %d times", (*aIt).first, (*aIt).second ); - // all values must at least be 1 - if( (*aIt).second > nMaxFreq ) - { - nNumberFormatKey = (*aIt).first; - bNumberFormatKeyFoundViaAttachedData = true; - nMaxFreq = (*aIt).second; - } - } - } - - if( bSearchForParallelAxisIfNothingIsFound ) - { - //no format is set to this axis and no data is set to this axis - //--> try to obtain the format from the parallel y-axis - if( !bNumberFormatKeyFoundViaAttachedData && nDimensionIndex == 1 ) - { - sal_Int32 nParallelAxisIndex = (nAxisIndex==1) ?0 :1; - Reference< XAxis > xParallelAxis( AxisHelper::getAxis( 1, nParallelAxisIndex, xCorrespondingCoordinateSystem ) ); - nNumberFormatKey = lcl_getExplicitNumberFormatKeyForAxis( xParallelAxis, xCorrespondingCoordinateSystem, xNumberFormatsSupplier, false ); - } - } - } - } - return nNumberFormatKey; -} - sal_Int32 ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( const Reference< chart2::XAxis >& xAxis , const Reference< chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem , const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier ) { - return lcl_getExplicitNumberFormatKeyForAxis( xAxis, xCorrespondingCoordinateSystem, xNumberFormatsSupplier + return AxisHelper::getExplicitNumberFormatKeyForAxis( xAxis, xCorrespondingCoordinateSystem, xNumberFormatsSupplier , true /*bSearchForParallelAxisIfNothingIsFound*/ ); } -sal_Int32 ExplicitValueProvider::getPercentNumberFormat( const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier ) -{ - sal_Int32 nRet=-1; - Reference< util::XNumberFormats > xNumberFormats( xNumberFormatsSupplier->getNumberFormats() ); - if( xNumberFormats.is() ) - { - sal_Bool bCreate = sal_True; - const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper(); - Sequence<sal_Int32> aKeySeq = xNumberFormats->queryKeys( util::NumberFormat::PERCENT, - rLocaleDataWrapper.getLocale(), bCreate ); - if( aKeySeq.getLength() ) - { - nRet = aKeySeq[0]; - } - } - return nRet; -} - - sal_Int32 ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( const uno::Reference< beans::XPropertySet >& xSeriesOrPointProp, const uno::Reference< XDataSeries >& xSeries, @@ -2003,7 +1898,7 @@ sal_Int32 ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabe return nFormat; if( !(xSeriesOrPointProp->getPropertyValue(C2U( "PercentageNumberFormat" )) >>= nFormat) ) { - nFormat = ExplicitValueProvider::getPercentNumberFormat( xNumberFormatsSupplier ); + nFormat = DiagramHelper::getPercentNumberFormat( xNumberFormatsSupplier ); } if(nFormat<0) nFormat=0; |