summaryrefslogtreecommitdiff
path: root/chart2/source/tools
diff options
context:
space:
mode:
authorIngrid Halama [iha] <Ingrid.Halama@oracle.com>2011-01-14 18:11:00 +0100
committerIngrid Halama [iha] <Ingrid.Halama@oracle.com>2011-01-14 18:11:00 +0100
commitdbf69a6612a5471d7ae23b1bf41afd1e9fec23a2 (patch)
tree9586af3b6af4e1d327004fa534a2dfbb2dd6cf2d /chart2/source/tools
parentbb15dfd763af19c547a27c40882d9cdf1477f375 (diff)
chart46: #i25706# implement date axis - #i116467# change behaviour of own data table
Diffstat (limited to 'chart2/source/tools')
-rw-r--r--chart2/source/tools/AxisHelper.cxx142
-rw-r--r--chart2/source/tools/DiagramHelper.cxx93
-rw-r--r--chart2/source/tools/ExplicitCategoriesProvider.cxx135
-rw-r--r--chart2/source/tools/InternalDataProvider.cxx42
-rwxr-xr-xchart2/source/tools/NumberFormatterWrapper.cxx188
-rw-r--r--chart2/source/tools/makefile.mk1
6 files changed, 471 insertions, 130 deletions
diff --git a/chart2/source/tools/AxisHelper.cxx b/chart2/source/tools/AxisHelper.cxx
index ec437cf7fd34..75bde77c801f 100644
--- a/chart2/source/tools/AxisHelper.cxx
+++ b/chart2/source/tools/AxisHelper.cxx
@@ -148,6 +148,148 @@ void AxisHelper::checkDateAxis( chart2::ScaleData& rScale, ExplicitCategoriesPro
}
}
+sal_Int32 AxisHelper::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 bFormatSet = false;
+ //check wether we have a percent scale -> use percent format
+ if( xNumberFormatsSupplier.is() )
+ {
+ ScaleData aData = AxisHelper::getDateCheckedScale( xAxis, Reference< frame::XModel >( xNumberFormatsSupplier, uno::UNO_QUERY ) );
+ if( aData.AxisType==AxisType::PERCENT )
+ {
+ sal_Int32 nPercentFormat = DiagramHelper::getPercentNumberFormat( xNumberFormatsSupplier );
+ if( nPercentFormat != -1 )
+ {
+ nNumberFormatKey = nPercentFormat;
+ bFormatSet = true;
+ }
+ }
+ else if( aData.AxisType==AxisType::DATE )
+ {
+ if( aData.Categories.is() )
+ {
+ Reference< data::XDataSequence > xSeq( aData.Categories->getValues());
+ Reference< chart2::XChartDocument > xChartDoc( xNumberFormatsSupplier, uno::UNO_QUERY );
+ if( xSeq.is() && !( xChartDoc.is() && xChartDoc->hasInternalDataProvider()) )
+ nNumberFormatKey = xSeq->getNumberFormatKeyByIndex( -1 );
+ else
+ nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier );
+ bFormatSet = true;
+ }
+ }
+ }
+
+ if( !bFormatSet )
+ {
+ 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;
+ }
+
+ Reference< data::XLabeledDataSequence > xLabeledSeq(
+ DataSeriesHelper::getDataSequenceByRole( xSource, aRoleToMatch ) );
+
+ if( !xLabeledSeq.is() && nDimensionIndex==0 )
+ {
+ ScaleData aData = xAxis->getScaleData();
+ xLabeledSeq = aData.Categories;
+ }
+
+ if( xLabeledSeq.is() )
+ {
+ Reference< data::XDataSequence > xSeq( xLabeledSeq->getValues());
+ if( xSeq.is() )
+ {
+ 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 = AxisHelper::getExplicitNumberFormatKeyForAxis( xParallelAxis, xCorrespondingCoordinateSystem, xNumberFormatsSupplier, false );
+ }
+ }
+ }
+ }
+ return nNumberFormatKey;
+}
+
//static
Reference< XAxis > AxisHelper::createAxis(
sal_Int32 nDimensionIndex
diff --git a/chart2/source/tools/DiagramHelper.cxx b/chart2/source/tools/DiagramHelper.cxx
index e9f060248afe..772994bf2498 100644
--- a/chart2/source/tools/DiagramHelper.cxx
+++ b/chart2/source/tools/DiagramHelper.cxx
@@ -1045,26 +1045,6 @@ Sequence< rtl::OUString > DiagramHelper::getExplicitSimpleCategories(
return aRet;
}
-bool DiagramHelper::mayToggleDateCategories( const Reference< XChartDocument >& xChartDoc )
-{
- Reference< frame::XModel > xChartModel( xChartDoc, uno::UNO_QUERY );
- if(xChartModel.is())
- {
- Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartModel ) );
- if( xCooSys.is() )
- {
- Reference< XAxis > xAxis( xCooSys->getAxisByDimension(0,0) );
- if( xAxis.is() )
- {
- ScaleData aScale( xAxis->getScaleData() );
- if( aScale.AxisType == chart2::AxisType::DATE || aScale.AxisType == chart2::AxisType::CATEGORY )
- return true;
- }
- }
- }
- return false;
-}
-
namespace
{
void lcl_switchToDateCategories( const Reference< XChartDocument >& xChartDoc, const Reference< XAxis >& xAxis )
@@ -1194,35 +1174,62 @@ void DiagramHelper::switchToTextCategories( const Reference< XChartDocument >& x
}
}
-void DiagramHelper::toggleDateCategories( const Reference< XChartDocument >& xChartDoc )
+bool DiagramHelper::isSupportingDateAxis( const Reference< chart2::XDiagram >& xDiagram )
{
- Reference< frame::XModel > xChartModel( xChartDoc, uno::UNO_QUERY );
- if(xChartModel.is())
+ return ::chart::ChartTypeHelper::isSupportingDateAxis(
+ DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), DiagramHelper::getDimension( xDiagram ), 0 );
+}
+
+bool DiagramHelper::isDateNumberFormat( sal_Int32 nNumberFormat, const Reference< util::XNumberFormats >& xNumberFormats )
+{
+ bool bIsDate = false;
+ if( !xNumberFormats.is() )
+ return bIsDate;
+
+ Reference< beans::XPropertySet > xKeyProps = xNumberFormats->getByKey( nNumberFormat );
+ if( xKeyProps.is() )
{
- ControllerLockGuard aCtrlLockGuard( xChartModel );
+ sal_Int32 nType = util::NumberFormat::UNDEFINED;
+ xKeyProps->getPropertyValue( C2U("Type") ) >>= nType;
+ bIsDate = nType & util::NumberFormat::DATE;
+ }
+ return bIsDate;
+}
- Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartModel ) );
- if( xCooSys.is() )
+sal_Int32 DiagramHelper::getDateNumberFormat( 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::DATE,
+ rLocaleDataWrapper.getLocale(), bCreate );
+ if( aKeySeq.getLength() )
{
- Reference< XAxis > xAxis( xCooSys->getAxisByDimension(0,0) );
- if( xAxis.is() )
- {
- ScaleData aScale( xAxis->getScaleData() );
- if( aScale.AxisType == chart2::AxisType::DATE )
- {
- lcl_switchToTextCategories( xChartDoc, xAxis );
- }
- else if( aScale.AxisType == chart2::AxisType::CATEGORY )
- {
- lcl_switchToDateCategories( xChartDoc, xAxis );
- }
- else
- {
- DBG_ERROR("Cannot toggle Date Categories for this axis type");
- }
- }
+ nRet = aKeySeq[0];
+ }
+ }
+ return nRet;
+}
+
+sal_Int32 DiagramHelper::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;
}
// static
diff --git a/chart2/source/tools/ExplicitCategoriesProvider.cxx b/chart2/source/tools/ExplicitCategoriesProvider.cxx
index 1c52a3c3e622..ef2d6ac22bf2 100644
--- a/chart2/source/tools/ExplicitCategoriesProvider.cxx
+++ b/chart2/source/tools/ExplicitCategoriesProvider.cxx
@@ -37,6 +37,7 @@
#include "ChartModelHelper.hxx"
#include "ContainerHelper.hxx"
#include "macros.hxx"
+#include "NumberFormatterWrapper.hxx"
#include <com/sun/star/chart2/AxisType.hpp>
#include <com/sun/star/util/NumberFormat.hpp>
@@ -61,6 +62,7 @@ ExplicitCategoriesProvider::ExplicitCategoriesProvider( const Reference< chart2:
, m_xCooSysModel( xCooSysModel )
, m_xChartModel( xChartModel )
, m_xOriginalCategories()
+ , m_bIsExplicitCategoriesInited(false)
, m_bIsDateAxis(false)
, m_bIsAutoDate(false)
{
@@ -188,30 +190,52 @@ std::vector<sal_Int32> lcl_getLimitingBorders( const std::vector< ComplexCategor
return aLimitingBorders;
}
-uno::Sequence< rtl::OUString > lcl_DataToStringSequence( const uno::Reference< data::XDataSequence >& xDataSequence )
+void ExplicitCategoriesProvider::convertCategoryAnysToText( uno::Sequence< rtl::OUString >& rOutTexts, const uno::Sequence< uno::Any >& rInAnys, Reference< frame::XModel > xChartModel )
{
- uno::Sequence< rtl::OUString > aStrings;
+ sal_Int32 nCount = rInAnys.getLength();
+ if(!nCount)
+ return;
+ rOutTexts.realloc(nCount);
+ Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartModel, uno::UNO_QUERY );
+ Reference< util::XNumberFormats > xNumberFormats;
+ if( xNumberFormatsSupplier.is() )
+ xNumberFormats = Reference< util::XNumberFormats >( xNumberFormatsSupplier->getNumberFormats() );
+
+ sal_Int32 nAxisNumberFormat = 0;
+ Reference< XCoordinateSystem > xCooSysModel( ChartModelHelper::getFirstCoordinateSystem( xChartModel ) );
+ if( xCooSysModel.is() )
+ {
+ Reference< chart2::XAxis > xAxis( xCooSysModel->getAxisByDimension(0,0) );
+ nAxisNumberFormat = AxisHelper::getExplicitNumberFormatKeyForAxis(
+ xAxis, xCooSysModel, xNumberFormatsSupplier, false );
+ }
- OSL_ASSERT( xDataSequence.is());
- if( !xDataSequence.is() )
- return aStrings;
+ sal_Int32 nLabelColor;
+ bool bColorChanged = false;
+ NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
+ SvNumberFormatter* pSvNumberFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
- uno::Reference< data::XTextualDataSequence > xTextualDataSequence( xDataSequence, uno::UNO_QUERY );
- if( xTextualDataSequence.is() )
+ for(sal_Int32 nN=0;nN<nCount;nN++)
{
- aStrings = xTextualDataSequence->getTextualData();
- }
- else
- {
- uno::Sequence< uno::Any > aValues = xDataSequence->getData();
- aStrings.realloc(aValues.getLength());
-
- for(sal_Int32 nN=aValues.getLength();nN--;)
- aValues[nN] >>= aStrings[nN];
+ rtl::OUString aText;
+ uno::Any aAny = rInAnys[nN];
+ if( aAny.hasValue() )
+ {
+ double fDouble;
+ if( aAny>>=fDouble )
+ {
+ if( !::rtl::math::isNan(fDouble) )
+ aText = aNumberFormatterWrapper.getFormattedString(
+ nAxisNumberFormat, fDouble, nLabelColor, bColorChanged );
+ }
+ else
+ {
+ aAny>>=aText;
+ }
+ }
+ rOutTexts[nN] = aText;
}
-
- return aStrings;
}
SplitCategoriesProvider::~SplitCategoriesProvider()
@@ -222,9 +246,13 @@ class SplitCategoriesProvider_ForLabeledDataSequences : public SplitCategoriesPr
{
public:
- explicit SplitCategoriesProvider_ForLabeledDataSequences( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
- ::com::sun::star::chart2::data::XLabeledDataSequence> >& rSplitCategoriesList )
+ explicit SplitCategoriesProvider_ForLabeledDataSequences(
+ const ::com::sun::star::uno::Sequence<
+ ::com::sun::star::uno::Reference<
+ ::com::sun::star::chart2::data::XLabeledDataSequence> >& rSplitCategoriesList
+ , const Reference< frame::XModel >& xChartModel )
: m_rSplitCategoriesList( rSplitCategoriesList )
+ , m_xChartModel( xChartModel )
{}
virtual ~SplitCategoriesProvider_ForLabeledDataSequences()
{}
@@ -235,6 +263,8 @@ public:
private:
const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
::com::sun::star::chart2::data::XLabeledDataSequence> >& m_rSplitCategoriesList;
+
+ Reference< frame::XModel > m_xChartModel;
};
sal_Int32 SplitCategoriesProvider_ForLabeledDataSequences::getLevelCount() const
@@ -246,7 +276,11 @@ uno::Sequence< rtl::OUString > SplitCategoriesProvider_ForLabeledDataSequences::
uno::Sequence< rtl::OUString > aRet;
Reference< data::XLabeledDataSequence > xLabeledDataSequence( m_rSplitCategoriesList[nLevel] );
if( xLabeledDataSequence.is() )
- aRet = lcl_DataToStringSequence( xLabeledDataSequence->getValues() );
+ {
+ uno::Reference< data::XDataSequence > xDataSequence( xLabeledDataSequence->getValues() );
+ if( xDataSequence.is() )
+ ExplicitCategoriesProvider::convertCategoryAnysToText( aRet, xDataSequence->getData(), m_xChartModel );
+ }
return aRet;
}
@@ -393,22 +427,6 @@ struct DatePlusIndexComparator
}
};
-bool lcl_isDateFormat( sal_Int32 nNumberFormat, const Reference< util::XNumberFormats >& xNumberFormats )
-{
- bool bIsDate = false;
- if( !xNumberFormats.is() )
- return bIsDate;
-
- Reference< beans::XPropertySet > xKeyProps = xNumberFormats->getByKey( nNumberFormat );
- if( xKeyProps.is() )
- {
- sal_Int32 nType = util::NumberFormat::UNDEFINED;
- xKeyProps->getPropertyValue( C2U("Type") ) >>= nType;
- bIsDate = nType & util::NumberFormat::DATE;
- }
- return bIsDate;
-}
-
bool lcl_fillDateCategories( const uno::Reference< data::XDataSequence >& xDataSequence, std::vector< DatePlusIndex >& rDateCategories, bool bIsAutoDate, Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier )
{
bool bOnlyDatesFound = true;
@@ -424,8 +442,8 @@ bool lcl_fillDateCategories( const uno::Reference< data::XDataSequence >& xDataS
xNumberFormats = Reference< util::XNumberFormats >( xNumberFormatsSupplier->getNumberFormats() );
bool bOwnData = false;
- bool bOwnDataAndDateFormat = false;
- sal_Int32 nAxisNumberFormat = 0;
+ bool bOwnDataAnddAxisHasAnyFormat = false;
+ bool bOwnDataAnddAxisHasDateFormat = false;
Reference< chart2::XChartDocument > xChartDoc( xNumberFormatsSupplier, uno::UNO_QUERY );
Reference< XCoordinateSystem > xCooSysModel( ChartModelHelper::getFirstCoordinateSystem( Reference< frame::XModel >( xChartDoc, uno::UNO_QUERY ) ) );
if( xChartDoc.is() && xCooSysModel.is() )
@@ -434,8 +452,12 @@ bool lcl_fillDateCategories( const uno::Reference< data::XDataSequence >& xDataS
{
bOwnData = true;
Reference< beans::XPropertySet > xAxisProps( xCooSysModel->getAxisByDimension(0,0), uno::UNO_QUERY );
+ sal_Int32 nAxisNumberFormat = 0;
if( xAxisProps.is() && (xAxisProps->getPropertyValue( C2U("NumberFormat") ) >>= nAxisNumberFormat) )
- bOwnDataAndDateFormat = lcl_isDateFormat( nAxisNumberFormat, xNumberFormats );
+ {
+ bOwnDataAnddAxisHasAnyFormat = true;
+ bOwnDataAnddAxisHasDateFormat = DiagramHelper::isDateNumberFormat( nAxisNumberFormat, xNumberFormats );
+ }
}
}
@@ -445,9 +467,9 @@ bool lcl_fillDateCategories( const uno::Reference< data::XDataSequence >& xDataS
if( bIsAutoDate )
{
if( bOwnData )
- bIsDate = bOwnDataAndDateFormat;
+ bIsDate = bOwnDataAnddAxisHasAnyFormat ? bOwnDataAnddAxisHasDateFormat : true;
else
- bIsDate = lcl_isDateFormat( xDataSequence->getNumberFormatKeyByIndex( nN ), xNumberFormats );
+ bIsDate = DiagramHelper::isDateNumberFormat( xDataSequence->getNumberFormatKeyByIndex( nN ), xNumberFormats );
}
else
bIsDate = true;
@@ -488,7 +510,6 @@ void ExplicitCategoriesProvider::init()
{
if( m_bDirty )
{
- m_aExplicitCategories.realloc(0);
m_aComplexCats.clear();//not one per index
m_aDateCategories.clear();
@@ -496,7 +517,6 @@ void ExplicitCategoriesProvider::init()
{
if( !hasComplexCategories() )
{
- m_aExplicitCategories = DataSequenceToStringSequence(m_xOriginalCategories->getValues());
if(m_bIsDateAxis)
{
if( ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( m_xCooSysModel, 0 ), 2, 0 ) )
@@ -507,15 +527,11 @@ void ExplicitCategoriesProvider::init()
}
else
{
- m_aExplicitCategories = lcl_getExplicitSimpleCategories(
- SplitCategoriesProvider_ForLabeledDataSequences( m_aSplitCategoriesList ), m_aComplexCats );
m_bIsDateAxis = false;
}
}
else
m_bIsDateAxis=false;
- if(!m_aExplicitCategories.getLength())
- m_aExplicitCategories = DiagramHelper::generateAutomaticCategoriesFromCooSys( m_xCooSysModel );
m_bDirty = false;
}
}
@@ -523,7 +539,28 @@ void ExplicitCategoriesProvider::init()
Sequence< ::rtl::OUString > ExplicitCategoriesProvider::getSimpleCategories()
{
- init();
+ if( !m_bIsExplicitCategoriesInited )
+ {
+ init();
+ m_aExplicitCategories.realloc(0);
+ if( m_xOriginalCategories.is() )
+ {
+ if( !hasComplexCategories() )
+ {
+ uno::Reference< data::XDataSequence > xDataSequence( m_xOriginalCategories->getValues() );
+ if( xDataSequence.is() )
+ ExplicitCategoriesProvider::convertCategoryAnysToText( m_aExplicitCategories, xDataSequence->getData(), m_xChartModel );
+ }
+ else
+ {
+ m_aExplicitCategories = lcl_getExplicitSimpleCategories(
+ SplitCategoriesProvider_ForLabeledDataSequences( m_aSplitCategoriesList, m_xChartModel ), m_aComplexCats );
+ }
+ }
+ if(!m_aExplicitCategories.getLength())
+ m_aExplicitCategories = DiagramHelper::generateAutomaticCategoriesFromCooSys( m_xCooSysModel );
+ m_bIsExplicitCategoriesInited = true;
+ }
return m_aExplicitCategories;
}
diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx
index b3f3058d6f05..88de8c94e977 100644
--- a/chart2/source/tools/InternalDataProvider.cxx
+++ b/chart2/source/tools/InternalDataProvider.cxx
@@ -375,17 +375,9 @@ InternalDataProvider::InternalDataProvider( const Reference< chart2::XChartDocum
if( !xLDS.is() )
continue;
Sequence< uno::Any > aDataSeq;
- Reference< chart2::data::XTextualDataSequence > xTextSeq( xLDS->getValues(), uno::UNO_QUERY );
- if( !bIsDateAxis && xTextSeq.is() )
- {
- aDataSeq = lcl_StringToAnySequence( xTextSeq->getTextualData() );
- }
- else
- {
- Reference< chart2::data::XDataSequence > xSeq( xLDS->getValues() );
- if( xSeq.is() )
- aDataSeq = xSeq->getData();
- }
+ Reference< chart2::data::XDataSequence > xSeq( xLDS->getValues() );
+ if( xSeq.is() )
+ aDataSeq = xSeq->getData();
sal_Int32 nLength = aDataSeq.getLength();
if( static_cast< sal_Int32 >(aNewCategories.size()) < nLength )
aNewCategories.resize( nLength );
@@ -790,40 +782,14 @@ Sequence< uno::Any > SAL_CALL InternalDataProvider::getDataByRangeRepresentation
}
else if( aRange.equals( lcl_aCategoriesRangeName ) )
{
- bool bReturnText = true;
vector< vector< uno::Any > > aCategories( m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels());
sal_Int32 nLevelCount = lcl_getInnerLevelCount( aCategories );
if( nLevelCount == 1 )
{
sal_Int32 nL=0;
aResult = this->getDataByRangeRepresentation( lcl_aCategoriesLevelRangeNamePrefix + OUString::valueOf( nL ) );
- bool bOnlyDatesFound = true;
- double fTest = 0.0;
- OUString aTest;
- for(sal_Int32 nN=aResult.getLength(); nN--;)
- {
- uno::Any aAny(aResult[nN]);
- if( !( aAny >>= fTest) )
- {
- if( aAny.hasValue() )
- {
- if( (aAny>>=aTest) && !aTest.getLength() )
- {
- //empty string does not count as non date value!
- aResult[nN] = uno::Any();
- }
- else
- {
- bOnlyDatesFound=false;
- break;
- }
- }
- }
- }
- if( bOnlyDatesFound )
- bReturnText = false;
}
- if( bReturnText )
+ else
{
Sequence< OUString > aLabels = m_bDataInColumns ? this->getRowDescriptions() : this->getColumnDescriptions();
aResult.realloc( aLabels.getLength() );
diff --git a/chart2/source/tools/NumberFormatterWrapper.cxx b/chart2/source/tools/NumberFormatterWrapper.cxx
new file mode 100755
index 000000000000..829a64cc6617
--- /dev/null
+++ b/chart2/source/tools/NumberFormatterWrapper.cxx
@@ -0,0 +1,188 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_chart2.hxx"
+#include "NumberFormatterWrapper.hxx"
+#include "macros.hxx"
+#include <comphelper/processfactory.hxx>
+// header for class SvNumberFormatsSupplierObj
+#include <svl/numuno.hxx>
+// header for class SvNumberformat
+#include <svl/zformat.hxx>
+#include <tools/color.hxx>
+#include <i18npool/mslangid.hxx>
+#include <tools/debug.hxx>
+#include <com/sun/star/util/DateTime.hpp>
+
+//.............................................................................
+namespace chart
+{
+//.............................................................................
+using namespace ::com::sun::star;
+
+FixedNumberFormatter::FixedNumberFormatter(
+ const uno::Reference< util::XNumberFormatsSupplier >& xSupplier
+ , sal_Int32 nNumberFormatKey )
+ : m_aNumberFormatterWrapper(xSupplier)
+ , m_nNumberFormatKey( nNumberFormatKey )
+{
+}
+
+FixedNumberFormatter::~FixedNumberFormatter()
+{
+}
+
+/*
+sal_Int32 FixedNumberFormatter::getTextAndColor( double fUnscaledValueForText, rtl::OUString& rLabel ) const
+{
+ sal_Int32 nLabelColor = Color(COL_BLUE).GetColor(); //@todo get this from somewheres
+ rLabel = getFormattedString( fUnscaledValueForText, nLabelColor );
+ return nLabelColor;
+}
+*/
+
+rtl::OUString FixedNumberFormatter::getFormattedString( double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const
+{
+ return m_aNumberFormatterWrapper.getFormattedString(
+ m_nNumberFormatKey, fValue, rLabelColor, rbColorChanged );
+}
+
+//-----------------------------------------------------------------------
+//-----------------------------------------------------------------------
+//-----------------------------------------------------------------------
+
+NumberFormatterWrapper::NumberFormatterWrapper( const uno::Reference< util::XNumberFormatsSupplier >& xSupplier )
+ : m_xNumberFormatsSupplier(xSupplier)
+ , m_pNumberFormatter(NULL)
+
+{
+ uno::Reference<beans::XPropertySet> xProp(m_xNumberFormatsSupplier,uno::UNO_QUERY);
+ rtl::OUString sNullDate( RTL_CONSTASCII_USTRINGPARAM("NullDate"));
+ if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(sNullDate) )
+ m_aNullDate = xProp->getPropertyValue(sNullDate);
+ SvNumberFormatsSupplierObj* pSupplierObj = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
+ if( pSupplierObj )
+ m_pNumberFormatter = pSupplierObj->GetNumberFormatter();
+ DBG_ASSERT(m_pNumberFormatter,"need a numberformatter");
+}
+
+NumberFormatterWrapper::~NumberFormatterWrapper()
+{
+}
+
+SvNumberFormatter* NumberFormatterWrapper::getSvNumberFormatter() const
+{
+ return m_pNumberFormatter;
+}
+
+Date NumberFormatterWrapper::getNullDate() const
+{
+ USHORT nYear = 1899,nDay = 30,nMonth = 12;
+ Date aRet(nDay,nMonth,nYear);
+
+ util::DateTime aUtilDate;
+ if( m_aNullDate.hasValue() && (m_aNullDate >>= aUtilDate) )
+ {
+ aRet = Date(aUtilDate.Day,aUtilDate.Month,aUtilDate.Year);
+ }
+ else if( m_pNumberFormatter )
+ {
+ Date* pDate = m_pNumberFormatter->GetNullDate();
+ if( pDate )
+ aRet = *pDate;
+ }
+ return aRet;
+}
+
+rtl::OUString NumberFormatterWrapper::getFormattedString(
+ sal_Int32 nNumberFormatKey, double fValue, sal_Int32& rLabelColor, bool& rbColorChanged ) const
+{
+ String aText;
+ Color* pTextColor = NULL;
+ if( !m_pNumberFormatter )
+ {
+ DBG_ERROR("Need a NumberFormatter");
+ return aText;
+ }
+ // i99104 handle null date correctly
+ USHORT nYear = 1899,nDay = 30,nMonth = 12;
+ if ( m_aNullDate.hasValue() )
+ {
+ Date* pDate = m_pNumberFormatter->GetNullDate();
+ if ( pDate )
+ {
+ nYear = pDate->GetYear();
+ nMonth = pDate->GetMonth();
+ nDay = pDate->GetDay();
+ } // if ( pDate )
+ util::DateTime aNewNullDate;
+ m_aNullDate >>= aNewNullDate;
+ m_pNumberFormatter->ChangeNullDate(aNewNullDate.Day,aNewNullDate.Month,aNewNullDate.Year);
+ }
+ m_pNumberFormatter->GetOutputString(
+ fValue, nNumberFormatKey, aText, &pTextColor);
+ if ( m_aNullDate.hasValue() )
+ {
+ m_pNumberFormatter->ChangeNullDate(nDay,nMonth,nYear);
+ }
+ rtl::OUString aRet( aText );
+
+ if(pTextColor)
+ {
+ rbColorChanged = true;
+ rLabelColor = pTextColor->GetColor();
+ }
+ else
+ rbColorChanged = false;
+
+ return aRet;
+}
+
+// to get the language type use MsLangId::convertLocaleToLanguage( rNumberFormat.aLocale )
+
+/*
+ uno::Reference< i18n::XNumberFormatCode > xNumberFormatCode(
+ m_xCC->getServiceManager()->createInstanceWithContext( C2U(
+ "com.sun.star.i18n.NumberFormatMapper" ), m_xCC ), uno::UNO_QUERY );
+
+ i18n::NumberFormatCode aNumberFormatCode = xNumberFormatCode->getDefault (
+ i18n::KNumberFormatType::MEDIUM,
+ i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER,
+ aLocale );
+
+ uno::Sequence< i18n::NumberFormatCode > aListOfNumberFormatCode = xNumberFormatCode->getAllFormatCode(
+ i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER,
+ aLocale );
+
+ i18n::NumberFormatCode aNumberFormatCode0 = aListOfNumberFormatCode[0];
+ i18n::NumberFormatCode aNumberFormatCode1 = aListOfNumberFormatCode[1];
+*/
+
+//.............................................................................
+} //namespace chart
+//.............................................................................
diff --git a/chart2/source/tools/makefile.mk b/chart2/source/tools/makefile.mk
index fd92b894bfab..7554bd19cd38 100644
--- a/chart2/source/tools/makefile.mk
+++ b/chart2/source/tools/makefile.mk
@@ -70,6 +70,7 @@ SLOFILES= \
$(SLO)$/LinearRegressionCurveCalculator.obj \
$(SLO)$/LogarithmicRegressionCurveCalculator.obj \
$(SLO)$/MeanValueRegressionCurveCalculator.obj \
+ $(SLO)$/NumberFormatterWrapper.obj \
$(SLO)$/OPropertySet.obj \
$(SLO)$/WrappedPropertySet.obj \
$(SLO)$/WrappedProperty.obj \