Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / view / charttypes / PieChart.hxx
bloba176adaaf44ab53db7c1c1cab9d0ed6fea0fbbfc
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 .
20 #ifndef INCLUDED_CHART2_SOURCE_VIEW_CHARTTYPES_PIECHART_HXX
21 #define INCLUDED_CHART2_SOURCE_VIEW_CHARTTYPES_PIECHART_HXX
23 #include <memory>
24 #include <VSeriesPlotter.hxx>
25 #include <basegfx/vector/b2ivector.hxx>
26 #include <com/sun/star/awt/Point.hpp>
28 namespace chart
30 class PiePositionHelper;
32 class PieChart : public VSeriesPlotter
34 struct ShapeParam;
36 public:
37 PieChart() = delete;
39 PieChart( const css::uno::Reference< css::chart2::XChartType >& xChartTypeModel
40 , sal_Int32 nDimensionCount, bool bExcludingPositioning );
41 virtual ~PieChart() override;
43 /** This method creates all shapes needed for representing the pie chart.
45 virtual void createShapes() override;
46 virtual void rearrangeLabelToAvoidOverlapIfRequested( const css::awt::Size& rPageSize ) override;
48 virtual void setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ) override;
49 virtual void addSeries( std::unique_ptr<VDataSeries> pSeries, sal_Int32 zSlot, sal_Int32 xSlot, sal_Int32 ySlot ) override;
51 virtual css::drawing::Direction3D getPreferredDiagramAspectRatio() const override;
52 virtual bool shouldSnapRectToUsedArea() override;
54 //MinimumAndMaximumSupplier
55 virtual double getMinimumX() override;
56 virtual double getMaximumX() override;
57 virtual double getMinimumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex ) override;
58 virtual double getMaximumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex ) override;
60 virtual bool isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex ) override;
61 virtual bool isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex ) override;
62 virtual bool isExpandWideValuesToZero( sal_Int32 nDimensionIndex ) override;
63 virtual bool isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex ) override;
64 virtual bool isSeparateStackingForDifferentSigns( sal_Int32 nDimensionIndex ) override;
66 private: //methods
67 css::uno::Reference<css::drawing::XShape>
68 createDataPoint(
69 const css::uno::Reference<css::drawing::XShapes>& xTarget,
70 const css::uno::Reference<css::beans::XPropertySet>& xObjectProperties,
71 tPropertyNameValueMap const * pOverWritePropertiesMap,
72 const ShapeParam& rParam );
74 /** This method creates a text shape for a label of a data point.
76 * @param xTextTarget
77 * where to append the new created text shape.
78 * @param rSeries
79 * the data series, the data point belongs to.
80 * @param nPointIndex
81 * the index of the data point the label is related to.
82 * @param rParam
83 * ShapeParam object.
85 void createTextLabelShape(
86 const css::uno::Reference<css::drawing::XShapes>& xTextTarget,
87 VDataSeries& rSeries, sal_Int32 nPointIndex, ShapeParam& rParam );
89 /** This method sets `m_fMaxOffset` to the maximum `Offset` property and
90 * returns it. There is a `Offset` property for each entry in a data
91 * series, moreover there exists a shared `Offset` property attached to
92 * the whole data series. The `Offset` property represents the
93 * relative distance offset of a slice from the pie center.
94 * The shared property is used for exploded pie chart, while the property
95 * attached to single data series entries is used for manual dragging of
96 * a slice.
97 * `m_fMaxOffset` is used by `PiePositionHelper::getInnerAndOuterRadius`.
98 * Note that only the `Offset` properties of the first (x slot) data series
99 * and its entries are utilized for computing the maximum offset.
101 double getMaxOffset();
102 bool detectLabelOverlapsAndMove(const css::awt::Size& rPageSize);//returns true when there might be more to do
103 void resetLabelPositionsToPreviousState();
104 struct PieLabelInfo;
105 bool tryMoveLabels( PieLabelInfo const * pFirstBorder, PieLabelInfo const * pSecondBorder
106 , PieLabelInfo* pCenter, bool bSingleCenter, bool& rbAlternativeMoveDirection
107 , const css::awt::Size& rPageSize );
109 bool performLabelBestFitInnerPlacement(ShapeParam& rShapeParam, PieLabelInfo const & rPieLabelInfo);
110 void performLabelBestFit(ShapeParam& rShapeParam, PieLabelInfo const & rPieLabelInfo);
112 private: //member
113 std::unique_ptr<PiePositionHelper>
114 m_pPosHelper;
115 bool m_bUseRings;
116 bool m_bSizeExcludesLabelsAndExplodedSegments;
118 struct PieLabelInfo
120 PieLabelInfo();
121 bool moveAwayFrom( const PieLabelInfo* pFix, const css::awt::Size& rPageSize
122 , bool bMoveHalfWay, bool bMoveClockwise );
124 css::uno::Reference< css::drawing::XShape > xTextShape;
125 css::uno::Reference< css::drawing::XShape > xLabelGroupShape;
126 ::basegfx::B2IVector aFirstPosition;
127 ::basegfx::B2IVector aOrigin;
128 double fValue;
129 bool bMovementAllowed;
130 bool bMoved;
131 css::uno::Reference< css::drawing::XShapes > xTextTarget;
132 PieLabelInfo* pPrevious;
133 PieLabelInfo* pNext;
134 css::awt::Point aPreviousPosition;
137 std::vector< PieLabelInfo > m_aLabelInfoList;
139 double m_fMaxOffset; /// cached max offset value (init'ed to NaN)
141 } //namespace chart
142 #endif
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */