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 INCLUDED_CHART2_SOURCE_VIEW_INC_VSERIESPLOTTER_HXX
20 #define INCLUDED_CHART2_SOURCE_VIEW_INC_VSERIESPLOTTER_HXX
23 #include "PlotterBase.hxx"
24 #include "VDataSeries.hxx"
25 #include "LabelAlignment.hxx"
26 #include "MinimumAndMaximumSupplier.hxx"
27 #include "LegendEntryProvider.hxx"
28 #include <ExplicitCategoriesProvider.hxx>
29 #include <com/sun/star/chart2/XChartType.hpp>
30 #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 bool 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 final
80 VDataSeriesGroup() = delete;
81 VDataSeriesGroup( VDataSeries
* pSeries
);
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 VSeriesPlotter() = delete;
125 virtual ~VSeriesPlotter() override
;
128 * A new series can be positioned relative to other series in a chart.
129 * This positioning has two dimensions. First a series can be placed
130 * next to each other on the category axis. This position is indicated by xSlot.
131 * Second a series can be stacked on top of another. This position is indicated by ySlot.
132 * The positions are counted from 0 on.
133 * xSlot < 0 : append the series to already existing x series
134 * xSlot > occupied : append the series to already existing x series
136 * If the xSlot is already occupied the given ySlot decides what should happen:
137 * ySlot < -1 : move all existing series in the xSlot to next slot
138 * ySlot == -1 : stack on top at given x position
139 * ySlot == already occupied : insert at given y and x position
140 * ySlot > occupied : stack on top at given x position
142 virtual void addSeries( VDataSeries
* pSeries
, sal_Int32 zSlot
, sal_Int32 xSlot
, sal_Int32 ySlot
);
144 /** a value <= 0 for a directions means that this direction can be stretched arbitrary
146 virtual css::drawing::Direction3D
getPreferredDiagramAspectRatio() const;
148 /** this enables you to handle series on the same x axis with different y axis
149 the property AttachedAxisIndex at a dataseries indicates which value scale is to use
150 (0==AttachedAxisIndex or a not set AttachedAxisIndex property indicates that this series should be scaled at the main y-axis;
151 1==AttachedAxisIndex indicates that the series should be scaled at the first secondary axis if there is any otherwise at the main y axis
153 The parameter nAxisIndex matches this DataSeries property 'AttachedAxisIndex'.
154 nAxisIndex must be greater than 0. nAxisIndex==1 refers to the first secondary axis.
157 @throws css::uno::RuntimeException
160 void addSecondaryValueScale( const ExplicitScaleData
& rScale
, sal_Int32 nAxisIndex
);
162 // MinimumAndMaximumSupplier
164 virtual double getMinimumX() override
;
165 virtual double getMaximumX() override
;
167 virtual double getMinimumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
) override
;
168 virtual double getMaximumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
) override
;
170 virtual double getMinimumZ() override
;
171 virtual double getMaximumZ() override
;
173 virtual bool isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex
) override
;
174 virtual bool isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex
) override
;
175 virtual bool isExpandWideValuesToZero( sal_Int32 nDimensionIndex
) override
;
176 virtual bool isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex
) override
;
177 virtual bool isSeparateStackingForDifferentSigns( sal_Int32 nDimensionIndex
) override
;
179 virtual long calculateTimeResolutionOnXAxis() override
;
180 virtual void setTimeResolutionOnXAxis( long nTimeResolution
, const Date
& rNullDate
) override
;
182 void getMinimumAndMaximiumX( double& rfMinimum
, double& rfMaximum
) const;
183 void getMinimumAndMaximiumYInContinuousXRange( double& rfMinY
, double& rfMaxY
, double fMinX
, double fMaxX
, sal_Int32 nAxisIndex
) const;
186 // Methods for handling legends and legend entries.
188 virtual std::vector
< ViewLegendEntry
> createLegendEntries(
189 const css::awt::Size
& rEntryKeyAspectRatio
,
190 css::chart::ChartLegendExpansion eLegendExpansion
,
191 const css::uno::Reference
< css::beans::XPropertySet
>& xTextProperties
,
192 const css::uno::Reference
< css::drawing::XShapes
>& xTarget
,
193 const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xShapeFactory
,
194 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
197 virtual LegendSymbolStyle
getLegendSymbolStyle();
198 virtual css::awt::Size
getPreferredLegendKeyAspectRatio() override
;
200 virtual css::uno::Any
getExplicitSymbol( const VDataSeries
& rSeries
, sal_Int32 nPointIndex
/*-1 for series symbol*/ );
202 css::uno::Reference
< css::drawing::XShape
> createLegendSymbolForSeries(
203 const css::awt::Size
& rEntryKeyAspectRatio
204 , const VDataSeries
& rSeries
205 , const css::uno::Reference
< css::drawing::XShapes
>& xTarget
206 , const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xShapeFactory
);
208 css::uno::Reference
< css::drawing::XShape
> createLegendSymbolForPoint(
209 const css::awt::Size
& rEntryKeyAspectRatio
210 , const VDataSeries
& rSeries
211 , sal_Int32 nPointIndex
212 , const css::uno::Reference
< css::drawing::XShapes
>& xTarget
213 , const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xShapeFactory
);
215 std::vector
< ViewLegendEntry
> createLegendEntriesForSeries(
216 const css::awt::Size
& rEntryKeyAspectRatio
,
217 const VDataSeries
& rSeries
,
218 const css::uno::Reference
< css::beans::XPropertySet
>& xTextProperties
,
219 const css::uno::Reference
< css::drawing::XShapes
>& xTarget
,
220 const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xShapeFactory
,
221 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
224 std::vector
< VDataSeries
* > getAllSeries();
226 // This method creates a series plotter of the requested type; e.g. : return new PieChart ....
227 static VSeriesPlotter
* createSeriesPlotter( const css::uno::Reference
< css::chart2::XChartType
>& xChartTypeModel
228 , sal_Int32 nDimensionCount
229 , bool bExcludingPositioning
/*for pie and donut charts labels and exploded segments are excluded from the given size*/);
231 sal_Int32
getPointCount() const;
233 // Methods for number formats and color schemes
235 void setNumberFormatsSupplier( const css::uno::Reference
< css::util::XNumberFormatsSupplier
> & xNumFmtSupplier
);
236 void setAxesNumberFormats( const AxesNumberFormats
& rAxesNumberFormats
) { m_aAxesNumberFormats
= rAxesNumberFormats
; };
238 void setColorScheme( const css::uno::Reference
< css::chart2::XColorScheme
>& xColorScheme
);
240 void setExplicitCategoriesProvider( ExplicitCategoriesProvider
* pExplicitCategoriesProvider
);
242 //get series names for the z axis labels
243 css::uno::Sequence
< OUString
> getSeriesNames() const;
245 void setPageReferenceSize( const css::awt::Size
& rPageRefSize
);
246 //better performance for big data
247 void setCoordinateSystemResolution( const css::uno::Sequence
< sal_Int32
>& rCoordinateSystemResolution
);
248 bool PointsWereSkipped() const { return m_bPointsWereSkipped
;}
250 //return the depth for a logic 1
251 double getTransformedDepth() const;
253 void releaseShapes();
255 virtual void rearrangeLabelToAvoidOverlapIfRequested( const css::awt::Size
& rPageSize
);
257 bool WantToPlotInFrontOfAxisLine();
258 virtual bool shouldSnapRectToUsedArea();
262 VSeriesPlotter( const css::uno::Reference
< css::chart2::XChartType
>& xChartTypeModel
263 , sal_Int32 nDimensionCount
264 , bool bCategoryXAxis
=true );
266 // Methods for group shapes.
268 css::uno::Reference
< css::drawing::XShapes
>
269 getSeriesGroupShape( VDataSeries
* pDataSeries
270 , const css:: uno::Reference
< css::drawing::XShapes
>& xTarget
);
272 //the following group shapes will be created as children of SeriesGroupShape on demand
273 //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)
274 //parameter xTarget will be used as parent for the series group shape
275 css::uno::Reference
< css::drawing::XShapes
>
276 getSeriesGroupShapeFrontChild( VDataSeries
* pDataSeries
277 , const css:: uno::Reference
< css::drawing::XShapes
>& xTarget
);
278 css::uno::Reference
< css::drawing::XShapes
>
279 getSeriesGroupShapeBackChild( VDataSeries
* pDataSeries
280 , const css:: uno::Reference
< css::drawing::XShapes
>& xTarget
);
282 /// This method creates a 2D group shape for containing all text shapes
283 /// needed for this series; the group is added to the text target;
284 css::uno::Reference
< css::drawing::XShapes
>
285 getLabelsGroupShape( VDataSeries
& rDataSeries
286 , const css:: uno::Reference
< css::drawing::XShapes
>& xTarget
);
288 css::uno::Reference
< css::drawing::XShapes
>
289 getErrorBarsGroupShape( VDataSeries
& rDataSeries
290 , const css:: uno::Reference
< css::drawing::XShapes
>& xTarget
, bool bYError
);
292 /** This method creates a text shape for a label related to a data point
293 * and append it to the root text shape group (xTarget).
296 * the main root text shape group.
298 * the data series, the data point belongs to.
300 * the index of the data point the label is related to.
302 * the value of the data point.
304 * the sum of all data point values in the data series.
305 * @param rScreenPosition2D
306 * the anchor point position for the label.
308 * the required alignment of the label.
310 * an optional offset depending on the label alignment.
312 * the maximum width of a text label (used for text wrapping).
315 * a reference to the created text shape.
317 css::uno::Reference
< css::drawing::XShape
>
318 createDataLabel( const css::uno::Reference
< css::drawing::XShapes
>& xTarget
319 , VDataSeries
& rDataSeries
320 , sal_Int32 nPointIndex
323 , const css::awt::Point
& rScreenPosition2D
324 , LabelAlignment eAlignment
325 , sal_Int32 nOffset
=0
326 , sal_Int32 nTextWidth
= 0 );
328 /// This method returns a text string representation of the passed numeric
329 /// value by exploiting a NumberFormatterWrapper object.
330 OUString
getLabelTextForValue( VDataSeries
const & rDataSeries
331 , sal_Int32 nPointIndex
333 , bool bAsPercentage
);
335 /** creates two T-shaped error bars in both directions (up/down or
336 left/right depending on the bVertical parameter)
341 @param xErrorBarProperties
342 the XPropertySet returned by the DataPoint-property "ErrorBarX" or
346 the index of the data point in rData for which the calculation is
350 for y-error bars this is true, for x-error-bars it is false.
353 const css::uno::Reference
< css::drawing::XShapes
>& xTarget
354 , const css::drawing::Position3D
& rPos
355 , const css::uno::Reference
< css::beans::XPropertySet
> & xErrorBarProperties
356 , const VDataSeries
& rVDataSeries
359 , const double* pfScaledLogicX
362 void createErrorBar_X( const css::drawing::Position3D
& rUnscaledLogicPosition
363 , VDataSeries
& rVDataSeries
, sal_Int32 nPointIndex
364 , const css::uno::Reference
< css::drawing::XShapes
>& xTarget
);
366 void createErrorBar_Y( const css::drawing::Position3D
& rUnscaledLogicPosition
367 , VDataSeries
& rVDataSeries
, sal_Int32 nPointIndex
368 , const css::uno::Reference
< css::drawing::XShapes
>& xTarget
369 , double const * pfScaledLogicX
);
371 void createRegressionCurvesShapes( VDataSeries
const & rVDataSeries
372 , const css::uno::Reference
< css::drawing::XShapes
>& xTarget
373 , const css::uno::Reference
< css::drawing::XShapes
>& xEquationTarget
374 , bool bMaySkipPointsInRegressionCalculation
);
376 void createRegressionCurveEquationShapes( const OUString
& rEquationCID
377 , const css::uno::Reference
< css::beans::XPropertySet
> & xEquationProperties
378 , const css::uno::Reference
< css::drawing::XShapes
>& xEquationTarget
379 , const css::uno::Reference
< css::chart2::XRegressionCurveCalculator
> & xRegressionCurveCalculator
380 , css::awt::Point aDefaultPos
);
382 static void setMappedProperties(
383 const css::uno::Reference
< css::drawing::XShape
>& xTarget
384 , const css::uno::Reference
< css::beans::XPropertySet
>& xSource
385 , const tPropertyNameMap
& rMap
386 , tPropertyNameValueMap
const * pOverwriteMap
=nullptr );
388 virtual PlottingPositionHelper
& getPlottingPositionHelper( sal_Int32 nAxisIndex
) const;//nAxisIndex indicates whether the position belongs to the main axis ( nAxisIndex==0 ) or secondary axis ( nAxisIndex==1 )
390 VDataSeries
* getFirstSeries() const;
392 OUString
getCategoryName( sal_Int32 nPointIndex
) const;
395 PlottingPositionHelper
* m_pMainPosHelper
;
397 css::uno::Reference
< css::chart2::XChartType
> m_xChartTypeModel
;
398 css::uno::Reference
< css::beans::XPropertySet
> m_xChartTypeModelProps
;
400 std::vector
< std::vector
< VDataSeriesGroup
> > m_aZSlots
;
402 bool m_bCategoryXAxis
;//true->xvalues are indices (this would not be necessary if series for category chart wouldn't have x-values)
403 long m_nTimeResolution
;
406 std::unique_ptr
< NumberFormatterWrapper
> m_apNumberFormatterWrapper
;
407 AxesNumberFormats m_aAxesNumberFormats
;//direct numberformats on axes, if empty ask the data series instead
409 css::uno::Reference
< css::chart2::XColorScheme
> m_xColorScheme
;
411 ExplicitCategoriesProvider
* m_pExplicitCategoriesProvider
;
413 //better performance for big data
414 css::uno::Sequence
< sal_Int32
> m_aCoordinateSystemResolution
;
415 bool m_bPointsWereSkipped
;
418 typedef std::map
< sal_Int32
, ExplicitScaleData
> tSecondaryValueScales
;
419 tSecondaryValueScales m_aSecondaryValueScales
;
421 typedef std::map
< sal_Int32
, PlottingPositionHelper
* > tSecondaryPosHelperMap
;
422 mutable tSecondaryPosHelperMap m_aSecondaryPosHelperMap
;
423 css::awt::Size m_aPageReferenceSize
;
429 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */