tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / view / inc / VSeriesPlotter.hxx
blob45676830b538bf2125bca136645365f27fc68424
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
21 #include <memory>
22 #include "PlotterBase.hxx"
23 #include "VDataSeries.hxx"
24 #include "LabelAlignment.hxx"
25 #include "MinimumAndMaximumSupplier.hxx"
26 #include "LegendEntryProvider.hxx"
27 #include <basegfx/range/b2irectangle.hxx>
28 #include <com/sun/star/drawing/Direction3D.hpp>
29 #include <rtl/ref.hxx>
30 #include <svx/unoshape.hxx>
32 namespace com::sun::star::awt { struct Point; }
33 namespace com::sun::star::chart2 { class XChartType; }
36 namespace chart { class ExplicitCategoriesProvider; }
37 namespace chart { struct ExplicitScaleData; }
38 namespace chart { class ChartModel; }
40 namespace com::sun::star {
41 namespace util {
42 class XNumberFormatsSupplier;
44 namespace chart2 {
45 class XColorScheme;
46 class XRegressionCurveCalculator;
50 namespace chart {
52 class ChartType;
53 class NumberFormatterWrapper;
55 class AxesNumberFormats
57 public:
58 AxesNumberFormats() {};
60 void setFormat( sal_Int32 nFormatKey, sal_Int32 nDimIndex, sal_Int32 nAxisIndex )
62 m_aNumberFormatMap[tFullAxisIndex(nDimIndex,nAxisIndex)] = nFormatKey;
65 private:
66 typedef std::pair< sal_Int32, sal_Int32 > tFullAxisIndex;
67 std::map< tFullAxisIndex, sal_Int32 > m_aNumberFormatMap;
70 /**
71 * A list of series that have the same CoordinateSystem. They are used to be
72 * plotted maybe in a stacked manner by a plotter.
74 class VDataSeriesGroup final
76 public:
77 VDataSeriesGroup() = delete;
78 VDataSeriesGroup( std::unique_ptr<VDataSeries> pSeries );
79 VDataSeriesGroup(VDataSeriesGroup&&) noexcept;
80 ~VDataSeriesGroup();
82 void addSeries( std::unique_ptr<VDataSeries> pSeries );//takes ownership of pSeries
83 sal_Int32 getSeriesCount() const;
84 void deleteSeries();
86 sal_Int32 getPointCount() const;
87 sal_Int32 getAttachedAxisIndexForFirstSeries() const;
89 void getMinimumAndMaximumX( double& rfMinimum, double& rfMaximum ) const;
90 void getMinimumAndMaximumYInContinuousXRange( double& rfMinY, double& rfMaxY, double fMinX, double fMaxX, sal_Int32 nAxisIndex ) const;
92 void calculateYMinAndMaxForCategory( sal_Int32 nCategoryIndex
93 , bool bSeparateStackingForDifferentSigns
94 , double& rfMinimumY, double& rfMaximumY, sal_Int32 nAxisIndex ) const;
95 void calculateYMinAndMaxForCategoryRange( sal_Int32 nStartCategoryIndex, sal_Int32 nEndCategoryIndex
96 , bool bSeparateStackingForDifferentSigns
97 , double& rfMinimumY, double& rfMaximumY, sal_Int32 nAxisIndex );
99 std::vector< std::unique_ptr<VDataSeries> > m_aSeriesVector;
101 private:
102 //cached values
103 struct CachedYValues
105 CachedYValues();
107 bool m_bValuesDirty;
108 double m_fMinimumY;
109 double m_fMaximumY;
112 mutable bool m_bMaxPointCountDirty;
113 mutable sal_Int32 m_nMaxPointCount;
114 typedef std::map< sal_Int32, CachedYValues > tCachedYValuesPerAxisIndexMap;
115 mutable std::vector< tCachedYValuesPerAxisIndexMap > m_aListOfCachedYValues;
118 class VSeriesPlotter : public PlotterBase, public MinimumAndMaximumSupplier, public LegendEntryProvider
120 public:
121 VSeriesPlotter() = delete;
123 virtual ~VSeriesPlotter() override;
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( std::unique_ptr<VDataSeries> pSeries, sal_Int32 zSlot, sal_Int32 xSlot, sal_Int32 ySlot );
142 /** a value <= 0 for a directions means that this direction can be stretched arbitrary
144 virtual css::drawing::Direction3D getPreferredDiagramAspectRatio() const;
146 /** this enables you to handle series on the same x axis with different y axis
147 the property AttachedAxisIndex at a dataseries indicates which value scale is to use
148 (0==AttachedAxisIndex or a not set AttachedAxisIndex property indicates that this series should be scaled at the main y-axis;
149 1==AttachedAxisIndex indicates that the series should be scaled at the first secondary axis if there is any otherwise at the main y axis
150 and so on.
151 The parameter nAxisIndex matches this DataSeries property 'AttachedAxisIndex'.
152 nAxisIndex must be greater than 0. nAxisIndex==1 refers to the first secondary axis.
155 @throws css::uno::RuntimeException
158 void addSecondaryValueScale( const ExplicitScaleData& rScale, sal_Int32 nAxisIndex );
160 // MinimumAndMaximumSupplier
162 virtual double getMinimumX() override;
163 virtual double getMaximumX() override;
165 virtual double getMinimumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex ) override;
166 virtual double getMaximumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex ) override;
168 virtual double getMinimumZ() override;
169 virtual double getMaximumZ() override;
171 virtual bool isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex ) override;
172 virtual bool isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex ) override;
173 virtual bool isExpandWideValuesToZero( sal_Int32 nDimensionIndex ) override;
174 virtual bool isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex ) override;
175 virtual bool isSeparateStackingForDifferentSigns( sal_Int32 nDimensionIndex ) override;
177 virtual tools::Long calculateTimeResolutionOnXAxis() override;
178 virtual void setTimeResolutionOnXAxis( tools::Long nTimeResolution, const Date& rNullDate ) override;
180 void getMinimumAndMaximumX( double& rfMinimum, double& rfMaximum ) const;
181 void getMinimumAndMaximumYInContinuousXRange( double& rfMinY, double& rfMaxY, double fMinX, double fMaxX, sal_Int32 nAxisIndex ) const;
184 // Methods for handling legends and legend entries.
186 virtual std::vector< ViewLegendEntry > createLegendEntries(
187 const css::awt::Size& rEntryKeyAspectRatio,
188 css::chart2::LegendPosition eLegendPosition,
189 const css::uno::Reference< css::beans::XPropertySet >& xTextProperties,
190 const rtl::Reference<SvxShapeGroupAnyD>& xTarget,
191 const css::uno::Reference< css::uno::XComponentContext >& xContext,
192 ChartModel& rModel
193 ) override;
195 virtual LegendSymbolStyle getLegendSymbolStyle();
196 virtual css::awt::Size getPreferredLegendKeyAspectRatio() override;
198 virtual css::uno::Any getExplicitSymbol( const VDataSeries& rSeries, sal_Int32 nPointIndex/*-1 for series symbol*/ );
200 rtl::Reference<SvxShapeGroup> createLegendSymbolForSeries(
201 const css::awt::Size& rEntryKeyAspectRatio
202 , const VDataSeries& rSeries
203 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget );
205 rtl::Reference< SvxShapeGroup > createLegendSymbolForPoint(
206 const css::awt::Size& rEntryKeyAspectRatio
207 , const VDataSeries& rSeries
208 , sal_Int32 nPointIndex
209 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget );
211 std::vector< ViewLegendEntry > createLegendEntriesForSeries(
212 const css::awt::Size& rEntryKeyAspectRatio,
213 const VDataSeries& rSeries,
214 const css::uno::Reference< css::beans::XPropertySet >& xTextProperties,
215 const rtl::Reference<SvxShapeGroupAnyD>& xTarget,
216 const css::uno::Reference< css::uno::XComponentContext >& xContext
219 std::vector<ViewLegendSymbol> createSymbols(
220 const css::awt::Size& rEntryKeyAspectRatio
221 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget
222 , const css::uno::Reference<css::uno::XComponentContext>& xContext);
224 std::vector<ViewLegendSymbol> createSymbolsForSeries(
225 const css::awt::Size& rEntryKeyAspectRatio
226 , const VDataSeries& rSeries
227 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget
228 , const css::uno::Reference<css::uno::XComponentContext>& xContext);
230 std::vector<VDataSeries*> getAllSeries();
231 std::vector<VDataSeries const*> getAllSeries() const;
233 // This method creates a series plotter of the requested type; e.g. : return new PieChart...
234 static VSeriesPlotter* createSeriesPlotter( const rtl::Reference< ::chart::ChartType >& xChartTypeModel
235 , sal_Int32 nDimensionCount
236 , bool bExcludingPositioning /*for pie and donut charts labels and exploded segments are excluded from the given size*/);
238 sal_Int32 getPointCount() const;
240 // Methods for number formats and color schemes
242 void setNumberFormatsSupplier( const css::uno::Reference< css::util::XNumberFormatsSupplier > & xNumFmtSupplier );
244 void setColorScheme( const css::uno::Reference< css::chart2::XColorScheme >& xColorScheme );
246 void setExplicitCategoriesProvider( ExplicitCategoriesProvider* pExplicitCategoriesProvider );
248 ExplicitCategoriesProvider* getExplicitCategoriesProvider() { return m_pExplicitCategoriesProvider; }
250 //get series names for the z axis labels
251 css::uno::Sequence<OUString> getSeriesNames() const;
253 //get all series names
254 css::uno::Sequence<OUString> getAllSeriesNames() const;
256 void setPageReferenceSize( const css::awt::Size & rPageRefSize );
257 //better performance for big data
258 void setCoordinateSystemResolution( const css::uno::Sequence< sal_Int32 >& rCoordinateSystemResolution );
259 bool PointsWereSkipped() const { return m_bPointsWereSkipped;}
260 void setPieLabelsAllowToMove( bool bIsPieOrDonut ) { m_bPieLabelsAllowToMove = bIsPieOrDonut; };
261 void setAvailableOuterRect( const basegfx::B2IRectangle& aAvailableOuterRect ) { m_aAvailableOuterRect = aAvailableOuterRect; };
263 //return the depth for a logic 1
264 double getTransformedDepth() const;
266 void releaseShapes();
268 virtual void rearrangeLabelToAvoidOverlapIfRequested( const css::awt::Size& rPageSize );
270 bool WantToPlotInFrontOfAxisLine();
271 virtual bool shouldSnapRectToUsedArea();
273 /// This method returns a text string representation of the passed numeric
274 /// value by exploiting a NumberFormatterWrapper object.
275 OUString getLabelTextForValue(VDataSeries const & rDataSeries, sal_Int32 nPointIndex,
276 double fValue, bool bAsPercentage);
278 sal_Int32 getRenderOrder() const;
280 protected:
282 VSeriesPlotter( rtl::Reference< ::chart::ChartType > xChartTypeModel
283 , sal_Int32 nDimensionCount
284 , bool bCategoryXAxis=true );
286 // Methods for group shapes.
288 rtl::Reference<SvxShapeGroupAnyD>
289 getSeriesGroupShape( VDataSeries* pDataSeries
290 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget );
292 //the following group shapes will be created as children of SeriesGroupShape on demand
293 //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)
294 //parameter xTarget will be used as parent for the series group shape
295 rtl::Reference<SvxShapeGroupAnyD>
296 getSeriesGroupShapeFrontChild( VDataSeries* pDataSeries
297 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget );
298 rtl::Reference<SvxShapeGroupAnyD>
299 getSeriesGroupShapeBackChild( VDataSeries* pDataSeries
300 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget );
302 /// This method creates a 2D group shape for containing all text shapes
303 /// needed for this series; the group is added to the text target;
304 static rtl::Reference<SvxShapeGroup>
305 getLabelsGroupShape( VDataSeries& rDataSeries
306 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget );
308 rtl::Reference<SvxShapeGroupAnyD>
309 getErrorBarsGroupShape( VDataSeries& rDataSeries
310 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget, bool bYError );
312 /** This method creates a text shape for a label related to a data point
313 * and append it to the root text shape group (xTarget).
315 * @param xTarget
316 * the main root text shape group.
317 * @param rDataSeries
318 * the data series, the data point belongs to.
319 * @param nPointIndex
320 * the index of the data point the label is related to.
321 * @param fValue
322 * the value of the data point.
323 * @param fSumValue
324 * the sum of all data point values in the data series.
325 * @param rScreenPosition2D
326 * the anchor point position for the label.
327 * @param eAlignment
328 * the required alignment of the label.
329 * @param offset
330 * an optional offset depending on the label alignment.
331 * @param nTextWidth
332 * the maximum width of a text label (used for text wrapping).
334 * @return
335 * a reference to the created text shape.
337 rtl::Reference<SvxShapeText>
338 createDataLabel( const rtl::Reference<SvxShapeGroupAnyD>& xTarget
339 , VDataSeries& rDataSeries
340 , sal_Int32 nPointIndex
341 , double fValue
342 , double fSumValue
343 , const css::awt::Point& rScreenPosition2D
344 , LabelAlignment eAlignment
345 , sal_Int32 nOffset=0
346 , sal_Int32 nTextWidth = 0 );
348 /** creates two T-shaped error bars in both directions (up/down or
349 left/right depending on the bVertical parameter)
351 @param rPos
352 logic coordinates
354 @param xErrorBarProperties
355 the XPropertySet returned by the DataPoint-property "ErrorBarX" or
356 "ErrorBarY".
358 @param nIndex
359 the index of the data point in rData for which the calculation is
360 done.
362 @param bVertical
363 for y-error bars this is true, for x-error-bars it is false.
365 void createErrorBar(
366 const rtl::Reference<SvxShapeGroupAnyD>& xTarget
367 , const css::drawing::Position3D & rPos
368 , const css::uno::Reference< css::beans::XPropertySet > & xErrorBarProperties
369 , const VDataSeries& rVDataSeries
370 , sal_Int32 nIndex
371 , bool bVertical
372 , const double* pfScaledLogicX
375 void createErrorRectangle(
376 const css::drawing::Position3D& rUnscaledLogicPosition
377 , VDataSeries& rVDataSeries
378 , sal_Int32 nIndex
379 , const rtl::Reference<SvxShapeGroupAnyD>& rTarget
380 , bool bUseXErrorData
381 , bool bUseYErrorData
384 static void addErrorBorder(
385 const css::drawing::Position3D& rPos0
386 , const css::drawing::Position3D& rPos1
387 , const rtl::Reference<SvxShapeGroupAnyD>& rTarget
388 , const css::uno::Reference< css::beans::XPropertySet >& rErrorBorderProp );
390 void createErrorBar_X( const css::drawing::Position3D& rUnscaledLogicPosition
391 , VDataSeries& rVDataSeries, sal_Int32 nPointIndex
392 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget );
394 void createErrorBar_Y( const css::drawing::Position3D& rUnscaledLogicPosition
395 , VDataSeries& rVDataSeries, sal_Int32 nPointIndex
396 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget
397 , double const * pfScaledLogicX );
399 void createRegressionCurvesShapes( VDataSeries const & rVDataSeries
400 , const rtl::Reference<SvxShapeGroupAnyD>& xTarget
401 , const rtl::Reference<SvxShapeGroupAnyD>& xEquationTarget
402 , bool bMaySkipPointsInRegressionCalculation );
404 void createRegressionCurveEquationShapes( const OUString & rEquationCID
405 , const css::uno::Reference< css::beans::XPropertySet > & xEquationProperties
406 , const rtl::Reference<SvxShapeGroupAnyD>& xEquationTarget
407 , const css::uno::Reference< css::chart2::XRegressionCurveCalculator > & xRegressionCurveCalculator
408 , css::awt::Point aDefaultPos );
410 virtual PlottingPositionHelper& getPlottingPositionHelper( sal_Int32 nAxisIndex ) const;//nAxisIndex indicates whether the position belongs to the main axis ( nAxisIndex==0 ) or secondary axis ( nAxisIndex==1 )
412 VDataSeries* getFirstSeries() const;
414 OUString getCategoryName( sal_Int32 nPointIndex ) const;
416 protected:
417 PlottingPositionHelper* m_pMainPosHelper;
419 rtl::Reference< ::chart::ChartType > m_xChartTypeModel;
421 std::vector< std::vector< VDataSeriesGroup > > m_aZSlots;
423 bool m_bCategoryXAxis;//true->xvalues are indices (this would not be necessary if series for category chart wouldn't have x-values)
424 tools::Long m_nTimeResolution;
425 Date m_aNullDate;
427 std::unique_ptr< NumberFormatterWrapper > m_apNumberFormatterWrapper;
429 css::uno::Reference< css::chart2::XColorScheme > m_xColorScheme;
431 ExplicitCategoriesProvider* m_pExplicitCategoriesProvider;
433 //better performance for big data
434 css::uno::Sequence< sal_Int32 > m_aCoordinateSystemResolution;
435 bool m_bPointsWereSkipped;
436 bool m_bPieLabelsAllowToMove;
437 basegfx::B2IRectangle m_aAvailableOuterRect;
438 css::awt::Size m_aPageReferenceSize;
440 private:
441 typedef std::map< sal_Int32 , ExplicitScaleData > tSecondaryValueScales;
442 tSecondaryValueScales m_aSecondaryValueScales;
444 typedef std::map< sal_Int32 , std::unique_ptr<PlottingPositionHelper> > tSecondaryPosHelperMap;
445 mutable tSecondaryPosHelperMap m_aSecondaryPosHelperMap;
448 } //namespace chart
450 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */