1cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5cde9e8dcSAndrew Rist  * distributed with this work for additional information
6cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cde9e8dcSAndrew Rist  *
11cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cde9e8dcSAndrew Rist  *
13cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18cde9e8dcSAndrew Rist  * under the License.
19cde9e8dcSAndrew Rist  *
20cde9e8dcSAndrew Rist  *************************************************************/
21cde9e8dcSAndrew Rist 
22cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "InternalData.hxx"
28cdf0e10cSrcweir #include "ResId.hxx"
29cdf0e10cSrcweir #include "Strings.hrc"
30cdf0e10cSrcweir #include "macros.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <rtl/math.hxx>
33*82c0ddf2SHerbert Dürr #include <algorithm>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
36cdf0e10cSrcweir using ::rtl::OUString;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using namespace ::com::sun::star;
39cdf0e10cSrcweir using namespace ::std;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace chart
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // ----------------------------------------
45cdf0e10cSrcweir namespace
46cdf0e10cSrcweir {
47cdf0e10cSrcweir struct lcl_NumberedStringGenerator
48cdf0e10cSrcweir {
lcl_NumberedStringGeneratorchart::__anonfd5419f90111::lcl_NumberedStringGenerator49cdf0e10cSrcweir     lcl_NumberedStringGenerator( const OUString & rStub, const OUString & rWildcard ) :
50cdf0e10cSrcweir             m_aStub( rStub ),
51cdf0e10cSrcweir             m_nCounter( 0 ),
52cdf0e10cSrcweir             m_nStubStartIndex( rStub.indexOf( rWildcard )),
53cdf0e10cSrcweir             m_nWildcardLength( rWildcard.getLength())
54cdf0e10cSrcweir     {
55cdf0e10cSrcweir     }
operator ()chart::__anonfd5419f90111::lcl_NumberedStringGenerator56cdf0e10cSrcweir     vector< uno::Any > operator()()
57cdf0e10cSrcweir     {
58cdf0e10cSrcweir         vector< uno::Any > aRet(1);
59cdf0e10cSrcweir         aRet[0] = uno::makeAny( m_aStub.replaceAt( m_nStubStartIndex, m_nWildcardLength, OUString::valueOf( ++m_nCounter )) );
60cdf0e10cSrcweir         return aRet;
61cdf0e10cSrcweir     }
62cdf0e10cSrcweir private:
63cdf0e10cSrcweir     OUString m_aStub;
64cdf0e10cSrcweir     sal_Int32 m_nCounter;
65cdf0e10cSrcweir     const sal_Int32 m_nStubStartIndex;
66cdf0e10cSrcweir     const sal_Int32 m_nWildcardLength;
67cdf0e10cSrcweir };
68cdf0e10cSrcweir 
69cdf0e10cSrcweir template< typename T >
lcl_ValarrayToSequence(const::std::valarray<T> & rValarray)70cdf0e10cSrcweir     Sequence< T > lcl_ValarrayToSequence( const ::std::valarray< T > & rValarray )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     // is there a more elegant way of conversion?
73cdf0e10cSrcweir     Sequence< T > aResult( rValarray.size());
74cdf0e10cSrcweir     for( size_t i = 0; i < rValarray.size(); ++i )
75cdf0e10cSrcweir         aResult[i] = rValarray[i];
76cdf0e10cSrcweir     return aResult;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir } // anonymous namespace
80cdf0e10cSrcweir // ----------------------------------------
81cdf0e10cSrcweir 
InternalData()82cdf0e10cSrcweir InternalData::InternalData()
83cdf0e10cSrcweir     : m_nColumnCount( 0 )
84cdf0e10cSrcweir     , m_nRowCount( 0 )
85cdf0e10cSrcweir     , m_aRowLabels( 0 )
86cdf0e10cSrcweir     , m_aColumnLabels( 0 )
87cdf0e10cSrcweir {}
88cdf0e10cSrcweir 
createDefaultData()89cdf0e10cSrcweir void InternalData::createDefaultData()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     const sal_Int32 nRowCount = 4;
92cdf0e10cSrcweir     const sal_Int32 nColumnCount = 3;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     m_nRowCount = nRowCount;
95cdf0e10cSrcweir     m_nColumnCount = nColumnCount;
96cdf0e10cSrcweir     const sal_Int32 nSize = nColumnCount * nRowCount;
97cdf0e10cSrcweir     // @todo: localize this!
98cdf0e10cSrcweir     const OUString aRowName( ::chart::SchResId::getResString( STR_ROW_LABEL ));
99cdf0e10cSrcweir     const OUString aColName( ::chart::SchResId::getResString( STR_COLUMN_LABEL ));
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     const double fDefaultData[ nSize ] =
102cdf0e10cSrcweir         { 9.10, 3.20, 4.54,
103cdf0e10cSrcweir           2.40, 8.80, 9.65,
104cdf0e10cSrcweir           3.10, 1.50, 3.70,
105cdf0e10cSrcweir           4.30, 9.02, 6.20 };
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     m_aData.resize( nSize );
108cdf0e10cSrcweir     for( sal_Int32 i=0; i<nSize; ++i )
109cdf0e10cSrcweir         m_aData[i] = fDefaultData[i];
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     m_aRowLabels.clear();
112cdf0e10cSrcweir     m_aRowLabels.reserve( m_nRowCount );
113cdf0e10cSrcweir     generate_n( back_inserter( m_aRowLabels ), m_nRowCount,
114cdf0e10cSrcweir         lcl_NumberedStringGenerator( aRowName, C2U("%ROWNUMBER") ));
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     m_aColumnLabels.clear();
117cdf0e10cSrcweir     m_aColumnLabels.reserve( m_nColumnCount );
118cdf0e10cSrcweir     generate_n( back_inserter( m_aColumnLabels ), m_nColumnCount,
119cdf0e10cSrcweir         lcl_NumberedStringGenerator( aColName, C2U("%COLUMNNUMBER") ));
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
setData(const Sequence<Sequence<double>> & rDataInRows)122cdf0e10cSrcweir void InternalData::setData( const Sequence< Sequence< double > >& rDataInRows )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     m_nRowCount = rDataInRows.getLength();
125cdf0e10cSrcweir     m_nColumnCount = (m_nRowCount ? rDataInRows[0].getLength() : 0);
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     if( m_aRowLabels.size() != static_cast< sal_uInt32 >( m_nRowCount ))
128cdf0e10cSrcweir         m_aRowLabels.resize( m_nRowCount );
129cdf0e10cSrcweir     if( m_aColumnLabels.size() != static_cast< sal_uInt32 >( m_nColumnCount ))
130cdf0e10cSrcweir         m_aColumnLabels.resize( m_nColumnCount );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     m_aData.resize( m_nRowCount * m_nColumnCount );
133cdf0e10cSrcweir     double fNan;
134cdf0e10cSrcweir     ::rtl::math::setNan( & fNan );
135cdf0e10cSrcweir     // set all values to Nan
136cdf0e10cSrcweir     m_aData = fNan;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     for( sal_Int32 nRow=0; nRow<m_nRowCount; ++nRow )
139cdf0e10cSrcweir     {
140cdf0e10cSrcweir         int nDataIdx = nRow*m_nColumnCount;
141cdf0e10cSrcweir         const sal_Int32 nMax = ::std::min( rDataInRows[nRow].getLength(), m_nColumnCount );
142cdf0e10cSrcweir         for( sal_Int32 nCol=0; nCol < nMax; ++nCol )
143cdf0e10cSrcweir         {
144cdf0e10cSrcweir             m_aData[nDataIdx] = rDataInRows[nRow][nCol];
145cdf0e10cSrcweir             nDataIdx += 1;
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
getData() const150cdf0e10cSrcweir Sequence< Sequence< double > > InternalData::getData() const
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     Sequence< Sequence< double > > aResult( m_nRowCount );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     for( sal_Int32 i=0; i<m_nRowCount; ++i )
155cdf0e10cSrcweir         aResult[i] = lcl_ValarrayToSequence< tDataType::value_type >(
156cdf0e10cSrcweir             m_aData[ ::std::slice( i*m_nColumnCount, m_nColumnCount, 1 ) ] );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     return aResult;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
getColumnValues(sal_Int32 nColumnIndex) const161cdf0e10cSrcweir Sequence< double > InternalData::getColumnValues( sal_Int32 nColumnIndex ) const
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     if( nColumnIndex >= 0 && nColumnIndex < m_nColumnCount )
164cdf0e10cSrcweir         return lcl_ValarrayToSequence< tDataType::value_type >(
165cdf0e10cSrcweir             m_aData[ ::std::slice( nColumnIndex, m_nRowCount, m_nColumnCount ) ] );
166cdf0e10cSrcweir     return Sequence< double >();
167cdf0e10cSrcweir }
getRowValues(sal_Int32 nRowIndex) const168cdf0e10cSrcweir Sequence< double > InternalData::getRowValues( sal_Int32 nRowIndex ) const
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     if( nRowIndex >= 0 && nRowIndex < m_nRowCount )
171cdf0e10cSrcweir         return lcl_ValarrayToSequence< tDataType::value_type >(
172cdf0e10cSrcweir             m_aData[ ::std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ] );
173cdf0e10cSrcweir     return Sequence< double >();
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
setColumnValues(sal_Int32 nColumnIndex,const vector<double> & rNewData)176cdf0e10cSrcweir void InternalData::setColumnValues( sal_Int32 nColumnIndex, const vector< double > & rNewData )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     if( nColumnIndex < 0 )
179cdf0e10cSrcweir         return;
180cdf0e10cSrcweir     enlargeData( nColumnIndex + 1, rNewData.size() );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     tDataType aSlice = m_aData[ ::std::slice( nColumnIndex, m_nRowCount, m_nColumnCount ) ];
183cdf0e10cSrcweir     for( vector< double >::size_type i = 0; i < rNewData.size(); ++i )
184cdf0e10cSrcweir         aSlice[i] = rNewData[i];
185cdf0e10cSrcweir     m_aData[ ::std::slice( nColumnIndex, m_nRowCount, m_nColumnCount ) ] = aSlice;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
setRowValues(sal_Int32 nRowIndex,const vector<double> & rNewData)188cdf0e10cSrcweir void InternalData::setRowValues( sal_Int32 nRowIndex, const vector< double > & rNewData )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     if( nRowIndex < 0 )
191cdf0e10cSrcweir         return;
192cdf0e10cSrcweir     enlargeData( rNewData.size(), nRowIndex+1 );
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     tDataType aSlice = m_aData[ ::std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ];
195cdf0e10cSrcweir     for( vector< double >::size_type i = 0; i < rNewData.size(); ++i )
196cdf0e10cSrcweir         aSlice[i] = rNewData[i];
197cdf0e10cSrcweir     m_aData[ ::std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ]= aSlice;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
setComplexColumnLabel(sal_Int32 nColumnIndex,const vector<uno::Any> & rComplexLabel)200cdf0e10cSrcweir void InternalData::setComplexColumnLabel( sal_Int32 nColumnIndex, const vector< uno::Any >& rComplexLabel )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir     if( nColumnIndex < 0 )
203cdf0e10cSrcweir         return;
204cdf0e10cSrcweir     if( nColumnIndex >= static_cast< sal_Int32 >( m_aColumnLabels.size() ) )
205cdf0e10cSrcweir     {
206cdf0e10cSrcweir         m_aColumnLabels.resize(nColumnIndex+1);
207cdf0e10cSrcweir         enlargeData( nColumnIndex+1, 0 );
208cdf0e10cSrcweir     }
209cdf0e10cSrcweir     m_aColumnLabels[nColumnIndex]=rComplexLabel;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
setComplexRowLabel(sal_Int32 nRowIndex,const vector<uno::Any> & rComplexLabel)212cdf0e10cSrcweir void InternalData::setComplexRowLabel( sal_Int32 nRowIndex, const vector< uno::Any >& rComplexLabel )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir     if( nRowIndex < 0 )
215cdf0e10cSrcweir         return;
216cdf0e10cSrcweir     if( nRowIndex >= static_cast< sal_Int32 >( m_aRowLabels.size() ) )
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         m_aRowLabels.resize(nRowIndex+1);
219cdf0e10cSrcweir         enlargeData( 0, nRowIndex+1 );
220cdf0e10cSrcweir     }
221cdf0e10cSrcweir     m_aRowLabels[nRowIndex] = rComplexLabel;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
getComplexColumnLabel(sal_Int32 nColumnIndex) const224cdf0e10cSrcweir vector< uno::Any > InternalData::getComplexColumnLabel( sal_Int32 nColumnIndex ) const
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     if( nColumnIndex < static_cast< sal_Int32 >( m_aColumnLabels.size() ) )
227cdf0e10cSrcweir         return m_aColumnLabels[nColumnIndex];
228cdf0e10cSrcweir     else
229cdf0e10cSrcweir         return vector< uno::Any >();
230cdf0e10cSrcweir }
getComplexRowLabel(sal_Int32 nRowIndex) const231cdf0e10cSrcweir vector< uno::Any > InternalData::getComplexRowLabel( sal_Int32 nRowIndex ) const
232cdf0e10cSrcweir {
233cdf0e10cSrcweir     if( nRowIndex < static_cast< sal_Int32 >( m_aRowLabels.size() ) )
234cdf0e10cSrcweir         return m_aRowLabels[nRowIndex];
235cdf0e10cSrcweir     else
236cdf0e10cSrcweir         return vector< uno::Any >();
237cdf0e10cSrcweir }
238cdf0e10cSrcweir 
swapRowWithNext(sal_Int32 nRowIndex)239cdf0e10cSrcweir void InternalData::swapRowWithNext( sal_Int32 nRowIndex )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir     if( nRowIndex < m_nRowCount - 1 )
242cdf0e10cSrcweir     {
243cdf0e10cSrcweir         const sal_Int32 nMax = m_nColumnCount;
244cdf0e10cSrcweir         for( sal_Int32 nColIdx=0; nColIdx<nMax; ++nColIdx )
245cdf0e10cSrcweir         {
246cdf0e10cSrcweir             size_t nIndex1 = nColIdx + nRowIndex*m_nColumnCount;
247cdf0e10cSrcweir             size_t nIndex2 = nIndex1 + m_nColumnCount;
248cdf0e10cSrcweir             double fTemp = m_aData[nIndex1];
249cdf0e10cSrcweir             m_aData[nIndex1] = m_aData[nIndex2];
250cdf0e10cSrcweir             m_aData[nIndex2] = fTemp;
251cdf0e10cSrcweir         }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir         vector< uno::Any > aTemp( m_aRowLabels[nRowIndex] );
254cdf0e10cSrcweir         m_aRowLabels[nRowIndex] = m_aRowLabels[nRowIndex + 1];
255cdf0e10cSrcweir         m_aRowLabels[nRowIndex + 1] = aTemp;
256cdf0e10cSrcweir     }
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
swapColumnWithNext(sal_Int32 nColumnIndex)259cdf0e10cSrcweir void InternalData::swapColumnWithNext( sal_Int32 nColumnIndex )
260cdf0e10cSrcweir {
261cdf0e10cSrcweir     if( nColumnIndex < m_nColumnCount - 1 )
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir         const sal_Int32 nMax = m_nRowCount;
264cdf0e10cSrcweir         for( sal_Int32 nRowIdx=0; nRowIdx<nMax; ++nRowIdx )
265cdf0e10cSrcweir         {
266cdf0e10cSrcweir             size_t nIndex1 = nColumnIndex + nRowIdx*m_nColumnCount;
267cdf0e10cSrcweir             size_t nIndex2 = nIndex1 + 1;
268cdf0e10cSrcweir             double fTemp = m_aData[nIndex1];
269cdf0e10cSrcweir             m_aData[nIndex1] = m_aData[nIndex2];
270cdf0e10cSrcweir             m_aData[nIndex2] = fTemp;
271cdf0e10cSrcweir         }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir         vector< uno::Any > aTemp( m_aColumnLabels[nColumnIndex] );
274cdf0e10cSrcweir         m_aColumnLabels[nColumnIndex] = m_aColumnLabels[nColumnIndex + 1];
275cdf0e10cSrcweir         m_aColumnLabels[nColumnIndex + 1] = aTemp;
276cdf0e10cSrcweir     }
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
enlargeData(sal_Int32 nColumnCount,sal_Int32 nRowCount)279cdf0e10cSrcweir bool InternalData::enlargeData( sal_Int32 nColumnCount, sal_Int32 nRowCount )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir     sal_Int32 nNewColumnCount( ::std::max<sal_Int32>( m_nColumnCount, nColumnCount ) );
282cdf0e10cSrcweir     sal_Int32 nNewRowCount( ::std::max<sal_Int32>( m_nRowCount, nRowCount ) );
283cdf0e10cSrcweir     sal_Int32 nNewSize( nNewColumnCount*nNewRowCount );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir     bool bGrow = (nNewSize > m_nColumnCount*m_nRowCount);
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     if( bGrow )
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir         double fNan;
290cdf0e10cSrcweir         ::rtl::math::setNan( &fNan );
291cdf0e10cSrcweir         tDataType aNewData( fNan, nNewSize );
292cdf0e10cSrcweir         // copy old data
293cdf0e10cSrcweir         for( int nCol=0; nCol<m_nColumnCount; ++nCol )
294cdf0e10cSrcweir             static_cast< tDataType >(
295cdf0e10cSrcweir                 aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] ) =
296cdf0e10cSrcweir                 m_aData[ ::std::slice( nCol, m_nRowCount, m_nColumnCount ) ];
297cdf0e10cSrcweir 
298cdf0e10cSrcweir         m_aData.resize( nNewSize );
299cdf0e10cSrcweir         m_aData = aNewData;
300cdf0e10cSrcweir     }
301cdf0e10cSrcweir     m_nColumnCount = nNewColumnCount;
302cdf0e10cSrcweir     m_nRowCount = nNewRowCount;
303cdf0e10cSrcweir     return bGrow;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
insertColumn(sal_Int32 nAfterIndex)306cdf0e10cSrcweir void InternalData::insertColumn( sal_Int32 nAfterIndex )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir     // note: -1 is allowed, as we insert after the given index
309cdf0e10cSrcweir     OSL_ASSERT( nAfterIndex < m_nColumnCount && nAfterIndex >= -1 );
310cdf0e10cSrcweir     if( nAfterIndex >= m_nColumnCount || nAfterIndex < -1 )
311cdf0e10cSrcweir         return;
312cdf0e10cSrcweir     sal_Int32 nNewColumnCount = m_nColumnCount + 1;
313cdf0e10cSrcweir     sal_Int32 nNewSize( nNewColumnCount * m_nRowCount );
314cdf0e10cSrcweir 
315cdf0e10cSrcweir     double fNan;
316cdf0e10cSrcweir     ::rtl::math::setNan( &fNan );
317cdf0e10cSrcweir     tDataType aNewData( fNan, nNewSize );
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     // copy old data
320cdf0e10cSrcweir     int nCol=0;
321cdf0e10cSrcweir     for( ; nCol<=nAfterIndex; ++nCol )
322cdf0e10cSrcweir         aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] =
323cdf0e10cSrcweir             static_cast< tDataType >(
324cdf0e10cSrcweir                 m_aData[ ::std::slice( nCol, m_nRowCount, m_nColumnCount ) ] );
325cdf0e10cSrcweir     for( ++nCol; nCol<nNewColumnCount; ++nCol )
326cdf0e10cSrcweir         aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] =
327cdf0e10cSrcweir             static_cast< tDataType >(
328cdf0e10cSrcweir                 m_aData[ ::std::slice( nCol - 1, m_nRowCount, m_nColumnCount ) ] );
329cdf0e10cSrcweir 
330cdf0e10cSrcweir     m_nColumnCount = nNewColumnCount;
331cdf0e10cSrcweir     m_aData.resize( nNewSize );
332cdf0e10cSrcweir     m_aData = aNewData;
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     // labels
335cdf0e10cSrcweir     if( nAfterIndex < static_cast< sal_Int32 >( m_aColumnLabels.size()))
336cdf0e10cSrcweir         m_aColumnLabels.insert( m_aColumnLabels.begin() + (nAfterIndex + 1), vector< uno::Any >(1) );
337cdf0e10cSrcweir 
338cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2
339cdf0e10cSrcweir     traceData();
340cdf0e10cSrcweir #endif
341cdf0e10cSrcweir }
342cdf0e10cSrcweir 
appendColumn()343cdf0e10cSrcweir sal_Int32 InternalData::appendColumn()
344cdf0e10cSrcweir {
345cdf0e10cSrcweir     insertColumn( getColumnCount() - 1 );
346cdf0e10cSrcweir     return getColumnCount() - 1;
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
appendRow()349cdf0e10cSrcweir sal_Int32 InternalData::appendRow()
350cdf0e10cSrcweir {
351cdf0e10cSrcweir     insertRow( getRowCount() - 1 );
352cdf0e10cSrcweir     return getRowCount() - 1;
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
insertRow(sal_Int32 nAfterIndex)355cdf0e10cSrcweir void InternalData::insertRow( sal_Int32 nAfterIndex )
356cdf0e10cSrcweir {
357cdf0e10cSrcweir     // note: -1 is allowed, as we insert after the given index
358cdf0e10cSrcweir     OSL_ASSERT( nAfterIndex < m_nRowCount && nAfterIndex >= -1 );
359cdf0e10cSrcweir     if( nAfterIndex >= m_nRowCount || nAfterIndex < -1 )
360cdf0e10cSrcweir         return;
361cdf0e10cSrcweir     sal_Int32 nNewRowCount = m_nRowCount + 1;
362cdf0e10cSrcweir     sal_Int32 nNewSize( m_nColumnCount * nNewRowCount );
363cdf0e10cSrcweir 
364cdf0e10cSrcweir     double fNan;
365cdf0e10cSrcweir     ::rtl::math::setNan( &fNan );
366cdf0e10cSrcweir     tDataType aNewData( fNan, nNewSize );
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     // copy old data
369cdf0e10cSrcweir     sal_Int32 nIndex = nAfterIndex + 1;
370cdf0e10cSrcweir     aNewData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] =
371cdf0e10cSrcweir         static_cast< tDataType >(
372cdf0e10cSrcweir             m_aData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] );
373cdf0e10cSrcweir 
374cdf0e10cSrcweir     if( nIndex < m_nRowCount )
375cdf0e10cSrcweir     {
376cdf0e10cSrcweir         sal_Int32 nRemainingCount = m_nColumnCount * (m_nRowCount - nIndex);
377cdf0e10cSrcweir         aNewData[ ::std::slice( (nIndex + 1) * m_nColumnCount, nRemainingCount, 1 ) ] =
378cdf0e10cSrcweir             static_cast< tDataType >(
379cdf0e10cSrcweir                 m_aData[ ::std::slice( nIndex * m_nColumnCount, nRemainingCount, 1 ) ] );
380cdf0e10cSrcweir     }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir     m_nRowCount = nNewRowCount;
383cdf0e10cSrcweir     m_aData.resize( nNewSize );
384cdf0e10cSrcweir     m_aData = aNewData;
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     // labels
387cdf0e10cSrcweir     if( nAfterIndex < static_cast< sal_Int32 >( m_aRowLabels.size()))
388cdf0e10cSrcweir         m_aRowLabels.insert( m_aRowLabels.begin() + nIndex, vector< uno::Any > (1));
389cdf0e10cSrcweir 
390cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2
391cdf0e10cSrcweir     traceData();
392cdf0e10cSrcweir #endif
393cdf0e10cSrcweir }
394cdf0e10cSrcweir 
deleteColumn(sal_Int32 nAtIndex)395cdf0e10cSrcweir void InternalData::deleteColumn( sal_Int32 nAtIndex )
396cdf0e10cSrcweir {
397cdf0e10cSrcweir     OSL_ASSERT( nAtIndex < m_nColumnCount && nAtIndex >= 0 );
398cdf0e10cSrcweir     if( nAtIndex >= m_nColumnCount || m_nColumnCount < 1 || nAtIndex < 0 )
399cdf0e10cSrcweir         return;
400cdf0e10cSrcweir     sal_Int32 nNewColumnCount = m_nColumnCount - 1;
401cdf0e10cSrcweir     sal_Int32 nNewSize( nNewColumnCount * m_nRowCount );
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     double fNan;
404cdf0e10cSrcweir     ::rtl::math::setNan( &fNan );
405cdf0e10cSrcweir     tDataType aNewData( fNan, nNewSize );
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     // copy old data
408cdf0e10cSrcweir     int nCol=0;
409cdf0e10cSrcweir     for( ; nCol<nAtIndex; ++nCol )
410cdf0e10cSrcweir         aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] =
411cdf0e10cSrcweir             static_cast< tDataType >(
412cdf0e10cSrcweir                 m_aData[ ::std::slice( nCol, m_nRowCount, m_nColumnCount ) ] );
413cdf0e10cSrcweir     for( ; nCol<nNewColumnCount; ++nCol )
414cdf0e10cSrcweir         aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] =
415cdf0e10cSrcweir             static_cast< tDataType >(
416cdf0e10cSrcweir                 m_aData[ ::std::slice( nCol + 1, m_nRowCount, m_nColumnCount ) ] );
417cdf0e10cSrcweir 
418cdf0e10cSrcweir     m_nColumnCount = nNewColumnCount;
419cdf0e10cSrcweir     m_aData.resize( nNewSize );
420cdf0e10cSrcweir     m_aData = aNewData;
421cdf0e10cSrcweir 
422cdf0e10cSrcweir     // labels
423cdf0e10cSrcweir     if( nAtIndex < static_cast< sal_Int32 >( m_aColumnLabels.size()))
424cdf0e10cSrcweir         m_aColumnLabels.erase( m_aColumnLabels.begin() + nAtIndex );
425cdf0e10cSrcweir 
426cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2
427cdf0e10cSrcweir     traceData();
428cdf0e10cSrcweir #endif
429cdf0e10cSrcweir }
430cdf0e10cSrcweir 
deleteRow(sal_Int32 nAtIndex)431cdf0e10cSrcweir void InternalData::deleteRow( sal_Int32 nAtIndex )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir     OSL_ASSERT( nAtIndex < m_nRowCount && nAtIndex >= 0 );
434cdf0e10cSrcweir     if( nAtIndex >= m_nRowCount || m_nRowCount < 1 || nAtIndex < 0 )
435cdf0e10cSrcweir         return;
436cdf0e10cSrcweir     sal_Int32 nNewRowCount = m_nRowCount - 1;
437cdf0e10cSrcweir     sal_Int32 nNewSize( m_nColumnCount * nNewRowCount );
438cdf0e10cSrcweir 
439cdf0e10cSrcweir     double fNan;
440cdf0e10cSrcweir     ::rtl::math::setNan( &fNan );
441cdf0e10cSrcweir     tDataType aNewData( fNan, nNewSize );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir     // copy old data
444cdf0e10cSrcweir     sal_Int32 nIndex = nAtIndex;
445cdf0e10cSrcweir     if( nIndex )
446cdf0e10cSrcweir         aNewData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] =
447cdf0e10cSrcweir             static_cast< tDataType >(
448cdf0e10cSrcweir                 m_aData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] );
449cdf0e10cSrcweir 
450cdf0e10cSrcweir     if( nIndex < nNewRowCount )
451cdf0e10cSrcweir     {
452cdf0e10cSrcweir         sal_Int32 nRemainingCount = m_nColumnCount * (nNewRowCount - nIndex);
453cdf0e10cSrcweir         aNewData[ ::std::slice( nIndex * m_nColumnCount, nRemainingCount, 1 ) ] =
454cdf0e10cSrcweir             static_cast< tDataType >(
455cdf0e10cSrcweir                 m_aData[ ::std::slice( (nIndex + 1) * m_nColumnCount, nRemainingCount, 1 ) ] );
456cdf0e10cSrcweir     }
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     m_nRowCount = nNewRowCount;
459cdf0e10cSrcweir     m_aData.resize( nNewSize );
460cdf0e10cSrcweir     m_aData = aNewData;
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     // labels
463cdf0e10cSrcweir     if( nAtIndex < static_cast< sal_Int32 >( m_aRowLabels.size()))
464cdf0e10cSrcweir         m_aRowLabels.erase( m_aRowLabels.begin() + nAtIndex );
465cdf0e10cSrcweir 
466cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2
467cdf0e10cSrcweir     traceData();
468cdf0e10cSrcweir #endif
469cdf0e10cSrcweir }
470cdf0e10cSrcweir 
getRowCount() const471cdf0e10cSrcweir sal_Int32 InternalData::getRowCount() const
472cdf0e10cSrcweir {
473cdf0e10cSrcweir     return m_nRowCount;
474cdf0e10cSrcweir }
475cdf0e10cSrcweir 
getColumnCount() const476cdf0e10cSrcweir sal_Int32 InternalData::getColumnCount() const
477cdf0e10cSrcweir {
478cdf0e10cSrcweir     return m_nColumnCount;
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
setComplexRowLabels(const vector<vector<uno::Any>> & rNewRowLabels)481cdf0e10cSrcweir void InternalData::setComplexRowLabels( const vector< vector< uno::Any > >& rNewRowLabels )
482cdf0e10cSrcweir {
483cdf0e10cSrcweir     m_aRowLabels = rNewRowLabels;
484cdf0e10cSrcweir     sal_Int32 nNewRowCount = static_cast< sal_Int32 >( m_aRowLabels.size() );
485cdf0e10cSrcweir     if( nNewRowCount < m_nRowCount )
486cdf0e10cSrcweir         m_aRowLabels.resize( m_nRowCount );
487cdf0e10cSrcweir     else
488cdf0e10cSrcweir         enlargeData( 0, nNewRowCount );
489cdf0e10cSrcweir }
490cdf0e10cSrcweir 
getComplexRowLabels() const491cdf0e10cSrcweir vector< vector< uno::Any > > InternalData::getComplexRowLabels() const
492cdf0e10cSrcweir {
493cdf0e10cSrcweir     return m_aRowLabels;
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
setComplexColumnLabels(const vector<vector<uno::Any>> & rNewColumnLabels)496cdf0e10cSrcweir void InternalData::setComplexColumnLabels( const vector< vector< uno::Any > >& rNewColumnLabels )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir     m_aColumnLabels = rNewColumnLabels;
499cdf0e10cSrcweir     sal_Int32 nNewColumnCount = static_cast< sal_Int32 >( m_aColumnLabels.size() );
500cdf0e10cSrcweir     if( nNewColumnCount < m_nColumnCount )
501cdf0e10cSrcweir         m_aColumnLabels.resize( m_nColumnCount );
502cdf0e10cSrcweir     else
503cdf0e10cSrcweir         enlargeData( nNewColumnCount, 0 );
504cdf0e10cSrcweir }
505cdf0e10cSrcweir 
getComplexColumnLabels() const506cdf0e10cSrcweir vector< vector< uno::Any > > InternalData::getComplexColumnLabels() const
507cdf0e10cSrcweir {
508cdf0e10cSrcweir     return m_aColumnLabels;
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2
traceData() const512cdf0e10cSrcweir void InternalData::traceData() const
513cdf0e10cSrcweir {
514cdf0e10cSrcweir     OSL_TRACE( "InternalData: Data in rows\n" );
515cdf0e10cSrcweir 
516cdf0e10cSrcweir     for( sal_Int32 i=0; i<m_nRowCount; ++i )
517cdf0e10cSrcweir     {
518cdf0e10cSrcweir         tDataType aSlice( m_aData[ ::std::slice( i*m_nColumnCount, m_nColumnCount, 1 ) ] );
519cdf0e10cSrcweir         for( sal_Int32 j=0; j<m_nColumnCount; ++j )
520cdf0e10cSrcweir             OSL_TRACE( "%lf ", aSlice[j] );
521cdf0e10cSrcweir         OSL_TRACE( "\n" );
522cdf0e10cSrcweir     }
523cdf0e10cSrcweir     OSL_TRACE( "\n" );
524cdf0e10cSrcweir }
525cdf0e10cSrcweir #endif
526cdf0e10cSrcweir 
527cdf0e10cSrcweir } //  namespace chart
528