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