1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VSeriesPlotter.hxx,v $
10 * $Revision: 1.25.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _CHART2_VSERIESPLOTTER_HXX
31 #define _CHART2_VSERIESPLOTTER_HXX
33 #include "PlotterBase.hxx"
34 #include "VDataSeries.hxx"
35 #include "LabelAlignment.hxx"
36 #include "MinimumAndMaximumSupplier.hxx"
37 #include "LegendEntryProvider.hxx"
38 #include <com/sun/star/chart2/LegendSymbolStyle.hpp>
39 #include <com/sun/star/chart2/XChartType.hpp>
40 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
41 #include <com/sun/star/drawing/Direction3D.hpp>
44 namespace com
{ namespace sun
{ namespace star
{
46 class XNumberFormatsSupplier
;
50 class XRegressionCurveCalculator
;
54 //.............................................................................
57 //.............................................................................
59 class NumberFormatterWrapper
;
61 class AxesNumberFormats
64 AxesNumberFormats() {};
66 void setFormat( sal_Int32 nFormatKey
, sal_Int32 nDimIndex
, sal_Int32 nAxisIndex
)
68 m_aNumberFormatMap
[tFullAxisIndex(nDimIndex
,nAxisIndex
)] = nFormatKey
;
70 sal_Int32
hasFormat( sal_Int32 nDimIndex
, sal_Int32 nAxisIndex
) const
72 return (m_aNumberFormatMap
.find(tFullAxisIndex(nDimIndex
,nAxisIndex
)) !=m_aNumberFormatMap
.end());
74 sal_Int32
getFormat( sal_Int32 nDimIndex
, sal_Int32 nAxisIndex
) const
76 tNumberFormatMap::const_iterator aIt
= m_aNumberFormatMap
.find(tFullAxisIndex(nDimIndex
,nAxisIndex
));
77 if( aIt
!=m_aNumberFormatMap
.end() )
83 typedef std::pair
< sal_Int32
, sal_Int32
> tFullAxisIndex
;
84 typedef std::map
< tFullAxisIndex
, sal_Int32
> tNumberFormatMap
;
85 tNumberFormatMap m_aNumberFormatMap
;
88 //-----------------------------------------------------------------------------
92 //enum StackType { STACK_NORMAL, STACK_NONE, STACK_BESIDES, STACK_ONTOP, STACK_BEHIND };
94 class VDataSeriesGroup
96 //a list of series that have the same CoordinateSystem
97 //they are used to be plotted maybe in a stacked manner by a plotter
101 VDataSeriesGroup( VDataSeries
* pSeries
);
102 virtual ~VDataSeriesGroup();
104 void addSeries( VDataSeries
* pSeries
);//takes ownership of pSeries
105 sal_Int32
getSeriesCount() const;
108 sal_Int32
getPointCount() const;
109 sal_Int32
getAttachedAxisIndexForFirstSeries() const;
111 void getMinimumAndMaximiumX( double& rfMinimum
, double& rfMaximum
) const;
112 void getMinimumAndMaximiumYInContinuousXRange( double& rfMinY
, double& rfMaxY
, double fMinX
, double fMaxX
, sal_Int32 nAxisIndex
) const;
114 void calculateYMinAndMaxForCategory( sal_Int32 nCategoryIndex
115 , bool bSeperateStackingForDifferentSigns
116 , double& rfMinimumY
, double& rfMaximumY
, sal_Int32 nAxisIndex
);
117 void calculateYMinAndMaxForCategoryRange( sal_Int32 nStartCategoryIndex
, sal_Int32 nEndCategoryIndex
118 , bool bSeperateStackingForDifferentSigns
119 , double& rfMinimumY
, double& rfMaximumY
, sal_Int32 nAxisIndex
);
121 ::std::vector
< VDataSeries
* > m_aSeriesVector
;
134 mutable bool m_bMaxPointCountDirty
;
135 mutable sal_Int32 m_nMaxPointCount
;
136 typedef std::map
< sal_Int32
, CachedYValues
> tCachedYValuesPerAxisIndexMap
;
137 mutable ::std::vector
< tCachedYValuesPerAxisIndexMap
> m_aListOfCachedYValues
;
140 class VSeriesPlotter
: public PlotterBase
, public MinimumAndMaximumSupplier
, public LegendEntryProvider
142 //-------------------------------------------------------------------------
144 //-------------------------------------------------------------------------
146 virtual ~VSeriesPlotter();
149 * A new series can be positioned relative to other series in a chart.
150 * This positioning has two dimensions. First a series can be placed
151 * next to each other on the category axis. This position is indicated by xSlot.
152 * Second a series can be stacked on top of another. This position is indicated by ySlot.
153 * The positions are counted from 0 on.
154 * xSlot < 0 : append the series to already existing x series
155 * xSlot > occupied : append the series to already existing x series
157 * If the xSlot is already occupied the given ySlot decides what should happen:
158 * ySlot < -1 : move all existing series in the xSlot to next slot
159 * ySlot == -1 : stack on top at given x position
160 * ySlot == already occupied : insert at given y and x position
161 * ySlot > occupied : stack on top at given x position
163 virtual void addSeries( VDataSeries
* pSeries
, sal_Int32 zSlot
= -1, sal_Int32 xSlot
= -1,sal_Int32 ySlot
= -1 );
165 /** a value <= 0 for a directions means that this direction can be stretched arbitrary
167 virtual ::com::sun::star::drawing::Direction3D
getPreferredDiagramAspectRatio() const;
168 virtual bool keepAspectRatio() const;
170 /** this enables you to handle series on the same x axis with different y axis
171 the property AttachedAxisIndex at a dataseries indicates which value scale is to use
172 (0==AttachedAxisIndex or a not set AttachedAxisIndex property indicates that this series should be scaled at the main y-axis;
173 1==AttachedAxisIndex indicates that the series should be scaled at the first secondary axis if there is any otherwise at the main y axis
175 The parameter nAxisIndex matches this DataSereis property 'AttachedAxisIndex'.
176 nAxisIndex must be greater than 0. nAxisIndex==1 referres to the first secondary axis.
180 virtual void SAL_CALL
addSecondaryValueScale( const
181 ::com::sun::star::chart2::ExplicitScaleData
& rScale
, sal_Int32 nAxisIndex
)
182 throw (::com::sun::star::uno::RuntimeException
);
184 //-------------------------------------------------------------------------
185 // MinimumAndMaximumSupplier
186 //-------------------------------------------------------------------------
188 virtual double getMinimumX();
189 virtual double getMaximumX();
191 virtual double getMinimumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
);
192 virtual double getMaximumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
);
194 virtual double getMinimumZ();
195 virtual double getMaximumZ();
197 virtual bool isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex
);
198 virtual bool isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex
);
199 virtual bool isExpandWideValuesToZero( sal_Int32 nDimensionIndex
);
200 virtual bool isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex
);
201 virtual bool isSeperateStackingForDifferentSigns( sal_Int32 nDimensionIndex
);
205 void getMinimumAndMaximiumX( double& rfMinimum
, double& rfMaximum
) const;
206 void getMinimumAndMaximiumYInContinuousXRange( double& rfMinY
, double& rfMaxY
, double fMinX
, double fMaxX
, sal_Int32 nAxisIndex
) const;
208 //-------------------------------------------------------------------------
209 //-------------------------------------------------------------------------
211 virtual ::com::sun::star::uno::Sequence
<
212 ::com::sun::star::chart2::ViewLegendEntry
> SAL_CALL
createLegendEntries(
213 ::com::sun::star::chart2::LegendExpansion eLegendExpansion
,
214 const ::com::sun::star::uno::Reference
<
215 ::com::sun::star::beans::XPropertySet
>& xTextProperties
,
216 const ::com::sun::star::uno::Reference
<
217 ::com::sun::star::drawing::XShapes
>& xTarget
,
218 const ::com::sun::star::uno::Reference
<
219 ::com::sun::star::lang::XMultiServiceFactory
>& xShapeFactory
,
220 const ::com::sun::star::uno::Reference
<
221 ::com::sun::star::uno::XComponentContext
>& xContext
223 throw (::com::sun::star::uno::RuntimeException
);
226 virtual ::com::sun::star::chart2::LegendSymbolStyle
getLegendSymbolStyle();
227 virtual ::com::sun::star::uno::Any
getExplicitSymbol( const VDataSeries
& rSeries
, sal_Int32 nPointIndex
=-1/*-1 for series symbol*/ );
229 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
> createLegendSymbolForSeries(
230 const VDataSeries
& rSeries
231 , const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& xTarget
232 , const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xShapeFactory
);
234 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
> createLegendSymbolForPoint(
235 const VDataSeries
& rSeries
236 , sal_Int32 nPointIndex
237 , const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& xTarget
238 , const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xShapeFactory
);
241 ::com::sun::star::chart2::ViewLegendEntry
> SAL_CALL
createLegendEntriesForSeries(
242 const VDataSeries
& rSeries
,
243 const ::com::sun::star::uno::Reference
<
244 ::com::sun::star::beans::XPropertySet
>& xTextProperties
,
245 const ::com::sun::star::uno::Reference
<
246 ::com::sun::star::drawing::XShapes
>& xTarget
,
247 const ::com::sun::star::uno::Reference
<
248 ::com::sun::star::lang::XMultiServiceFactory
>& xShapeFactory
,
249 const ::com::sun::star::uno::Reference
<
250 ::com::sun::star::uno::XComponentContext
>& xContext
254 ::com::sun::star::chart2::ViewLegendEntry
> SAL_CALL
createLegendEntriesForChartType(
255 const ::com::sun::star::uno::Reference
<
256 ::com::sun::star::beans::XPropertySet
>& xTextProperties
,
257 const ::com::sun::star::uno::Reference
<
258 ::com::sun::star::drawing::XShapes
>& xTarget
,
259 const ::com::sun::star::uno::Reference
<
260 ::com::sun::star::lang::XMultiServiceFactory
>& xShapeFactory
,
261 const ::com::sun::star::uno::Reference
<
262 ::com::sun::star::uno::XComponentContext
>& xContext
265 //-------------------------------------------------------------------------
266 //-------------------------------------------------------------------------
268 static VSeriesPlotter
* createSeriesPlotter( const ::com::sun::star::uno::Reference
<
269 ::com::sun::star::chart2::XChartType
>& xChartTypeModel
270 , sal_Int32 nDimensionCount
);
272 sal_Int32
getPointCount() const;
274 void setNumberFormatsSupplier( const ::com::sun::star::uno::Reference
<
275 ::com::sun::star::util::XNumberFormatsSupplier
> & xNumFmtSupplier
);
276 void setAxesNumberFormats( const AxesNumberFormats
& rAxesNumberFormats
) { m_aAxesNumberFormats
= rAxesNumberFormats
; };
278 void setColorScheme( const ::com::sun::star::uno::Reference
<
279 ::com::sun::star::chart2::XColorScheme
>& xColorScheme
);
281 void setExplicitCategoriesProvider( const ::com::sun::star::uno::Reference
<
282 ::com::sun::star::chart2::data::XTextualDataSequence
>& xExplicitCategoriesProvider
);
284 //get series names for the z axis labels
285 ::com::sun::star::uno::Sequence
< rtl::OUString
> getSeriesNames() const;
287 void setPageReferenceSize( const ::com::sun::star::awt::Size
& rPageRefSize
);
288 //better performance for big data
289 void setCoordinateSystemResolution( const ::com::sun::star::uno::Sequence
< sal_Int32
>& rCoordinateSystemResolution
);
290 bool PointsWereSkipped() const;
292 //return the depth for a logic 1
293 double getTransformedDepth() const;
295 void releaseShapes();
297 virtual void rearrangeLabelToAvoidOverlapIfRequested( const ::com::sun::star::awt::Size
& rPageSize
);
299 bool WantToPlotInFrontOfAxisLine();
301 //-------------------------------------------------------------------------
302 //-------------------------------------------------------------------------
303 //-------------------------------------------------------------------------
305 //no default constructor
310 VSeriesPlotter( const ::com::sun::star::uno::Reference
<
311 ::com::sun::star::chart2::XChartType
>& xChartTypeModel
312 , sal_Int32 nDimensionCount
313 , bool bCategoryXAxis
=true );
315 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>
316 getSeriesGroupShape( VDataSeries
* pDataSeries
317 , const::com::sun::star:: uno::Reference
<
318 ::com::sun::star::drawing::XShapes
>& xTarget
);
320 //the following group shapes will be created as children of SeriesGroupShape on demand
321 //they can be used to assure that some parts of a series shape are always in front of others (e.g. symbols in front of lines)
322 //parameter xTarget will be used as parent for the series group shape
323 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>
324 getSeriesGroupShapeFrontChild( VDataSeries
* pDataSeries
325 , const::com::sun::star:: uno::Reference
<
326 ::com::sun::star::drawing::XShapes
>& xTarget
);
327 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>
328 getSeriesGroupShapeBackChild( VDataSeries
* pDataSeries
329 , const::com::sun::star:: uno::Reference
<
330 ::com::sun::star::drawing::XShapes
>& xTarget
);
332 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>
333 getLabelsGroupShape( VDataSeries
& rDataSeries
334 , const::com::sun::star:: uno::Reference
<
335 ::com::sun::star::drawing::XShapes
>& xTarget
);
337 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>
338 getErrorBarsGroupShape( VDataSeries
& rDataSeries
339 , const::com::sun::star:: uno::Reference
<
340 ::com::sun::star::drawing::XShapes
>& xTarget
);
342 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>
343 createDataLabel( const ::com::sun::star::uno::Reference
<
344 ::com::sun::star::drawing::XShapes
>& xTarget
345 , VDataSeries
& rDataSeries
346 , sal_Int32 nPointIndex
349 , const ::com::sun::star::awt::Point
& rScreenPosition2D
350 , LabelAlignment eAlignment
=LABEL_ALIGN_CENTER
351 , sal_Int32 nOffset
=0 );
353 ::rtl::OUString
getLabelTextForValue( VDataSeries
& rDataSeries
354 , sal_Int32 nPointIndex
356 , bool bAsPercentage
);
358 /** creates two T-shaped error bars in both directions (up/down or
359 left/right depending on the bVertical parameter)
364 @param xErrorBarProperties
365 the XPropertySet returned by the DataPoint-property "ErrorBarX" or
369 the index of the data point in rData for which the calculation is
373 for y-error bars this is true, for x-error-bars it is false.
375 virtual void createErrorBar(
376 const ::com::sun::star::uno::Reference
<
377 ::com::sun::star::drawing::XShapes
>& xTarget
378 , const ::com::sun::star::drawing::Position3D
& rPos
379 , const ::com::sun::star::uno::Reference
<
380 ::com::sun::star::beans::XPropertySet
> & xErrorBarProperties
381 , const VDataSeries
& rVDataSeries
386 virtual void createErrorBar_Y( const ::com::sun::star::drawing::Position3D
& rUnscaledLogicPosition
387 , VDataSeries
& rVDataSeries
, sal_Int32 nPointIndex
388 , const ::com::sun::star::uno::Reference
<
389 ::com::sun::star::drawing::XShapes
>& xTarget
);
391 virtual void createRegressionCurvesShapes( VDataSeries
& rVDataSeries
392 , const ::com::sun::star::uno::Reference
<
393 ::com::sun::star::drawing::XShapes
>& xTarget
394 , const ::com::sun::star::uno::Reference
<
395 ::com::sun::star::drawing::XShapes
>& xEquationTarget
396 , bool bMaySkipPointsInRegressionCalculation
);
398 virtual void createRegressionCurveEquationShapes( const ::rtl::OUString
& rEquationCID
399 , const ::com::sun::star::uno::Reference
<
400 ::com::sun::star::beans::XPropertySet
> & xEquationProperties
401 , const ::com::sun::star::uno::Reference
<
402 ::com::sun::star::drawing::XShapes
>& xEquationTarget
403 , const ::com::sun::star::uno::Reference
<
404 ::com::sun::star::chart2::XRegressionCurveCalculator
> & xRegressionCurveCalculator
405 , ::com::sun::star::awt::Point aDefaultPos
);
407 virtual void setMappedProperties(
408 const ::com::sun::star::uno::Reference
<
409 ::com::sun::star::drawing::XShape
>& xTarget
410 , const ::com::sun::star::uno::Reference
<
411 ::com::sun::star::beans::XPropertySet
>& xSource
412 , const tPropertyNameMap
& rMap
413 , tPropertyNameValueMap
* pOverwriteMap
=0 );
415 virtual PlottingPositionHelper
& getPlottingPositionHelper( sal_Int32 nAxisIndex
) const;//nAxisIndex indicates wether the position belongs to the main axis ( nAxisIndex==0 ) or secondary axis ( nAxisIndex==1 )
417 VDataSeries
* getFirstSeries() const;
420 PlottingPositionHelper
* m_pMainPosHelper
;
422 ::com::sun::star::uno::Reference
<
423 ::com::sun::star::chart2::XChartType
> m_xChartTypeModel
;
424 ::com::sun::star::uno::Reference
<
425 ::com::sun::star::beans::XPropertySet
> m_xChartTypeModelProps
;
427 ::std::vector
< ::std::vector
< VDataSeriesGroup
> > m_aZSlots
;
429 bool m_bCategoryXAxis
;//true->xvalues are indices (this would not be necessary if series for category chart wouldn't have x-values)
431 ::std::auto_ptr
< NumberFormatterWrapper
> m_apNumberFormatterWrapper
;
432 AxesNumberFormats m_aAxesNumberFormats
;//direct numberformats on axes, if empty ask the data series instead
434 ::com::sun::star::uno::Reference
<
435 ::com::sun::star::chart2::XColorScheme
> m_xColorScheme
;
437 ::com::sun::star::uno::Reference
<
438 ::com::sun::star::chart2::data::XTextualDataSequence
> m_xExplicitCategoriesProvider
;
440 //better performance for big data
441 ::com::sun::star::uno::Sequence
< sal_Int32
> m_aCoordinateSystemResolution
;
442 bool m_bPointsWereSkipped
;
445 typedef std::map
< sal_Int32
, ::com::sun::star::chart2::ExplicitScaleData
> tSecondaryValueScales
;
446 tSecondaryValueScales m_aSecondaryValueScales
;
448 typedef std::map
< sal_Int32
, PlottingPositionHelper
* > tSecondaryPosHelperMap
;
449 mutable tSecondaryPosHelperMap m_aSecondaryPosHelperMap
;
450 ::com::sun::star::awt::Size m_aPageReferenceSize
;
453 //.............................................................................
455 //.............................................................................