PieDataSet.java
6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package com.github.mikephil.charting.data;
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import com.github.mikephil.charting.utils.Utils;
import com.huaheng.wms.WMSLog;
import java.util.ArrayList;
import java.util.List;
public class PieDataSet extends DataSet<PieEntry> implements IPieDataSet {
/**
* the space in pixels between the chart-slices, default 0f
*/
private float mSliceSpace = 0f;
private boolean mAutomaticallyDisableSliceSpacing;
/**
* indicates the selection distance of a pie slice
*/
private float mShift = 18f;
private ValuePosition mXValuePosition = ValuePosition.INSIDE_SLICE;
private ValuePosition mYValuePosition = ValuePosition.INSIDE_SLICE;
private boolean mUsingSliceColorAsValueLineColor = false;
private int mValueLineColor = 0xff000000;
private float mValueLineWidth = 1.0f;
private float mValueLinePart1OffsetPercentage = 75.f;
private float mValueLinePart1Length = 0.3f;
private float mValueLinePart2Length = 0.4f;
private boolean mValueLineVariableLength = true;
public PieDataSet(List<PieEntry> yVals, String label) {
super(yVals, label);
WMSLog.d("yVals:" + yVals);
// mShift = Utils.convertDpToPixel(12f);
}
@Override
public DataSet<PieEntry> copy() {
List<PieEntry> entries = new ArrayList<>();
for (int i = 0; i < mValues.size(); i++) {
entries.add(mValues.get(i).copy());
}
PieDataSet copied = new PieDataSet(entries, getLabel());
copy(copied);
return copied;
}
protected void copy(PieDataSet pieDataSet) {
super.copy(pieDataSet);
}
@Override
protected void calcMinMax(PieEntry e) {
if (e == null)
return;
calcMinMaxY(e);
}
/**
* Sets the space that is left out between the piechart-slices in dp.
* Default: 0 --> no space, maximum 20f
*
* @param spaceDp
*/
public void setSliceSpace(float spaceDp) {
if (spaceDp > 20)
spaceDp = 20f;
if (spaceDp < 0)
spaceDp = 0f;
mSliceSpace = Utils.convertDpToPixel(spaceDp);
}
@Override
public float getSliceSpace() {
return mSliceSpace;
}
/**
* When enabled, slice spacing will be 0.0 when the smallest value is going to be
* smaller than the slice spacing itself.
*
* @param autoDisable
*/
public void setAutomaticallyDisableSliceSpacing(boolean autoDisable) {
mAutomaticallyDisableSliceSpacing = autoDisable;
}
/**
* When enabled, slice spacing will be 0.0 when the smallest value is going to be
* smaller than the slice spacing itself.
*
* @return
*/
@Override
public boolean isAutomaticallyDisableSliceSpacingEnabled() {
return mAutomaticallyDisableSliceSpacing;
}
/**
* sets the distance the highlighted piechart-slice of this DataSet is
* "shifted" away from the center of the chart, default 12f
*
* @param shift
*/
public void setSelectionShift(float shift) {
mShift = Utils.convertDpToPixel(shift);
}
@Override
public float getSelectionShift() {
return mShift;
}
@Override
public ValuePosition getXValuePosition() {
return mXValuePosition;
}
public void setXValuePosition(ValuePosition xValuePosition) {
this.mXValuePosition = xValuePosition;
}
@Override
public ValuePosition getYValuePosition() {
return mYValuePosition;
}
public void setYValuePosition(ValuePosition yValuePosition) {
this.mYValuePosition = yValuePosition;
}
/**
* When valuePosition is OutsideSlice, use slice colors as line color if true
*/
@Override
public boolean isUsingSliceColorAsValueLineColor() {
return mUsingSliceColorAsValueLineColor;
}
public void setUsingSliceColorAsValueLineColor(boolean usingSliceColorAsValueLineColor) {
this.mUsingSliceColorAsValueLineColor = usingSliceColorAsValueLineColor;
}
/**
* When valuePosition is OutsideSlice, indicates line color
*/
@Override
public int getValueLineColor() {
return mValueLineColor;
}
public void setValueLineColor(int valueLineColor) {
this.mValueLineColor = valueLineColor;
}
/**
* When valuePosition is OutsideSlice, indicates line width
*/
@Override
public float getValueLineWidth() {
return mValueLineWidth;
}
public void setValueLineWidth(float valueLineWidth) {
this.mValueLineWidth = valueLineWidth;
}
/**
* When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size
*/
@Override
public float getValueLinePart1OffsetPercentage() {
return mValueLinePart1OffsetPercentage;
}
public void setValueLinePart1OffsetPercentage(float valueLinePart1OffsetPercentage) {
this.mValueLinePart1OffsetPercentage = valueLinePart1OffsetPercentage;
}
/**
* When valuePosition is OutsideSlice, indicates length of first half of the line
*/
@Override
public float getValueLinePart1Length() {
return mValueLinePart1Length;
}
public void setValueLinePart1Length(float valueLinePart1Length) {
this.mValueLinePart1Length = valueLinePart1Length;
}
/**
* When valuePosition is OutsideSlice, indicates length of second half of the line
*/
@Override
public float getValueLinePart2Length() {
return mValueLinePart2Length;
}
public void setValueLinePart2Length(float valueLinePart2Length) {
this.mValueLinePart2Length = valueLinePart2Length;
}
/**
* When valuePosition is OutsideSlice, this allows variable line length
*/
@Override
public boolean isValueLineVariableLength() {
return mValueLineVariableLength;
}
public void setValueLineVariableLength(boolean valueLineVariableLength) {
this.mValueLineVariableLength = valueLineVariableLength;
}
public enum ValuePosition {
INSIDE_SLICE,
OUTSIDE_SLICE
}
}