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 .
23 #include <VSeriesPlotter.hxx>
24 #include <basegfx/vector/b2ivector.hxx>
25 #include <com/sun/star/awt/Point.hpp>
29 class PiePositionHelper
;
31 class PieChart
: public VSeriesPlotter
38 PieChart( const css::uno::Reference
< css::chart2::XChartType
>& xChartTypeModel
39 , sal_Int32 nDimensionCount
, bool bExcludingPositioning
);
40 virtual ~PieChart() override
;
42 /** This method creates all shapes needed for representing the pie chart.
44 virtual void createShapes() override
;
45 virtual void rearrangeLabelToAvoidOverlapIfRequested( const css::awt::Size
& rPageSize
) override
;
47 virtual void setScales( const std::vector
< ExplicitScaleData
>& rScales
, bool bSwapXAndYAxis
) override
;
48 virtual void addSeries( std::unique_ptr
<VDataSeries
> pSeries
, sal_Int32 zSlot
, sal_Int32 xSlot
, sal_Int32 ySlot
) override
;
50 virtual css::drawing::Direction3D
getPreferredDiagramAspectRatio() const override
;
51 virtual bool shouldSnapRectToUsedArea() override
;
53 //MinimumAndMaximumSupplier
54 virtual double getMinimumX() override
;
55 virtual double getMaximumX() override
;
56 virtual double getMinimumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
) override
;
57 virtual double getMaximumYInRange( double fMinimumX
, double fMaximumX
, sal_Int32 nAxisIndex
) override
;
59 virtual bool isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex
) override
;
60 virtual bool isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex
) override
;
61 virtual bool isExpandWideValuesToZero( sal_Int32 nDimensionIndex
) override
;
62 virtual bool isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex
) override
;
63 virtual bool isSeparateStackingForDifferentSigns( sal_Int32 nDimensionIndex
) override
;
66 css::uno::Reference
<css::drawing::XShape
>
68 const css::uno::Reference
<css::drawing::XShapes
>& xTarget
,
69 const css::uno::Reference
<css::beans::XPropertySet
>& xObjectProperties
,
70 tPropertyNameValueMap
const * pOverWritePropertiesMap
,
71 const ShapeParam
& rParam
);
73 /** This method creates a text shape for a label of a data point.
76 * where to append the new created text shape.
78 * the data series, the data point belongs to.
80 * the index of the data point the label is related to.
84 void createTextLabelShape(
85 const css::uno::Reference
<css::drawing::XShapes
>& xTextTarget
,
86 VDataSeries
& rSeries
, sal_Int32 nPointIndex
, ShapeParam
& rParam
);
88 /** This method sets `m_fMaxOffset` to the maximum `Offset` property and
89 * returns it. There is a `Offset` property for each entry in a data
90 * series, moreover there exists a shared `Offset` property attached to
91 * the whole data series. The `Offset` property represents the
92 * relative distance offset of a slice from the pie center.
93 * The shared property is used for exploded pie chart, while the property
94 * attached to single data series entries is used for manual dragging of
96 * `m_fMaxOffset` is used by `PiePositionHelper::getInnerAndOuterRadius`.
97 * Note that only the `Offset` properties of the first (x slot) data series
98 * and its entries are utilized for computing the maximum offset.
100 double getMaxOffset();
101 bool detectLabelOverlapsAndMove(const css::awt::Size
& rPageSize
);//returns true when there might be more to do
102 void resetLabelPositionsToPreviousState();
104 bool tryMoveLabels( PieLabelInfo
const * pFirstBorder
, PieLabelInfo
const * pSecondBorder
105 , PieLabelInfo
* pCenter
, bool bSingleCenter
, bool& rbAlternativeMoveDirection
106 , const css::awt::Size
& rPageSize
);
108 bool performLabelBestFitInnerPlacement( ShapeParam
& rShapeParam
109 , PieLabelInfo
const & rPieLabelInfo
);
112 std::unique_ptr
<PiePositionHelper
>
115 bool m_bSizeExcludesLabelsAndExplodedSegments
;
120 bool moveAwayFrom( const PieLabelInfo
* pFix
, const css::awt::Size
& rPageSize
121 , bool bMoveHalfWay
, bool bMoveClockwise
);
123 css::uno::Reference
< css::drawing::XShape
> xTextShape
;
124 css::uno::Reference
< css::drawing::XShape
> xLabelGroupShape
;
125 ::basegfx::B2IVector aFirstPosition
;
126 ::basegfx::B2IVector aOuterPosition
;
127 ::basegfx::B2IVector aOrigin
;
129 bool bMovementAllowed
;
131 bool bShowLeaderLine
;
132 css::uno::Reference
< css::drawing::XShapes
> xTextTarget
;
133 PieLabelInfo
* pPrevious
;
135 css::awt::Point aPreviousPosition
;
138 std::vector
< PieLabelInfo
> m_aLabelInfoList
;
140 double m_fMaxOffset
; /// cached max offset value (init'ed to NaN)
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */