summaryrefslogtreecommitdiffstats
path: root/chart2/source/tools
diff options
context:
space:
mode:
authorIngrid Halama [iha] <Ingrid.Halama@oracle.com>2011-02-03 12:49:56 +0100
committerIngrid Halama [iha] <Ingrid.Halama@oracle.com>2011-02-03 12:49:56 +0100
commitc9bfd6cdebb754d1c33a7dcae0041d64dcdca792 (patch)
tree1b1722a1a795e2e93eb3146170e024c130337ae0 /chart2/source/tools
parentchart52: #28670# make the legend within charts resizeable - part 7 (diff)
parent#i10000# WAE: initialize variables (diff)
downloadcore-c9bfd6cdebb754d1c33a7dcae0041d64dcdca792.tar.gz
core-c9bfd6cdebb754d1c33a7dcae0041d64dcdca792.zip
chart52: merge with DEV300_m99
Diffstat (limited to 'chart2/source/tools')
-rwxr-xr-xchart2/source/tools/AxisHelper.cxx232
-rwxr-xr-xchart2/source/tools/ChartTypeHelper.cxx25
-rwxr-xr-x[-rw-r--r--]chart2/source/tools/DataSourceHelper.cxx19
-rwxr-xr-xchart2/source/tools/DiagramHelper.cxx214
-rwxr-xr-xchart2/source/tools/ExplicitCategoriesProvider.cxx242
-rwxr-xr-xchart2/source/tools/InternalData.cxx42
-rwxr-xr-xchart2/source/tools/InternalDataProvider.cxx337
-rwxr-xr-xchart2/source/tools/NumberFormatterWrapper.cxx188
-rwxr-xr-x[-rw-r--r--]chart2/source/tools/ResId.cxx2
-rw-r--r--chart2/source/tools/makefile.mk1
10 files changed, 1114 insertions, 188 deletions
diff --git a/chart2/source/tools/AxisHelper.cxx b/chart2/source/tools/AxisHelper.cxx
index b5f7abfb8206..4fd21e2c3b8b 100755
--- a/chart2/source/tools/AxisHelper.cxx
+++ b/chart2/source/tools/AxisHelper.cxx
@@ -38,7 +38,10 @@
#include "servicenames_coosystems.hxx"
#include "DataSeriesHelper.hxx"
#include "Scaling.hxx"
+#include "ChartModelHelper.hxx"
+#include "DataSourceHelper.hxx"
+#include <tools/debug.hxx>
#include <unotools/saveopt.hxx>
#include <com/sun/star/chart/ChartAxisPosition.hpp>
@@ -50,6 +53,8 @@
// header for class OUStringBuffer
#include <rtl/ustrbuf.hxx>
+#include <rtl/math.hxx>
+
#include <com/sun/star/util/XCloneable.hpp>
#include <com/sun/star/lang/XServiceName.hpp>
@@ -78,6 +83,8 @@ ScaleData AxisHelper::createDefaultScale()
{
ScaleData aScaleData;
aScaleData.AxisType = chart2::AxisType::REALNUMBER;
+ aScaleData.AutoDateAxis = true;
+ aScaleData.ShiftedCategoryPosition = false;//this is adapted in the view code currently
Sequence< SubIncrement > aSubIncrements(1);
aSubIncrements[0] = SubIncrement();
aScaleData.IncrementData.SubIncrements = aSubIncrements;
@@ -89,6 +96,9 @@ void AxisHelper::removeExplicitScaling( ScaleData& rScaleData )
uno::Any aEmpty;
rScaleData.Minimum = rScaleData.Maximum = rScaleData.Origin = aEmpty;
rScaleData.Scaling = 0;
+ ScaleData aDefaultScale( createDefaultScale() );
+ rScaleData.IncrementData = aDefaultScale.IncrementData;
+ rScaleData.TimeIncrement = aDefaultScale.TimeIncrement;
}
bool AxisHelper::isLogarithmic( const Reference< XScaling >& xScaling )
@@ -100,6 +110,227 @@ bool AxisHelper::isLogarithmic( const Reference< XScaling >& xScaling )
return bReturn;
}
+chart2::ScaleData AxisHelper::getDateCheckedScale( const Reference< chart2::XAxis >& xAxis, const Reference< frame::XModel >& xChartModel )
+{
+ DBG_ASSERT(xChartModel.is(),"missing chart model");
+ ScaleData aScale = xAxis->getScaleData();
+ Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartModel ) );
+ if( aScale.AutoDateAxis && aScale.AxisType == AxisType::CATEGORY )
+ {
+ sal_Int32 nDimensionIndex=0; sal_Int32 nAxisIndex=0;
+ AxisHelper::getIndicesForAxis(xAxis, xCooSys, nDimensionIndex, nAxisIndex );
+ bool bChartTypeAllowsDateAxis = ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( xCooSys, 0 ), 2, nDimensionIndex );
+ if( bChartTypeAllowsDateAxis )
+ aScale.AxisType = AxisType::DATE;
+ }
+ if( aScale.AxisType == AxisType::DATE )
+ {
+ ExplicitCategoriesProvider aExplicitCategoriesProvider( xCooSys,xChartModel );
+ if( !aExplicitCategoriesProvider.isDateAxis() )
+ aScale.AxisType = AxisType::CATEGORY;
+ }
+ return aScale;
+}
+
+void AxisHelper::checkDateAxis( chart2::ScaleData& rScale, ExplicitCategoriesProvider* pExplicitCategoriesProvider, bool bChartTypeAllowsDateAxis )
+{
+ if( rScale.AutoDateAxis && rScale.AxisType == AxisType::CATEGORY && bChartTypeAllowsDateAxis )
+ {
+ rScale.AxisType = AxisType::DATE;
+ removeExplicitScaling( rScale );
+ }
+ if( rScale.AxisType == AxisType::DATE && (!pExplicitCategoriesProvider || !pExplicitCategoriesProvider->isDateAxis()) )
+ {
+ rScale.AxisType = AxisType::CATEGORY;
+ removeExplicitScaling( rScale );
+ }
+}
+
+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);
+ bool bNumberFormatKeyFoundViaAttachedData = false;
+ sal_Int32 nAxisIndex = 0;
+ sal_Int32 nDimensionIndex = 1;
+ AxisHelper::getIndicesForAxis( xAxis, xCorrespondingCoordinateSystem, nDimensionIndex, nAxisIndex );
+ Reference< chart2::XChartDocument > xChartDoc( xNumberFormatsSupplier, uno::UNO_QUERY );
+
+ 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());
+ if( xSeq.is() && !( xChartDoc.is() && xChartDoc->hasInternalDataProvider()) )
+ nNumberFormatKey = xSeq->getNumberFormatKeyByIndex( -1 );
+ else
+ nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier );
+ bFormatSet = true;
+ }
+ }
+ else if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() && nDimensionIndex == 0 ) //maybe date axis
+ {
+ Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram() );
+ if( DiagramHelper::isSupportingDateAxis( xDiagram ) )
+ {
+ nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier );
+ }
+ else
+ {
+ Reference< data::XDataSource > xSource( DataSourceHelper::getUsedData( xChartDoc ) );
+ if( xSource.is() )
+ {
+ ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aXValues(
+ DataSeriesHelper::getAllDataSequencesByRole( xSource->getDataSequences(), C2U("values-x"), true ) );
+ if( aXValues.empty() )
+ {
+ Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
+ if( xCategories.is() )
+ {
+ Reference< data::XDataSequence > xSeq( xCategories->getValues());
+ if( xSeq.is() )
+ {
+ bool bHasValidDoubles = false;
+ double fTest=0.0;
+ Sequence< uno::Any > aCats( xSeq->getData() );
+ sal_Int32 nCount = aCats.getLength();
+ for( sal_Int32 i = 0; i < nCount; ++i )
+ {
+ if( (aCats[i]>>=fTest) && !::rtl::math::isNan(fTest) )
+ {
+ bHasValidDoubles=true;
+ break;
+ }
+ }
+ if( bHasValidDoubles )
+ nNumberFormatKey = DiagramHelper::getDateNumberFormat( xNumberFormatsSupplier );
+ }
+ }
+ }
+ }
+ }
+ bFormatSet = true;
+ }
+ }
+
+ if( !bFormatSet )
+ {
+ typedef ::std::map< sal_Int32, sal_Int32 > tNumberformatFrequency;
+ tNumberformatFrequency aKeyMap;
+
+ try
+ {
+ Reference< XChartTypeContainer > xCTCnt( xCorrespondingCoordinateSystem, uno::UNO_QUERY_THROW );
+ if( xCTCnt.is() )
+ {
+ ::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;
+}
+
Reference< XAxis > AxisHelper::createAxis(
sal_Int32 nDimensionIndex
, sal_Int32 nAxisIndex // 0==main or 1==secondary axis
@@ -131,6 +362,7 @@ Reference< XAxis > AxisHelper::createAxis(
ScaleData aMainScale = xMainAxis->getScaleData();
aScale.AxisType = aMainScale.AxisType;
+ aScale.AutoDateAxis = aMainScale.AutoDateAxis;
aScale.Categories = aMainScale.Categories;
aScale.Orientation = aMainScale.Orientation;
diff --git a/chart2/source/tools/ChartTypeHelper.cxx b/chart2/source/tools/ChartTypeHelper.cxx
index debb241e9604..83ab4a26315b 100755
--- a/chart2/source/tools/ChartTypeHelper.cxx
+++ b/chart2/source/tools/ChartTypeHelper.cxx
@@ -415,13 +415,34 @@ bool ChartTypeHelper::isSupportingAxisPositioning( const uno::Reference< chart2:
return true;
}
-bool ChartTypeHelper::shiftTicksAtXAxisPerDefault( const uno::Reference< chart2::XChartType >& xChartType )
+bool ChartTypeHelper::isSupportingDateAxis( const uno::Reference< chart2::XChartType >& xChartType, sal_Int32 /*nDimensionCount*/, sal_Int32 nDimensionIndex )
+{
+ if( nDimensionIndex!=0 )
+ return false;
+ if( xChartType.is() )
+ {
+ sal_Int32 nType = ChartTypeHelper::getAxisType( xChartType, nDimensionIndex );
+ if( nType != AxisType::CATEGORY )
+ return false;
+ rtl::OUString aChartTypeName = xChartType->getChartType();
+ if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
+ return false;
+ if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
+ return false;
+ if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
+ return false;
+ }
+ return true;
+}
+
+bool ChartTypeHelper::shiftCategoryPosAtXAxisPerDefault( const uno::Reference< chart2::XChartType >& xChartType )
{
if(xChartType.is())
{
rtl::OUString aChartTypeName = xChartType->getChartType();
if( aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN)
- || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR) )
+ || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_BAR)
+ || aChartTypeName.match(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
return true;
}
return false;
diff --git a/chart2/source/tools/DataSourceHelper.cxx b/chart2/source/tools/DataSourceHelper.cxx
index 0cc6ef4a4315..21fc16156397 100644..100755
--- a/chart2/source/tools/DataSourceHelper.cxx
+++ b/chart2/source/tools/DataSourceHelper.cxx
@@ -461,25 +461,8 @@ void DataSourceHelper::setRangeSegmentation(
if( !xDataSource.is() )
return;
- DiagramHelper::tTemplateWithServiceName aTemplateAndService =
- DiagramHelper::getTemplateForDiagram( xDiagram, xTemplateFactory );
-
- rtl::OUString aServiceName( aTemplateAndService.second );
- uno::Reference< chart2::XChartTypeTemplate > xTemplate = aTemplateAndService.first;
-
- if( !xTemplate.is() )
- {
- if( aServiceName.getLength() == 0 )
- aServiceName = C2U("com.sun.star.chart2.template.Column");
- xTemplate.set( xTemplateFactory->createInstance( aServiceName ), uno::UNO_QUERY );
- }
- if( !xTemplate.is() )
- return;
-
- // /-- locked controllers
ControllerLockGuard aCtrlLockGuard( xChartModel );
- xTemplate->changeDiagramData( xDiagram, xDataSource, aArguments );
- // \-- locked controllers
+ xDiagram->setDiagramData( xDataSource, aArguments );
}
Sequence< OUString > DataSourceHelper::getRangesFromLabeledDataSequence(
diff --git a/chart2/source/tools/DiagramHelper.cxx b/chart2/source/tools/DiagramHelper.cxx
index b3ae733c4067..d442797d8ce1 100755
--- a/chart2/source/tools/DiagramHelper.cxx
+++ b/chart2/source/tools/DiagramHelper.cxx
@@ -42,10 +42,12 @@
#include "ChartModelHelper.hxx"
#include "RelativePositionHelper.hxx"
#include "ControllerLockGuard.hxx"
+#include "NumberFormatterWrapper.hxx"
#include <com/sun/star/chart/MissingValueTreatment.hpp>
#include <com/sun/star/chart/XChartDocument.hpp>
#include <com/sun/star/chart/XDiagramPositioning.hpp>
+#include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
#include <com/sun/star/chart2/XTitled.hpp>
#include <com/sun/star/chart2/XChartTypeContainer.hpp>
#include <com/sun/star/chart2/XChartTypeTemplate.hpp>
@@ -57,10 +59,15 @@
#include <com/sun/star/chart2/RelativePosition.hpp>
#include <com/sun/star/chart2/RelativeSize.hpp>
+#include <com/sun/star/util/NumberFormat.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
+#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
+
#include <unotools/saveopt.hxx>
#include <rtl/math.hxx>
-
-#include <com/sun/star/util/XModifiable.hpp>
+#include <svl/zformat.hxx>
+// header for class Application
+#include <vcl/svapp.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::chart2;
@@ -68,7 +75,9 @@ using namespace ::std;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::uno::Any;
using ::rtl::OUString;
+using ::com::sun::star::chart2::XAnyDescriptionAccess;
namespace chart
{
@@ -864,7 +873,7 @@ bool DiagramHelper::isCategoryDiagram(
if( xAxis.is())
{
ScaleData aScaleData = xAxis->getScaleData();
- if( aScaleData.AxisType == AxisType::CATEGORY )
+ if( aScaleData.AxisType == AxisType::CATEGORY || aScaleData.AxisType == AxisType::DATE )
return true;
}
}
@@ -902,7 +911,7 @@ void DiagramHelper::setCategoriesToDiagram(
{
if( bCategoryAxis )
aScaleData.AxisType = AxisType::CATEGORY;
- else if( aScaleData.AxisType == AxisType::CATEGORY )
+ else if( aScaleData.AxisType == AxisType::CATEGORY || aScaleData.AxisType == AxisType::DATE )
aScaleData.AxisType = AxisType::REALNUMBER;
}
xCatAxis->setScaleData( aScaleData );
@@ -1018,6 +1027,203 @@ Sequence< rtl::OUString > DiagramHelper::getExplicitSimpleCategories(
return aRet;
}
+namespace
+{
+void lcl_switchToDateCategories( const Reference< XChartDocument >& xChartDoc, const Reference< XAxis >& xAxis )
+{
+ if( !xAxis.is() )
+ return;
+ if( !xChartDoc.is() )
+ return;
+
+ ScaleData aScale( xAxis->getScaleData() );
+ if( xChartDoc->hasInternalDataProvider() )
+ {
+ //remove all content the is not of type double and remove multiple level
+ Reference< XAnyDescriptionAccess > xDataAccess( xChartDoc->getDataProvider(), uno::UNO_QUERY );
+ if( xDataAccess.is() )
+ {
+ Sequence< Sequence< Any > > aAnyCategories( xDataAccess->getAnyRowDescriptions() );
+ double fTest = 0.0;
+ double fNan = 0.0;
+ ::rtl::math::setNan( & fNan );
+ sal_Int32 nN = aAnyCategories.getLength();
+ for( ; nN--; )
+ {
+ Sequence< Any >& rCat = aAnyCategories[nN];
+ if( rCat.getLength() > 1 )
+ rCat.realloc(1);
+ if( rCat.getLength() == 1 )
+ {
+ Any& rAny = rCat[0];
+ if( !(rAny>>=fTest) )
+ {
+ rAny = uno::makeAny(fNan);
+ }
+ }
+ }
+ xDataAccess->setAnyRowDescriptions( aAnyCategories );
+ }
+ //check the numberformat at the axis
+ Reference< beans::XPropertySet > xAxisProps( xAxis, uno::UNO_QUERY );
+ Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartDoc, uno::UNO_QUERY );
+ if( xAxisProps.is() && xNumberFormatsSupplier.is() )
+ {
+ sal_Int32 nNumberFormat = -1;
+ xAxisProps->getPropertyValue( C2U("NumberFormat") ) >>= nNumberFormat;
+
+ Reference< util::XNumberFormats > xNumberFormats = Reference< util::XNumberFormats >( xNumberFormatsSupplier->getNumberFormats() );
+ if( xNumberFormats.is() )
+ {
+ Reference< beans::XPropertySet > xKeyProps;
+ try
+ {
+ xKeyProps = xNumberFormats->getByKey( nNumberFormat );
+ }
+ catch( uno::Exception & ex )
+ {
+ ASSERT_EXCEPTION( ex );
+ }
+ sal_Int32 nType = util::NumberFormat::UNDEFINED;
+ if( xKeyProps.is() )
+ xKeyProps->getPropertyValue( C2U("Type") ) >>= nType;
+ if( !( nType & util::NumberFormat::DATE ) )
+ {
+ //set a date format to the axis
+ 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() )
+ {
+ xAxisProps->setPropertyValue( C2U("NumberFormat"), uno::makeAny(aKeySeq[0]) );
+ }
+ }
+ }
+ }
+ }
+ if( aScale.AxisType != chart2::AxisType::DATE )
+ AxisHelper::removeExplicitScaling( aScale );
+ aScale.AxisType = chart2::AxisType::DATE;
+ xAxis->setScaleData( aScale );
+}
+
+void lcl_switchToTextCategories( const Reference< XChartDocument >& xChartDoc, const Reference< XAxis >& xAxis )
+{
+ if( !xAxis.is() )
+ return;
+ if( !xChartDoc.is() )
+ return;
+ ScaleData aScale( xAxis->getScaleData() );
+ if( aScale.AxisType != chart2::AxisType::CATEGORY )
+ AxisHelper::removeExplicitScaling( aScale );
+ //todo migrate dates to text?
+ aScale.AxisType = chart2::AxisType::CATEGORY;
+ aScale.AutoDateAxis = false;
+ xAxis->setScaleData( aScale );
+}
+
+}
+
+void DiagramHelper::switchToDateCategories( const Reference< XChartDocument >& xChartDoc )
+{
+ Reference< frame::XModel > xChartModel( xChartDoc, uno::UNO_QUERY );
+ if(xChartModel.is())
+ {
+ ControllerLockGuard aCtrlLockGuard( xChartModel );
+
+ Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartModel ) );
+ if( xCooSys.is() )
+ {
+ Reference< XAxis > xAxis( xCooSys->getAxisByDimension(0,0) );
+ lcl_switchToDateCategories( xChartDoc, xAxis );
+ }
+ }
+}
+
+void DiagramHelper::switchToTextCategories( const Reference< XChartDocument >& xChartDoc )
+{
+ Reference< frame::XModel > xChartModel( xChartDoc, uno::UNO_QUERY );
+ if(xChartModel.is())
+ {
+ ControllerLockGuard aCtrlLockGuard( xChartModel );
+
+ Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartModel ) );
+ if( xCooSys.is() )
+ {
+ Reference< XAxis > xAxis( xCooSys->getAxisByDimension(0,0) );
+ lcl_switchToTextCategories( xChartDoc, xAxis );
+ }
+ }
+}
+
+bool DiagramHelper::isSupportingDateAxis( const Reference< chart2::XDiagram >& xDiagram )
+{
+ 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() )
+ {
+ sal_Int32 nType = util::NumberFormat::UNDEFINED;
+ xKeyProps->getPropertyValue( C2U("Type") ) >>= nType;
+ bIsDate = nType & util::NumberFormat::DATE;
+ }
+ return bIsDate;
+}
+
+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() )
+ {
+ nRet = aKeySeq[0];
+ }
+ }
+
+ //try to get a date format with full year display
+ NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
+ SvNumberFormatter* pNumFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
+ if( pNumFormatter )
+ {
+ const SvNumberformat* pFormat = pNumFormatter->GetEntry( nRet );
+ if( pFormat )
+ nRet = pNumFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYYYY, pFormat->GetLanguage() );
+ }
+ 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;
+}
+
Sequence< Reference< XChartType > >
DiagramHelper::getChartTypesFromDiagram(
const Reference< XDiagram > & xDiagram )
diff --git a/chart2/source/tools/ExplicitCategoriesProvider.cxx b/chart2/source/tools/ExplicitCategoriesProvider.cxx
index a59610b1fc3a..a0376aa95d46 100755
--- a/chart2/source/tools/ExplicitCategoriesProvider.cxx
+++ b/chart2/source/tools/ExplicitCategoriesProvider.cxx
@@ -30,11 +30,18 @@
#include "ExplicitCategoriesProvider.hxx"
#include "DiagramHelper.hxx"
+#include "ChartTypeHelper.hxx"
+#include "AxisHelper.hxx"
#include "CommonConverters.hxx"
#include "DataSourceHelper.hxx"
#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>
+#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
//.............................................................................
namespace chart
@@ -53,7 +60,11 @@ ExplicitCategoriesProvider::ExplicitCategoriesProvider( const Reference< chart2:
, const uno::Reference< frame::XModel >& xChartModel )
: m_bDirty(true)
, m_xCooSysModel( xCooSysModel )
+ , m_xChartModel( xChartModel )
, m_xOriginalCategories()
+ , m_bIsExplicitCategoriesInited(false)
+ , m_bIsDateAxis(false)
+ , m_bIsAutoDate(false)
{
try
{
@@ -61,7 +72,12 @@ ExplicitCategoriesProvider::ExplicitCategoriesProvider( const Reference< chart2:
{
uno::Reference< XAxis > xAxis( xCooSysModel->getAxisByDimension(0,0) );
if( xAxis.is() )
- m_xOriginalCategories = xAxis->getScaleData().Categories;
+ {
+ ScaleData aScale( xAxis->getScaleData() );
+ m_xOriginalCategories = aScale.Categories;
+ m_bIsAutoDate = (aScale.AutoDateAxis && aScale.AxisType==chart2::AxisType::CATEGORY);
+ m_bIsDateAxis = (aScale.AxisType == chart2::AxisType::DATE || m_bIsAutoDate);
+ }
}
if( m_xOriginalCategories.is() )
@@ -134,6 +150,13 @@ ExplicitCategoriesProvider::~ExplicitCategoriesProvider()
{
}
+Reference< chart2::data::XDataSequence > ExplicitCategoriesProvider::getOriginalCategories()
+{
+ if( m_xOriginalCategories.is() )
+ return m_xOriginalCategories->getValues();
+ return 0;
+}
+
const Sequence< Reference< data::XLabeledDataSequence> >& ExplicitCategoriesProvider::getSplitCategoriesList()
{
return m_aSplitCategoriesList;
@@ -167,30 +190,51 @@ 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 );
- 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 = 0;
+ 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()
@@ -201,9 +245,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()
{}
@@ -214,6 +262,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
@@ -225,7 +275,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;
}
@@ -362,23 +416,120 @@ Sequence< OUString > ExplicitCategoriesProvider::getExplicitSimpleCategories(
return lcl_getExplicitSimpleCategories( rSplitCategoriesProvider, aComplexCats );
}
+struct DatePlusIndexComparator
+{
+ inline bool operator() ( const DatePlusIndex& aFirst,
+ const DatePlusIndex& aSecond )
+ {
+ return ( aFirst.fValue < aSecond.fValue );
+ }
+};
+
+bool lcl_fillDateCategories( const uno::Reference< data::XDataSequence >& xDataSequence, std::vector< DatePlusIndex >& rDateCategories, bool bIsAutoDate, Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier )
+{
+ bool bOnlyDatesFound = true;
+ bool bAnyDataFound = false;
+
+ if( xDataSequence.is() )
+ {
+ uno::Sequence< uno::Any > aValues = xDataSequence->getData();
+ sal_Int32 nCount = aValues.getLength();
+ rDateCategories.reserve(nCount);
+ Reference< util::XNumberFormats > xNumberFormats;
+ if( xNumberFormatsSupplier.is() )
+ xNumberFormats = Reference< util::XNumberFormats >( xNumberFormatsSupplier->getNumberFormats() );
+
+ bool bOwnData = false;
+ 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() )
+ {
+ if( xChartDoc->hasInternalDataProvider() )
+ {
+ 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) )
+ {
+ bOwnDataAnddAxisHasAnyFormat = true;
+ bOwnDataAnddAxisHasDateFormat = DiagramHelper::isDateNumberFormat( nAxisNumberFormat, xNumberFormats );
+ }
+ }
+ }
+
+ for(sal_Int32 nN=0;nN<nCount;nN++)
+ {
+ bool bIsDate = false;
+ if( bIsAutoDate )
+ {
+ if( bOwnData )
+ bIsDate = bOwnDataAnddAxisHasAnyFormat ? bOwnDataAnddAxisHasDateFormat : true;
+ else
+ bIsDate = DiagramHelper::isDateNumberFormat( xDataSequence->getNumberFormatKeyByIndex( nN ), xNumberFormats );
+ }
+ else
+ bIsDate = true;
+
+ bool bContainsEmptyString = false;
+ bool bContainsNan = false;
+ uno::Any aAny = aValues[nN];
+ if( aAny.hasValue() )
+ {
+ OUString aTest;
+ double fTest = 0;
+ if( (aAny>>=aTest) && !aTest.getLength() ) //empty String
+ bContainsEmptyString = true;
+ else if( (aAny>>=fTest) && ::rtl::math::isNan(fTest) )
+ bContainsNan = true;
+
+ if( !bContainsEmptyString && !bContainsNan )
+ bAnyDataFound = true;
+ }
+ DatePlusIndex aDatePlusIndex( 1.0, nN );
+ if( bIsDate && (aAny >>= aDatePlusIndex.fValue) )
+ rDateCategories.push_back( aDatePlusIndex );
+ else
+ {
+ if( aAny.hasValue() && !bContainsEmptyString )//empty string does not count as non date value!
+ bOnlyDatesFound=false;
+ ::rtl::math::setNan( &aDatePlusIndex.fValue );
+ rDateCategories.push_back( aDatePlusIndex );
+ }
+ }
+ ::std::sort( rDateCategories.begin(), rDateCategories.end(), DatePlusIndexComparator() );
+ }
+
+ return bAnyDataFound && bOnlyDatesFound;
+}
+
void ExplicitCategoriesProvider::init()
{
if( m_bDirty )
{
- m_aExplicitCategories.realloc(0);
m_aComplexCats.clear();//not one per index
+ m_aDateCategories.clear();
if( m_xOriginalCategories.is() )
{
if( !hasComplexCategories() )
- m_aExplicitCategories = DataSequenceToStringSequence(m_xOriginalCategories->getValues());
+ {
+ if(m_bIsDateAxis)
+ {
+ if( ChartTypeHelper::isSupportingDateAxis( AxisHelper::getChartTypeByIndex( m_xCooSysModel, 0 ), 2, 0 ) )
+ m_bIsDateAxis = lcl_fillDateCategories( m_xOriginalCategories->getValues(), m_aDateCategories, m_bIsAutoDate, Reference< util::XNumberFormatsSupplier >( m_xChartModel.get(), uno::UNO_QUERY ) );
+ else
+ m_bIsDateAxis = false;
+ }
+ }
else
- m_aExplicitCategories = lcl_getExplicitSimpleCategories(
- SplitCategoriesProvider_ForLabeledDataSequences( m_aSplitCategoriesList ), m_aComplexCats );
+ {
+ m_bIsDateAxis = false;
+ }
}
- if(!m_aExplicitCategories.getLength())
- m_aExplicitCategories = DiagramHelper::generateAutomaticCategoriesFromCooSys( m_xCooSysModel );
+ else
+ m_bIsDateAxis=false;
m_bDirty = false;
}
}
@@ -386,7 +537,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;
}
@@ -415,6 +587,18 @@ OUString ExplicitCategoriesProvider::getCategoryByIndex(
return OUString();
}
+bool ExplicitCategoriesProvider::isDateAxis()
+{
+ init();
+ return m_bIsDateAxis;
+}
+
+const std::vector< DatePlusIndex >& ExplicitCategoriesProvider::getDateCategories()
+{
+ init();
+ return m_aDateCategories;
+}
+
//.............................................................................
} //namespace chart
//.............................................................................
diff --git a/chart2/source/tools/InternalData.cxx b/chart2/source/tools/InternalData.cxx
index 65fc97a04b38..e9b0cf689768 100755
--- a/chart2/source/tools/InternalData.cxx
+++ b/chart2/source/tools/InternalData.cxx
@@ -38,6 +38,7 @@
using ::com::sun::star::uno::Sequence;
using ::rtl::OUString;
+using namespace ::com::sun::star;
using namespace ::std;
namespace chart
@@ -55,10 +56,10 @@ struct lcl_NumberedStringGenerator
m_nWildcardLength( rWildcard.getLength())
{
}
- vector< OUString > operator()()
+ vector< uno::Any > operator()()
{
- vector< OUString > aRet(1);
- aRet[0] = m_aStub.replaceAt( m_nStubStartIndex, m_nWildcardLength, OUString::valueOf( ++m_nCounter ));
+ vector< uno::Any > aRet(1);
+ aRet[0] = uno::makeAny( m_aStub.replaceAt( m_nStubStartIndex, m_nWildcardLength, OUString::valueOf( ++m_nCounter )) );
return aRet;
}
private:
@@ -113,12 +114,12 @@ void InternalData::createDefaultData()
m_aRowLabels.clear();
m_aRowLabels.reserve( m_nRowCount );
generate_n( back_inserter( m_aRowLabels ), m_nRowCount,
- lcl_NumberedStringGenerator( aRowName, C2U("%ROWNUMBER") ));
+ lcl_NumberedStringGenerator( aRowName, C2U("%ROWNUMBER") ));
m_aColumnLabels.clear();
m_aColumnLabels.reserve( m_nColumnCount );
generate_n( back_inserter( m_aColumnLabels ), m_nColumnCount,
- lcl_NumberedStringGenerator( aColName, C2U("%COLUMNNUMBER") ));
+ lcl_NumberedStringGenerator( aColName, C2U("%COLUMNNUMBER") ));
}
void InternalData::setData( const Sequence< Sequence< double > >& rDataInRows )
@@ -199,7 +200,7 @@ void InternalData::setRowValues( sal_Int32 nRowIndex, const vector< double > & r
m_aData[ ::std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ]= aSlice;
}
-void InternalData::setComplexColumnLabel( sal_Int32 nColumnIndex, const vector< OUString >& rComplexLabel )
+void InternalData::setComplexColumnLabel( sal_Int32 nColumnIndex, const vector< uno::Any >& rComplexLabel )
{
if( nColumnIndex < 0 )
return;
@@ -208,10 +209,10 @@ void InternalData::setComplexColumnLabel( sal_Int32 nColumnIndex, const vector<
m_aColumnLabels.resize(nColumnIndex+1);
enlargeData( nColumnIndex+1, 0 );
}
-
m_aColumnLabels[nColumnIndex]=rComplexLabel;
}
-void InternalData::setComplexRowLabel( sal_Int32 nRowIndex, const vector< OUString >& rComplexLabel )
+
+void InternalData::setComplexRowLabel( sal_Int32 nRowIndex, const vector< uno::Any >& rComplexLabel )
{
if( nRowIndex < 0 )
return;
@@ -220,23 +221,22 @@ void InternalData::setComplexRowLabel( sal_Int32 nRowIndex, const vector< OUStri
m_aRowLabels.resize(nRowIndex+1);
enlargeData( 0, nRowIndex+1 );
}
-
m_aRowLabels[nRowIndex] = rComplexLabel;
}
-vector< OUString > InternalData::getComplexColumnLabel( sal_Int32 nColumnIndex ) const
+vector< uno::Any > InternalData::getComplexColumnLabel( sal_Int32 nColumnIndex ) const
{
if( nColumnIndex < static_cast< sal_Int32 >( m_aColumnLabels.size() ) )
return m_aColumnLabels[nColumnIndex];
else
- return vector< OUString >();
+ return vector< uno::Any >();
}
-vector< OUString > InternalData::getComplexRowLabel( sal_Int32 nRowIndex ) const
+vector< uno::Any > InternalData::getComplexRowLabel( sal_Int32 nRowIndex ) const
{
if( nRowIndex < static_cast< sal_Int32 >( m_aRowLabels.size() ) )
return m_aRowLabels[nRowIndex];
else
- return vector< OUString >();
+ return vector< uno::Any >();
}
void InternalData::swapRowWithNext( sal_Int32 nRowIndex )
@@ -253,7 +253,7 @@ void InternalData::swapRowWithNext( sal_Int32 nRowIndex )
m_aData[nIndex2] = fTemp;
}
- vector< OUString > aTemp( m_aRowLabels[nRowIndex] );
+ vector< uno::Any > aTemp( m_aRowLabels[nRowIndex] );
m_aRowLabels[nRowIndex] = m_aRowLabels[nRowIndex + 1];
m_aRowLabels[nRowIndex + 1] = aTemp;
}
@@ -273,7 +273,7 @@ void InternalData::swapColumnWithNext( sal_Int32 nColumnIndex )
m_aData[nIndex2] = fTemp;
}
- vector< OUString > aTemp( m_aColumnLabels[nColumnIndex] );
+ vector< uno::Any > aTemp( m_aColumnLabels[nColumnIndex] );
m_aColumnLabels[nColumnIndex] = m_aColumnLabels[nColumnIndex + 1];
m_aColumnLabels[nColumnIndex + 1] = aTemp;
}
@@ -336,7 +336,7 @@ void InternalData::insertColumn( sal_Int32 nAfterIndex )
// labels
if( nAfterIndex < static_cast< sal_Int32 >( m_aColumnLabels.size()))
- m_aColumnLabels.insert( m_aColumnLabels.begin() + (nAfterIndex + 1), vector< OUString >(1) );
+ m_aColumnLabels.insert( m_aColumnLabels.begin() + (nAfterIndex + 1), vector< uno::Any >(1) );
#if OSL_DEBUG_LEVEL > 2
traceData();
@@ -388,7 +388,7 @@ void InternalData::insertRow( sal_Int32 nAfterIndex )
// labels
if( nAfterIndex < static_cast< sal_Int32 >( m_aRowLabels.size()))
- m_aRowLabels.insert( m_aRowLabels.begin() + nIndex, vector< OUString> (1));
+ m_aRowLabels.insert( m_aRowLabels.begin() + nIndex, vector< uno::Any > (1));
#if OSL_DEBUG_LEVEL > 2
traceData();
@@ -481,7 +481,7 @@ sal_Int32 InternalData::getColumnCount() const
return m_nColumnCount;
}
-void InternalData::setComplexRowLabels( const vector< vector< OUString > >& rNewRowLabels )
+void InternalData::setComplexRowLabels( const vector< vector< uno::Any > >& rNewRowLabels )
{
m_aRowLabels = rNewRowLabels;
sal_Int32 nNewRowCount = static_cast< sal_Int32 >( m_aRowLabels.size() );
@@ -491,12 +491,12 @@ void InternalData::setComplexRowLabels( const vector< vector< OUString > >& rNew
enlargeData( 0, nNewRowCount );
}
-vector< vector< OUString > > InternalData::getComplexRowLabels() const
+vector< vector< uno::Any > > InternalData::getComplexRowLabels() const
{
return m_aRowLabels;
}
-void InternalData::setComplexColumnLabels( const vector< vector< OUString > >& rNewColumnLabels )
+void InternalData::setComplexColumnLabels( const vector< vector< uno::Any > >& rNewColumnLabels )
{
m_aColumnLabels = rNewColumnLabels;
sal_Int32 nNewColumnCount = static_cast< sal_Int32 >( m_aColumnLabels.size() );
@@ -506,7 +506,7 @@ void InternalData::setComplexColumnLabels( const vector< vector< OUString > >& r
enlargeData( nNewColumnCount, 0 );
}
-vector< vector< OUString > > InternalData::getComplexColumnLabels() const
+vector< vector< uno::Any > > InternalData::getComplexColumnLabels() const
{
return m_aColumnLabels;
}
diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx
index 26b2db4fc253..2d51bd0f7acd 100755
--- a/chart2/source/tools/InternalDataProvider.cxx
+++ b/chart2/source/tools/InternalDataProvider.cxx
@@ -93,6 +93,24 @@ static const ::rtl::OUString lcl_aCompleteRange(
typedef ::std::multimap< OUString, uno::WeakReference< chart2::data::XDataSequence > >
lcl_tSequenceMap;
+Sequence< OUString > lcl_AnyToStringSequence( const Sequence< uno::Any >& aAnySeq )
+{
+ Sequence< OUString > aResult;
+ aResult.realloc( aAnySeq.getLength() );
+ transform( aAnySeq.getConstArray(), aAnySeq.getConstArray() + aAnySeq.getLength(),
+ aResult.getArray(), CommonFunctors::AnyToString() );
+ return aResult;
+}
+
+Sequence< uno::Any > lcl_StringToAnySequence( const Sequence< OUString >& aStringSeq )
+{
+ Sequence< uno::Any > aResult;
+ aResult.realloc( aStringSeq.getLength() );
+ transform( aStringSeq.getConstArray(), aStringSeq.getConstArray() + aStringSeq.getLength(),
+ aResult.getArray(), CommonFunctors::makeAny< OUString >() );
+ return aResult;
+}
+
struct lcl_setModified : public ::std::unary_function< lcl_tSequenceMap, void >
{
void operator() ( const lcl_tSequenceMap::value_type & rMapEntry )
@@ -154,9 +172,9 @@ struct lcl_internalizeSeries : public ::std::unary_function< Reference< chart2::
if( xLabel.is() )
{
if( m_bDataInColumns )
- m_rInternalData.setComplexColumnLabel( nNewIndex, ContainerHelper::SequenceToVector( xLabel->getTextualData() ) );
+ m_rInternalData.setComplexColumnLabel( nNewIndex, ContainerHelper::SequenceToVector( lcl_StringToAnySequence( xLabel->getTextualData() ) ) );
else
- m_rInternalData.setComplexRowLabel( nNewIndex, ContainerHelper::SequenceToVector( xLabel->getTextualData() ) );
+ m_rInternalData.setComplexRowLabel( nNewIndex, ContainerHelper::SequenceToVector( lcl_StringToAnySequence( xLabel->getTextualData() ) ) );
if( m_bConnectToModel )
{
Reference< chart2::data::XDataSequence > xNewLabel(
@@ -187,37 +205,37 @@ private:
bool m_bDataInColumns;
};
-struct lcl_makeAnyFromLevelVector : public ::std::unary_function< vector< OUString >, uno::Any >
+struct lcl_copyFromLevel : public ::std::unary_function< vector< uno::Any >, uno::Any >
{
public:
- explicit lcl_makeAnyFromLevelVector( sal_Int32 nLevel ) : m_nLevel( nLevel )
+ explicit lcl_copyFromLevel( sal_Int32 nLevel ) : m_nLevel( nLevel )
{}
- uno::Any operator() ( const vector< OUString >& rVector )
+ uno::Any operator() ( const vector< uno::Any >& rVector )
{
- OUString aString;
+ uno::Any aRet;
if( m_nLevel < static_cast< sal_Int32 >(rVector.size()) )
- aString = rVector[m_nLevel];
- return uno::makeAny( aString );
+ aRet = rVector[m_nLevel];
+ return aRet;
}
private:
sal_Int32 m_nLevel;
};
-struct lcl_getStringFromLevelVector : public ::std::unary_function< vector< OUString >, OUString >
+struct lcl_getStringFromLevelVector : public ::std::unary_function< vector< uno::Any >, OUString >
{
public:
explicit lcl_getStringFromLevelVector( sal_Int32 nLevel ) : m_nLevel( nLevel )
{}
- OUString operator() ( const vector< OUString >& rVector )
+ OUString operator() ( const vector< uno::Any >& rVector )
{
OUString aString;
if( m_nLevel < static_cast< sal_Int32 >(rVector.size()) )
- aString = rVector[m_nLevel];
+ aString = CommonFunctors::AnyToString()(rVector[m_nLevel]);
return aString;
}
@@ -226,19 +244,19 @@ private:
};
-struct lcl_setStringAtLevel : public ::std::binary_function< vector< OUString >, OUString, vector< OUString > >
+struct lcl_setAnyAtLevel : public ::std::binary_function< vector< uno::Any >, uno::Any, vector< uno::Any > >
{
public:
- explicit lcl_setStringAtLevel( sal_Int32 nLevel ) : m_nLevel( nLevel )
+ explicit lcl_setAnyAtLevel( sal_Int32 nLevel ) : m_nLevel( nLevel )
{}
- vector< OUString > operator() ( const vector< OUString >& rVector, const OUString& rNewText )
+ vector< uno::Any > operator() ( const vector< uno::Any >& rVector, const uno::Any& rNewValue )
{
- vector< OUString > aRet( rVector );
+ vector< uno::Any > aRet( rVector );
if( m_nLevel >= static_cast< sal_Int32 >(aRet.size()) )
aRet.resize( m_nLevel+1 );
- aRet[ m_nLevel ]=rNewText;
+ aRet[ m_nLevel ]=rNewValue;
return aRet;
}
@@ -246,41 +264,61 @@ private:
sal_Int32 m_nLevel;
};
-struct lcl_insertStringAtLevel : public ::std::unary_function< vector< OUString >, void >
+struct lcl_setAnyAtLevelFromStringSequence : public ::std::binary_function< vector< uno::Any >, OUString, vector< uno::Any > >
{
public:
- explicit lcl_insertStringAtLevel( sal_Int32 nLevel ) : m_nLevel( nLevel )
+ explicit lcl_setAnyAtLevelFromStringSequence( sal_Int32 nLevel ) : m_nLevel( nLevel )
{}
- void operator() ( vector< OUString >& rVector )
+ vector< uno::Any > operator() ( const vector< uno::Any >& rVector, const OUString& rNewValue )
+ {
+ vector< uno::Any > aRet( rVector );
+ if( m_nLevel >= static_cast< sal_Int32 >(aRet.size()) )
+ aRet.resize( m_nLevel+1 );
+ aRet[ m_nLevel ]=uno::makeAny(rNewValue);
+ return aRet;
+ }
+
+private:
+ sal_Int32 m_nLevel;
+};
+
+struct lcl_insertAnyAtLevel : public ::std::unary_function< vector< uno::Any >, void >
+{
+public:
+
+ explicit lcl_insertAnyAtLevel( sal_Int32 nLevel ) : m_nLevel( nLevel )
+ {}
+
+ void operator() ( vector< uno::Any >& rVector )
{
if( m_nLevel > static_cast< sal_Int32 >(rVector.size()) )
rVector.resize( m_nLevel );
- vector< OUString >::iterator aIt( rVector.begin() );
+ vector< uno::Any >::iterator aIt( rVector.begin() );
for( sal_Int32 nN=0; aIt<rVector.end(); aIt++, nN++)
{
if( nN==m_nLevel )
break;
}
- rVector.insert( aIt, OUString() );
+ rVector.insert( aIt, uno::Any() );
}
private:
sal_Int32 m_nLevel;
};
-struct lcl_removeStringAtLevel : public ::std::unary_function< vector< OUString >, void >
+struct lcl_removeAnyAtLevel : public ::std::unary_function< vector< uno::Any >, void >
{
public:
- explicit lcl_removeStringAtLevel( sal_Int32 nLevel ) : m_nLevel( nLevel )
+ explicit lcl_removeAnyAtLevel( sal_Int32 nLevel ) : m_nLevel( nLevel )
{}
- void operator() ( vector< OUString >& rVector )
+ void operator() ( vector< uno::Any >& rVector )
{
- vector< OUString >::iterator aIt( rVector.begin() );
+ vector< uno::Any >::iterator aIt( rVector.begin() );
for( sal_Int32 nN=0; aIt<rVector.end(); aIt++, nN++)
{
if( nN==m_nLevel )
@@ -295,23 +333,6 @@ private:
sal_Int32 m_nLevel;
};
-vector< OUString > lcl_AnyToStringVector( const Sequence< uno::Any >& aAnySeq )
-{
- vector< OUString > aStringVec;
- transform( aAnySeq.getConstArray(), aAnySeq.getConstArray() + aAnySeq.getLength(),
- back_inserter( aStringVec ), CommonFunctors::AnyToString() );
- return aStringVec;
-}
-
-Sequence< OUString > lcl_AnyToStringSequence( const Sequence< uno::Any >& aAnySeq )
-{
- Sequence< OUString > aResult;
- aResult.realloc( aAnySeq.getLength() );
- transform( aAnySeq.getConstArray(), aAnySeq.getConstArray() + aAnySeq.getLength(),
- aResult.getArray(), CommonFunctors::AnyToString() );
- return aResult;
-}
-
} // anonymous namespace
// ================================================================================
@@ -341,9 +362,10 @@ InternalDataProvider::InternalDataProvider( const Reference< chart2::XChartDocum
// categories
{
- vector< vector< OUString > > aNewCategories;//inner count is level
+ vector< vector< uno::Any > > aNewCategories;//inner count is level
{
ExplicitCategoriesProvider aExplicitCategoriesProvider( ChartModelHelper::getFirstCoordinateSystem(xChartModel), xChartModel );
+
const Sequence< Reference< chart2::data::XLabeledDataSequence> >& rSplitCategoriesList( aExplicitCategoriesProvider.getSplitCategoriesList() );
sal_Int32 nLevelCount = rSplitCategoriesList.getLength();
for( sal_Int32 nL = 0; nL<nLevelCount; nL++ )
@@ -351,18 +373,18 @@ InternalDataProvider::InternalDataProvider( const Reference< chart2::XChartDocum
Reference< chart2::data::XLabeledDataSequence > xLDS( rSplitCategoriesList[nL] );
if( !xLDS.is() )
continue;
- Reference< chart2::data::XTextualDataSequence > xSeq( xLDS->getValues(), uno::UNO_QUERY );
- Sequence< OUString > aStringSeq;
+ Sequence< uno::Any > aDataSeq;
+ Reference< chart2::data::XDataSequence > xSeq( xLDS->getValues() );
if( xSeq.is() )
- aStringSeq = xSeq->getTextualData(); // @todo: be able to deal with XDataSequence, too
- sal_Int32 nLength = aStringSeq.getLength();
+ aDataSeq = xSeq->getData();
+ sal_Int32 nLength = aDataSeq.getLength();
sal_Int32 nCatLength = static_cast< sal_Int32 >(aNewCategories.size());
if( nCatLength < nLength )
aNewCategories.resize( nLength );
else if( nLength < nCatLength )
- aStringSeq.realloc( nCatLength );
- transform( aNewCategories.begin(), aNewCategories.end(), aStringSeq.getConstArray(),
- aNewCategories.begin(), lcl_setStringAtLevel(nL) );
+ aDataSeq.realloc( nCatLength );
+ transform( aNewCategories.begin(), aNewCategories.end(), aDataSeq.getConstArray(),
+ aNewCategories.begin(), lcl_setAnyAtLevel(nL) );
}
if( !nLevelCount )
{
@@ -371,9 +393,9 @@ InternalDataProvider::InternalDataProvider( const Reference< chart2::XChartDocum
aNewCategories.reserve( nLength );
for( sal_Int32 nN=0; nN<nLength; nN++)
{
- vector< OUString > aStringVector(1);
- aStringVector[0] = aSimplecategories[nN];
- aNewCategories.push_back( aStringVector );
+ vector< uno::Any > aVector(1);
+ aVector[0] = uno::makeAny( aSimplecategories[nN] );
+ aNewCategories.push_back( aVector );
}
}
}
@@ -520,14 +542,14 @@ void InternalDataProvider::createDefaultData()
namespace
{
-sal_Int32 lcl_getInnerLevelCount( const vector< vector< OUString > >& rLabels )
+sal_Int32 lcl_getInnerLevelCount( const vector< vector< uno::Any > >& rLabels )
{
sal_Int32 nCount = 1;//minimum is 1!
- vector< vector< OUString > >::const_iterator aLevelIt( rLabels.begin() );
- vector< vector< OUString > >::const_iterator aLevelEnd( rLabels.end() );
+ vector< vector< uno::Any > >::const_iterator aLevelIt( rLabels.begin() );
+ vector< vector< uno::Any > >::const_iterator aLevelEnd( rLabels.end() );
for( ;aLevelIt!=aLevelEnd; ++aLevelIt )
{
- const vector< ::rtl::OUString >& rCurrentLevelLabels = *aLevelIt;
+ const vector< uno::Any >& rCurrentLevelLabels = *aLevelIt;
nCount = std::max<sal_Int32>( rCurrentLevelLabels.size(), nCount );
}
return nCount;
@@ -551,7 +573,7 @@ Reference< chart2::data::XDataSource > SAL_CALL InternalDataProvider::createData
{
//return split complex categories if we have any:
::std::vector< Reference< chart2::data::XLabeledDataSequence > > aComplexCategories;
- vector< vector< OUString > > aCategories( m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels());
+ vector< vector< uno::Any > > aCategories( m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels());
if( bUseColumns==m_bDataInColumns )
{
sal_Int32 nLevelCount = lcl_getInnerLevelCount( aCategories );
@@ -733,46 +755,48 @@ Sequence< uno::Any > SAL_CALL InternalDataProvider::getDataByRangeRepresentation
if( aRange.match( lcl_aLabelRangePrefix ) )
{
sal_Int32 nIndex = aRange.copy( lcl_aLabelRangePrefix.getLength()).toInt32();
- vector< OUString > aComplexLabel = m_bDataInColumns
+ vector< uno::Any > aComplexLabel = m_bDataInColumns
? m_aInternalData.getComplexColumnLabel( nIndex )
: m_aInternalData.getComplexRowLabel( nIndex );
if( !aComplexLabel.empty() )
- {
- aResult.realloc( aComplexLabel.size() );
- transform( aComplexLabel.begin(), aComplexLabel.end(),
- aResult.getArray(), CommonFunctors::makeAny< OUString >());
- }
+ aResult = ContainerHelper::ContainerToSequence(aComplexLabel);
}
else if( aRange.match( lcl_aCategoriesPointRangeNamePrefix ) )
{
sal_Int32 nPointIndex = aRange.copy( lcl_aCategoriesPointRangeNamePrefix.getLength() ).toInt32();
- vector< OUString > aComplexCategory = m_bDataInColumns
+ vector< uno::Any > aComplexCategory = m_bDataInColumns
? m_aInternalData.getComplexRowLabel( nPointIndex )
: m_aInternalData.getComplexColumnLabel( nPointIndex );
if( !aComplexCategory.empty() )
- {
- aResult.realloc( aComplexCategory.size() );
- transform( aComplexCategory.begin(), aComplexCategory.end(),
- aResult.getArray(), CommonFunctors::makeAny< OUString >());
- }
+ aResult = ContainerHelper::ContainerToSequence(aComplexCategory);
}
else if( aRange.match( lcl_aCategoriesLevelRangeNamePrefix ) )
{
sal_Int32 nLevel = aRange.copy( lcl_aCategoriesLevelRangeNamePrefix.getLength() ).toInt32();
- vector< vector< OUString > > aCategories( m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels());
+ vector< vector< uno::Any > > aCategories( m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels());
if( nLevel < lcl_getInnerLevelCount( aCategories ) )
{
aResult.realloc( aCategories.size() );
transform( aCategories.begin(), aCategories.end(),
- aResult.getArray(), lcl_makeAnyFromLevelVector(nLevel) );
+ aResult.getArray(), lcl_copyFromLevel(nLevel) );
}
}
else if( aRange.equals( lcl_aCategoriesRangeName ) )
{
- Sequence< OUString > aLabels = m_bDataInColumns ? this->getRowDescriptions() : this->getColumnDescriptions();
- aResult.realloc( aLabels.getLength() );
- transform( aLabels.getConstArray(), aLabels.getConstArray() + aLabels.getLength(),
- aResult.getArray(), CommonFunctors::makeAny< OUString >() );
+ 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 ) );
+ }
+ else
+ {
+ Sequence< OUString > aLabels = m_bDataInColumns ? this->getRowDescriptions() : this->getColumnDescriptions();
+ aResult.realloc( aLabels.getLength() );
+ transform( aLabels.getConstArray(), aLabels.getConstArray() + aLabels.getLength(),
+ aResult.getArray(), CommonFunctors::makeAny< OUString >() );
+ }
}
else
{
@@ -800,38 +824,36 @@ void SAL_CALL InternalDataProvider::setDataByRangeRepresentation(
const OUString& aRange, const Sequence< uno::Any >& aNewData )
throw (uno::RuntimeException)
{
+ vector< uno::Any > aNewVector( ContainerHelper::SequenceToVector(aNewData) );
if( aRange.match( lcl_aLabelRangePrefix ) )
{
- vector< OUString > aNewStrings( lcl_AnyToStringVector( aNewData ) );
sal_uInt32 nIndex = aRange.copy( lcl_aLabelRangePrefix.getLength()).toInt32();
if( m_bDataInColumns )
- m_aInternalData.setComplexColumnLabel( nIndex, aNewStrings );
+ m_aInternalData.setComplexColumnLabel( nIndex, aNewVector );
else
- m_aInternalData.setComplexRowLabel( nIndex, aNewStrings );
+ m_aInternalData.setComplexRowLabel( nIndex, aNewVector );
}
else if( aRange.match( lcl_aCategoriesPointRangeNamePrefix ) )
{
- vector< OUString > aNewStrings( lcl_AnyToStringVector( aNewData ) );
sal_Int32 nPointIndex = aRange.copy( lcl_aCategoriesLevelRangeNamePrefix.getLength()).toInt32();
if( m_bDataInColumns )
- m_aInternalData.setComplexRowLabel( nPointIndex, aNewStrings );
+ m_aInternalData.setComplexRowLabel( nPointIndex, aNewVector );
else
- m_aInternalData.setComplexColumnLabel( nPointIndex, aNewStrings );
+ m_aInternalData.setComplexColumnLabel( nPointIndex, aNewVector );
}
else if( aRange.match( lcl_aCategoriesLevelRangeNamePrefix ) )
{
- vector< OUString > aNewStrings( lcl_AnyToStringVector( aNewData ) );
sal_Int32 nLevel = aRange.copy( lcl_aCategoriesLevelRangeNamePrefix.getLength()).toInt32();
- vector< vector< OUString > > aComplexCategories = m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels();
+ vector< vector< uno::Any > > aComplexCategories = m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels();
//ensure equal length
- if( aNewStrings.size() > aComplexCategories.size() )
- aComplexCategories.resize( aNewStrings.size() );
- else if( aNewStrings.size() < aComplexCategories.size() )
- aNewStrings.resize( aComplexCategories.size() );
+ if( aNewVector.size() > aComplexCategories.size() )
+ aComplexCategories.resize( aNewVector.size() );
+ else if( aNewVector.size() < aComplexCategories.size() )
+ aNewVector.resize( aComplexCategories.size() );
- transform( aComplexCategories.begin(), aComplexCategories.end(), aNewStrings.begin(),
- aComplexCategories.begin(), lcl_setStringAtLevel(nLevel) );
+ transform( aComplexCategories.begin(), aComplexCategories.end(), aNewVector.begin(),
+ aComplexCategories.begin(), lcl_setAnyAtLevel(nLevel) );
if( m_bDataInColumns )
m_aInternalData.setComplexRowLabels( aComplexCategories );
@@ -840,10 +862,14 @@ void SAL_CALL InternalDataProvider::setDataByRangeRepresentation(
}
else if( aRange.equals( lcl_aCategoriesRangeName ) )
{
+ vector< vector< uno::Any > > aComplexCategories;
+ aComplexCategories.resize( aNewVector.size() );
+ transform( aComplexCategories.begin(), aComplexCategories.end(), aNewVector.begin(),
+ aComplexCategories.begin(), lcl_setAnyAtLevel(0) );
if( m_bDataInColumns )
- this->setRowDescriptions( lcl_AnyToStringSequence(aNewData) );
+ m_aInternalData.setComplexRowLabels( aComplexCategories );
else
- this->setColumnDescriptions( lcl_AnyToStringSequence(aNewData) );
+ m_aInternalData.setComplexColumnLabels( aComplexCategories );
}
else
{
@@ -908,8 +934,8 @@ void SAL_CALL InternalDataProvider::insertComplexCategoryLevel( sal_Int32 nLevel
OSL_ENSURE( nLevel> 0, "you can only insert category levels > 0" );//the first categories level cannot be deleted, check the calling code for error
if( nLevel>0 )
{
- vector< vector< OUString > > aComplexCategories = m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels();
- ::std::for_each( aComplexCategories.begin(), aComplexCategories.end(), lcl_insertStringAtLevel(nLevel) );
+ vector< vector< uno::Any > > aComplexCategories = m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels();
+ ::std::for_each( aComplexCategories.begin(), aComplexCategories.end(), lcl_insertAnyAtLevel(nLevel) );
if( m_bDataInColumns )
m_aInternalData.setComplexRowLabels( aComplexCategories );
else
@@ -925,8 +951,8 @@ void SAL_CALL InternalDataProvider::deleteComplexCategoryLevel( sal_Int32 nLevel
OSL_ENSURE( nLevel>0, "you can only delete category levels > 0" );//the first categories level cannot be deleted, check the calling code for error
if( nLevel>0 )
{
- vector< vector< OUString > > aComplexCategories = m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels();
- ::std::for_each( aComplexCategories.begin(), aComplexCategories.end(), lcl_removeStringAtLevel(nLevel) );
+ vector< vector< uno::Any > > aComplexCategories = m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels();
+ ::std::for_each( aComplexCategories.begin(), aComplexCategories.end(), lcl_removeAnyAtLevel(nLevel) );
if( m_bDataInColumns )
m_aInternalData.setComplexRowLabels( aComplexCategories );
else
@@ -1136,7 +1162,36 @@ OUString SAL_CALL InternalDataProvider::convertRangeFromXML( const OUString& aXM
namespace
{
-Sequence< Sequence< OUString > > lcl_convertComplexVectorToSequence( const vector< vector< OUString > >& rIn )
+
+template< class Type >
+Sequence< Sequence< Type > > lcl_convertVectorVectorToSequenceSequence( const vector< vector< Type > >& rIn )
+{
+ Sequence< Sequence< Type > > aRet;
+ sal_Int32 nOuterCount = rIn.size();
+ if( nOuterCount )
+ {
+ aRet.realloc(nOuterCount);
+ for( sal_Int32 nN=0; nN<nOuterCount; nN++)
+ aRet[nN]= ContainerHelper::ContainerToSequence( rIn[nN] );
+ }
+ return aRet;
+}
+
+template< class Type >
+vector< vector< Type > > lcl_convertSequenceSequenceToVectorVector( const Sequence< Sequence< Type > >& rIn )
+{
+ vector< vector< Type > > aRet;
+ sal_Int32 nOuterCount = rIn.getLength();
+ if( nOuterCount )
+ {
+ aRet.resize(nOuterCount);
+ for( sal_Int32 nN=0; nN<nOuterCount; nN++)
+ aRet[nN]= ContainerHelper::SequenceToVector( rIn[nN] );
+ }
+ return aRet;
+}
+
+Sequence< Sequence< OUString > > lcl_convertComplexAnyVectorToStringSequence( const vector< vector< uno::Any > >& rIn )
{
Sequence< Sequence< OUString > > aRet;
sal_Int32 nOuterCount = rIn.size();
@@ -1144,17 +1199,17 @@ Sequence< Sequence< OUString > > lcl_convertComplexVectorToSequence( const vecto
{
aRet.realloc(nOuterCount);
for( sal_Int32 nN=0; nN<nOuterCount; nN++)
- aRet[nN]=ContainerHelper::ContainerToSequence( rIn[nN] );
+ aRet[nN]= lcl_AnyToStringSequence( ContainerHelper::ContainerToSequence( rIn[nN] ) );
}
return aRet;
}
-vector< vector< OUString > > lcl_convertComplexSequenceToVector( const Sequence< Sequence< OUString > >& rIn )
+vector< vector< uno::Any > > lcl_convertComplexStringSequenceToAnyVector( const Sequence< Sequence< OUString > >& rIn )
{
- vector< vector< OUString > > aRet;
+ vector< vector< uno::Any > > aRet;
sal_Int32 nOuterCount = rIn.getLength();
for( sal_Int32 nN=0; nN<nOuterCount; nN++)
- aRet.push_back( ContainerHelper::SequenceToVector( rIn[nN] ) );
+ aRet.push_back( ContainerHelper::SequenceToVector( lcl_StringToAnySequence( rIn[nN] ) ) );
return aRet;
}
@@ -1162,7 +1217,7 @@ class SplitCategoriesProvider_ForComplexDescriptions : public SplitCategoriesPro
{
public:
- explicit SplitCategoriesProvider_ForComplexDescriptions( const ::std::vector< ::std::vector< ::rtl::OUString > >& rComplexDescriptions )
+ explicit SplitCategoriesProvider_ForComplexDescriptions( const ::std::vector< ::std::vector< uno::Any > >& rComplexDescriptions )
: m_rComplexDescriptions( rComplexDescriptions )
{}
virtual ~SplitCategoriesProvider_ForComplexDescriptions()
@@ -1172,7 +1227,7 @@ public:
virtual uno::Sequence< rtl::OUString > getStringsForLevel( sal_Int32 nIndex ) const;
private:
- const ::std::vector< ::std::vector< ::rtl::OUString > >& m_rComplexDescriptions;
+ const ::std::vector< ::std::vector< uno::Any > >& m_rComplexDescriptions;
};
sal_Int32 SplitCategoriesProvider_ForComplexDescriptions::getLevelCount() const
@@ -1193,22 +1248,78 @@ uno::Sequence< rtl::OUString > SplitCategoriesProvider_ForComplexDescriptions::g
}//anonymous namespace
+// ____ XDateCategories ____
+Sequence< double > SAL_CALL InternalDataProvider::getDateCategories() throw (uno::RuntimeException)
+{
+ double fNan = InternalDataProvider::getNotANumber();
+ double fValue = fNan;
+ vector< vector< uno::Any > > aCategories( m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels());
+ sal_Int32 nCount = aCategories.size();
+ Sequence< double > aDoubles( nCount );
+ vector< vector< uno::Any > >::iterator aIt( aCategories.begin() );
+ vector< vector< uno::Any > >::const_iterator aEnd( aCategories.end() );
+ for(sal_Int32 nN=0; nN<nCount && aIt!=aEnd; ++nN, ++aIt )
+ {
+ if( !( !aIt->empty() && ((*aIt)[0]>>=fValue) ) )
+ fValue = fNan;
+ aDoubles[nN]=fValue;
+ }
+ return aDoubles;
+}
+
+void SAL_CALL InternalDataProvider::setDateCategories( const Sequence< double >& rDates ) throw (uno::RuntimeException)
+{
+ sal_Int32 nCount = rDates.getLength();
+ vector< vector< uno::Any > > aNewCategories;
+ aNewCategories.reserve(nCount);
+ vector< uno::Any > aSingleLabel(1);
+
+ for(sal_Int32 nN=0; nN<nCount; ++nN )
+ {
+ aSingleLabel[0]=uno::makeAny(rDates[nN]);
+ aNewCategories.push_back(aSingleLabel);
+ }
+
+ if( m_bDataInColumns )
+ m_aInternalData.setComplexRowLabels( aNewCategories );
+ else
+ m_aInternalData.setComplexColumnLabels( aNewCategories );
+}
+
+// ____ XAnyDescriptionAccess ____
+Sequence< Sequence< uno::Any > > SAL_CALL InternalDataProvider::getAnyRowDescriptions() throw (uno::RuntimeException)
+{
+ return lcl_convertVectorVectorToSequenceSequence( m_aInternalData.getComplexRowLabels() );
+}
+void SAL_CALL InternalDataProvider::setAnyRowDescriptions( const Sequence< Sequence< uno::Any > >& aRowDescriptions ) throw (uno::RuntimeException)
+{
+ m_aInternalData.setComplexRowLabels( lcl_convertSequenceSequenceToVectorVector( aRowDescriptions ) );
+}
+Sequence< Sequence< uno::Any > > SAL_CALL InternalDataProvider::getAnyColumnDescriptions() throw (uno::RuntimeException)
+{
+ return lcl_convertVectorVectorToSequenceSequence( m_aInternalData.getComplexColumnLabels() );
+}
+void SAL_CALL InternalDataProvider::setAnyColumnDescriptions( const Sequence< Sequence< uno::Any > >& aColumnDescriptions ) throw (uno::RuntimeException)
+{
+ m_aInternalData.setComplexColumnLabels( lcl_convertSequenceSequenceToVectorVector( aColumnDescriptions ) );
+}
+
// ____ XComplexDescriptionAccess ____
Sequence< Sequence< OUString > > SAL_CALL InternalDataProvider::getComplexRowDescriptions() throw (uno::RuntimeException)
{
- return lcl_convertComplexVectorToSequence( m_aInternalData.getComplexRowLabels() );
+ return lcl_convertComplexAnyVectorToStringSequence( m_aInternalData.getComplexRowLabels() );
}
void SAL_CALL InternalDataProvider::setComplexRowDescriptions( const Sequence< Sequence< ::rtl::OUString > >& aRowDescriptions ) throw (uno::RuntimeException)
{
- m_aInternalData.setComplexRowLabels( lcl_convertComplexSequenceToVector(aRowDescriptions) );
+ m_aInternalData.setComplexRowLabels( lcl_convertComplexStringSequenceToAnyVector(aRowDescriptions) );
}
Sequence< Sequence< ::rtl::OUString > > SAL_CALL InternalDataProvider::getComplexColumnDescriptions() throw (uno::RuntimeException)
{
- return lcl_convertComplexVectorToSequence( m_aInternalData.getComplexColumnLabels() );
+ return lcl_convertComplexAnyVectorToStringSequence( m_aInternalData.getComplexColumnLabels() );
}
void SAL_CALL InternalDataProvider::setComplexColumnDescriptions( const Sequence< Sequence< ::rtl::OUString > >& aColumnDescriptions ) throw (uno::RuntimeException)
{
- m_aInternalData.setComplexColumnLabels( lcl_convertComplexSequenceToVector(aColumnDescriptions) );
+ m_aInternalData.setComplexColumnLabels( lcl_convertComplexStringSequenceToAnyVector(aColumnDescriptions) );
}
// ____ XChartDataArray ____
@@ -1227,25 +1338,25 @@ void SAL_CALL InternalDataProvider::setData( const Sequence< Sequence< double >
void SAL_CALL InternalDataProvider::setRowDescriptions( const Sequence< OUString >& aRowDescriptions )
throw (uno::RuntimeException)
{
- vector< vector< OUString > > aComplexDescriptions( aRowDescriptions.getLength() );
+ vector< vector< uno::Any > > aComplexDescriptions( aRowDescriptions.getLength() );
transform( aComplexDescriptions.begin(), aComplexDescriptions.end(), aRowDescriptions.getConstArray(),
- aComplexDescriptions.begin(), lcl_setStringAtLevel(0) );
+ aComplexDescriptions.begin(), lcl_setAnyAtLevelFromStringSequence(0) );
m_aInternalData.setComplexRowLabels( aComplexDescriptions );
}
void SAL_CALL InternalDataProvider::setColumnDescriptions( const Sequence< OUString >& aColumnDescriptions )
throw (uno::RuntimeException)
{
- vector< vector< OUString > > aComplexDescriptions( aColumnDescriptions.getLength() );
+ vector< vector< uno::Any > > aComplexDescriptions( aColumnDescriptions.getLength() );
transform( aComplexDescriptions.begin(), aComplexDescriptions.end(), aColumnDescriptions.getConstArray(),
- aComplexDescriptions.begin(), lcl_setStringAtLevel(0) );
+ aComplexDescriptions.begin(), lcl_setAnyAtLevelFromStringSequence(0) );
m_aInternalData.setComplexColumnLabels( aComplexDescriptions );
}
Sequence< OUString > SAL_CALL InternalDataProvider::getRowDescriptions()
throw (uno::RuntimeException)
{
- vector< vector< OUString > > aComplexLabels( m_aInternalData.getComplexRowLabels() );
+ vector< vector< uno::Any > > aComplexLabels( m_aInternalData.getComplexRowLabels() );
SplitCategoriesProvider_ForComplexDescriptions aProvider( aComplexLabels );
return ExplicitCategoriesProvider::getExplicitSimpleCategories( aProvider );
}
@@ -1253,7 +1364,7 @@ Sequence< OUString > SAL_CALL InternalDataProvider::getRowDescriptions()
Sequence< OUString > SAL_CALL InternalDataProvider::getColumnDescriptions()
throw (uno::RuntimeException)
{
- vector< vector< OUString > > aComplexLabels( m_aInternalData.getComplexColumnLabels() );
+ vector< vector< uno::Any > > aComplexLabels( m_aInternalData.getComplexColumnLabels() );
SplitCategoriesProvider_ForComplexDescriptions aProvider( aComplexLabels );
return ExplicitCategoriesProvider::getExplicitSimpleCategories( aProvider );
}
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/ResId.cxx b/chart2/source/tools/ResId.cxx
index 0d6e35974aaa..b7d4c725d367 100644..100755
--- a/chart2/source/tools/ResId.cxx
+++ b/chart2/source/tools/ResId.cxx
@@ -41,7 +41,7 @@ SchResId::SchResId( sal_Int16 nId )
::rtl::OUString SchResId::getResString( sal_Int16 nId )
{
- return ::rtl::OUString( String( SchResId( nId )));
+ return String( SchResId( nId ));
}
} // 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 \