/
LimitLine.java
215 lines (185 loc) 路 5.39 KB
/
LimitLine.java
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
package com.github.mikephil.charting.components;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Typeface;
import com.github.mikephil.charting.utils.Utils;
/**
* The limit line is an additional feature for all Line-, Bar- and
* ScatterCharts. It allows the displaying of an additional line in the chart
* that marks a certain maximum / limit on the specified axis (x- or y-axis).
*
* @author Philipp Jahoda
*/
public class LimitLine extends ComponentBase {
/** limit / maximum (the y-value or xIndex) */
private float mLimit = 0f;
/** the width of the limit line */
private float mLineWidth = 2f;
/** the color of the limit line */
private int mLineColor = Color.rgb(237, 91, 91);
/** the style of the label text */
private Paint.Style mTextStyle = Paint.Style.FILL_AND_STROKE;
/** label string that is drawn next to the limit line */
private String mLabel = "";
/** the path effect of this LimitLine that makes dashed lines possible */
private DashPathEffect mDashPathEffect = null;
/** indicates the position of the LimitLine label */
private LimitLabelPosition mLabelPosition = LimitLabelPosition.RIGHT_TOP;
/** enum that indicates the position of the LimitLine label */
public enum LimitLabelPosition {
LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM
}
/**
* Constructor with limit.
*
* @param limit - the position (the value) on the y-axis (y-value) or x-axis
* (xIndex) where this line should appear
*/
public LimitLine(float limit) {
mLimit = limit;
}
/**
* Constructor with limit and label.
*
* @param limit - the position (the value) on the y-axis (y-value) or x-axis
* (xIndex) where this line should appear
* @param label - provide "" if no label is required
*/
public LimitLine(float limit, String label) {
mLimit = limit;
mLabel = label;
}
/**
* Returns the limit that is set for this line.
*
* @return
*/
public float getLimit() {
return mLimit;
}
/**
* set the line width of the chart (min = 0.2f, max = 12f); default 2f NOTE:
* thinner line == better performance, thicker line == worse performance
*
* @param width
*/
public void setLineWidth(float width) {
if (width < 0.2f)
width = 0.2f;
if (width > 12.0f)
width = 12.0f;
mLineWidth = Utils.convertDpToPixel(width);
}
/**
* returns the width of limit line
*
* @return
*/
public float getLineWidth() {
return mLineWidth;
}
/**
* Sets the linecolor for this LimitLine. Make sure to use
* getResources().getColor(...)
*
* @param color
*/
public void setLineColor(int color) {
mLineColor = color;
}
/**
* Returns the color that is used for this LimitLine
*
* @return
*/
public int getLineColor() {
return mLineColor;
}
/**
* Enables the line to be drawn in dashed mode, e.g. like this "- - - - - -"
*
* @param lineLength the length of the line pieces
* @param spaceLength the length of space inbetween the pieces
* @param phase offset, in degrees (normally, use 0)
*/
public void enableDashedLine(float lineLength, float spaceLength, float phase) {
mDashPathEffect = new DashPathEffect(new float[] {
lineLength, spaceLength
}, phase);
}
/**
* Disables the line to be drawn in dashed mode.
*/
public void disableDashedLine() {
mDashPathEffect = null;
}
/**
* Returns true if the dashed-line effect is enabled, false if not. Default:
* disabled
*
* @return
*/
public boolean isDashedLineEnabled() {
return mDashPathEffect == null ? false : true;
}
/**
* returns the DashPathEffect that is set for this LimitLine
*
* @return
*/
public DashPathEffect getDashPathEffect() {
return mDashPathEffect;
}
/**
* Sets the color of the value-text that is drawn next to the LimitLine.
* Default: Paint.Style.FILL_AND_STROKE
*
* @param style
*/
public void setTextStyle(Paint.Style style) {
this.mTextStyle = style;
}
/**
* Returns the color of the value-text that is drawn next to the LimitLine.
*
* @return
*/
public Paint.Style getTextStyle() {
return mTextStyle;
}
/**
* Sets the position of the LimitLine value label (either on the right or on
* the left edge of the chart). Not supported for RadarChart.
*
* @param pos
*/
public void setLabelPosition(LimitLabelPosition pos) {
mLabelPosition = pos;
}
/**
* Returns the position of the LimitLine label (value).
*
* @return
*/
public LimitLabelPosition getLabelPosition() {
return mLabelPosition;
}
/**
* Sets the label that is drawn next to the limit line. Provide "" if no
* label is required.
*
* @param label
*/
public void setLabel(String label) {
mLabel = label;
}
/**
* Returns the label that is drawn next to the limit line.
*
* @return
*/
public String getLabel() {
return mLabel;
}
}