Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_CHART2_SOURCE_VIEW_CHARTTYPES_PIECHART_HXX
21 : #define INCLUDED_CHART2_SOURCE_VIEW_CHARTTYPES_PIECHART_HXX
22 :
23 : #include "VSeriesPlotter.hxx"
24 : #include <basegfx/vector/b2dvector.hxx>
25 : #include <basegfx/range/b2irectangle.hxx>
26 :
27 : namespace chart
28 : {
29 : class PiePositionHelper;
30 :
31 : class PieChart : public VSeriesPlotter
32 : {
33 : struct ShapeParam;
34 :
35 : public:
36 : PieChart( const ::com::sun::star::uno::Reference<
37 : ::com::sun::star::chart2::XChartType >& xChartTypeModel
38 : , sal_Int32 nDimensionCount, bool bExcludingPositioning );
39 : virtual ~PieChart();
40 :
41 : /** This method creates all shapes needed for representing the pie chart.
42 : */
43 : virtual void createShapes() SAL_OVERRIDE;
44 : virtual void rearrangeLabelToAvoidOverlapIfRequested( const ::com::sun::star::awt::Size& rPageSize ) SAL_OVERRIDE;
45 :
46 : virtual void setScales( const ::std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis ) SAL_OVERRIDE;
47 : virtual void addSeries( VDataSeries* pSeries, sal_Int32 zSlot = -1, sal_Int32 xSlot = -1,sal_Int32 ySlot = -1 ) SAL_OVERRIDE;
48 :
49 : virtual ::com::sun::star::drawing::Direction3D getPreferredDiagramAspectRatio() const SAL_OVERRIDE;
50 : virtual bool keepAspectRatio() const SAL_OVERRIDE;
51 : virtual bool shouldSnapRectToUsedArea() SAL_OVERRIDE;
52 :
53 : //MinimumAndMaximumSupplier
54 : virtual double getMinimumX() SAL_OVERRIDE;
55 : virtual double getMaximumX() SAL_OVERRIDE;
56 : virtual double getMinimumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex ) SAL_OVERRIDE;
57 : virtual double getMaximumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex ) SAL_OVERRIDE;
58 :
59 : virtual bool isExpandBorderToIncrementRhythm( sal_Int32 nDimensionIndex ) SAL_OVERRIDE;
60 : virtual bool isExpandIfValuesCloseToBorder( sal_Int32 nDimensionIndex ) SAL_OVERRIDE;
61 : virtual bool isExpandWideValuesToZero( sal_Int32 nDimensionIndex ) SAL_OVERRIDE;
62 : virtual bool isExpandNarrowValuesTowardZero( sal_Int32 nDimensionIndex ) SAL_OVERRIDE;
63 : virtual bool isSeparateStackingForDifferentSigns( sal_Int32 nDimensionIndex ) SAL_OVERRIDE;
64 :
65 : private: //methods
66 : //no default constructor
67 : PieChart();
68 :
69 : css::uno::Reference<css::drawing::XShape>
70 : createDataPoint(
71 : const css::uno::Reference<css::drawing::XShapes>& xTarget,
72 : const css::uno::Reference<css::beans::XPropertySet>& xObjectProperties,
73 : tPropertyNameValueMap* pOverWritePropertiesMap,
74 : const ShapeParam& rParam );
75 :
76 : /** This method creates a text shape for a label of a data point.
77 : *
78 : * @param xTextTarget
79 : * where to append the new created text shape.
80 : * @param rSeries
81 : * the data series, the data point belongs to.
82 : * @param nPointIndex
83 : * the index of the data point the label is related to.
84 : * @param rParam
85 : * ShapeParam object.
86 : */
87 : void createTextLabelShape(
88 : const css::uno::Reference<css::drawing::XShapes>& xTextTarget,
89 : VDataSeries& rSeries, sal_Int32 nPointIndex, ShapeParam& rParam );
90 :
91 : /** This method sets `m_fMaxOffset` to the maximum `Offset` property and
92 : * returns it. There is a `Offset` property for each entry in a data
93 : * series, moreover there exists a shared `Offset` property attached to
94 : * the whole data series. The `Offset` property represents the
95 : * relative distance offset of a slice from the pie center.
96 : * The shared property is used for exploded pie chart, while the property
97 : * attached to single data series entries is used for manual dragging of
98 : * a slice.
99 : * `m_fMaxOffset` is used by `PiePositionHelper::getInnerAndOuterRadius`.
100 : * Note that only the `Offset` properties of the first (x slot) data series
101 : * and its entries are utilized for computing the maximum offset.
102 : */
103 : double getMaxOffset();
104 : bool detectLabelOverlapsAndMove(const ::com::sun::star::awt::Size& rPageSize);//returns true when there might be more to do
105 : void resetLabelPositionsToPreviousState();
106 : struct PieLabelInfo;
107 : bool tryMoveLabels( PieLabelInfo* pFirstBorder, PieLabelInfo* pSecondBorder
108 : , PieLabelInfo* pCenter, bool bSingleCenter, bool& rbAlternativeMoveDirection
109 : , const ::com::sun::star::awt::Size& rPageSize );
110 :
111 : bool performLabelBestFitInnerPlacement(ShapeParam& rShapeParam, PieLabelInfo& rPieLabelInfo);
112 : static bool performLabelBestFitOuterPlacement(ShapeParam& rShapeParam, PieLabelInfo& rPieLabelInfo);
113 : void performLabelBestFit(ShapeParam& rShapeParam, PieLabelInfo& rPieLabelInfo);
114 :
115 : private: //member
116 : PiePositionHelper* m_pPosHelper;
117 : bool m_bUseRings;
118 : bool m_bSizeExcludesLabelsAndExplodedSegments;
119 :
120 376 : struct PieLabelInfo
121 : {
122 : PieLabelInfo();
123 : bool moveAwayFrom( const PieLabelInfo* pFix, const ::com::sun::star::awt::Size& rPageSize
124 : , bool bMoveHalfWay, bool bMoveClockwise, bool bAlternativeMoveDirection );
125 :
126 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xTextShape;
127 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xLabelGroupShape;
128 : ::basegfx::B2IVector aFirstPosition;
129 : ::basegfx::B2IVector aOrigin;
130 : double fValue;
131 : bool bMovementAllowed;
132 : bool bMoved;
133 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > xTextTarget;
134 : PieLabelInfo* pPrevious;
135 : PieLabelInfo* pNext;
136 : ::com::sun::star::awt::Point aPreviousPosition;
137 : };
138 :
139 : ::std::vector< PieLabelInfo > m_aLabelInfoList;
140 :
141 : double m_fMaxOffset; /// cached max offset value (init'ed to NaN)
142 : };
143 : } //namespace chart
144 : #endif
145 :
146 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|