aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Cohen Gindi <Danielgindi@gmail.com>2020-09-21 17:53:08 +0300
committerGitHub <noreply@github.com>2020-09-21 17:53:08 +0300
commit8c92fcdd2ed21a9e29b8aa4c392ca3281fd5e2e7 (patch)
tree7b40d32f5f1f290ab64fb47e33a6e7ec82577655
parent8e4dccf3f8ea76a3ff4d84079054bb8cb2af6602 (diff)
parentbc0be2cfe13e32a5d8adefaa507e3512d22d85fb (diff)
downloadMPAndroidChart-8c92fcdd2ed21a9e29b8aa4c392ca3281fd5e2e7.tar.gz
Merge pull request #5011 from danielgindi/fix/value_formatter
Revert: e5b66192 - bring back polymorphism to value formatters
-rw-r--r--.gitignore6
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java9
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java8
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java19
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java8
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java8
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PieChartActivity.java2
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java8
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java6
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java21
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/DayAxisValueFormatter.java7
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyAxisValueFormatter.java21
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyCustomXAxisValueFormatter.java7
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyValueFormatter.java27
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/XYMarkerView.java9
-rw-r--r--MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/YearXAxisFormatter.java6
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java5
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java11
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java8
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/data/ChartData.java5
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultAxisValueFormatter.java8
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultValueFormatter.java8
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IAxisValueFormatter.java6
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IValueFormatter.java10
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IndexAxisValueFormatter.java12
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/formatter/LargeValueFormatter.java16
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java51
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/formatter/StackedValueFormatter.java24
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/formatter/ValueFormatter.java137
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/ChartInterface.java4
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.java7
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.java25
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.java13
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java20
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CombinedChartRenderer.java7
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/DataRenderer.java21
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java17
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java13
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java29
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java20
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.java19
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java3
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.java7
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererRadarChart.java4
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/utils/Utils.java24
-rw-r--r--MPChartLib/src/test/java/com/github/mikephil/charting/test/LargeValueFormatterTest.java50
-rw-r--r--MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java2
47 files changed, 340 insertions, 418 deletions
diff --git a/.gitignore b/.gitignore
index 1f0e3083..feed37b2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@
bin/
gen/
generated/
+docs/
finalOutput/
projectFilesBackup/
@@ -23,8 +24,6 @@ local.properties
# Eclipse project files
.classpath
.project
-.settings/
-.vscode/
# Proguard folder generated by Eclipse
proguard/
@@ -33,8 +32,7 @@ proguard/
*.iml
*.ipr
*.iws
-/.idea/*
-!/.idea/runConfigurations
+.idea/
.directory
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java
index 89ec00a8..0d83e344 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java
@@ -1,3 +1,4 @@
+
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
@@ -27,7 +28,7 @@ import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
@@ -35,7 +36,7 @@ import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.Fill;
import com.github.mikephil.charting.utils.MPPointF;
import com.xxmassdeveloper.mpchartexample.custom.DayAxisValueFormatter;
-import com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter;
+import com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.XYMarkerView;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@@ -85,7 +86,7 @@ public class BarChartActivity extends DemoBase implements OnSeekBarChangeListene
chart.setDrawGridBackground(false);
// chart.setDrawYLabels(false);
- ValueFormatter xAxisFormatter = new DayAxisValueFormatter(chart);
+ IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(chart);
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
@@ -95,7 +96,7 @@ public class BarChartActivity extends DemoBase implements OnSeekBarChangeListene
xAxis.setLabelCount(7);
xAxis.setValueFormatter(xAxisFormatter);
- ValueFormatter custom = new MyValueFormatter("$");
+ IAxisValueFormatter custom = new MyAxisValueFormatter();
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setTypeface(tfLight);
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java
index 3369dbf6..075af0ed 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java
@@ -1,3 +1,4 @@
+
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
@@ -16,6 +17,7 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.github.mikephil.charting.charts.BarChart;
+import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
@@ -23,8 +25,8 @@ import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.LargeValueFormatter;
-import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
@@ -98,9 +100,9 @@ public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarC
xAxis.setTypeface(tfLight);
xAxis.setGranularity(1f);
xAxis.setCenterAxisLabels(true);
- xAxis.setValueFormatter(new ValueFormatter() {
+ xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
return String.valueOf((int) value);
}
});
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java
index 8960dc77..4fec7dd6 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java
@@ -1,3 +1,4 @@
+
package com.xxmassdeveloper.mpchartexample;
import android.content.Intent;
@@ -9,13 +10,17 @@ import android.view.MenuItem;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.BarChart;
+import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.data.Entry;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
+import com.github.mikephil.charting.formatter.IValueFormatter;
+import com.github.mikephil.charting.utils.ViewPortHandler;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.text.DecimalFormat;
@@ -83,9 +88,9 @@ public class BarChartPositiveNegative extends DemoBase {
data.add(new Data(3f, -442.3f, "01-01"));
data.add(new Data(4f, -2280.1f, "01-02"));
- xAxis.setValueFormatter(new ValueFormatter() {
+ xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
return data.get(Math.min(Math.max((int) value, 0), data.size()-1)).xAxisValue;
}
});
@@ -130,7 +135,7 @@ public class BarChartPositiveNegative extends DemoBase {
BarData data = new BarData(set);
data.setValueTextSize(13f);
data.setValueTypeface(tfRegular);
- data.setValueFormatter(new Formatter());
+ data.setValueFormatter(new ValueFormatter());
data.setBarWidth(0.8f);
chart.setData(data);
@@ -154,17 +159,17 @@ public class BarChartPositiveNegative extends DemoBase {
}
}
- private class Formatter extends ValueFormatter
+ private class ValueFormatter implements IValueFormatter
{
private final DecimalFormat mFormat;
- Formatter() {
+ ValueFormatter() {
mFormat = new DecimalFormat("######.0");
}
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return mFormat.format(value);
}
}
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java
index 53dd3806..0308b9a8 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java
@@ -1,3 +1,4 @@
+
package com.xxmassdeveloper.mpchartexample;
import android.content.Intent;
@@ -10,6 +11,7 @@ import android.view.WindowManager;
import com.github.mikephil.charting.charts.CombinedChart;
import com.github.mikephil.charting.charts.CombinedChart.DrawOrder;
+import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
@@ -29,7 +31,7 @@ import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.ScatterData;
import com.github.mikephil.charting.data.ScatterDataSet;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@@ -81,9 +83,9 @@ public class CombinedChartActivity extends DemoBase {
xAxis.setPosition(XAxisPosition.BOTH_SIDED);
xAxis.setAxisMinimum(0f);
xAxis.setGranularity(1f);
- xAxis.setValueFormatter(new ValueFormatter() {
+ xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
return months[(int) value % months.length];
}
});
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java
index e9ae3c0e..212b90ff 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java
@@ -1,3 +1,4 @@
+
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
@@ -15,6 +16,7 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.github.mikephil.charting.charts.LineChart;
+import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
@@ -22,7 +24,7 @@ import com.github.mikephil.charting.components.YAxis.AxisDependency;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@@ -90,12 +92,12 @@ public class LineChartTime extends DemoBase implements OnSeekBarChangeListener {
xAxis.setTextColor(Color.rgb(255, 192, 56));
xAxis.setCenterAxisLabels(true);
xAxis.setGranularity(1f); // one hour
- xAxis.setValueFormatter(new ValueFormatter() {
+ xAxis.setValueFormatter(new IAxisValueFormatter() {
private final SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH);
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
long millis = TimeUnit.HOURS.toMillis((long) value);
return mFormat.format(new Date(millis));
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PieChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PieChartActivity.java
index 4aeb1b3e..830025fb 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PieChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PieChartActivity.java
@@ -160,7 +160,7 @@ public class PieChartActivity extends DemoBase implements OnSeekBarChangeListene
//dataSet.setSelectionShift(0f);
PieData data = new PieData(dataSet);
- data.setValueFormatter(new PercentFormatter(chart));
+ data.setValueFormatter(new PercentFormatter());
data.setValueTextSize(11f);
data.setValueTextColor(Color.WHITE);
data.setValueTypeface(tfLight);
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java
index 9fdae983..883eb7df 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java
@@ -1,3 +1,4 @@
+
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
@@ -13,6 +14,7 @@ import android.view.WindowManager;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.RadarChart;
+import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.components.XAxis;
@@ -20,7 +22,7 @@ import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.RadarData;
import com.github.mikephil.charting.data.RadarDataSet;
import com.github.mikephil.charting.data.RadarEntry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import com.xxmassdeveloper.mpchartexample.custom.RadarMarkerView;
@@ -67,12 +69,12 @@ public class RadarChartActivity extends DemoBase {
xAxis.setTextSize(9f);
xAxis.setYOffset(0f);
xAxis.setXOffset(0f);
- xAxis.setValueFormatter(new ValueFormatter() {
+ xAxis.setValueFormatter(new IAxisValueFormatter() {
private final String[] mActivities = new String[]{"Burger", "Steak", "Salad", "Pasta", "Pizza"};
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
return mActivities[(int) value % mActivities.length];
}
});
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java
index 1def86e8..676e0e62 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java
@@ -24,11 +24,11 @@ import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
-import com.github.mikephil.charting.formatter.StackedValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
+import com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@@ -78,7 +78,7 @@ public class StackedBarActivity extends DemoBase implements OnSeekBarChangeListe
// change the position of the y-labels
YAxis leftAxis = chart.getAxisLeft();
- leftAxis.setValueFormatter(new MyValueFormatter("K"));
+ leftAxis.setValueFormatter(new MyAxisValueFormatter());
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
chart.getAxisRight().setEnabled(false);
@@ -142,7 +142,7 @@ public class StackedBarActivity extends DemoBase implements OnSeekBarChangeListe
dataSets.add(set1);
BarData data = new BarData(dataSets);
- data.setValueFormatter(new StackedValueFormatter(false, "", 1));
+ data.setValueFormatter(new MyValueFormatter());
data.setValueTextColor(Color.WHITE);
chart.setData(data);
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java
index a4e510a2..7af58c85 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java
@@ -1,3 +1,4 @@
+
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
@@ -13,6 +14,7 @@ import android.view.MenuItem;
import android.view.WindowManager;
import com.github.mikephil.charting.charts.HorizontalBarChart;
+import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
@@ -21,10 +23,12 @@ import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IValueFormatter;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
+import com.github.mikephil.charting.utils.ViewPortHandler;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.text.DecimalFormat;
@@ -76,12 +80,12 @@ public class StackedBarActivityNegative extends DemoBase implements
xAxis.setCenterAxisLabels(true);
xAxis.setLabelCount(12);
xAxis.setGranularity(10f);
- xAxis.setValueFormatter(new ValueFormatter() {
+ xAxis.setValueFormatter(new IAxisValueFormatter() {
private final DecimalFormat format = new DecimalFormat("###");
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
return format.format(value) + "-" + format.format(value + 10);
}
});
@@ -238,7 +242,7 @@ public class StackedBarActivityNegative extends DemoBase implements
Log.i("NOTING SELECTED", "");
}
- private class CustomFormatter extends ValueFormatter {
+ private class CustomFormatter implements IValueFormatter, IAxisValueFormatter {
private final DecimalFormat mFormat;
@@ -246,8 +250,15 @@ public class StackedBarActivityNegative extends DemoBase implements
mFormat = new DecimalFormat("###");
}
+ // data
+ @Override
+ public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
+ return mFormat.format(Math.abs(value)) + "m";
+ }
+
+ // YAxis
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
return mFormat.format(Math.abs(value)) + "m";
}
}
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/DayAxisValueFormatter.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/DayAxisValueFormatter.java
index 1fba5cc9..ba4d860d 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/DayAxisValueFormatter.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/DayAxisValueFormatter.java
@@ -1,12 +1,13 @@
package com.xxmassdeveloper.mpchartexample.custom;
import com.github.mikephil.charting.charts.BarLineChartBase;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.components.AxisBase;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
/**
* Created by philipp on 02/06/16.
*/
-public class DayAxisValueFormatter extends ValueFormatter
+public class DayAxisValueFormatter implements IAxisValueFormatter
{
private final String[] mMonths = new String[]{
@@ -20,7 +21,7 @@ public class DayAxisValueFormatter extends ValueFormatter
}
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
int days = (int) value;
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyAxisValueFormatter.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyAxisValueFormatter.java
new file mode 100644
index 00000000..e7cdbfcd
--- /dev/null
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyAxisValueFormatter.java
@@ -0,0 +1,21 @@
+package com.xxmassdeveloper.mpchartexample.custom;
+
+import com.github.mikephil.charting.components.AxisBase;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
+
+import java.text.DecimalFormat;
+
+public class MyAxisValueFormatter implements IAxisValueFormatter
+{
+
+ private final DecimalFormat mFormat;
+
+ public MyAxisValueFormatter() {
+ mFormat = new DecimalFormat("###,###,###,##0.0");
+ }
+
+ @Override
+ public String getFormattedValue(float value, AxisBase axis) {
+ return mFormat.format(value) + " $";
+ }
+}
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyCustomXAxisValueFormatter.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyCustomXAxisValueFormatter.java
index 2cf2eab7..bea4908e 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyCustomXAxisValueFormatter.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyCustomXAxisValueFormatter.java
@@ -1,6 +1,7 @@
package com.xxmassdeveloper.mpchartexample.custom;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.components.AxisBase;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.text.DecimalFormat;
@@ -11,7 +12,7 @@ import java.text.DecimalFormat;
* @deprecated The {@link MyAxisValueFormatter} does exactly the same thing and is more functional.
*/
@Deprecated
-public class MyCustomXAxisValueFormatter extends ValueFormatter
+public class MyCustomXAxisValueFormatter implements IAxisValueFormatter
{
private final DecimalFormat mFormat;
@@ -24,7 +25,7 @@ public class MyCustomXAxisValueFormatter extends ValueFormatter
}
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
//Log.i("TRANS", "x: " + viewPortHandler.getTransX() + ", y: " + viewPortHandler.getTransY());
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyValueFormatter.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyValueFormatter.java
index 0b0bf2f2..ec1c1198 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyValueFormatter.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/MyValueFormatter.java
@@ -1,35 +1,22 @@
package com.xxmassdeveloper.mpchartexample.custom;
-import com.github.mikephil.charting.components.AxisBase;
-import com.github.mikephil.charting.components.XAxis;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.data.Entry;
+import com.github.mikephil.charting.formatter.IValueFormatter;
+import com.github.mikephil.charting.utils.ViewPortHandler;
import java.text.DecimalFormat;
-public class MyValueFormatter extends ValueFormatter
+public class MyValueFormatter implements IValueFormatter
{
private final DecimalFormat mFormat;
- private String suffix;
- public MyValueFormatter(String suffix) {
+ public MyValueFormatter() {
mFormat = new DecimalFormat("###,###,###,##0.0");
- this.suffix = suffix;
}
@Override
- public String getFormattedValue(float value) {
- return mFormat.format(value) + suffix;
- }
-
- @Override
- public String getAxisLabel(float value, AxisBase axis) {
- if (axis instanceof XAxis) {
- return mFormat.format(value);
- } else if (value > 0) {
- return mFormat.format(value) + suffix;
- } else {
- return mFormat.format(value);
- }
+ public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
+ return mFormat.format(value) + " $";
}
}
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/XYMarkerView.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/XYMarkerView.java
index ed9dcb8a..51e4247d 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/XYMarkerView.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/XYMarkerView.java
@@ -1,3 +1,4 @@
+
package com.xxmassdeveloper.mpchartexample.custom;
import android.annotation.SuppressLint;
@@ -6,7 +7,7 @@ import android.widget.TextView;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;
import com.xxmassdeveloper.mpchartexample.R;
@@ -22,11 +23,11 @@ import java.text.DecimalFormat;
public class XYMarkerView extends MarkerView {
private final TextView tvContent;
- private final ValueFormatter xAxisValueFormatter;
+ private final IAxisValueFormatter xAxisValueFormatter;
private final DecimalFormat format;
- public XYMarkerView(Context context, ValueFormatter xAxisValueFormatter) {
+ public XYMarkerView(Context context, IAxisValueFormatter xAxisValueFormatter) {
super(context, R.layout.custom_marker_view);
this.xAxisValueFormatter = xAxisValueFormatter;
@@ -39,7 +40,7 @@ public class XYMarkerView extends MarkerView {
@Override
public void refreshContent(Entry e, Highlight highlight) {
- tvContent.setText(String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(e.getX()), format.format(e.getY())));
+ tvContent.setText(String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(e.getX(), null), format.format(e.getY())));
super.refreshContent(e, highlight);
}
diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/YearXAxisFormatter.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/YearXAxisFormatter.java
index d45853f8..7122e0d8 100644
--- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/YearXAxisFormatter.java
+++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/custom/YearXAxisFormatter.java
@@ -1,13 +1,13 @@
package com.xxmassdeveloper.mpchartexample.custom;
import com.github.mikephil.charting.components.AxisBase;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
/**
* Created by Philipp Jahoda on 14/09/15.
*/
@SuppressWarnings("unused")
-public class YearXAxisFormatter extends ValueFormatter
+public class YearXAxisFormatter implements IAxisValueFormatter
{
private final String[] mMonths = new String[]{
@@ -19,7 +19,7 @@ public class YearXAxisFormatter extends ValueFormatter
}
@Override
- public String getAxisLabel(float value, AxisBase axis) {
+ public String getFormattedValue(float value, AxisBase axis) {
float percent = value / axis.mAxisRange;
return mMonths[(int) (mMonths.length * percent)];
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java
index b104935d..5cf49ea9 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.charts;
import android.animation.ValueAnimator;
@@ -34,7 +35,7 @@ import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.DefaultValueFormatter;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.highlight.ChartHighlighter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.highlight.IHighlighter;
@@ -1021,7 +1022,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
*
* @return
*/
- public ValueFormatter getDefaultValueFormatter() {
+ public IValueFormatter getDefaultValueFormatter() {
return mDefaultValueFormatter;
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java
index 96f706a3..c90b4fc9 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.components;
import android.graphics.Color;
@@ -5,7 +6,7 @@ import android.graphics.DashPathEffect;
import android.util.Log;
import com.github.mikephil.charting.formatter.DefaultAxisValueFormatter;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
@@ -21,7 +22,7 @@ public abstract class AxisBase extends ComponentBase {
/**
* custom formatter that is used instead of the auto-formatter if set
*/
- protected ValueFormatter mAxisValueFormatter;
+ protected IAxisValueFormatter mAxisValueFormatter;
private int mGridColor = Color.GRAY;
@@ -518,7 +519,7 @@ public abstract class AxisBase extends ComponentBase {
if (index < 0 || index >= mEntries.length)
return "";
else
- return getValueFormatter().getAxisLabel(mEntries[index], this);
+ return getValueFormatter().getFormattedValue(mEntries[index], this);
}
/**
@@ -530,7 +531,7 @@ public abstract class AxisBase extends ComponentBase {
*
* @param f
*/
- public void setValueFormatter(ValueFormatter f) {
+ public void setValueFormatter(IAxisValueFormatter f) {
if (f == null)
mAxisValueFormatter = new DefaultAxisValueFormatter(mDecimals);
@@ -543,7 +544,7 @@ public abstract class AxisBase extends ComponentBase {
*
* @return
*/
- public ValueFormatter getValueFormatter() {
+ public IAxisValueFormatter getValueFormatter() {
if (mAxisValueFormatter == null ||
(mAxisValueFormatter instanceof DefaultAxisValueFormatter &&
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java
index a4279629..7e7445ca 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java
@@ -7,7 +7,7 @@ import android.graphics.Typeface;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.YAxis;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.MPPointF;
@@ -51,7 +51,7 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
/**
* custom formatter that is used instead of the auto-formatter if set
*/
- protected transient ValueFormatter mValueFormatter;
+ protected transient IValueFormatter mValueFormatter;
/**
* the typeface used for the value text
@@ -274,7 +274,7 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
}
@Override
- public void setValueFormatter(ValueFormatter f) {
+ public void setValueFormatter(IValueFormatter f) {
if (f == null)
return;
@@ -283,7 +283,7 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
}
@Override
- public ValueFormatter getValueFormatter() {
+ public IValueFormatter getValueFormatter() {
if (needsFormatter())
return Utils.getDefaultValueFormatter();
return mValueFormatter;
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/ChartData.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/ChartData.java
index 95d439a7..bfc5ed70 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/ChartData.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/ChartData.java
@@ -1,10 +1,11 @@
+
package com.github.mikephil.charting.data;
import android.graphics.Typeface;
import android.util.Log;
import com.github.mikephil.charting.components.YAxis.AxisDependency;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
@@ -658,7 +659,7 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
*
* @param f
*/
- public void setValueFormatter(ValueFormatter f) {
+ public void setValueFormatter(IValueFormatter f) {
if (f == null)
return;
else {
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultAxisValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultAxisValueFormatter.java
index c8834c3e..552c150e 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultAxisValueFormatter.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultAxisValueFormatter.java
@@ -1,11 +1,13 @@
package com.github.mikephil.charting.formatter;
+import com.github.mikephil.charting.components.AxisBase;
+
import java.text.DecimalFormat;
/**
* Created by philipp on 02/06/16.
*/
-public class DefaultAxisValueFormatter extends ValueFormatter
+public class DefaultAxisValueFormatter implements IAxisValueFormatter
{
/**
@@ -16,7 +18,7 @@ public class DefaultAxisValueFormatter extends ValueFormatter
/**
* the number of decimal digits this formatter uses
*/
- protected int digits;
+ protected int digits = 0;
/**
* Constructor that specifies to how many digits the value should be
@@ -38,7 +40,7 @@ public class DefaultAxisValueFormatter extends ValueFormatter
}
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
// avoid memory allocations here (for performance)
return mFormat.format(value);
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultValueFormatter.java
index 40668b91..e2fea4b0 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultValueFormatter.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/DefaultValueFormatter.java
@@ -1,5 +1,9 @@
+
package com.github.mikephil.charting.formatter;
+import com.github.mikephil.charting.data.Entry;
+import com.github.mikephil.charting.utils.ViewPortHandler;
+
import java.text.DecimalFormat;
/**
@@ -8,7 +12,7 @@ import java.text.DecimalFormat;
*
* @author Philipp Jahoda
*/
-public class DefaultValueFormatter extends ValueFormatter
+public class DefaultValueFormatter implements IValueFormatter
{
/**
@@ -48,7 +52,7 @@ public class DefaultValueFormatter extends ValueFormatter
}
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
// put more logic here ...
// avoid memory allocations here (for performance reasons)
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IAxisValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IAxisValueFormatter.java
index 970ea6fc..51939b54 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IAxisValueFormatter.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IAxisValueFormatter.java
@@ -6,10 +6,7 @@ import com.github.mikephil.charting.components.AxisBase;
* Created by Philipp Jahoda on 20/09/15.
* Custom formatter interface that allows formatting of
* axis labels before they are being drawn.
- *
- * @deprecated Extend {@link ValueFormatter} instead
*/
-@Deprecated
public interface IAxisValueFormatter
{
@@ -21,9 +18,6 @@ public interface IAxisValueFormatter
* @param value the value to be formatted
* @param axis the axis the value belongs to
* @return
- *
- * @deprecated Extend {@link ValueFormatter} and use {@link ValueFormatter#getAxisLabel(float, AxisBase)}
*/
- @Deprecated
String getFormattedValue(float value, AxisBase axis);
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IValueFormatter.java
index 0dde7012..75d2363f 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IValueFormatter.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IValueFormatter.java
@@ -4,12 +4,13 @@ import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
- * Interface to format all values before they are drawn as labels.
+ * Interface that allows custom formatting of all values inside the chart before they are
+ * being drawn to the screen. Simply create your own formatting class and let
+ * it implement IValueFormatter. Then override the getFormattedValue(...) method
+ * and return whatever you want.
*
* @author Philipp Jahoda
- * @deprecated Extend {@link ValueFormatter} instead
*/
-@Deprecated
public interface IValueFormatter
{
@@ -23,9 +24,6 @@ public interface IValueFormatter
* @param dataSetIndex the index of the DataSet the entry in focus belongs to
* @param viewPortHandler provides information about the current chart state (scale, translation, ...)
* @return the formatted label ready for being drawn
- *
- * @deprecated Extend {@link ValueFormatter} and override an appropriate method
*/
- @Deprecated
String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler);
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IndexAxisValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IndexAxisValueFormatter.java
index 7ab7bdbe..07349a6a 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IndexAxisValueFormatter.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/IndexAxisValueFormatter.java
@@ -1,11 +1,18 @@
+
package com.github.mikephil.charting.formatter;
+import com.github.mikephil.charting.components.AxisBase;
+import com.github.mikephil.charting.data.Entry;
+import com.github.mikephil.charting.utils.ViewPortHandler;
+
+import java.text.DecimalFormat;
+import java.util.Arrays;
import java.util.Collection;
/**
* This formatter is used for passing an array of x-axis labels, on whole x steps.
*/
-public class IndexAxisValueFormatter extends ValueFormatter
+public class IndexAxisValueFormatter implements IAxisValueFormatter
{
private String[] mValues = new String[] {};
private int mValueCount = 0;
@@ -37,8 +44,7 @@ public class IndexAxisValueFormatter extends ValueFormatter
setValues(values.toArray(new String[values.size()]));
}
- @Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
int index = Math.round(value);
if (index < 0 || index >= mValueCount || index != (int)value)
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/LargeValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/LargeValueFormatter.java
index 4870a4cf..211401ad 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/LargeValueFormatter.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/LargeValueFormatter.java
@@ -1,5 +1,10 @@
+
package com.github.mikephil.charting.formatter;
+import com.github.mikephil.charting.components.AxisBase;
+import com.github.mikephil.charting.data.Entry;
+import com.github.mikephil.charting.utils.ViewPortHandler;
+
import java.text.DecimalFormat;
/**
@@ -12,7 +17,7 @@ import java.text.DecimalFormat;
* @author Philipp Jahoda
* @author Oleksandr Tyshkovets <olexandr.tyshkovets@gmail.com>
*/
-public class LargeValueFormatter extends ValueFormatter
+public class LargeValueFormatter implements IValueFormatter, IAxisValueFormatter
{
private String[] mSuffix = new String[]{
@@ -36,8 +41,15 @@ public class LargeValueFormatter extends ValueFormatter
mText = appendix;
}
+ // IValueFormatter
+ @Override
+ public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
+ return makePretty(value) + mText;
+ }
+
+ // IAxisValueFormatter
@Override
- public String getFormattedValue(float value) {
+ public String getFormattedValue(float value, AxisBase axis) {
return makePretty(value) + mText;
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java
index 012fab77..de8a1025 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java
@@ -1,54 +1,49 @@
+
package com.github.mikephil.charting.formatter;
-import com.github.mikephil.charting.charts.PieChart;
-import com.github.mikephil.charting.data.PieEntry;
+import com.github.mikephil.charting.components.AxisBase;
+import com.github.mikephil.charting.data.Entry;
+import com.github.mikephil.charting.utils.ViewPortHandler;
import java.text.DecimalFormat;
/**
* This IValueFormatter is just for convenience and simply puts a "%" sign after
- * each value. (Recommended for PieChart)
+ * each value. (Recommeded for PieChart)
*
* @author Philipp Jahoda
*/
-public class PercentFormatter extends ValueFormatter
+public class PercentFormatter implements IValueFormatter, IAxisValueFormatter
{
- public DecimalFormat mFormat;
- private PieChart pieChart;
- private boolean percentSignSeparated;
+ protected DecimalFormat mFormat;
public PercentFormatter() {
mFormat = new DecimalFormat("###,###,##0.0");
- percentSignSeparated = true;
- }
-
- // Can be used to remove percent signs if the chart isn't in percent mode
- public PercentFormatter(PieChart pieChart) {
- this();
- this.pieChart = pieChart;
}
- // Can be used to remove percent signs if the chart isn't in percent mode
- public PercentFormatter(PieChart pieChart, boolean percentSignSeparated) {
- this(pieChart);
- this.percentSignSeparated = percentSignSeparated;
+ /**
+ * Allow a custom decimalformat
+ *
+ * @param format
+ */
+ public PercentFormatter(DecimalFormat format) {
+ this.mFormat = format;
}
+ // IValueFormatter
@Override
- public String getFormattedValue(float value) {
- return mFormat.format(value) + (percentSignSeparated ? " %" : "%");
+ public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
+ return mFormat.format(value) + " %";
}
+ // IAxisValueFormatter
@Override
- public String getPieLabel(float value, PieEntry pieEntry) {
- if (pieChart != null && pieChart.isUsePercentValuesEnabled()) {
- // Converted to percent
- return getFormattedValue(value);
- } else {
- // raw value, skip percent sign
- return mFormat.format(value);
- }
+ public String getFormattedValue(float value, AxisBase axis) {
+ return mFormat.format(value) + " %";
}
+ public int getDecimalDigits() {
+ return 1;
+ }
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/StackedValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/StackedValueFormatter.java
index 7c69dcf5..0e835163 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/StackedValueFormatter.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/StackedValueFormatter.java
@@ -1,6 +1,8 @@
package com.github.mikephil.charting.formatter;
import com.github.mikephil.charting.data.BarEntry;
+import com.github.mikephil.charting.data.Entry;
+import com.github.mikephil.charting.utils.ViewPortHandler;
import java.text.DecimalFormat;
@@ -10,7 +12,7 @@ import java.text.DecimalFormat;
* A formatter specifically for stacked BarChart that allows to specify whether the all stack values
* or just the top value should be drawn.
*/
-public class StackedValueFormatter extends ValueFormatter
+public class StackedValueFormatter implements IValueFormatter
{
/**
@@ -21,7 +23,7 @@ public class StackedValueFormatter extends ValueFormatter
/**
* a string that should be appended behind the value
*/
- private String mSuffix;
+ private String mAppendix;
private DecimalFormat mFormat;
@@ -29,12 +31,12 @@ public class StackedValueFormatter extends ValueFormatter
* Constructor.
*
* @param drawWholeStack if true, all stack values of the stacked bar entry are drawn, else only top
- * @param suffix a string that should be appended behind the value
+ * @param appendix a string that should be appended behind the value
* @param decimals the number of decimal digits to use
*/
- public StackedValueFormatter(boolean drawWholeStack, String suffix, int decimals) {
+ public StackedValueFormatter(boolean drawWholeStack, String appendix, int decimals) {
this.mDrawWholeStack = drawWholeStack;
- this.mSuffix = suffix;
+ this.mAppendix = appendix;
StringBuffer b = new StringBuffer();
for (int i = 0; i < decimals; i++) {
@@ -47,10 +49,12 @@ public class StackedValueFormatter extends ValueFormatter
}
@Override
- public String getBarStackedLabel(float value, BarEntry entry) {
- if (!mDrawWholeStack) {
+ public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
- float[] vals = entry.getYVals();
+ if (!mDrawWholeStack && entry instanceof BarEntry) {
+
+ BarEntry barEntry = (BarEntry) entry;
+ float[] vals = barEntry.getYVals();
if (vals != null) {
@@ -58,7 +62,7 @@ public class StackedValueFormatter extends ValueFormatter
if (vals[vals.length - 1] == value) {
// return the "sum" across all stack values
- return mFormat.format(entry.getY()) + mSuffix;
+ return mFormat.format(barEntry.getY()) + mAppendix;
} else {
return ""; // return empty
}
@@ -66,6 +70,6 @@ public class StackedValueFormatter extends ValueFormatter
}
// return the "proposed" value
- return mFormat.format(value) + mSuffix;
+ return mFormat.format(value) + mAppendix;
}
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/ValueFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/ValueFormatter.java
deleted file mode 100644
index d2f53cb7..00000000
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/ValueFormatter.java
+++ /dev/null
@@ -1,137 +0,0 @@
-package com.github.mikephil.charting.formatter;
-
-import com.github.mikephil.charting.components.AxisBase;
-import com.github.mikephil.charting.data.BarEntry;
-import com.github.mikephil.charting.data.BubbleEntry;
-import com.github.mikephil.charting.data.CandleEntry;
-import com.github.mikephil.charting.data.Entry;
-import com.github.mikephil.charting.data.PieEntry;
-import com.github.mikephil.charting.data.RadarEntry;
-import com.github.mikephil.charting.utils.ViewPortHandler;
-
-/**
- * Class to format all values before they are drawn as labels.
- */
-public abstract class ValueFormatter implements IAxisValueFormatter, IValueFormatter{
-
- /**
- * <b>DO NOT USE</b>, only for backwards compatibility and will be removed in future versions.
- *
- * @param value the value to be formatted
- * @param axis the axis the value belongs to
- * @return formatted string label
- */
- @Override
- @Deprecated
- public String getFormattedValue(float value, AxisBase axis) {
- return getFormattedValue(value);
- }
-
- /**
- * <b>DO NOT USE</b>, only for backwards compatibility and will be removed in future versions.
- * @param value the value to be formatted
- * @param entry the entry the value belongs to - in e.g. BarChart, this is of class BarEntry
- * @param dataSetIndex the index of the DataSet the entry in focus belongs to
- * @param viewPortHandler provides information about the current chart state (scale, translation, ...)
- * @return formatted string label
- */
- @Override
- @Deprecated
- public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
- return getFormattedValue(value);
- }
-
- /**
- * Called when drawing any label, used to change numbers into formatted strings.
- *
- * @param value float to be formatted
- * @return formatted string label
- */
- public String getFormattedValue(float value) {
- return String.valueOf(value);
- }
-
- /**
- * Used to draw axis labels, calls {@link #getFormattedValue(float)} by default.
- *
- * @param value float to be formatted
- * @param axis axis being labeled
- * @return formatted string label
- */
- public String getAxisLabel(float value, AxisBase axis) {
- return getFormattedValue(value);
- }
-
- /**
- * Used to draw bar labels, calls {@link #getFormattedValue(float)} by default.
- *
- * @param barEntry bar being labeled
- * @return formatted string label
- */
- public String getBarLabel(BarEntry barEntry) {
- return getFormattedValue(barEntry.getY());
- }
-
- /**
- * Used to draw stacked bar labels, calls {@link #getFormattedValue(float)} by default.
- *
- * @param value current value to be formatted
- * @param stackedEntry stacked entry being labeled, contains all Y values
- * @return formatted string label
- */
- public String getBarStackedLabel(float value, BarEntry stackedEntry) {
- return getFormattedValue(value);
- }
-
- /**
- * Used to draw line and scatter labels, calls {@link #getFormattedValue(float)} by default.
- *
- * @param entry point being labeled, contains X value
- * @return formatted string label
- */
- public String getPointLabel(Entry entry) {
- return getFormattedValue(entry.getY());
- }
-
- /**
- * Used to draw pie value labels, calls {@link #getFormattedValue(float)} by default.
- *
- * @param value float to be formatted, may have been converted to percentage
- * @param pieEntry slice being labeled, contains original, non-percentage Y value
- * @return formatted string label
- */
- public String getPieLabel(float value, PieEntry pieEntry) {
- return getFormattedValue(value);
- }
-
- /**
- * Used to draw radar value labels, calls {@link #getFormattedValue(float)} by default.
- *
- * @param radarEntry entry being labeled
- * @return formatted string label
- */
- public String getRadarLabel(RadarEntry radarEntry) {
- return getFormattedValue(radarEntry.getY());
- }
-
- /**
- * Used to draw bubble size labels, calls {@link #getFormattedValue(float)} by default.
- *
- * @param bubbleEntry bubble being labeled, also contains X and Y values
- * @return formatted string label
- */
- public String getBubbleLabel(BubbleEntry bubbleEntry) {
- return getFormattedValue(bubbleEntry.getSize());
- }
-
- /**
- * Used to draw high labels, calls {@link #getFormattedValue(float)} by default.
- *
- * @param candleEntry candlestick being labeled
- * @return formatted string label
- */
- public String getCandleLabel(CandleEntry candleEntry) {
- return getFormattedValue(candleEntry.getHigh());
- }
-
-}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/ChartInterface.java b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/ChartInterface.java
index 182aa287..219b46bd 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/ChartInterface.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/dataprovider/ChartInterface.java
@@ -3,7 +3,7 @@ package com.github.mikephil.charting.interfaces.dataprovider;
import android.graphics.RectF;
import com.github.mikephil.charting.data.ChartData;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.utils.MPPointF;
/**
@@ -61,7 +61,7 @@ public interface ChartInterface {
RectF getContentRect();
- ValueFormatter getDefaultValueFormatter();
+ IValueFormatter getDefaultValueFormatter();
ChartData getData();
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.java
index ccd4cb4f..fd8af706 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/interfaces/datasets/IDataSet.java
@@ -1,13 +1,14 @@
package com.github.mikephil.charting.interfaces.datasets;
import android.graphics.DashPathEffect;
+import android.graphics.PointF;
import android.graphics.Typeface;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.utils.MPPointF;
import java.util.List;
@@ -317,14 +318,14 @@ public interface IDataSet<T extends Entry> {
*
* @param f
*/
- void setValueFormatter(ValueFormatter f);
+ void setValueFormatter(IValueFormatter f);
/**
* Returns the formatter used for drawing the values inside the chart.
*
* @return
*/
- ValueFormatter getValueFormatter();
+ IValueFormatter getValueFormatter();
/**
* Returns true if the valueFormatter object of this DataSet is null.
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.java
index 18975557..1656a3a3 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BarChartRenderer.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@@ -10,7 +11,6 @@ import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.buffer.BarBuffer;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarEntry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.highlight.Range;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
@@ -241,8 +241,6 @@ public class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
final float phaseY = mAnimator.getPhaseY();
- ValueFormatter formatter = dataSet.getValueFormatter();
-
MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
@@ -265,7 +263,8 @@ public class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
float val = entry.getY();
if (dataSet.isDrawValuesEnabled()) {
- drawValue(c, formatter.getBarLabel(entry), x, val >= 0 ?
+ drawValue(c, dataSet.getValueFormatter(), val, entry, i, x,
+ val >= 0 ?
(buffer.buffer[j + 1] + posOffset) :
(buffer.buffer[j + 3] + negOffset),
dataSet.getValueTextColor(j / 4));
@@ -323,7 +322,8 @@ public class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
continue;
if (dataSet.isDrawValuesEnabled()) {
- drawValue(c, formatter.getBarLabel(entry), x, buffer.buffer[bufferIndex + 1] +
+ drawValue(c, dataSet.getValueFormatter(), entry.getY(), entry, i, x,
+ buffer.buffer[bufferIndex + 1] +
(entry.getY() >= 0 ? posOffset : negOffset),
color);
}
@@ -394,7 +394,14 @@ public class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
continue;
if (dataSet.isDrawValuesEnabled()) {
- drawValue(c, formatter.getBarStackedLabel(val, entry), x, y, color);
+ drawValue(c,
+ dataSet.getValueFormatter(),
+ vals[k / 2],
+ entry,
+ i,
+ x,
+ y,
+ color);
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@@ -423,12 +430,6 @@ public class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
}
@Override
- public void drawValue(Canvas c, String valueText, float x, float y, int color) {
- mValuePaint.setColor(color);
- c.drawText(valueText, x, y, mValuePaint);
- }
-
- @Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
BarData barData = mChart.getBarData();
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.java
index be141c46..5ce19c2c 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/BubbleChartRenderer.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@@ -8,7 +9,6 @@ import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.data.BubbleData;
import com.github.mikephil.charting.data.BubbleEntry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.BubbleDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet;
@@ -150,8 +150,6 @@ public class BubbleChartRenderer extends BarLineScatterCandleBubbleRenderer {
final float alpha = phaseX == 1 ? phaseY : phaseX;
- ValueFormatter formatter = dataSet.getValueFormatter();
-
MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
@@ -174,7 +172,8 @@ public class BubbleChartRenderer extends BarLineScatterCandleBubbleRenderer {
BubbleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
if (dataSet.isDrawValuesEnabled()) {
- drawValue(c, formatter.getBubbleLabel(entry), x, y + (0.5f * lineHeight), valueTextColor);
+ drawValue(c, dataSet.getValueFormatter(), entry.getSize(), entry, i, x,
+ y + (0.5f * lineHeight), valueTextColor);
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@@ -197,12 +196,6 @@ public class BubbleChartRenderer extends BarLineScatterCandleBubbleRenderer {
}
@Override
- public void drawValue(Canvas c, String valueText, float x, float y, int color) {
- mValuePaint.setColor(color);
- c.drawText(valueText, x, y, mValuePaint);
- }
-
- @Override
public void drawExtras(Canvas c) {
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java
index 027dda31..991b7021 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CandleStickChartRenderer.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@@ -7,7 +8,6 @@ import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.data.CandleData;
import com.github.mikephil.charting.data.CandleEntry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.CandleDataProvider;
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
@@ -279,8 +279,6 @@ public class CandleStickChartRenderer extends LineScatterCandleRadarRenderer {
float yOffset = Utils.convertDpToPixel(5f);
- ValueFormatter formatter = dataSet.getValueFormatter();
-
MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
@@ -299,7 +297,15 @@ public class CandleStickChartRenderer extends LineScatterCandleRadarRenderer {
CandleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
if (dataSet.isDrawValuesEnabled()) {
- drawValue(c, formatter.getCandleLabel(entry), x, y - yOffset, dataSet.getValueTextColor(j / 2));
+ drawValue(c,
+ dataSet.getValueFormatter(),
+ entry.getHigh(),
+ entry,
+ i,
+ x,
+ y - yOffset,
+ dataSet
+ .getValueTextColor(j / 2));
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@@ -322,12 +328,6 @@ public class CandleStickChartRenderer extends LineScatterCandleRadarRenderer {
}
@Override
- public void drawValue(Canvas c, String valueText, float x, float y, int color) {
- mValuePaint.setColor(color);
- c.drawText(valueText, x, y, mValuePaint);
- }
-
- @Override
public void drawExtras(Canvas c) {
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CombinedChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CombinedChartRenderer.java
index 8f6be3c0..6d0d4d3d 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CombinedChartRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/CombinedChartRenderer.java
@@ -1,7 +1,6 @@
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
-import android.util.Log;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.charts.Chart;
@@ -10,6 +9,7 @@ import com.github.mikephil.charting.charts.CombinedChart.DrawOrder;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.highlight.Highlight;
+import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.lang.ref.WeakReference;
@@ -90,11 +90,6 @@ public class CombinedChartRenderer extends DataRenderer {
}
@Override
- public void drawValue(Canvas c, String valueText, float x, float y, int color) {
- Log.e("MPAndroidChart", "Erroneous call to drawValue() in CombinedChartRenderer!");
- }
-
- @Override
public void drawValues(Canvas c) {
for (DataRenderer renderer : mRenderers)
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/DataRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/DataRenderer.java
index da4a26ed..e8e5446f 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/DataRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/DataRenderer.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@@ -5,11 +6,15 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
+import android.graphics.drawable.Drawable;
import com.github.mikephil.charting.animation.ChartAnimator;
+import com.github.mikephil.charting.data.Entry;
+import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.ChartInterface;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
+import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
@@ -133,13 +138,19 @@ public abstract class DataRenderer extends Renderer {
/**
* Draws the value of the given entry by using the provided IValueFormatter.
*
- * @param c canvas
- * @param valueText label to draw
- * @param x position
- * @param y position
+ * @param c canvas
+ * @param formatter formatter for custom value-formatting
+ * @param value the value to be drawn
+ * @param entry the entry the value belongs to
+ * @param dataSetIndex the index of the DataSet the drawn Entry belongs to
+ * @param x position
+ * @param y position
* @param color
*/
- public abstract void drawValue(Canvas c, String valueText, float x, float y, int color);
+ public void drawValue(Canvas c, IValueFormatter formatter, float value, Entry entry, int dataSetIndex, float x, float y, int color) {
+ mValuePaint.setColor(color);
+ c.drawText(formatter.getFormattedValue(value, entry, dataSetIndex, mViewPortHandler), x, y, mValuePaint);
+ }
/**
* Draws any kind of additional information (e.g. line-circles).
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java
index b42ef128..0cd72345 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/HorizontalBarChartRenderer.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@@ -10,7 +11,7 @@ import com.github.mikephil.charting.buffer.BarBuffer;
import com.github.mikephil.charting.buffer.HorizontalBarBuffer;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarEntry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.interfaces.dataprovider.ChartInterface;
@@ -181,7 +182,7 @@ public class HorizontalBarChartRenderer extends BarChartRenderer {
applyValueTextStyle(dataSet);
final float halfTextHeight = Utils.calcTextHeight(mValuePaint, "10") / 2f;
- ValueFormatter formatter = dataSet.getValueFormatter();
+ IValueFormatter formatter = dataSet.getValueFormatter();
// get the buffer
BarBuffer buffer = mBarBuffers[i];
@@ -210,7 +211,7 @@ public class HorizontalBarChartRenderer extends BarChartRenderer {
BarEntry entry = dataSet.getEntryForIndex(j / 4);
float val = entry.getY();
- String formattedValue = formatter.getBarLabel(entry);
+ String formattedValue = formatter.getFormattedValue(val, entry, i, mViewPortHandler);
// calculate the correct offset depending on the draw position of the value
float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
@@ -280,7 +281,9 @@ public class HorizontalBarChartRenderer extends BarChartRenderer {
if (!mViewPortHandler.isInBoundsBottom(buffer.buffer[bufferIndex + 1]))
continue;
- String formattedValue = formatter.getBarLabel(entry);
+ float val = entry.getY();
+ String formattedValue = formatter.getFormattedValue(val,
+ entry, i, mViewPortHandler);
// calculate the correct offset depending on the draw position of the value
float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
@@ -350,7 +353,8 @@ public class HorizontalBarChartRenderer extends BarChartRenderer {
for (int k = 0; k < transformed.length; k += 2) {
final float val = vals[k / 2];
- String formattedValue = formatter.getBarStackedLabel(val, entry);
+ String formattedValue = formatter.getFormattedValue(val,
+ entry, i, mViewPortHandler);
// calculate the correct offset depending on the draw position of the value
float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
@@ -408,8 +412,7 @@ public class HorizontalBarChartRenderer extends BarChartRenderer {
}
}
- @Override
- public void drawValue(Canvas c, String valueText, float x, float y, int color) {
+ protected void drawValue(Canvas c, String valueText, float x, float y, int color) {
mValuePaint.setColor(color);
c.drawText(valueText, x, y, mValuePaint);
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java
index a00860b5..a86c16f7 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/LineChartRenderer.java
@@ -12,7 +12,6 @@ import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
-import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
@@ -295,7 +294,7 @@ public class LineChartRenderer extends LineRadarRenderer {
int entryCount = dataSet.getEntryCount();
- final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED;
+ final boolean isDrawSteppedEnabled = dataSet.isDrawSteppedEnabled();
final int pointsPerEntryPair = isDrawSteppedEnabled ? 4 : 2;
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
@@ -562,7 +561,6 @@ public class LineChartRenderer extends LineRadarRenderer {
float[] positions = trans.generateTransformedValuesLine(dataSet, mAnimator.getPhaseX(), mAnimator
.getPhaseY(), mXBounds.min, mXBounds.max);
- ValueFormatter formatter = dataSet.getValueFormatter();
MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
@@ -582,7 +580,8 @@ public class LineChartRenderer extends LineRadarRenderer {
Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
if (dataSet.isDrawValuesEnabled()) {
- drawValue(c, formatter.getPointLabel(entry), x, y - valOffset, dataSet.getValueTextColor(j / 2));
+ drawValue(c, dataSet.getValueFormatter(), entry.getY(), entry, i, x,
+ y - valOffset, dataSet.getValueTextColor(j / 2));
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@@ -605,12 +604,6 @@ public class LineChartRenderer extends LineRadarRenderer {
}
@Override
- public void drawValue(Canvas c, String valueText, float x, float y, int color) {
- mValuePaint.setColor(color);
- c.drawText(valueText, x, y, mValuePaint);
- }
-
- @Override
public void drawExtras(Canvas c) {
drawCircles(c);
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java
index f427ffe5..f35c775d 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.renderer;
import android.graphics.Bitmap;
@@ -21,7 +22,7 @@ import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
@@ -464,7 +465,7 @@ public class PieChartRenderer extends DataRenderer {
float lineHeight = Utils.calcTextHeight(mValuePaint, "Q")
+ Utils.convertDpToPixel(4f);
- ValueFormatter formatter = dataSet.getValueFormatter();
+ IValueFormatter formatter = dataSet.getValueFormatter();
int entryCount = dataSet.getEntryCount();
@@ -500,7 +501,6 @@ public class PieChartRenderer extends DataRenderer {
float value = mChart.isUsePercentValuesEnabled() ? entry.getY()
/ yValueSum * 100f : entry.getY();
- String formattedValue = formatter.getPieLabel(value, entry);
String entryLabel = entry.getLabel();
final float sliceXBase = (float) Math.cos(transformedAngle * Utils.FDEG2RAD);
@@ -583,7 +583,14 @@ public class PieChartRenderer extends DataRenderer {
// draw everything, depending on settings
if (drawXOutside && drawYOutside) {
- drawValue(c, formattedValue, labelPtx, labelPty, dataSet.getValueTextColor(j));
+ drawValue(c,
+ formatter,
+ value,
+ entry,
+ 0,
+ labelPtx,
+ labelPty,
+ dataSet.getValueTextColor(j));
if (j < data.getEntryCount() && entryLabel != null) {
drawEntryLabel(c, entryLabel, labelPtx, labelPty + lineHeight);
@@ -595,7 +602,8 @@ public class PieChartRenderer extends DataRenderer {
}
} else if (drawYOutside) {
- drawValue(c, formattedValue, labelPtx, labelPty + lineHeight / 2.f, dataSet.getValueTextColor(j));
+ drawValue(c, formatter, value, entry, 0, labelPtx, labelPty + lineHeight / 2.f, dataSet
+ .getValueTextColor(j));
}
}
@@ -609,7 +617,7 @@ public class PieChartRenderer extends DataRenderer {
// draw everything, depending on settings
if (drawXInside && drawYInside) {
- drawValue(c, formattedValue, x, y, dataSet.getValueTextColor(j));
+ drawValue(c, formatter, value, entry, 0, x, y, dataSet.getValueTextColor(j));
if (j < data.getEntryCount() && entryLabel != null) {
drawEntryLabel(c, entryLabel, x, y + lineHeight);
@@ -620,7 +628,8 @@ public class PieChartRenderer extends DataRenderer {
drawEntryLabel(c, entryLabel, x, y + lineHeight / 2f);
}
} else if (drawYInside) {
- drawValue(c, formattedValue, x, y + lineHeight / 2f, dataSet.getValueTextColor(j));
+
+ drawValue(c, formatter, value, entry, 0, x, y + lineHeight / 2f, dataSet.getValueTextColor(j));
}
}
@@ -650,12 +659,6 @@ public class PieChartRenderer extends DataRenderer {
c.restore();
}
- @Override
- public void drawValue(Canvas c, String valueText, float x, float y, int color) {
- mValuePaint.setColor(color);
- c.drawText(valueText, x, y, mValuePaint);
- }
-
/**
* Draws an entry label at the specified position.
*
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java
index 3f932f87..dbf0e8f8 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@@ -10,7 +11,6 @@ import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.charts.RadarChart;
import com.github.mikephil.charting.data.RadarData;
import com.github.mikephil.charting.data.RadarEntry;
-import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
@@ -174,8 +174,6 @@ public class RadarChartRenderer extends LineRadarRenderer {
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
- ValueFormatter formatter = dataSet.getValueFormatter();
-
MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
@@ -191,7 +189,15 @@ public class RadarChartRenderer extends LineRadarRenderer {
pOut);
if (dataSet.isDrawValuesEnabled()) {
- drawValue(c, formatter.getRadarLabel(entry), pOut.x, pOut.y - yoffset, dataSet.getValueTextColor(j));
+ drawValue(c,
+ dataSet.getValueFormatter(),
+ entry.getY(),
+ entry,
+ i,
+ pOut.x,
+ pOut.y - yoffset,
+ dataSet.getValueTextColor
+ (j));
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@@ -226,12 +232,6 @@ public class RadarChartRenderer extends LineRadarRenderer {
}
@Override
- public void drawValue(Canvas c, String valueText, float x, float y, int color) {
- mValuePaint.setColor(color);
- c.drawText(valueText, x, y, mValuePaint);
- }
-
- @Override
public void drawExtras(Canvas c) {
drawWeb(c);
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.java
index 98dddb93..ccd077e5 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/ScatterChartRenderer.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@@ -7,7 +8,6 @@ import android.util.Log;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.ScatterData;
-import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.ScatterDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet;
@@ -118,8 +118,6 @@ public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());
- ValueFormatter formatter = dataSet.getValueFormatter();
-
MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
@@ -137,7 +135,14 @@ public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
if (dataSet.isDrawValuesEnabled()) {
- drawValue(c, formatter.getPointLabel(entry), positions[j], positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + mXBounds.min));
+ drawValue(c,
+ dataSet.getValueFormatter(),
+ entry.getY(),
+ entry,
+ i,
+ positions[j],
+ positions[j + 1] - shapeSize,
+ dataSet.getValueTextColor(j / 2 + mXBounds.min));
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@@ -160,12 +165,6 @@ public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
}
@Override
- public void drawValue(Canvas c, String valueText, float x, float y, int color) {
- mValuePaint.setColor(color);
- c.drawText(valueText, x, y, mValuePaint);
- }
-
- @Override
public void drawExtras(Canvas c) {
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java
index 046f3469..8adb56c7 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRenderer.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@@ -201,7 +202,7 @@ public class XAxisRenderer extends AxisRenderer {
if (mViewPortHandler.isInBoundsX(x)) {
- String label = mXAxis.getValueFormatter().getAxisLabel(mXAxis.mEntries[i / 2], mXAxis);
+ String label = mXAxis.getValueFormatter().getFormattedValue(mXAxis.mEntries[i / 2], mXAxis);
if (mXAxis.isAvoidFirstLastClippingEnabled()) {
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.java
index 9054dcb6..86047cf1 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererHorizontalBarChart.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@@ -56,10 +57,10 @@ public class XAxisRendererHorizontalBarChart extends XAxisRenderer {
computeAxisValues(min, max);
}
-
+
@Override
protected void computeSize() {
-
+
mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
@@ -155,7 +156,7 @@ public class XAxisRendererHorizontalBarChart extends XAxisRenderer {
if (mViewPortHandler.isInBoundsY(y)) {
- String label = mXAxis.getValueFormatter().getAxisLabel(mXAxis.mEntries[i / 2], mXAxis);
+ String label = mXAxis.getValueFormatter().getFormattedValue(mXAxis.mEntries[i / 2], mXAxis);
drawLabel(c, label, pos, y, anchor, labelRotationAngleDegrees);
}
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererRadarChart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererRadarChart.java
index 6d83cf59..956e8c7d 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererRadarChart.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererRadarChart.java
@@ -1,6 +1,8 @@
+
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
+import android.graphics.PointF;
import com.github.mikephil.charting.charts.RadarChart;
import com.github.mikephil.charting.components.XAxis;
@@ -41,7 +43,7 @@ public class XAxisRendererRadarChart extends XAxisRenderer {
MPPointF pOut = MPPointF.getInstance(0,0);
for (int i = 0; i < mChart.getData().getMaxEntryCountSet().getEntryCount(); i++) {
- String label = mXAxis.getValueFormatter().getAxisLabel(i, mXAxis);
+ String label = mXAxis.getValueFormatter().getFormattedValue(i, mXAxis);
float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f;
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/utils/Utils.java b/MPChartLib/src/main/java/com/github/mikephil/charting/utils/Utils.java
index 60ff6ba3..c3026739 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/utils/Utils.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/utils/Utils.java
@@ -1,3 +1,4 @@
+
package com.github.mikephil.charting.utils;
import android.annotation.SuppressLint;
@@ -6,6 +7,7 @@ import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
+import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.Layout;
@@ -13,13 +15,14 @@ import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.DisplayMetrics;
import android.util.Log;
+import android.util.SizeF;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import com.github.mikephil.charting.formatter.DefaultValueFormatter;
-import com.github.mikephil.charting.formatter.ValueFormatter;
+import com.github.mikephil.charting.formatter.IValueFormatter;
import java.util.List;
@@ -226,14 +229,15 @@ public abstract class Utils {
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
};
- private static ValueFormatter mDefaultValueFormatter = generateDefaultValueFormatter();
+ private static IValueFormatter mDefaultValueFormatter = generateDefaultValueFormatter();
- private static ValueFormatter generateDefaultValueFormatter() {
- return new DefaultValueFormatter(1);
+ private static IValueFormatter generateDefaultValueFormatter() {
+ final DefaultValueFormatter formatter = new DefaultValueFormatter(1);
+ return formatter;
}
/// - returns: The default value formatter used for all chart components that needs a default
- public static ValueFormatter getDefaultValueFormatter()
+ public static IValueFormatter getDefaultValueFormatter()
{
return mDefaultValueFormatter;
}
@@ -349,11 +353,11 @@ public abstract class Utils {
* @return
*/
public static float roundToNextSignificant(double number) {
- if (Double.isInfinite(number) ||
- Double.isNaN(number) ||
+ if (Double.isInfinite(number) ||
+ Double.isNaN(number) ||
number == 0.0)
return 0;
-
+
final float d = (float) Math.ceil((float) Math.log10(number < 0 ? -number : number));
final int pw = 1 - (int) d;
final float magnitude = (float) Math.pow(10, pw);
@@ -371,10 +375,10 @@ public abstract class Utils {
public static int getDecimals(float number) {
float i = roundToNextSignificant(number);
-
+
if (Float.isInfinite(i))
return 0;
-
+
return (int) Math.ceil(-Math.log10(i)) + 2;
}
diff --git a/MPChartLib/src/test/java/com/github/mikephil/charting/test/LargeValueFormatterTest.java b/MPChartLib/src/test/java/com/github/mikephil/charting/test/LargeValueFormatterTest.java
index fc7eb93e..f1e1e027 100644
--- a/MPChartLib/src/test/java/com/github/mikephil/charting/test/LargeValueFormatterTest.java
+++ b/MPChartLib/src/test/java/com/github/mikephil/charting/test/LargeValueFormatterTest.java
@@ -16,80 +16,80 @@ public class LargeValueFormatterTest {
LargeValueFormatter formatter = new LargeValueFormatter();
- String result = formatter.getFormattedValue(5f);
+ String result = formatter.getFormattedValue(5f, null);
assertEquals("5", result);
- result = formatter.getFormattedValue(5.5f);
+ result = formatter.getFormattedValue(5.5f, null);
assertEquals("5.5", result);
- result = formatter.getFormattedValue(50f);
+ result = formatter.getFormattedValue(50f, null);
assertEquals("50", result);
- result = formatter.getFormattedValue(50.5f);
+ result = formatter.getFormattedValue(50.5f, null);
assertEquals("50.5", result);
- result = formatter.getFormattedValue(500f);
+ result = formatter.getFormattedValue(500f, null);
assertEquals("500", result);
- result = formatter.getFormattedValue(1100f);
+ result = formatter.getFormattedValue(1100f, null);
assertEquals("1.1k", result);
- result = formatter.getFormattedValue(10000f);
+ result = formatter.getFormattedValue(10000f, null);
assertEquals("10k", result);
- result = formatter.getFormattedValue(10500f);
+ result = formatter.getFormattedValue(10500f, null);
assertEquals("10.5k", result);
- result = formatter.getFormattedValue(100000f);
+ result = formatter.getFormattedValue(100000f, null);
assertEquals("100k", result);
- result = formatter.getFormattedValue(1000000f);
+ result = formatter.getFormattedValue(1000000f, null);
assertEquals("1m", result);
- result = formatter.getFormattedValue(1500000f);
+ result = formatter.getFormattedValue(1500000f, null);
assertEquals("1.5m", result);
- result = formatter.getFormattedValue(9500000f);
+ result = formatter.getFormattedValue(9500000f, null);
assertEquals("9.5m", result);
- result = formatter.getFormattedValue(22200000f);
+ result = formatter.getFormattedValue(22200000f, null);
assertEquals("22.2m", result);
- result = formatter.getFormattedValue(222000000f);
+ result = formatter.getFormattedValue(222000000f, null);
assertEquals("222m", result);
- result = formatter.getFormattedValue(1000000000f);
+ result = formatter.getFormattedValue(1000000000f, null);
assertEquals("1b", result);
- result = formatter.getFormattedValue(9900000000f);
+ result = formatter.getFormattedValue(9900000000f, null);
assertEquals("9.9b", result);
- result = formatter.getFormattedValue(99000000000f);
+ result = formatter.getFormattedValue(99000000000f, null);
assertEquals("99b", result);
- result = formatter.getFormattedValue(99500000000f);
+ result = formatter.getFormattedValue(99500000000f, null);
assertEquals("99.5b", result);
- result = formatter.getFormattedValue(999000000000f);
+ result = formatter.getFormattedValue(999000000000f, null);
assertEquals("999b", result);
- result = formatter.getFormattedValue(1000000000000f);
+ result = formatter.getFormattedValue(1000000000000f, null);
assertEquals("1t", result);
formatter.setSuffix(new String[]{"", "k", "m", "b", "t", "q"}); // quadrillion support
- result = formatter.getFormattedValue(1000000000000000f);
+ result = formatter.getFormattedValue(1000000000000000f, null);
assertEquals("1q", result);
- result = formatter.getFormattedValue(1100000000000000f);
+ result = formatter.getFormattedValue(1100000000000000f, null);
assertEquals("1.1q", result);
- result = formatter.getFormattedValue(10000000000000000f);
+ result = formatter.getFormattedValue(10000000000000000f, null);
assertEquals("10q", result);
- result = formatter.getFormattedValue(13300000000000000f);
+ result = formatter.getFormattedValue(13300000000000000f, null);
assertEquals("13.3q", result);
- result = formatter.getFormattedValue(100000000000000000f);
+ result = formatter.getFormattedValue(100000000000000000f, null);
assertEquals("100q", result);
}
}
diff --git a/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java b/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java
index 44946cf4..e1dbe81b 100644
--- a/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java
+++ b/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java
@@ -2,7 +2,7 @@ package com.github.mikephil.charting.test;
import com.github.mikephil.charting.utils.ObjectPool;
-import org.junit.Assert;
+import junit.framework.Assert;
import org.junit.Test;