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