-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkipLabelValueFormatter.java
More file actions
47 lines (37 loc) · 1.27 KB
/
SkipLabelValueFormatter.java
File metadata and controls
47 lines (37 loc) · 1.27 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
package com.piyush.mpchartutil;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
/**
* AxisValueFormatter
* Description: This helps to skip the labels in axises, Can be extended to provide different decorator for values.
* Date: 10/3/17
*
* @author Piyush Agarwal
*/
public class SkipLabelFormatter implements IAxisValueFormatter {
private int mSkippedCount = 0;
private int mNoOfLabelsToSkip;
private int newLabelToSkip;
public SkipLabelFormatter(int noOfLabelsToSkip) {
mNoOfLabelsToSkip = noOfLabelsToSkip;
newLabelToSkip = mNoOfLabelsToSkip;
}
@Override
public String getFormattedValue(float value, AxisBase axis) {
String label;
//Always show first one and never show the zeroth one
if (mSkippedCount == 1) {
label = getDecoratedValue(value);
} else if (mSkippedCount - 2 >= newLabelToSkip) {
label = getDecoratedValue(value);
newLabelToSkip = newLabelToSkip + mNoOfLabelsToSkip + 1;
} else {
label = "";
}
mSkippedCount++;
return label;
}
protected String getDecoratedValue(float value) {
return String.valueOf(value);
}
}