• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 package com.github.mikephil.charting.components;
3 
4 import android.graphics.Color;
5 import android.graphics.Typeface;
6 
7 import com.github.mikephil.charting.utils.Utils;
8 
9 /**
10  * This class encapsulates everything both Axis, Legend and LimitLines have in common.
11  *
12  * @author Philipp Jahoda
13  */
14 public abstract class ComponentBase {
15 
16     /**
17      * flag that indicates if this axis / legend is enabled or not
18      */
19     protected boolean mEnabled = true;
20 
21     /**
22      * the offset in pixels this component has on the x-axis
23      */
24     protected float mXOffset = 5f;
25 
26     /**
27      * the offset in pixels this component has on the Y-axis
28      */
29     protected float mYOffset = 5f;
30 
31     /**
32      * the typeface used for the labels
33      */
34     protected Typeface mTypeface = null;
35 
36     /**
37      * the text size of the labels
38      */
39     protected float mTextSize = Utils.convertDpToPixel(10f);
40 
41     /**
42      * the text color to use for the labels
43      */
44     protected int mTextColor = Color.BLACK;
45 
46 
ComponentBase()47     public ComponentBase() {
48 
49     }
50 
51     /**
52      * Returns the used offset on the x-axis for drawing the axis or legend
53      * labels. This offset is applied before and after the label.
54      *
55      * @return
56      */
getXOffset()57     public float getXOffset() {
58         return mXOffset;
59     }
60 
61     /**
62      * Sets the used x-axis offset for the labels on this axis.
63      *
64      * @param xOffset
65      */
setXOffset(float xOffset)66     public void setXOffset(float xOffset) {
67         mXOffset = Utils.convertDpToPixel(xOffset);
68     }
69 
70     /**
71      * Returns the used offset on the x-axis for drawing the axis labels. This
72      * offset is applied before and after the label.
73      *
74      * @return
75      */
getYOffset()76     public float getYOffset() {
77         return mYOffset;
78     }
79 
80     /**
81      * Sets the used y-axis offset for the labels on this axis. For the legend,
82      * higher offset means the legend as a whole will be placed further away
83      * from the top.
84      *
85      * @param yOffset
86      */
setYOffset(float yOffset)87     public void setYOffset(float yOffset) {
88         mYOffset = Utils.convertDpToPixel(yOffset);
89     }
90 
91     /**
92      * returns the Typeface used for the labels, returns null if none is set
93      *
94      * @return
95      */
getTypeface()96     public Typeface getTypeface() {
97         return mTypeface;
98     }
99 
100     /**
101      * sets a specific Typeface for the labels
102      *
103      * @param tf
104      */
setTypeface(Typeface tf)105     public void setTypeface(Typeface tf) {
106         mTypeface = tf;
107     }
108 
109     /**
110      * sets the size of the label text in density pixels min = 6f, max = 24f, default
111      * 10f
112      *
113      * @param size the text size, in DP
114      */
setTextSize(float size)115     public void setTextSize(float size) {
116 
117         if (size > 24f)
118             size = 24f;
119         if (size < 6f)
120             size = 6f;
121 
122         mTextSize = Utils.convertDpToPixel(size);
123     }
124 
125     /**
126      * returns the text size that is currently set for the labels, in pixels
127      *
128      * @return
129      */
getTextSize()130     public float getTextSize() {
131         return mTextSize;
132     }
133 
134 
135     /**
136      * Sets the text color to use for the labels. Make sure to use
137      * getResources().getColor(...) when using a color from the resources.
138      *
139      * @param color
140      */
setTextColor(int color)141     public void setTextColor(int color) {
142         mTextColor = color;
143     }
144 
145     /**
146      * Returns the text color that is set for the labels.
147      *
148      * @return
149      */
getTextColor()150     public int getTextColor() {
151         return mTextColor;
152     }
153 
154     /**
155      * Set this to true if this component should be enabled (should be drawn),
156      * false if not. If disabled, nothing of this component will be drawn.
157      * Default: true
158      *
159      * @param enabled
160      */
setEnabled(boolean enabled)161     public void setEnabled(boolean enabled) {
162         mEnabled = enabled;
163     }
164 
165     /**
166      * Returns true if this comonent is enabled (should be drawn), false if not.
167      *
168      * @return
169      */
isEnabled()170     public boolean isEnabled() {
171         return mEnabled;
172     }
173 }
174