merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / model / template / ChartTypeTemplate.hxx
blob3f43e0ca603843f8fb45535981d16cb7c4b42c16
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifndef CHART_CHARTTYPETEMPLATE_HXX
28 #define CHART_CHARTTYPETEMPLATE_HXX
30 #include <cppuhelper/implbase2.hxx>
31 #include "ServiceMacros.hxx"
32 #include "DataInterpreter.hxx"
33 #include "StackMode.hxx"
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <com/sun/star/chart2/XChartTypeTemplate.hpp>
36 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
37 #include <com/sun/star/chart2/XLegend.hpp>
38 #include <com/sun/star/lang/XServiceName.hpp>
39 #include <com/sun/star/chart2/XChartType.hpp>
40 #include <com/sun/star/chart2/XDataSeries.hpp>
42 #include <utility>
44 namespace chart
47 /** For creating diagrams and modifying existing diagrams. A base class that
48 implements XChartTypeTemplate and offers some tooling for classes that
49 derive from this class.
51 createDiagramByDataSource
52 -------------------------
54 This does the following steps using some virtual helper-methods, that may be
55 overloaded by derived classes:
57 * creates an XDiagram via service-factory.
59 * convert the given XDataSource to a sequence of XDataSeries using the
60 method createDataSeries(). In this class the DataInterpreter helper class
61 is used to create a standard interpretation (just y-values).
63 * call applyDefaultStyle() for all XDataSeries in order to apply default
64 styles. In this class the series get the system-wide default colors as
65 "Color" property.
67 * call applyStyle() for applying chart-type specific styles to all series.
68 The default implementation is empty.
70 * call createCoordinateSystems() and apply them to the diagram. As
71 default one cartesian system with Scales using a linear Scaling is
72 created.
74 * createChartTypes() is called in order to define the structure of the
75 diagram. For details see comment of this function. As default this
76 method creates a tree where all series appear in one branch with the chart
77 type determined by getChartTypeForNewSeries(). The stacking is determined
78 via the method getStackMode().
80 * create an XLegend via the global service factory, set it at the diagram.
82 class ChartTypeTemplate : public ::cppu::WeakImplHelper2<
83 ::com::sun::star::chart2::XChartTypeTemplate,
84 ::com::sun::star::lang::XServiceName >
86 public:
87 explicit ChartTypeTemplate(
88 ::com::sun::star::uno::Reference<
89 ::com::sun::star::uno::XComponentContext > const & xContext,
90 const ::rtl::OUString & rServiceName );
91 virtual ~ChartTypeTemplate();
93 APPHELPER_XSERVICEINFO_DECL()
94 /// establish methods for factory instatiation
95 // APPHELPER_SERVICE_FACTORY_HELPER( ChartTypeTemplate )
97 protected:
98 // ____ XChartTypeTemplate ____
99 virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram > SAL_CALL createDiagramByDataSource(
100 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource,
101 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
102 throw (::com::sun::star::uno::RuntimeException);
103 /// denotes if the chart needs categories at the first scale
104 virtual sal_Bool SAL_CALL supportsCategories()
105 throw (::com::sun::star::uno::RuntimeException);
106 virtual void SAL_CALL changeDiagram(
107 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
108 throw (::com::sun::star::uno::RuntimeException);
109 virtual void SAL_CALL changeDiagramData(
110 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram,
111 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource,
112 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
113 throw (::com::sun::star::uno::RuntimeException);
114 virtual ::sal_Bool SAL_CALL matchesTemplate(
115 const ::com::sun::star::uno::Reference<
116 ::com::sun::star::chart2::XDiagram >& xDiagram,
117 ::sal_Bool bAdaptProperties )
118 throw (::com::sun::star::uno::RuntimeException);
119 // still abstract: getChartTypeForNewSeries()
120 virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataInterpreter > SAL_CALL getDataInterpreter()
121 throw (::com::sun::star::uno::RuntimeException);
122 virtual void SAL_CALL applyStyle(
123 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries,
124 ::sal_Int32 nChartTypeIndex,
125 ::sal_Int32 nSeriesIndex,
126 ::sal_Int32 nSeriesCount )
127 throw (::com::sun::star::uno::RuntimeException);
128 virtual void SAL_CALL resetStyles(
129 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
130 throw (::com::sun::star::uno::RuntimeException);
133 virtual void SAL_CALL applyStyles(
134 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
135 throw (::com::sun::star::uno::RuntimeException);
137 // ____ XServiceName ____
138 virtual ::rtl::OUString SAL_CALL getServiceName()
139 throw (::com::sun::star::uno::RuntimeException);
141 // Methods to overload for automatic creation
142 // ------------------------------------------
144 /// returns 2 by default. Supported are 2 and 3
145 virtual sal_Int32 getDimension() const;
147 /** returns StackMode_NONE by default. This is a global flag used for all
148 series of a specific chart type. If percent stacking is supported, the
149 percent stacking mode is retrieved from the first chart type (index 0)
151 @param nChartTypeIndex denotes the index of the charttype in means
152 defined by the template creation order, i.e., 0 means the first
153 chart type that a template creates.
155 virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const;
157 virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >
158 getChartTypeForIndex( sal_Int32 nChartTypeIndex ) = 0;
160 virtual bool isSwapXAndY() const;
162 // Methods for creating the diagram piecewise
163 // ------------------------------------------
165 /** Allows derived classes to manipulate the diagramas whole, like changing
166 the wall color. The default implementation is empty. It is called by
167 FillDiagram which is called by createDiagramByDataSource and
168 changeDiagram
170 virtual void adaptDiagram(
171 const ::com::sun::star::uno::Reference<
172 ::com::sun::star::chart2::XDiagram > & xDiagram );
174 /** Creates a 2d or 3d cartesian coordinate system with mathematically
175 oriented, linear scales with auto-min/max. If the given
176 CoordinateSystemContainer is not empty, those coordinate system should
177 be reused.
179 <p>The dimension depends on the value returned by getDimension().</p>
181 virtual void createCoordinateSystems(
182 const ::com::sun::star::uno::Reference<
183 ::com::sun::star::chart2::XCoordinateSystemContainer > & xOutCooSysCnt );
185 /** Sets categories at the scales of dimension 0 and the percent stacking at
186 the scales of dimension 1 of all given coordinate systems.
188 <p>Called by FillDiagram.</p>
190 virtual void adaptScales(
191 const ::com::sun::star::uno::Sequence<
192 ::com::sun::star::uno::Reference<
193 ::com::sun::star::chart2::XCoordinateSystem > > & aCooSysSeq,
194 const ::com::sun::star::uno::Reference<
195 ::com::sun::star::chart2::data::XLabeledDataSequence > & xCategories );
197 /** create a data series tree, that fits the requirements of the chart type.
199 <p>As default, this creates a tree with the following structure:</p>
201 <pre>
202 root
204 +-- chart type (determined by getChartTypeForNewSeries())
206 +-- category (DiscreteStackableScaleGroup using scale 0)
208 +-- values (ContinuousStackableScaleGroup using scale 1)
210 +-- series 0
212 +-- series 1
216 +.. series n-1
217 </pre>
219 <p>If there are less than two scales available the returned tree is
220 empty.</p>
222 virtual void createChartTypes(
223 const ::com::sun::star::uno::Sequence<
224 ::com::sun::star::uno::Sequence<
225 ::com::sun::star::uno::Reference<
226 ::com::sun::star::chart2::XDataSeries > > > & aSeriesSeq,
227 const ::com::sun::star::uno::Sequence<
228 ::com::sun::star::uno::Reference<
229 ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys,
230 const ::com::sun::star::uno::Sequence<
231 ::com::sun::star::uno::Reference<
232 ::com::sun::star::chart2::XChartType > > & aOldChartTypesSeq
235 /** create axes and add them to the given container. If there are already
236 compatible axes in the container these should be maintained.
238 <p>As default, this method creates as many axes as there are dimensions
239 in the given first coordinate system. Each of the axis
240 represents one of the dimensions of the coordinate systems. If there are series
241 requesting asecondary axes a secondary y axes is added</p>
243 virtual void createAxes(
244 const ::com::sun::star::uno::Sequence<
245 ::com::sun::star::uno::Reference<
246 ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys );
248 /** Give the number of requested axis per dimension here. Default is one
249 axis for each dimension
251 virtual sal_Int32 getAxisCountByDimension( sal_Int32 nDimension );
253 /** adapt properties of exsisting axes and remove superfluous axes
255 virtual void adaptAxes(
256 const ::com::sun::star::uno::Sequence<
257 ::com::sun::star::uno::Reference<
258 ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys );
260 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
261 GetComponentContext() const;
263 static void copyPropertiesFromOldToNewCoordianteSystem(
264 const ::com::sun::star::uno::Sequence<
265 ::com::sun::star::uno::Reference<
266 ::com::sun::star::chart2::XChartType > > & rOldChartTypesSeq,
267 const ::com::sun::star::uno::Reference<
268 ::com::sun::star::chart2::XChartType > & xNewChartType );
270 protected:
271 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
272 m_xContext;
273 mutable ::com::sun::star::uno::Reference<
274 ::com::sun::star::chart2::XDataInterpreter > m_xDataInterpreter;
276 private:
277 const ::rtl::OUString m_aServiceName;
279 private:
280 /** modifies the given diagram
282 void FillDiagram( const ::com::sun::star::uno::Reference<
283 ::com::sun::star::chart2::XDiagram > & xDiagram,
284 const ::com::sun::star::uno::Sequence<
285 ::com::sun::star::uno::Sequence<
286 ::com::sun::star::uno::Reference<
287 ::com::sun::star::chart2::XDataSeries > > > & aSeriesSeq,
288 ::com::sun::star::uno::Reference<
289 ::com::sun::star::chart2::data::XLabeledDataSequence > xCategories,
290 const ::com::sun::star::uno::Sequence<
291 ::com::sun::star::uno::Reference<
292 ::com::sun::star::chart2::XChartType > > & aOldChartTypesSeq,
293 bool bCreate );
296 } // namespace chart
298 // CHART_CHARTTYPETEMPLATE_HXX
299 #endif