1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CHART2_PIECHART_HXX
25 #define _CHART2_PIECHART_HXX
26 
27 #include "VSeriesPlotter.hxx"
28 #include <basegfx/vector/b2dvector.hxx>
29 #include <basegfx/range/b2irectangle.hxx>
30 
31 //.............................................................................
32 namespace chart
33 {
34 //.............................................................................
35 class PiePositionHelper;
36 
37 class PieChart : public VSeriesPlotter
38 {
39 	//-------------------------------------------------------------------------
40 	// public methods
41 	//-------------------------------------------------------------------------
42 public:
43     PieChart( const ::com::sun::star::uno::Reference<
44             ::com::sun::star::chart2::XChartType >& xChartTypeModel
45             , sal_Int32 nDimensionCount, bool bExcludingPositioning );
46 	virtual ~PieChart();
47 
48 	virtual void createShapes();
49     virtual void rearrangeLabelToAvoidOverlapIfRequested( const ::com::sun::star::awt::Size& rPageSize );
50 
51     virtual void setScales( const ::std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis );
52     virtual void addSeries( VDataSeries* pSeries, sal_Int32 zSlot = -1, sal_Int32 xSlot = -1,sal_Int32 ySlot = -1 );
53 
54     //-------------------
55     virtual ::com::sun::star::drawing::Direction3D  getPreferredDiagramAspectRatio() const;
56     virtual bool keepAspectRatio() const;
57     virtual bool shouldSnapRectToUsedArea();
58 
59     //MinimumAndMaximumSupplier
60     virtual double getMinimumX();
61     virtual double getMaximumX();
62     virtual double getMinimumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex );
63     virtual double getMaximumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex );
64 
65     virtual bool isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex );
66     virtual bool isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex );
67     virtual bool isExpandWideValuesToZero( sal_Int32 nDimensionIndex );
68     virtual bool isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex );
69     virtual bool isSeperateStackingForDifferentSigns( sal_Int32 nDimensionIndex );
70 
71     //-------------------------------------------------------------------------
72     //-------------------------------------------------------------------------
73     //-------------------------------------------------------------------------
74 private: //methods
75 	//no default constructor
76 	PieChart();
77 
78     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
79         createDataPoint(  const ::com::sun::star::uno::Reference<
80                                 ::com::sun::star::drawing::XShapes >& xTarget
81                         , const ::com::sun::star::uno::Reference<
82                                 ::com::sun::star::beans::XPropertySet >& xObjectProperties
83                         , double fUnitCircleStartAngleDegree, double fWidthAngleDegree
84                         , double fUnitCircleInnerRadius, double fUnitCircleOuterRadius
85                         , double fLogicZ, double fDepth, double fExplodePercentage
86                         , tPropertyNameValueMap* pOverWritePropertiesMap );
87 
88     double              getMaxOffset();
89     bool                detectLabelOverlapsAndMove(const ::com::sun::star::awt::Size& rPageSize);//returns true when there might be more to do
90     void                resetLabelPositionsToPreviousState();
91 struct PieLabelInfo;
92     bool                tryMoveLabels( PieLabelInfo* pFirstBorder, PieLabelInfo* pSecondBorder
93                                 , PieLabelInfo* pCenter, bool bSingleCenter, bool& rbAlternativeMoveDirection
94                                 , const ::com::sun::star::awt::Size& rPageSize );
95 
96 private: //member
97     PiePositionHelper*    m_pPosHelper;
98     bool                  m_bUseRings;
99     bool                  m_bSizeExcludesLabelsAndExplodedSegments;
100 
101     struct PieLabelInfo
102     {
103         PieLabelInfo();
104         bool moveAwayFrom( const PieLabelInfo* pFix, const ::com::sun::star::awt::Size& rPageSize
105             , bool bMoveHalfWay, bool bMoveClockwise, bool bAlternativeMoveDirection );
106 
107         ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xTextShape;
108         ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xLabelGroupShape;
109         ::basegfx::B2IVector aFirstPosition;
110         ::basegfx::B2IVector aOrigin;
111         double fValue;
112         bool bMovementAllowed;
113         bool bMoved;
114         ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > xTextTarget;
115         PieLabelInfo* pPrevious;
116         PieLabelInfo* pNext;
117         ::com::sun::star::awt::Point aPreviousPosition;
118     };
119 
120     ::std::vector< PieLabelInfo > m_aLabelInfoList;
121 
122     double m_fMaxOffset;    /// cached max offset value (init'ed to NaN)
123 };
124 //.............................................................................
125 } //namespace chart
126 //.............................................................................
127 #endif
128