diff --git a/chart2/source/inc/InternalData.hxx b/chart2/source/inc/InternalData.hxx index 6b6590cffdac..c94e3346175e 100644 --- a/chart2/source/inc/InternalData.hxx +++ b/chart2/source/inc/InternalData.hxx @@ -41,6 +41,8 @@ public: InternalData(); void createDefaultData(); + bool isDefaultData(); + void clearDefaultData(); void setData( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > > & rDataInRows ); diff --git a/chart2/source/tools/InternalData.cxx b/chart2/source/tools/InternalData.cxx index ecd34372641e..10729906f4d1 100644 --- a/chart2/source/tools/InternalData.cxx +++ b/chart2/source/tools/InternalData.cxx @@ -89,6 +89,13 @@ InternalData::InternalData() , m_aColumnLabels( 0 ) {} +static const double fDefaultData[] = { + 9.10, 3.20, 4.54, + 2.40, 8.80, 9.65, + 3.10, 1.50, 3.70, + 4.30, 9.02, 6.20 +}; + void InternalData::createDefaultData() { const sal_Int32 nRowCount = 4; @@ -101,12 +108,6 @@ void InternalData::createDefaultData() const OUString aRowName( ::chart::SchResId::getResString( STR_ROW_LABEL )); const OUString aColName( ::chart::SchResId::getResString( STR_COLUMN_LABEL )); - const double fDefaultData[ nSize ] = - { 9.10, 3.20, 4.54, - 2.40, 8.80, 9.65, - 3.10, 1.50, 3.70, - 4.30, 9.02, 6.20 }; - m_aData.resize( nSize ); for( sal_Int32 i=0; i >& rDataInRows ) { m_nRowCount = rDataInRows.getLength(); diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx index 66c17da1186d..634a3c26db4d 100644 --- a/chart2/source/tools/InternalDataProvider.cxx +++ b/chart2/source/tools/InternalDataProvider.cxx @@ -488,9 +488,80 @@ void InternalDataProvider::lcl_decreaseMapReferences( Reference< chart2::data::XDataSequence > InternalDataProvider::lcl_createDataSequenceAndAddToMap( const OUString & rRangeRepresentation ) { + OUString aRangeRepresentation = rRangeRepresentation; + if( aRangeRepresentation.indexOf('{') >= 0 ) + { + sal_Int32 i, m, n; + ::std::vector< double > aNewData; + ::std::vector< OUString > aNewLabels; + OUString aToken; + sal_Int32 nCategories = 0; + sal_Int32 nIndex = 0; + bool bValues = true; + bool bLabelSet = false; + OUString str = aRangeRepresentation.replace('{',' ').replace('}',' '); + + m_aInternalData.clearDefaultData(); + n = m_aInternalData.getColumnCount(); + if( n ) + n = n - 1; + + do + { + // TODO: This will be problematic if ';' is used in label names + // '"' character also needs to be considered in such cases + aToken = str.getToken(0,';',nIndex); + if( !aToken.getLength() ) + break; + if( aToken.indexOf('"') < 0 ) + { + aNewData.push_back( aToken.toDouble() ); + } + else + { + aNewLabels.push_back( aToken.replace('"', ' ').trim() ); + if( !nCategories && + ( !m_aInternalData.getComplexColumnLabel(n).size() || + !m_aInternalData.getComplexColumnLabel(n).front().getLength() ) ) + { + m_aInternalData.setComplexColumnLabel( n, aNewLabels ); + bLabelSet = true; + } + else + { + m_aInternalData.setComplexRowLabel(nCategories, aNewLabels); + if(nCategories==1 && bLabelSet) + { + ::std::vector< OUString > aLabels; + m_aInternalData.setComplexRowLabel( 0, m_aInternalData.getComplexColumnLabel( n ) ); + m_aInternalData.setComplexColumnLabel( n, aLabels ); + } + } + aNewLabels.pop_back(); + nCategories++; + bValues = false; + } + } while( nIndex >= 0 ); + + if( bValues ) + { + m_aInternalData.insertColumn( n ); + m_aInternalData.setColumnValues( n, aNewData ); + aRangeRepresentation = OUString::valueOf( n ); + } + else if( nCategories > 1 ) + { + aRangeRepresentation = lcl_aCategoriesRangeName; + } + else + { + aRangeRepresentation = lcl_aLabelRangePrefix+OUString::valueOf( n ); + } + } + Reference< chart2::data::XDataSequence > xSeq( - new UncachedDataSequence( this, rRangeRepresentation )); - lcl_addDataSequenceToMap( rRangeRepresentation, xSeq ); + new UncachedDataSequence( this, aRangeRepresentation )); + lcl_addDataSequenceToMap( aRangeRepresentation, xSeq ); return xSeq; } @@ -685,8 +756,7 @@ Reference< chart2::data::XDataSequence > SAL_CALL InternalDataProvider::createDa else if( aRangeRepresentation.getLength()) { // data - sal_Int32 nIndex = aRangeRepresentation.toInt32(); - return lcl_createDataSequenceAndAddToMap( OUString::valueOf( nIndex )); + return lcl_createDataSequenceAndAddToMap( aRangeRepresentation ); } return Reference< chart2::data::XDataSequence >();