ComponentBase.java
3.75 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
package com.github.mikephil.charting.components;
import android.graphics.Color;
import android.graphics.Typeface;
import com.github.mikephil.charting.utils.Utils;
/**
* This class encapsulates everything both Axis, Legend and LimitLines have in common.
*
* @author Philipp Jahoda
*/
public abstract class ComponentBase {
/**
* flag that indicates if this axis / legend is enabled or not
*/
protected boolean mEnabled = true;
/**
* the offset in pixels this component has on the x-axis
*/
protected float mXOffset = 5f;
/**
* the offset in pixels this component has on the Y-axis
*/
protected float mYOffset = 5f;
/**
* the typeface used for the labels
*/
protected Typeface mTypeface = null;
/**
* the text size of the labels
*/
protected float mTextSize = Utils.convertDpToPixel(10f);
/**
* the text color to use for the labels
*/
protected int mTextColor = Color.BLACK;
public ComponentBase() {
}
/**
* Returns the used offset on the x-axis for drawing the axis or legend
* labels. This offset is applied before and after the label.
*
* @return
*/
public float getXOffset() {
return mXOffset;
}
/**
* Sets the used x-axis offset for the labels on this axis.
*
* @param xOffset
*/
public void setXOffset(float xOffset) {
mXOffset = Utils.convertDpToPixel(xOffset);
}
/**
* Returns the used offset on the x-axis for drawing the axis labels. This
* offset is applied before and after the label.
*
* @return
*/
public float getYOffset() {
return mYOffset;
}
/**
* Sets the used y-axis offset for the labels on this axis. For the legend,
* higher offset means the legend as a whole will be placed further away
* from the top.
*
* @param yOffset
*/
public void setYOffset(float yOffset) {
mYOffset = Utils.convertDpToPixel(yOffset);
}
/**
* returns the Typeface used for the labels, returns null if none is set
*
* @return
*/
public Typeface getTypeface() {
return mTypeface;
}
/**
* sets a specific Typeface for the labels
*
* @param tf
*/
public void setTypeface(Typeface tf) {
mTypeface = tf;
}
/**
* sets the size of the label text in density pixels min = 6f, max = 24f, default
* 10f
*
* @param size the text size, in DP
*/
public void setTextSize(float size) {
if (size > 24f)
size = 24f;
if (size < 6f)
size = 6f;
mTextSize = Utils.convertDpToPixel(size);
}
/**
* returns the text size that is currently set for the labels, in pixels
*
* @return
*/
public float getTextSize() {
return mTextSize;
}
/**
* Sets the text color to use for the labels. Make sure to use
* getResources().getColor(...) when using a color from the resources.
*
* @param color
*/
public void setTextColor(int color) {
mTextColor = color;
}
/**
* Returns the text color that is set for the labels.
*
* @return
*/
public int getTextColor() {
return mTextColor;
}
/**
* Set this to true if this component should be enabled (should be drawn),
* false if not. If disabled, nothing of this component will be drawn.
* Default: true
*
* @param enabled
*/
public void setEnabled(boolean enabled) {
mEnabled = enabled;
}
/**
* Returns true if this comonent is enabled (should be drawn), false if not.
*
* @return
*/
public boolean isEnabled() {
return mEnabled;
}
}