forked from PhilJay/MPAndroidChart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCandleDataSet.java
More file actions
249 lines (202 loc) · 5.8 KB
/
CandleDataSet.java
File metadata and controls
249 lines (202 loc) · 5.8 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package com.github.mikephil.charting.data;
import android.graphics.Paint;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
import java.util.List;
/**
* DataSet for the CandleStickChart.
*
* @author Philipp Jahoda
*/
public class CandleDataSet extends BarLineScatterCandleDataSet<CandleEntry> {
/** the width of the shadow of the candle */
private float mShadowWidth = 3f;
/** the space between the candle entries, default 0.1f (10%) */
private float mBodySpace = 0.1f;
/** paint style when open <= close */
protected Paint.Style mIncreasingPaintStyle = Paint.Style.FILL;
/** paint style when open > close */
protected Paint.Style mDecreasingPaintStyle = Paint.Style.STROKE;
/** color for open <= close */
protected int mIncreasingColor = ColorTemplate.COLOR_NONE;
/** color for open > close */
protected int mDecreasingColor = ColorTemplate.COLOR_NONE;
/**
* shadow line color, set -1 for backward compatibility and uses default
* color
*/
protected int mShadowColor = ColorTemplate.COLOR_NONE;
public CandleDataSet(List<CandleEntry> yVals, String label) {
super(yVals, label);
}
@Override
public DataSet<CandleEntry> copy() {
List<CandleEntry> yVals = new ArrayList<CandleEntry>();
for (int i = 0; i < mYVals.size(); i++) {
yVals.add(((CandleEntry) mYVals.get(i)).copy());
}
CandleDataSet copied = new CandleDataSet(yVals, getLabel());
copied.mColors = mColors;
copied.mShadowWidth = mShadowWidth;
copied.mBodySpace = mBodySpace;
copied.mHighLightColor = mHighLightColor;
copied.mIncreasingPaintStyle = mIncreasingPaintStyle;
copied.mDecreasingPaintStyle = mDecreasingPaintStyle;
copied.mShadowColor = mShadowColor;
return copied;
}
@Override
protected void calcMinMax(int start, int end) {
// super.calcMinMax();
if (mYVals.size() == 0)
return;
List<CandleEntry> entries = mYVals;
int endValue;
if (end == 0)
endValue = mYVals.size() - 1;
else
endValue = end;
mLastStart = start;
mLastEnd = endValue;
mYMin = mYVals.get(start).getLow();
mYMax = mYVals.get(start).getHigh();
for (int i = start + 1; i <= endValue; i++) {
CandleEntry e = entries.get(i);
if (e.getLow() < mYMin)
mYMin = e.getLow();
if (e.getHigh() > mYMax)
mYMax = e.getHigh();
}
}
/**
* Sets the space that is left out on the left and right side of each
* candle, default 0.1f (10%), max 0.45f, min 0f
*
* @param space
*/
public void setBodySpace(float space) {
if (space < 0f)
space = 0f;
if (space > 0.45f)
space = 0.45f;
mBodySpace = space;
}
/**
* Returns the space that is left out on the left and right side of each
* candle.
*
* @return
*/
public float getBodySpace() {
return mBodySpace;
}
/**
* Sets the width of the candle-shadow-line in pixels. Default 3f.
*
* @param width
*/
public void setShadowWidth(float width) {
mShadowWidth = Utils.convertDpToPixel(width);
}
/**
* Returns the width of the candle-shadow-line in pixels.
*
* @return
*/
public float getShadowWidth() {
return mShadowWidth;
}
// TODO
/**
* It is necessary to implement ColorsList class that will encapsulate
* colors list functionality, because It's wrong to copy paste setColor,
* addColor, ... resetColors for each time when we want to add a coloring
* options for one of objects
*
* @author Mesrop
*/
/** BELOW THIS COLOR HANDLING */
/**
* Sets the one and ONLY color that should be used for this DataSet when
* open > close.
*
* @param color
*/
public void setDecreasingColor(int color) {
mDecreasingColor = color;
}
/**
* Returns the decreasing color.
*
* @return
*/
public int getDecreasingColor() {
return mDecreasingColor;
}
/**
* Sets the one and ONLY color that should be used for this DataSet when
* open <= close.
*
* @param color
*/
public void setIncreasingColor(int color) {
mIncreasingColor = color;
}
/**
* Returns the increasing color.
*
* @return
*/
public int getIncreasingColor() {
return mIncreasingColor;
}
/**
* Returns paint style when open > close
*
* @return
*/
public Paint.Style getDecreasingPaintStyle() {
return mDecreasingPaintStyle;
}
/**
* Sets paint style when open > close
*
* @param decreasingPaintStyle
*/
public void setDecreasingPaintStyle(Paint.Style decreasingPaintStyle) {
this.mDecreasingPaintStyle = decreasingPaintStyle;
}
/**
* Returns paint style when open <= close
*
* @return
*/
public Paint.Style getIncreasingPaintStyle() {
return mIncreasingPaintStyle;
}
/**
* Sets paint style when open <= close
*
* @param paintStyle
*/
public void setIncreasingPaintStyle(Paint.Style paintStyle) {
this.mIncreasingPaintStyle = paintStyle;
}
/**
* Returns shadow color for all entries
*
* @return
*/
public int getShadowColor() {
return mShadowColor;
}
/**
* Sets shadow color for all entries
*
* @param shadowColor
*/
public void setShadowColor(int shadowColor) {
this.mShadowColor = shadowColor;
}
}