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_chart2.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
ColumnLineDataInterpreter(sal_Int32 nNumberOfLines,const Reference<uno::XComponentContext> & xContext)53 ColumnLineDataInterpreter::ColumnLineDataInterpreter(
54     sal_Int32 nNumberOfLines,
55     const Reference< uno::XComponentContext > & xContext ) :
56         DataInterpreter( xContext ),
57         m_nNumberOfLines( nNumberOfLines )
58 {}
59 
~ColumnLineDataInterpreter()60 ColumnLineDataInterpreter::~ColumnLineDataInterpreter()
61 {}
62 
63 // ____ XDataInterpreter ____
interpretDataSource(const Reference<data::XDataSource> & xSource,const Sequence<beans::PropertyValue> & aArguments,const Sequence<Reference<XDataSeries>> & aSeriesToReUse)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     throw (uno::RuntimeException)
69 {
70     InterpretedData aResult(  DataInterpreter::interpretDataSource( xSource, aArguments, aSeriesToReUse ));
71 
72     // the base class should return one group
73     OSL_ASSERT( aResult.Series.getLength() == 1 );
74     if( aResult.Series.getLength() == 1 )
75     {
76         sal_Int32 nNumberOfSeries = aResult.Series[0].getLength();
77 
78         // if we have more than one series put the last nNumOfLines ones into a new group
79         if( nNumberOfSeries > 1 && m_nNumberOfLines > 0 )
80         {
81             sal_Int32 nNumOfLines = ::std::min( m_nNumberOfLines, nNumberOfSeries - 1 );
82             aResult.Series.realloc(2);
83 
84             Sequence< Reference< XDataSeries > > & rColumnDataSeries = aResult.Series[0];
85             Sequence< Reference< XDataSeries > > & rLineDataSeries   = aResult.Series[1];
86             rLineDataSeries.realloc( nNumOfLines );
87             ::std::copy( rColumnDataSeries.getConstArray() + nNumberOfSeries - nNumOfLines,
88                          rColumnDataSeries.getConstArray() + nNumberOfSeries,
89                          rLineDataSeries.getArray() );
90             rColumnDataSeries.realloc( nNumberOfSeries - nNumOfLines );
91         }
92     }
93 
94     return aResult;
95 }
96 
97 } // namespace chart
98