|
2 | 2 |
|
3 | 3 | import android.graphics.Paint;
|
4 | 4 |
|
5 |
| -import com.github.mikephil.charting.utils.DefaultValueFormatter; |
| 5 | +import com.github.mikephil.charting.formatter.DefaultValueFormatter; |
| 6 | +import com.github.mikephil.charting.formatter.DefaultYAxisValueFormatter; |
6 | 7 | import com.github.mikephil.charting.utils.Utils;
|
7 |
| -import com.github.mikephil.charting.utils.ValueFormatter; |
| 8 | +import com.github.mikephil.charting.formatter.YAxisValueFormatter; |
8 | 9 |
|
9 | 10 | /**
|
10 | 11 | * Class representing the y-axis labels settings and its entries. Only use the setter methods to modify it. Do not
|
|
17 | 18 | public class YAxis extends AxisBase {
|
18 | 19 |
|
19 | 20 | /** custom formatter that is used instead of the auto-formatter if set */
|
20 |
| - protected ValueFormatter mValueFormatter; |
| 21 | + protected YAxisValueFormatter mYAxisValueFormatter; |
21 | 22 |
|
22 | 23 | /** the actual array of entries */
|
23 | 24 | public float[] mEntries = new float[] {};
|
@@ -358,42 +359,46 @@ public String getFormattedLabel(int index) {
|
358 | 359 | if (index < 0 || index >= mEntries.length)
|
359 | 360 | return "";
|
360 | 361 | else
|
361 |
| - return getValueFormatter().getFormattedValue(mEntries[index]); |
| 362 | + return getValueFormatter().getFormattedValue(mEntries[index], this); |
362 | 363 | }
|
363 | 364 |
|
364 | 365 | /**
|
365 |
| - * Sets the formatter to be used for drawing the values inside the chart. If no formatter is set, the chart will |
| 366 | + * Sets the formatter to be used for formatting the axis labels. If no formatter is set, the chart will |
366 | 367 | * automatically determine a reasonable formatting (concerning decimals) for all the values that are drawn inside
|
367 | 368 | * the chart. Use chart.getDefaultValueFormatter() to use the formatter calculated by the chart.
|
368 | 369 | *
|
369 | 370 | * @param f
|
370 | 371 | */
|
371 |
| - public void setValueFormatter(ValueFormatter f) { |
| 372 | + public void setValueFormatter(YAxisValueFormatter f) { |
372 | 373 |
|
373 | 374 | if (f == null)
|
374 |
| - return; |
| 375 | + mYAxisValueFormatter = new DefaultYAxisValueFormatter(mDecimals); |
375 | 376 | else
|
376 |
| - mValueFormatter = f; |
| 377 | + mYAxisValueFormatter = f; |
377 | 378 | }
|
378 | 379 |
|
379 | 380 | /**
|
380 |
| - * Returns the formatter used for drawing the values inside the chart. |
| 381 | + * Returns the formatter used for formatting the axis labels. |
381 | 382 | *
|
382 | 383 | * @return
|
383 | 384 | */
|
384 |
| - public ValueFormatter getValueFormatter() { |
385 |
| - return mValueFormatter; |
| 385 | + public YAxisValueFormatter getValueFormatter() { |
| 386 | + |
| 387 | + if(mYAxisValueFormatter == null) |
| 388 | + mYAxisValueFormatter = new DefaultYAxisValueFormatter(mDecimals); |
| 389 | + |
| 390 | + return mYAxisValueFormatter; |
386 | 391 | }
|
387 | 392 |
|
388 | 393 | /**
|
389 |
| - * If this component has no ValueFormatter or is only equipped with the default one (no custom set), return true. |
| 394 | + * If this component has no YAxisValueFormatter or is only equipped with the default one (no custom set), return true. |
390 | 395 | *
|
391 | 396 | * @return
|
392 | 397 | */
|
393 | 398 | public boolean needsDefaultFormatter() {
|
394 |
| - if (mValueFormatter == null) |
| 399 | + if (mYAxisValueFormatter == null) |
395 | 400 | return true;
|
396 |
| - if (mValueFormatter instanceof DefaultValueFormatter) |
| 401 | + if (mYAxisValueFormatter instanceof DefaultValueFormatter) |
397 | 402 | return true;
|
398 | 403 |
|
399 | 404 | return false;
|
|
0 commit comments