7
7
import android .graphics .Paint .Style ;
8
8
9
9
import com .github .mikephil .charting .components .AxisBase ;
10
- import com .github .mikephil .charting .utils .MPPointD ;
11
10
import com .github .mikephil .charting .utils .Transformer ;
12
11
import com .github .mikephil .charting .utils .Utils ;
13
12
import com .github .mikephil .charting .utils .ViewPortHandler ;
@@ -115,73 +114,26 @@ public Transformer getTransformer() {
115
114
* @param min - the minimum value in the data object for this axis
116
115
* @param max - the maximum value in the data object for this axis
117
116
*/
118
- public void computeAxis (float min , float max , boolean inverted ) {
117
+ public abstract void computeAxis (float min , float max , boolean inverted );
119
118
120
- // calculate the starting and entry point of the y-labels (depending on
121
- // zoom / contentrect bounds)
122
- if (mViewPortHandler != null && mViewPortHandler .contentWidth () > 10 && !mViewPortHandler .isFullyZoomedOutY ()) {
123
-
124
- MPPointD p1 = mTrans .getValuesByTouchPoint (mViewPortHandler .contentLeft (), mViewPortHandler .contentTop ());
125
- MPPointD p2 = mTrans .getValuesByTouchPoint (mViewPortHandler .contentLeft (), mViewPortHandler .contentBottom ());
126
-
127
- if (!inverted ) {
128
-
129
- min = (float ) p2 .y ;
130
- max = (float ) p1 .y ;
131
- } else {
132
-
133
- min = (float ) p1 .y ;
134
- max = (float ) p2 .y ;
135
- }
136
-
137
- MPPointD .recycleInstance (p1 );
138
- MPPointD .recycleInstance (p2 );
139
- }
140
-
141
- computeAxisValues (min , max );
142
- }
143
119
144
120
/**
145
- * Sets up the axis values. Computes the desired number of labels between the two given extremes.
146
- *
147
- * @return
121
+ * Compute axis interval and desired number of labels between the two given extremes
122
+ * @param min
123
+ * @param max
148
124
*/
149
- protected void computeAxisValues (float min , float max ) {
150
-
151
- float yMin = min ;
152
- float yMax = max ;
153
-
154
- int labelCount = mAxis .getLabelCount ();
155
- double range = Math .abs (yMax - yMin );
156
-
157
- if (labelCount == 0 || range <= 0 || Double .isInfinite (range )) {
158
- mAxis .mEntries = new float []{};
159
- mAxis .mCenteredEntries = new float []{};
160
- mAxis .mEntryCount = 0 ;
161
- return ;
162
- }
163
-
164
- // Find out how much spacing (in y value space) between axis values
165
- double rawInterval = range / labelCount ;
166
- double interval = Utils .roundToNextSignificant (rawInterval );
167
-
168
- // If granularity is enabled, then do not allow the interval to go below specified granularity.
169
- // This is used to avoid repeated values when rounding values for display.
170
- if (mAxis .isGranularityEnabled ())
171
- interval = interval < mAxis .getGranularity () ? mAxis .getGranularity () : interval ;
172
-
173
- // Normalize interval
174
- double intervalMagnitude = Utils .roundToNextSignificant (Math .pow (10 , (int ) Math .log10 (interval )));
175
- int intervalSigDigit = (int ) (interval / intervalMagnitude );
176
- if (intervalSigDigit > 5 ) {
177
- // Use one order of magnitude higher, to avoid intervals like 0.9 or 90
178
- // if it's 0.0 after floor(), we use the old value
179
- interval = Math .floor (10.0 * intervalMagnitude ) == 0.0
180
- ? interval
181
- : Math .floor (10.0 * intervalMagnitude );
182
-
183
- }
125
+ protected abstract void computeAxisInterval (float min , float max );
184
126
127
+ /**
128
+ * Setup axis entries and decimals based on the previously computed interval and labels count
129
+ * @param min
130
+ * @param max
131
+ * @param labelCount
132
+ * @param range
133
+ * @param interval
134
+ */
135
+ protected void computeAxisValues (float min , float max , int labelCount , double range , double interval ) {
136
+
185
137
int n = mAxis .isCenterAxisLabelsEnabled () ? 1 : 0 ;
186
138
187
139
// force label count
@@ -207,12 +159,12 @@ protected void computeAxisValues(float min, float max) {
207
159
// no forced count
208
160
} else {
209
161
210
- double first = interval == 0.0 ? 0.0 : Math .ceil (yMin / interval ) * interval ;
162
+ double first = interval == 0.0 ? 0.0 : Math .ceil (min / interval ) * interval ;
211
163
if (mAxis .isCenterAxisLabelsEnabled ()) {
212
164
first -= interval ;
213
165
}
214
166
215
- double last = interval == 0.0 ? 0.0 : Utils .nextUp (Math .floor (yMax / interval ) * interval );
167
+ double last = interval == 0.0 ? 0.0 : Utils .nextUp (Math .floor (max / interval ) * interval );
216
168
217
169
double f ;
218
170
int i ;
@@ -262,7 +214,7 @@ else if (last == first && n == 0) {
262
214
}
263
215
}
264
216
}
265
-
217
+
266
218
/**
267
219
* Draws the axis labels to the screen.
268
220
*
0 commit comments