1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _CHART2_VSERIESPLOTTER_HXX
20 #define _CHART2_VSERIESPLOTTER_HXX
22 #include "PlotterBase.hxx"
23 #include "VDataSeries.hxx"
24 #include "LabelAlignment.hxx"
25 #include "MinimumAndMaximumSupplier.hxx"
26 #include "LegendEntryProvider.hxx"
27 #include "ExplicitCategoriesProvider.hxx"
28 #include <com/sun/star/chart2/XChartType.hpp>
29 #include <com/sun/star/drawing/Direction3D.hpp>
32 namespace com
{ namespace sun
{ namespace star
{
34 class XNumberFormatsSupplier
;
38 class XRegressionCurveCalculator
;
44 class NumberFormatterWrapper
;
46 class AxesNumberFormats
49 AxesNumberFormats() {};
51 void setFormat( sal_Int32 nFormatKey
, sal_Int32 nDimIndex
, sal_Int32 nAxisIndex
)
53 m_aNumberFormatMap
[tFullAxisIndex(nDimIndex
,nAxisIndex
)] = nFormatKey
;
55 sal_Int32
hasFormat( sal_Int32 nDimIndex
, sal_Int32 nAxisIndex
) const
57 return (m_aNumberFormatMap
.find(tFullAxisIndex(nDimIndex
,nAxisIndex
)) !=m_aNumberFormatMap
.end());
59 sal_Int32
getFormat( sal_Int32 nDimIndex
, sal_Int32 nAxisIndex
) const
61 tNumberFormatMap::const_iterator aIt
= m_aNumberFormatMap
.find(tFullAxisIndex(nDimIndex
,nAxisIndex
));
62 if( aIt
!=m_aNumberFormatMap
.end() )
68 typedef std::pair
< sal_Int32
, sal_Int32
> tFullAxisIndex
;
69 typedef std::map
< tFullAxisIndex
, sal_Int32
> tNumberFormatMap
;
70 tNumberFormatMap m_aNumberFormatMap
;
74 * A list of series that have the same CoordinateSystem. They are used to be
75 * plotted maybe in a stacked manner by a plotter.
77 class VDataSeriesGroup
81 VDataSeriesGroup( VDataSeries
* pSeries
);
82 virtual ~VDataSeriesGroup();
84 void addSeries( VDataSeries
* pSeries
);//takes ownership of pSeries
85 sal_Int32
getSeriesCount() const;
88 sal_Int32
getPointCount() const;
89 sal_Int32
getAttachedAxisIndexForFirstSeries() const;
91 void getMinimumAndMaximiumX( double& rfMinimum
, double& rfMaximum
) const;
92 void getMinimumAndMaximiumYInContinuousXRange( double& rfMinY
, double& rfMaxY
, double fMinX
, double fMaxX
, sal_Int32 nAxisIndex
) const;
94 void calculateYMinAndMaxForCategory( sal_Int32 nCategoryIndex
95 , bool bSeparateStackingForDifferentSigns
96 , double& rfMinimumY
, double& rfMaximumY
, sal_Int32 nAxisIndex
);
97 void calculateYMinAndMaxForCategoryRange( sal_Int32 nStartCategoryIndex
, sal_Int32 nEndCategoryIndex
98 , bool bSeparateStackingForDifferentSigns
99 , double& rfMinimumY
, double& rfMaximumY
, sal_Int32 nAxisIndex
);
101 ::std::vector
< VDataSeries
* > m_aSeriesVector
;
114 mutable bool m_bMaxPointCountDirty
;
115 mutable sal_Int32 m_nMaxPointCount
;
116 typedef std::map
< sal_Int32
, CachedYValues
> tCachedYValuesPerAxisIndexMap
;
117 mutable ::std::vector
< tCachedYValuesPerAxisIndexMap
> m_aListOfCachedYValues
;
120 class VSeriesPlotter
: public PlotterBase
, public MinimumAndMaximumSupplier
, public LegendEntryProvider
123 virtual ~VSeriesPlotter();
126 * A new series can be positioned relative to other series in a chart.
127 * This positioning has two dimensions. First a series can be placed
128 * next to each other on the category axis. This position is indicated by xSlot.
129 * Second a series can be stacked on top of another. This position is indicated by ySlot.
130 * The positions are counted from 0 on.
131 * xSlot < 0 : append the series to already existing x series
132 * xSlot > occupied : append the series to already existing x series
134 * If the xSlot is already occupied the given ySlot decides what should happen:
135 * ySlot < -1 : move all existing series in the xSlot to next slot
136 * ySlot == -1 : stack on top at given x position
137 * ySlot == already occupied : insert at given y and x position
138 * ySlot > occupied : stack on top at given x position
140 virtual void addSeries( VDataSeries
* pSeries
, sal_Int32 zSlot
= -1, sal_Int32 xSlot
= -1,sal_Int32 ySlot
= -1 );
142 /** a value <= 0 for a directions means that this direction can be stretched arbitrary
144 virtual ::com::sun::star::drawing::Direction3D
getPreferredDiagramAspectRatio() const;
145 virtual bool keepAspectRatio() const;
147 /** this enables you to handle series on the same x axis with different y axis
148 the property AttachedAxisIndex at a dataseries indicates which value scale is to use
149 (0==AttachedAxisIndex or a not set AttachedAxisIndex property indicates that this series should be scaled at the main y-axis;
150 1==AttachedAxisIndex indicates that the series should be scaled at the first secondary axis if there is any otherwise at the main y axis
152 The parameter nAxisIndex matches this DataSereis property 'AttachedAxisIndex'.
153 nAxisIndex must be greater than 0. nAxisIndex==1 referres to the first secondary axis.
157 virtual void addSecondaryValueScale( const ExplicitScaleData
& rScale
, sal_Int32 nAxisIndex
)
158 throw (::com::sun::star::uno::RuntimeException
);
160 //-------------------------------------------------------------------------
161 // MinimumAndMaximumSupplier
162 //-------------------------------------------------------------------------
164 virtual double getMinimumX();
165 virtual double getMaximumX();
167 virtual double getMinimumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
);
168 virtual double getMaximumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
);
170 virtual double getMinimumZ();
171 virtual double getMaximumZ();
173 virtual bool isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex
);
174 virtual bool isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex
);
175 virtual bool isExpandWideValuesToZero( sal_Int32 nDimensionIndex
);
176 virtual bool isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex
);
177 virtual bool isSeparateStackingForDifferentSigns( sal_Int32 nDimensionIndex
);
179 virtual long calculateTimeResolutionOnXAxis();
180 virtual void setTimeResolutionOnXAxis( long nTimeResolution
, const Date
& rNullDate
);
184 void getMinimumAndMaximiumX( double& rfMinimum
, double& rfMaximum
) const;
185 void getMinimumAndMaximiumYInContinuousXRange( double& rfMinY
, double& rfMaxY
, double fMinX
, double fMaxX
, sal_Int32 nAxisIndex
) const;
187 //-------------------------------------------------------------------------
188 //-------------------------------------------------------------------------
190 virtual std::vector
< ViewLegendEntry
> createLegendEntries(
191 const ::com::sun::star::awt::Size
& rEntryKeyAspectRatio
,
192 ::com::sun::star::chart::ChartLegendExpansion eLegendExpansion
,
193 const ::com::sun::star::uno::Reference
<
194 ::com::sun::star::beans::XPropertySet
>& xTextProperties
,
195 const ::com::sun::star::uno::Reference
<
196 ::com::sun::star::drawing::XShapes
>& xTarget
,
197 const ::com::sun::star::uno::Reference
<
198 ::com::sun::star::lang::XMultiServiceFactory
>& xShapeFactory
,
199 const ::com::sun::star::uno::Reference
<
200 ::com::sun::star::uno::XComponentContext
>& xContext
204 virtual LegendSymbolStyle
getLegendSymbolStyle();
205 virtual com::sun::star::awt::Size
getPreferredLegendKeyAspectRatio();
207 virtual ::com::sun::star::uno::Any
getExplicitSymbol( const VDataSeries
& rSeries
, sal_Int32 nPointIndex
=-1/*-1 for series symbol*/ );
209 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
> createLegendSymbolForSeries(
210 const ::com::sun::star::awt::Size
& rEntryKeyAspectRatio
211 , const VDataSeries
& rSeries
212 , const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& xTarget
213 , const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xShapeFactory
);
215 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
> createLegendSymbolForPoint(
216 const ::com::sun::star::awt::Size
& rEntryKeyAspectRatio
217 , const VDataSeries
& rSeries
218 , sal_Int32 nPointIndex
219 , const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>& xTarget
220 , const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xShapeFactory
);
222 virtual std::vector
< ViewLegendEntry
> createLegendEntriesForSeries(
223 const ::com::sun::star::awt::Size
& rEntryKeyAspectRatio
,
224 const VDataSeries
& rSeries
,
225 const ::com::sun::star::uno::Reference
<
226 ::com::sun::star::beans::XPropertySet
>& xTextProperties
,
227 const ::com::sun::star::uno::Reference
<
228 ::com::sun::star::drawing::XShapes
>& xTarget
,
229 const ::com::sun::star::uno::Reference
<
230 ::com::sun::star::lang::XMultiServiceFactory
>& xShapeFactory
,
231 const ::com::sun::star::uno::Reference
<
232 ::com::sun::star::uno::XComponentContext
>& xContext
235 ::std::vector
< VDataSeries
* > getAllSeries();
237 static VSeriesPlotter
* createSeriesPlotter( const ::com::sun::star::uno::Reference
<
238 ::com::sun::star::chart2::XChartType
>& xChartTypeModel
239 , sal_Int32 nDimensionCount
240 , bool bExcludingPositioning
= false /*for pie and donut charts labels and exploded segments are excluded from the given size*/);
242 sal_Int32
getPointCount() const;
244 void setNumberFormatsSupplier( const ::com::sun::star::uno::Reference
<
245 ::com::sun::star::util::XNumberFormatsSupplier
> & xNumFmtSupplier
);
246 void setAxesNumberFormats( const AxesNumberFormats
& rAxesNumberFormats
) { m_aAxesNumberFormats
= rAxesNumberFormats
; };
248 void setColorScheme( const ::com::sun::star::uno::Reference
<
249 ::com::sun::star::chart2::XColorScheme
>& xColorScheme
);
251 void setExplicitCategoriesProvider( ExplicitCategoriesProvider
* pExplicitCategoriesProvider
);
253 //get series names for the z axis labels
254 ::com::sun::star::uno::Sequence
< OUString
> getSeriesNames() const;
256 void setPageReferenceSize( const ::com::sun::star::awt::Size
& rPageRefSize
);
257 //better performance for big data
258 void setCoordinateSystemResolution( const ::com::sun::star::uno::Sequence
< sal_Int32
>& rCoordinateSystemResolution
);
259 bool PointsWereSkipped() const;
261 //return the depth for a logic 1
262 double getTransformedDepth() const;
264 void releaseShapes();
266 virtual void rearrangeLabelToAvoidOverlapIfRequested( const ::com::sun::star::awt::Size
& rPageSize
);
268 bool WantToPlotInFrontOfAxisLine();
269 virtual bool shouldSnapRectToUsedArea();
272 //no default constructor
277 VSeriesPlotter( const ::com::sun::star::uno::Reference
<
278 ::com::sun::star::chart2::XChartType
>& xChartTypeModel
279 , sal_Int32 nDimensionCount
280 , bool bCategoryXAxis
=true );
282 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>
283 getSeriesGroupShape( VDataSeries
* pDataSeries
284 , const::com::sun::star:: uno::Reference
<
285 ::com::sun::star::drawing::XShapes
>& xTarget
);
287 //the following group shapes will be created as children of SeriesGroupShape on demand
288 //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)
289 //parameter xTarget will be used as parent for the series group shape
290 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>
291 getSeriesGroupShapeFrontChild( VDataSeries
* pDataSeries
292 , const::com::sun::star:: uno::Reference
<
293 ::com::sun::star::drawing::XShapes
>& xTarget
);
294 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>
295 getSeriesGroupShapeBackChild( VDataSeries
* pDataSeries
296 , const::com::sun::star:: uno::Reference
<
297 ::com::sun::star::drawing::XShapes
>& xTarget
);
299 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>
300 getLabelsGroupShape( VDataSeries
& rDataSeries
301 , const::com::sun::star:: uno::Reference
<
302 ::com::sun::star::drawing::XShapes
>& xTarget
);
304 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShapes
>
305 getErrorBarsGroupShape( VDataSeries
& rDataSeries
306 , const::com::sun::star:: uno::Reference
<
307 ::com::sun::star::drawing::XShapes
>& xTarget
, bool bYError
);
309 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>
310 createDataLabel( const ::com::sun::star::uno::Reference
<
311 ::com::sun::star::drawing::XShapes
>& xTarget
312 , VDataSeries
& rDataSeries
313 , sal_Int32 nPointIndex
316 , const ::com::sun::star::awt::Point
& rScreenPosition2D
317 , LabelAlignment eAlignment
=LABEL_ALIGN_CENTER
318 , sal_Int32 nOffset
=0 );
320 OUString
getLabelTextForValue( VDataSeries
& rDataSeries
321 , sal_Int32 nPointIndex
323 , bool bAsPercentage
);
325 /** creates two T-shaped error bars in both directions (up/down or
326 left/right depending on the bVertical parameter)
331 @param xErrorBarProperties
332 the XPropertySet returned by the DataPoint-property "ErrorBarX" or
336 the index of the data point in rData for which the calculation is
340 for y-error bars this is true, for x-error-bars it is false.
342 virtual void createErrorBar(
343 const ::com::sun::star::uno::Reference
<
344 ::com::sun::star::drawing::XShapes
>& xTarget
345 , const ::com::sun::star::drawing::Position3D
& rPos
346 , const ::com::sun::star::uno::Reference
<
347 ::com::sun::star::beans::XPropertySet
> & xErrorBarProperties
348 , const VDataSeries
& rVDataSeries
351 , double* pfScaledLogicX
354 virtual void createErrorBar_X( const ::com::sun::star::drawing::Position3D
& rUnscaledLogicPosition
355 , VDataSeries
& rVDataSeries
, sal_Int32 nPointIndex
356 , const ::com::sun::star::uno::Reference
<
357 ::com::sun::star::drawing::XShapes
>& xTarget
358 , double* pfScaledLogicX
=0 );
360 virtual void createErrorBar_Y( const ::com::sun::star::drawing::Position3D
& rUnscaledLogicPosition
361 , VDataSeries
& rVDataSeries
, sal_Int32 nPointIndex
362 , const ::com::sun::star::uno::Reference
<
363 ::com::sun::star::drawing::XShapes
>& xTarget
364 , double* pfScaledLogicX
=0 );
366 virtual void createRegressionCurvesShapes( VDataSeries
& rVDataSeries
367 , const ::com::sun::star::uno::Reference
<
368 ::com::sun::star::drawing::XShapes
>& xTarget
369 , const ::com::sun::star::uno::Reference
<
370 ::com::sun::star::drawing::XShapes
>& xEquationTarget
371 , bool bMaySkipPointsInRegressionCalculation
);
373 virtual void createRegressionCurveEquationShapes( const OUString
& rEquationCID
374 , const ::com::sun::star::uno::Reference
<
375 ::com::sun::star::beans::XPropertySet
> & xEquationProperties
376 , const ::com::sun::star::uno::Reference
<
377 ::com::sun::star::drawing::XShapes
>& xEquationTarget
378 , const ::com::sun::star::uno::Reference
<
379 ::com::sun::star::chart2::XRegressionCurveCalculator
> & xRegressionCurveCalculator
380 , ::com::sun::star::awt::Point aDefaultPos
);
382 virtual void setMappedProperties(
383 const ::com::sun::star::uno::Reference
<
384 ::com::sun::star::drawing::XShape
>& xTarget
385 , const ::com::sun::star::uno::Reference
<
386 ::com::sun::star::beans::XPropertySet
>& xSource
387 , const tPropertyNameMap
& rMap
388 , tPropertyNameValueMap
* pOverwriteMap
=0 );
390 virtual PlottingPositionHelper
& getPlottingPositionHelper( sal_Int32 nAxisIndex
) const;//nAxisIndex indicates whether the position belongs to the main axis ( nAxisIndex==0 ) or secondary axis ( nAxisIndex==1 )
392 VDataSeries
* getFirstSeries() const;
395 PlottingPositionHelper
* m_pMainPosHelper
;
397 ::com::sun::star::uno::Reference
<
398 ::com::sun::star::chart2::XChartType
> m_xChartTypeModel
;
399 ::com::sun::star::uno::Reference
<
400 ::com::sun::star::beans::XPropertySet
> m_xChartTypeModelProps
;
402 ::std::vector
< ::std::vector
< VDataSeriesGroup
> > m_aZSlots
;
404 bool m_bCategoryXAxis
;//true->xvalues are indices (this would not be necessary if series for category chart wouldn't have x-values)
405 long m_nTimeResolution
;
408 ::std::auto_ptr
< NumberFormatterWrapper
> m_apNumberFormatterWrapper
;
409 AxesNumberFormats m_aAxesNumberFormats
;//direct numberformats on axes, if empty ask the data series instead
411 ::com::sun::star::uno::Reference
<
412 ::com::sun::star::chart2::XColorScheme
> m_xColorScheme
;
414 ExplicitCategoriesProvider
* m_pExplicitCategoriesProvider
;
416 //better performance for big data
417 ::com::sun::star::uno::Sequence
< sal_Int32
> m_aCoordinateSystemResolution
;
418 bool m_bPointsWereSkipped
;
421 typedef std::map
< sal_Int32
, ExplicitScaleData
> tSecondaryValueScales
;
422 tSecondaryValueScales m_aSecondaryValueScales
;
424 typedef std::map
< sal_Int32
, PlottingPositionHelper
* > tSecondaryPosHelperMap
;
425 mutable tSecondaryPosHelperMap m_aSecondaryPosHelperMap
;
426 ::com::sun::star::awt::Size m_aPageReferenceSize
;
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */