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 #ifndef CHART_CHARTTYPETEMPLATE_HXX
24 #define CHART_CHARTTYPETEMPLATE_HXX
25 
26 #include <cppuhelper/implbase2.hxx>
27 #include "ServiceMacros.hxx"
28 #include "DataInterpreter.hxx"
29 #include "StackMode.hxx"
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <com/sun/star/chart2/XChartTypeTemplate.hpp>
32 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
33 #include <com/sun/star/chart2/XLegend.hpp>
34 #include <com/sun/star/lang/XServiceName.hpp>
35 #include <com/sun/star/chart2/XChartType.hpp>
36 #include <com/sun/star/chart2/XDataSeries.hpp>
37 
38 #include <utility>
39 
40 namespace chart
41 {
42 
43 /** For creating diagrams and modifying existing diagrams.  A base class that
44     implements XChartTypeTemplate and offers some tooling for classes that
45     derive from this class.
46 
47     createDiagramByDataSource
48     -------------------------
49 
50     This does the following steps using some virtual helper-methods, that may be
51     overloaded by derived classes:
52 
53     * creates an XDiagram via service-factory.
54 
55     * convert the given XDataSource to a sequence of XDataSeries using the
56       method createDataSeries().  In this class the DataInterpreter helper class
57       is used to create a standard interpretation (just y-values).
58 
59     * call applyDefaultStyle() for all XDataSeries in order to apply default
60       styles.  In this class the series get the system-wide default colors as
61       "Color" property.
62 
63     * call applyStyle() for applying chart-type specific styles to all series.
64       The default implementation is empty.
65 
66     * call createCoordinateSystems() and apply them to the diagram.  As
67       default one cartesian system with Scales using a linear Scaling is
68       created.
69 
70     * createChartTypes() is called in order to define the structure of the
71       diagram.  For details see comment of this function.  As default this
72       method creates a tree where all series appear in one branch with the chart
73       type determined by getChartTypeForNewSeries().  The stacking is determined
74       via the method getStackMode().
75 
76     * create an XLegend via the global service factory, set it at the diagram.
77  */
78 class ChartTypeTemplate : public ::cppu::WeakImplHelper2<
79         ::com::sun::star::chart2::XChartTypeTemplate,
80         ::com::sun::star::lang::XServiceName >
81 {
82 public:
83 	explicit ChartTypeTemplate(
84         ::com::sun::star::uno::Reference<
85             ::com::sun::star::uno::XComponentContext > const & xContext,
86         const ::rtl::OUString & rServiceName );
87 	virtual ~ChartTypeTemplate();
88 
89     APPHELPER_XSERVICEINFO_DECL()
90     /// establish methods for factory instatiation
91 // 	APPHELPER_SERVICE_FACTORY_HELPER( ChartTypeTemplate )
92 
93 protected:
94     // ____ XChartTypeTemplate ____
95     virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram > SAL_CALL createDiagramByDataSource(
96         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource,
97         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
98         throw (::com::sun::star::uno::RuntimeException);
99     /// denotes if the chart needs categories at the first scale
100     virtual sal_Bool SAL_CALL supportsCategories()
101         throw (::com::sun::star::uno::RuntimeException);
102     virtual void SAL_CALL changeDiagram(
103         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
104         throw (::com::sun::star::uno::RuntimeException);
105     virtual void SAL_CALL changeDiagramData(
106         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram,
107         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource,
108         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
109         throw (::com::sun::star::uno::RuntimeException);
110     virtual ::sal_Bool SAL_CALL matchesTemplate(
111         const ::com::sun::star::uno::Reference<
112         ::com::sun::star::chart2::XDiagram >& xDiagram,
113         ::sal_Bool bAdaptProperties )
114         throw (::com::sun::star::uno::RuntimeException);
115     // still abstract: getChartTypeForNewSeries()
116     virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataInterpreter > SAL_CALL getDataInterpreter()
117         throw (::com::sun::star::uno::RuntimeException);
118     virtual void SAL_CALL applyStyle(
119         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries,
120         ::sal_Int32 nChartTypeIndex,
121         ::sal_Int32 nSeriesIndex,
122         ::sal_Int32 nSeriesCount )
123         throw (::com::sun::star::uno::RuntimeException);
124     virtual void SAL_CALL resetStyles(
125         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
126         throw (::com::sun::star::uno::RuntimeException);
127 
128     //
129     virtual void SAL_CALL applyStyles(
130         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
131         throw (::com::sun::star::uno::RuntimeException);
132 
133     // ____ XServiceName ____
134     virtual ::rtl::OUString SAL_CALL getServiceName()
135         throw (::com::sun::star::uno::RuntimeException);
136 
137     // Methods to overload for automatic creation
138     // ------------------------------------------
139 
140     /// returns 2 by default.  Supported are 2 and 3
141     virtual sal_Int32 getDimension() const;
142 
143     /** returns StackMode_NONE by default.  This is a global flag used for all
144         series of a specific chart type.  If percent stacking is supported, the
145         percent stacking mode is retrieved from the first chart type (index 0)
146 
147         @param nChartTypeIndex denotes the index of the charttype in means
148             defined by the template creation order, i.e., 0 means the first
149             chart type that a template creates.
150      */
151     virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const;
152 
153     virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >
154                 getChartTypeForIndex( sal_Int32 nChartTypeIndex ) = 0;
155 
156     virtual bool isSwapXAndY() const;
157 
158     // Methods for creating the diagram piecewise
159     // ------------------------------------------
160 
161     /** Allows derived classes to manipulate the diagramas whole, like changing
162         the wall color. The default implementation is empty. It is called by
163         FillDiagram which is called by createDiagramByDataSource and
164         changeDiagram
165      */
166     virtual void adaptDiagram(
167         const ::com::sun::star::uno::Reference<
168             ::com::sun::star::chart2::XDiagram > & xDiagram );
169 
170     /** Creates a 2d or 3d cartesian coordinate system with mathematically
171         oriented, linear scales with auto-min/max.  If the given
172         CoordinateSystemContainer is not empty, those coordinate system should
173         be reused.
174 
175         <p>The dimension depends on the value returned by getDimension().</p>
176      */
177     virtual void createCoordinateSystems(
178         const ::com::sun::star::uno::Reference<
179             ::com::sun::star::chart2::XCoordinateSystemContainer > & xOutCooSysCnt );
180 
181     /** Sets categories at the scales of dimension 0 and the percent stacking at
182         the scales of dimension 1 of all given coordinate systems.
183 
184         <p>Called by FillDiagram.</p>
185      */
186     virtual void adaptScales(
187         const ::com::sun::star::uno::Sequence<
188             ::com::sun::star::uno::Reference<
189                 ::com::sun::star::chart2::XCoordinateSystem > > & aCooSysSeq,
190         const ::com::sun::star::uno::Reference<
191             ::com::sun::star::chart2::data::XLabeledDataSequence > & xCategories );
192 
193     /** create a data series tree, that fits the requirements of the chart type.
194 
195         <p>As default, this creates a tree with the following structure:</p>
196 
197         <pre>
198           root
199            |
200            +-- chart type (determined by getChartTypeForNewSeries())
201                    |
202                    +-- category (DiscreteStackableScaleGroup using scale 0)
203                           |
204                           +-- values (ContinuousStackableScaleGroup using scale 1)
205                                 |
206                                 +-- series 0
207                                 |
208                                 +-- series 1
209                                 |
210                                 ...
211                                 |
212                                 +.. series n-1
213         </pre>
214 
215         <p>If there are less than two scales available the returned tree is
216         empty.</p>
217      */
218     virtual void createChartTypes(
219             const ::com::sun::star::uno::Sequence<
220                 ::com::sun::star::uno::Sequence<
221                     ::com::sun::star::uno::Reference<
222                         ::com::sun::star::chart2::XDataSeries > > > & aSeriesSeq,
223             const ::com::sun::star::uno::Sequence<
224                 ::com::sun::star::uno::Reference<
225                     ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys,
226             const ::com::sun::star::uno::Sequence<
227                       ::com::sun::star::uno::Reference<
228                           ::com::sun::star::chart2::XChartType > > & aOldChartTypesSeq
229             );
230 
231     /** create axes and add them to the given container. If there are already
232         compatible axes in the container these should be maintained.
233 
234         <p>As default, this method creates as many axes as there are dimensions
235         in the given first coordinate system.  Each of the axis
236         represents one of the dimensions of the coordinate systems. If there are series
237         requesting asecondary axes a secondary y axes is added</p>
238      */
239     virtual void createAxes(
240         const ::com::sun::star::uno::Sequence<
241             ::com::sun::star::uno::Reference<
242                 ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys );
243 
244     /** Give the number of requested axis per dimension here.  Default is one
245         axis for each dimension
246      */
247     virtual sal_Int32 getAxisCountByDimension( sal_Int32 nDimension );
248 
249     /** adapt properties of exsisting axes and remove superfluous axes
250     */
251     virtual void adaptAxes(
252         const ::com::sun::star::uno::Sequence<
253             ::com::sun::star::uno::Reference<
254                 ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys );
255 
256     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
257         GetComponentContext() const;
258 
259     static void copyPropertiesFromOldToNewCoordianteSystem(
260                     const ::com::sun::star::uno::Sequence<
261                       ::com::sun::star::uno::Reference<
262                           ::com::sun::star::chart2::XChartType > > & rOldChartTypesSeq,
263                     const ::com::sun::star::uno::Reference<
264                           ::com::sun::star::chart2::XChartType > & xNewChartType );
265 
266 protected:
267     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
268         m_xContext;
269     mutable ::com::sun::star::uno::Reference<
270             ::com::sun::star::chart2::XDataInterpreter > m_xDataInterpreter;
271 
272 private:
273     const ::rtl::OUString m_aServiceName;
274 
275 private:
276     /** modifies the given diagram
277      */
278     void FillDiagram( const ::com::sun::star::uno::Reference<
279                           ::com::sun::star::chart2::XDiagram > & xDiagram,
280                       const ::com::sun::star::uno::Sequence<
281                           ::com::sun::star::uno::Sequence<
282                               ::com::sun::star::uno::Reference<
283                                   ::com::sun::star::chart2::XDataSeries > > > & aSeriesSeq,
284                       ::com::sun::star::uno::Reference<
285                           ::com::sun::star::chart2::data::XLabeledDataSequence > xCategories,
286                       const ::com::sun::star::uno::Sequence<
287                               ::com::sun::star::uno::Reference<
288                                   ::com::sun::star::chart2::XChartType > > & aOldChartTypesSeq,
289                       bool bCreate );
290 };
291 
292 } //  namespace chart
293 
294 // CHART_CHARTTYPETEMPLATE_HXX
295 #endif
296