xref: /trunk/main/chart2/source/model/template/ColumnLineDataInterpreter.cxx (revision 9d37da743abb7db0a497688391f6e55a19f27c44)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chartmodel.hxx"
26 
27 #include "ColumnLineDataInterpreter.hxx"
28 #include "DataSeries.hxx"
29 #include "macros.hxx"
30 #include "DataSeriesHelper.hxx"
31 #include "CommonConverters.hxx"
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/chart2/data/XDataSink.hpp>
34 
35 // #include <deque>
36 
37 #include <vector>
38 #include <algorithm>
39 #include <iterator>
40 
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::chart2;
43 using namespace ::std;
44 
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::Sequence;
47 using ::rtl::OUString;
48 
49 namespace chart
50 {
51 
52 // explicit
53 ColumnLineDataInterpreter::ColumnLineDataInterpreter(
54     sal_Int32 nNumberOfLines,
55     const Reference< uno::XComponentContext > & xContext ) :
56         DataInterpreter( xContext ),
57         m_nNumberOfLines( nNumberOfLines )
58 {}
59 
60 ColumnLineDataInterpreter::~ColumnLineDataInterpreter()
61 {}
62 
63 // ____ XDataInterpreter ____
64 InterpretedData SAL_CALL ColumnLineDataInterpreter::interpretDataSource(
65     const Reference< data::XDataSource >& xSource,
66     const Sequence< beans::PropertyValue >& aArguments,
67     const Sequence< Reference< XDataSeries > >& aSeriesToReUse )
68 {
69     InterpretedData aResult(  DataInterpreter::interpretDataSource( xSource, aArguments, aSeriesToReUse ));
70 
71     // the base class should return one group
72     OSL_ASSERT( aResult.Series.getLength() == 1 );
73     if( aResult.Series.getLength() == 1 )
74     {
75         sal_Int32 nNumberOfSeries = aResult.Series[0].getLength();
76 
77         // if we have more than one series put the last nNumOfLines ones into a new group
78         if( nNumberOfSeries > 1 && m_nNumberOfLines > 0 )
79         {
80             sal_Int32 nNumOfLines = ::std::min( m_nNumberOfLines, nNumberOfSeries - 1 );
81             aResult.Series.realloc(2);
82 
83             Sequence< Reference< XDataSeries > > & rColumnDataSeries = aResult.Series[0];
84             Sequence< Reference< XDataSeries > > & rLineDataSeries   = aResult.Series[1];
85             rLineDataSeries.realloc( nNumOfLines );
86             ::std::copy( rColumnDataSeries.getConstArray() + nNumberOfSeries - nNumOfLines,
87                          rColumnDataSeries.getConstArray() + nNumberOfSeries,
88                          rLineDataSeries.getArray() );
89             rColumnDataSeries.realloc( nNumberOfSeries - nNumOfLines );
90         }
91     }
92 
93     return aResult;
94 }
95 
96 } // namespace chart
97