New ValueFormatter

I created a simplified value formatter class, which is an abstract class rather
than an interface.

The switch was chosen because the new format has all the methods predefined
(something an interface wouldn't allow) meaning you can extend it and only
change what you want. This also means that you only need one value formatting
class for labels rather than two different classes, it just makes more sense.

Please check the method signatures to learn how to use them, I'm sure you'll
find this new format is much more customizable and faster to use.

I've made the class abstract even though there are no abstract methods or
fields, this is because it would certainly be a mistake to create a
ValueFormatter and not override any methods.

To convert existing code, just use 'extends' instead of 'implements' and change
the names to 'ValueFormatter'. You'll need to change the methods you overwrite
as well, just check the class and use the one you need.
This commit is contained in:
almic 2018-11-07 12:41:53 -07:00
parent 608d9e29f5
commit e5b66192e7
No known key found for this signature in database
GPG key ID: 432BBCA8E2FFF871
47 changed files with 408 additions and 338 deletions

6
.gitignore vendored
View file

@ -12,7 +12,6 @@
bin/
gen/
generated/
docs/
finalOutput/
build.xml
@ -23,6 +22,8 @@ local.properties
# Eclipse project files
.classpath
.project
.settings/
.vscode/
# Proguard folder generated by Eclipse
proguard/
@ -31,7 +32,8 @@ proguard/
*.iml
*.ipr
*.iws
.idea/
/.idea/*
!/.idea/runConfigurations
.directory

View file

@ -1,4 +1,3 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
@ -28,7 +27,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.IAxisValueFormatter;
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.interfaces.datasets.IDataSet;
@ -36,7 +35,7 @@ import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.model.GradientColor;
import com.github.mikephil.charting.utils.MPPointF;
import com.xxmassdeveloper.mpchartexample.custom.DayAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter;
import com.xxmassdeveloper.mpchartexample.custom.XYMarkerView;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@ -86,7 +85,7 @@ public class BarChartActivity extends DemoBase implements OnSeekBarChangeListene
chart.setDrawGridBackground(false);
// chart.setDrawYLabels(false);
IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(chart);
ValueFormatter xAxisFormatter = new DayAxisValueFormatter(chart);
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
@ -96,7 +95,7 @@ public class BarChartActivity extends DemoBase implements OnSeekBarChangeListene
xAxis.setLabelCount(7);
xAxis.setValueFormatter(xAxisFormatter);
IAxisValueFormatter custom = new MyAxisValueFormatter();
ValueFormatter custom = new MyValueFormatter("$");
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setTypeface(tfLight);

View file

@ -1,4 +1,3 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
@ -17,7 +16,6 @@ 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;
@ -25,8 +23,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;
@ -100,9 +98,9 @@ public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarC
xAxis.setTypeface(tfLight);
xAxis.setGranularity(1f);
xAxis.setCenterAxisLabels(true);
xAxis.setValueFormatter(new IAxisValueFormatter() {
xAxis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getFormattedValue(float value) {
return String.valueOf((int) value);
}
});

View file

@ -1,4 +1,3 @@
package com.xxmassdeveloper.mpchartexample;
import android.content.Intent;
@ -10,17 +9,13 @@ 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.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.github.mikephil.charting.formatter.ValueFormatter;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.text.DecimalFormat;
@ -88,9 +83,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 IAxisValueFormatter() {
xAxis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getFormattedValue(float value) {
return data.get(Math.min(Math.max((int) value, 0), data.size()-1)).xAxisValue;
}
});
@ -135,7 +130,7 @@ public class BarChartPositiveNegative extends DemoBase {
BarData data = new BarData(set);
data.setValueTextSize(13f);
data.setValueTypeface(tfRegular);
data.setValueFormatter(new ValueFormatter());
data.setValueFormatter(new Formatter());
data.setBarWidth(0.8f);
chart.setData(data);
@ -159,17 +154,17 @@ public class BarChartPositiveNegative extends DemoBase {
}
}
private class ValueFormatter implements IValueFormatter
private class Formatter extends ValueFormatter
{
private final DecimalFormat mFormat;
ValueFormatter() {
Formatter() {
mFormat = new DecimalFormat("######.0");
}
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
public String getFormattedValue(float value) {
return mFormat.format(value);
}
}

View file

@ -1,4 +1,3 @@
package com.xxmassdeveloper.mpchartexample;
import android.content.Intent;
@ -11,7 +10,6 @@ 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;
@ -31,7 +29,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.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@ -83,9 +81,9 @@ public class CombinedChartActivity extends DemoBase {
xAxis.setPosition(XAxisPosition.BOTH_SIDED);
xAxis.setAxisMinimum(0f);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
xAxis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getFormattedValue(float value) {
return months[(int) value % months.length];
}
});

View file

@ -1,4 +1,3 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
@ -16,7 +15,6 @@ 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;
@ -24,7 +22,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.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@ -92,12 +90,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 IAxisValueFormatter() {
xAxis.setValueFormatter(new ValueFormatter() {
private final SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH);
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getFormattedValue(float value) {
long millis = TimeUnit.HOURS.toMillis((long) value);
return mFormat.format(new Date(millis));

View file

@ -160,7 +160,7 @@ public class PieChartActivity extends DemoBase implements OnSeekBarChangeListene
//dataSet.setSelectionShift(0f);
PieData data = new PieData(dataSet);
data.setValueFormatter(new PercentFormatter());
data.setValueFormatter(new PercentFormatter(chart));
data.setValueTextSize(11f);
data.setValueTextColor(Color.WHITE);
data.setValueTypeface(tfLight);

View file

@ -1,4 +1,3 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
@ -14,7 +13,6 @@ 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;
@ -22,7 +20,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.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
import com.xxmassdeveloper.mpchartexample.custom.RadarMarkerView;
@ -69,12 +67,12 @@ public class RadarChartActivity extends DemoBase {
xAxis.setTextSize(9f);
xAxis.setYOffset(0f);
xAxis.setXOffset(0f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
xAxis.setValueFormatter(new ValueFormatter() {
private final String[] mActivities = new String[]{"Burger", "Steak", "Salad", "Pasta", "Pizza"};
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getFormattedValue(float value) {
return mActivities[(int) value % mActivities.length];
}
});

View file

@ -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 MyAxisValueFormatter());
leftAxis.setValueFormatter(new MyValueFormatter("K"));
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 MyValueFormatter());
data.setValueFormatter(new StackedValueFormatter(false, "", 1));
data.setValueTextColor(Color.WHITE);
chart.setData(data);

View file

@ -1,4 +1,3 @@
package com.xxmassdeveloper.mpchartexample;
import android.Manifest;
@ -14,7 +13,6 @@ 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;
@ -23,12 +21,10 @@ 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.IValueFormatter;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
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;
import com.github.mikephil.charting.utils.ViewPortHandler;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
import java.text.DecimalFormat;
@ -80,12 +76,12 @@ public class StackedBarActivityNegative extends DemoBase implements
xAxis.setCenterAxisLabels(true);
xAxis.setLabelCount(12);
xAxis.setGranularity(10f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
xAxis.setValueFormatter(new ValueFormatter() {
private final DecimalFormat format = new DecimalFormat("###");
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getFormattedValue(float value) {
return format.format(value) + "-" + format.format(value + 10);
}
});
@ -242,7 +238,7 @@ public class StackedBarActivityNegative extends DemoBase implements
Log.i("NOTING SELECTED", "");
}
private class CustomFormatter implements IValueFormatter, IAxisValueFormatter {
private class CustomFormatter extends ValueFormatter {
private final DecimalFormat mFormat;
@ -250,15 +246,8 @@ 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, AxisBase axis) {
public String getFormattedValue(float value) {
return mFormat.format(Math.abs(value)) + "m";
}
}

View file

@ -1,13 +1,12 @@
package com.xxmassdeveloper.mpchartexample.custom;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
/**
* Created by philipp on 02/06/16.
*/
public class DayAxisValueFormatter implements IAxisValueFormatter
public class DayAxisValueFormatter extends ValueFormatter
{
private final String[] mMonths = new String[]{
@ -21,7 +20,7 @@ public class DayAxisValueFormatter implements IAxisValueFormatter
}
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getFormattedValue(float value) {
int days = (int) value;

View file

@ -1,21 +0,0 @@
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) + " $";
}
}

View file

@ -1,7 +1,6 @@
package com.xxmassdeveloper.mpchartexample.custom;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.text.DecimalFormat;
@ -12,7 +11,7 @@ import java.text.DecimalFormat;
* @deprecated The {@link MyAxisValueFormatter} does exactly the same thing and is more functional.
*/
@Deprecated
public class MyCustomXAxisValueFormatter implements IAxisValueFormatter
public class MyCustomXAxisValueFormatter extends ValueFormatter
{
private final DecimalFormat mFormat;
@ -25,7 +24,7 @@ public class MyCustomXAxisValueFormatter implements IAxisValueFormatter
}
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getFormattedValue(float value) {
//Log.i("TRANS", "x: " + viewPortHandler.getTransX() + ", y: " + viewPortHandler.getTransY());

View file

@ -1,22 +1,35 @@
package com.xxmassdeveloper.mpchartexample.custom;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.utils.ViewPortHandler;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.formatter.ValueFormatter;
import java.text.DecimalFormat;
public class MyValueFormatter implements IValueFormatter
public class MyValueFormatter extends ValueFormatter
{
private final DecimalFormat mFormat;
private String suffix;
public MyValueFormatter() {
public MyValueFormatter(String suffix) {
mFormat = new DecimalFormat("###,###,###,##0.0");
this.suffix = suffix;
}
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return mFormat.format(value) + " $";
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);
}
}
}

View file

@ -1,4 +1,3 @@
package com.xxmassdeveloper.mpchartexample.custom;
import android.annotation.SuppressLint;
@ -7,7 +6,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.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;
import com.xxmassdeveloper.mpchartexample.R;
@ -23,11 +22,11 @@ import java.text.DecimalFormat;
public class XYMarkerView extends MarkerView {
private final TextView tvContent;
private final IAxisValueFormatter xAxisValueFormatter;
private final ValueFormatter xAxisValueFormatter;
private final DecimalFormat format;
public XYMarkerView(Context context, IAxisValueFormatter xAxisValueFormatter) {
public XYMarkerView(Context context, ValueFormatter xAxisValueFormatter) {
super(context, R.layout.custom_marker_view);
this.xAxisValueFormatter = xAxisValueFormatter;
@ -40,7 +39,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(), null), format.format(e.getY())));
tvContent.setText(String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(e.getX()), format.format(e.getY())));
super.refreshContent(e, highlight);
}

View file

@ -1,13 +1,13 @@
package com.xxmassdeveloper.mpchartexample.custom;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
/**
* Created by Philipp Jahoda on 14/09/15.
*/
@SuppressWarnings("unused")
public class YearXAxisFormatter implements IAxisValueFormatter
public class YearXAxisFormatter extends ValueFormatter
{
private final String[] mMonths = new String[]{
@ -19,7 +19,7 @@ public class YearXAxisFormatter implements IAxisValueFormatter
}
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getAxisLabel(float value, AxisBase axis) {
float percent = value / axis.mAxisRange;
return mMonths[(int) (mMonths.length * percent)];

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.charts;
import android.animation.ValueAnimator;
@ -35,7 +34,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.IValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.ChartHighlighter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.highlight.IHighlighter;
@ -1015,7 +1014,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
*
* @return
*/
public IValueFormatter getDefaultValueFormatter() {
public ValueFormatter getDefaultValueFormatter() {
return mDefaultValueFormatter;
}

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.components;
import android.graphics.Color;
@ -6,7 +5,7 @@ import android.graphics.DashPathEffect;
import android.util.Log;
import com.github.mikephil.charting.formatter.DefaultAxisValueFormatter;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.utils.Utils;
import java.util.ArrayList;
@ -22,7 +21,7 @@ public abstract class AxisBase extends ComponentBase {
/**
* custom formatter that is used instead of the auto-formatter if set
*/
protected IAxisValueFormatter mAxisValueFormatter;
protected ValueFormatter mAxisValueFormatter;
private int mGridColor = Color.GRAY;
@ -486,7 +485,7 @@ public abstract class AxisBase extends ComponentBase {
if (index < 0 || index >= mEntries.length)
return "";
else
return getValueFormatter().getFormattedValue(mEntries[index], this);
return getValueFormatter().getAxisLabel(mEntries[index], this);
}
/**
@ -498,7 +497,7 @@ public abstract class AxisBase extends ComponentBase {
*
* @param f
*/
public void setValueFormatter(IAxisValueFormatter f) {
public void setValueFormatter(ValueFormatter f) {
if (f == null)
mAxisValueFormatter = new DefaultAxisValueFormatter(mDecimals);
@ -511,7 +510,7 @@ public abstract class AxisBase extends ComponentBase {
*
* @return
*/
public IAxisValueFormatter getValueFormatter() {
public ValueFormatter getValueFormatter() {
if (mAxisValueFormatter == null ||
(mAxisValueFormatter instanceof DefaultAxisValueFormatter &&

View file

@ -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.IValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.model.GradientColor;
import com.github.mikephil.charting.utils.ColorTemplate;
@ -56,7 +56,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 IValueFormatter mValueFormatter;
protected transient ValueFormatter mValueFormatter;
/**
* the typeface used for the value text
@ -313,7 +313,7 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
}
@Override
public void setValueFormatter(IValueFormatter f) {
public void setValueFormatter(ValueFormatter f) {
if (f == null)
return;
@ -322,7 +322,7 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
}
@Override
public IValueFormatter getValueFormatter() {
public ValueFormatter getValueFormatter() {
if (needsFormatter())
return Utils.getDefaultValueFormatter();
return mValueFormatter;

View file

@ -1,11 +1,10 @@
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.IValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
@ -659,7 +658,7 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
*
* @param f
*/
public void setValueFormatter(IValueFormatter f) {
public void setValueFormatter(ValueFormatter f) {
if (f == null)
return;
else {

View file

@ -1,13 +1,11 @@
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 implements IAxisValueFormatter
public class DefaultAxisValueFormatter extends ValueFormatter
{
/**
@ -18,7 +16,7 @@ public class DefaultAxisValueFormatter implements IAxisValueFormatter
/**
* the number of decimal digits this formatter uses
*/
protected int digits = 0;
protected int digits;
/**
* Constructor that specifies to how many digits the value should be
@ -40,7 +38,7 @@ public class DefaultAxisValueFormatter implements IAxisValueFormatter
}
@Override
public String getFormattedValue(float value, AxisBase axis) {
public String getFormattedValue(float value) {
// avoid memory allocations here (for performance)
return mFormat.format(value);
}

View file

@ -1,9 +1,5 @@
package com.github.mikephil.charting.formatter;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.text.DecimalFormat;
/**
@ -12,7 +8,7 @@ import java.text.DecimalFormat;
*
* @author Philipp Jahoda
*/
public class DefaultValueFormatter implements IValueFormatter
public class DefaultValueFormatter extends ValueFormatter
{
/**
@ -52,7 +48,7 @@ public class DefaultValueFormatter implements IValueFormatter
}
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
public String getFormattedValue(float value) {
// put more logic here ...
// avoid memory allocations here (for performance reasons)

View file

@ -6,7 +6,10 @@ 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
{
@ -18,6 +21,9 @@ 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);
}

View file

@ -4,13 +4,12 @@ import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.utils.ViewPortHandler;
/**
* 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.
* Interface to format all values before they are drawn as labels.
*
* @author Philipp Jahoda
* @deprecated Extend {@link ValueFormatter} instead
*/
@Deprecated
public interface IValueFormatter
{
@ -24,6 +23,9 @@ 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);
}

View file

@ -1,18 +1,11 @@
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 implements IAxisValueFormatter
public class IndexAxisValueFormatter extends ValueFormatter
{
private String[] mValues = new String[] {};
private int mValueCount = 0;
@ -44,7 +37,8 @@ public class IndexAxisValueFormatter implements IAxisValueFormatter
setValues(values.toArray(new String[values.size()]));
}
public String getFormattedValue(float value, AxisBase axis) {
@Override
public String getFormattedValue(float value) {
int index = Math.round(value);
if (index < 0 || index >= mValueCount || index != (int)value)

View file

@ -1,10 +1,5 @@
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;
/**
@ -17,7 +12,7 @@ import java.text.DecimalFormat;
* @author Philipp Jahoda
* @author Oleksandr Tyshkovets <olexandr.tyshkovets@gmail.com>
*/
public class LargeValueFormatter implements IValueFormatter, IAxisValueFormatter
public class LargeValueFormatter extends ValueFormatter
{
private String[] mSuffix = new String[]{
@ -41,15 +36,8 @@ public class LargeValueFormatter implements IValueFormatter, IAxisValueFormatter
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, AxisBase axis) {
public String getFormattedValue(float value) {
return makePretty(value) + mText;
}

View file

@ -1,9 +1,7 @@
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 com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.PieEntry;
import java.text.DecimalFormat;
@ -13,37 +11,36 @@ import java.text.DecimalFormat;
*
* @author Philipp Jahoda
*/
public class PercentFormatter implements IValueFormatter, IAxisValueFormatter
public class PercentFormatter extends ValueFormatter
{
protected DecimalFormat mFormat;
public DecimalFormat mFormat;
private PieChart pieChart;
public PercentFormatter() {
mFormat = new DecimalFormat("###,###,##0.0");
}
/**
* Allow a custom decimalformat
*
* @param format
*/
public PercentFormatter(DecimalFormat format) {
this.mFormat = format;
// Can be used to remove percent signs if the chart isn't in percent mode
public PercentFormatter(PieChart pieChart) {
this();
this.pieChart = pieChart;
}
// IValueFormatter
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
public String getFormattedValue(float value) {
return mFormat.format(value) + " %";
}
// IAxisValueFormatter
@Override
public String getFormattedValue(float value, AxisBase axis) {
return mFormat.format(value) + " %";
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 int getDecimalDigits() {
return 1;
}
}

View file

@ -1,8 +1,6 @@
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;
@ -12,7 +10,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 implements IValueFormatter
public class StackedValueFormatter extends ValueFormatter
{
/**
@ -23,7 +21,7 @@ public class StackedValueFormatter implements IValueFormatter
/**
* a string that should be appended behind the value
*/
private String mAppendix;
private String mSuffix;
private DecimalFormat mFormat;
@ -31,12 +29,12 @@ public class StackedValueFormatter implements IValueFormatter
* Constructor.
*
* @param drawWholeStack if true, all stack values of the stacked bar entry are drawn, else only top
* @param appendix a string that should be appended behind the value
* @param suffix a string that should be appended behind the value
* @param decimals the number of decimal digits to use
*/
public StackedValueFormatter(boolean drawWholeStack, String appendix, int decimals) {
public StackedValueFormatter(boolean drawWholeStack, String suffix, int decimals) {
this.mDrawWholeStack = drawWholeStack;
this.mAppendix = appendix;
this.mSuffix = suffix;
StringBuffer b = new StringBuffer();
for (int i = 0; i < decimals; i++) {
@ -49,12 +47,10 @@ public class StackedValueFormatter implements IValueFormatter
}
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
public String getBarStackedLabel(float value, BarEntry entry) {
if (!mDrawWholeStack) {
if (!mDrawWholeStack && entry instanceof BarEntry) {
BarEntry barEntry = (BarEntry) entry;
float[] vals = barEntry.getYVals();
float[] vals = entry.getYVals();
if (vals != null) {
@ -62,7 +58,7 @@ public class StackedValueFormatter implements IValueFormatter
if (vals[vals.length - 1] == value) {
// return the "sum" across all stack values
return mFormat.format(barEntry.getY()) + mAppendix;
return mFormat.format(entry.getY()) + mSuffix;
} else {
return ""; // return empty
}
@ -70,6 +66,6 @@ public class StackedValueFormatter implements IValueFormatter
}
// return the "proposed" value
return mFormat.format(value) + mAppendix;
return mFormat.format(value) + mSuffix;
}
}

View file

@ -0,0 +1,137 @@
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());
}
}

View file

@ -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.IValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.utils.MPPointF;
/**
@ -61,7 +61,7 @@ public interface ChartInterface {
RectF getContentRect();
IValueFormatter getDefaultValueFormatter();
ValueFormatter getDefaultValueFormatter();
ChartData getData();

View file

@ -1,14 +1,13 @@
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.IValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.model.GradientColor;
@ -341,14 +340,14 @@ public interface IDataSet<T extends Entry> {
*
* @param f
*/
void setValueFormatter(IValueFormatter f);
void setValueFormatter(ValueFormatter f);
/**
* Returns the formatter used for drawing the values inside the chart.
*
* @return
*/
IValueFormatter getValueFormatter();
ValueFormatter getValueFormatter();
/**
* Returns true if the valueFormatter object of this DataSet is null.

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@ -11,6 +10,7 @@ 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;
@ -254,6 +254,8 @@ 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);
@ -276,8 +278,7 @@ public class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
float val = entry.getY();
if (dataSet.isDrawValuesEnabled()) {
drawValue(c, dataSet.getValueFormatter(), val, entry, i, x,
val >= 0 ?
drawValue(c, formatter.getBarLabel(entry), x, val >= 0 ?
(buffer.buffer[j + 1] + posOffset) :
(buffer.buffer[j + 3] + negOffset),
dataSet.getValueTextColor(j / 4));
@ -335,8 +336,7 @@ public class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
continue;
if (dataSet.isDrawValuesEnabled()) {
drawValue(c, dataSet.getValueFormatter(), entry.getY(), entry, i, x,
buffer.buffer[bufferIndex + 1] +
drawValue(c, formatter.getBarLabel(entry), x, buffer.buffer[bufferIndex + 1] +
(entry.getY() >= 0 ? posOffset : negOffset),
color);
}
@ -407,14 +407,7 @@ public class BarChartRenderer extends BarLineScatterCandleBubbleRenderer {
continue;
if (dataSet.isDrawValuesEnabled()) {
drawValue(c,
dataSet.getValueFormatter(),
vals[k / 2],
entry,
i,
x,
y,
color);
drawValue(c, formatter.getBarStackedLabel(val, entry), x, y, color);
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@ -442,6 +435,12 @@ 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) {

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@ -9,6 +8,7 @@ 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,6 +150,8 @@ 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);
@ -172,8 +174,7 @@ public class BubbleChartRenderer extends BarLineScatterCandleBubbleRenderer {
BubbleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
if (dataSet.isDrawValuesEnabled()) {
drawValue(c, dataSet.getValueFormatter(), entry.getSize(), entry, i, x,
y + (0.5f * lineHeight), valueTextColor);
drawValue(c, formatter.getBubbleLabel(entry), x, y + (0.5f * lineHeight), valueTextColor);
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@ -195,6 +196,12 @@ 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) {
}

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@ -8,6 +7,7 @@ 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,6 +279,8 @@ 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);
@ -297,15 +299,7 @@ public class CandleStickChartRenderer extends LineScatterCandleRadarRenderer {
CandleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
if (dataSet.isDrawValuesEnabled()) {
drawValue(c,
dataSet.getValueFormatter(),
entry.getHigh(),
entry,
i,
x,
y - yOffset,
dataSet
.getValueTextColor(j / 2));
drawValue(c, formatter.getCandleLabel(entry), x, y - yOffset, dataSet.getValueTextColor(j / 2));
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@ -327,6 +321,12 @@ 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) {
}

View file

@ -1,6 +1,7 @@
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;
@ -9,7 +10,6 @@ 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;
@ -89,6 +89,11 @@ public class CombinedChartRenderer extends DataRenderer {
renderer.drawData(c);
}
@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) {

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@ -6,15 +5,11 @@ 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;
@ -138,19 +133,13 @@ public abstract class DataRenderer extends Renderer {
/**
* Draws the value of the given entry by using the provided IValueFormatter.
*
* @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 c canvas
* @param valueText label to draw
* @param x position
* @param y position
* @param 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);
}
public abstract void drawValue(Canvas c, String valueText, float x, float y, int color);
/**
* Draws any kind of additional information (e.g. line-circles).

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@ -11,7 +10,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.IValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.interfaces.dataprovider.ChartInterface;
@ -167,7 +166,7 @@ public class HorizontalBarChartRenderer extends BarChartRenderer {
applyValueTextStyle(dataSet);
final float halfTextHeight = Utils.calcTextHeight(mValuePaint, "10") / 2f;
IValueFormatter formatter = dataSet.getValueFormatter();
ValueFormatter formatter = dataSet.getValueFormatter();
// get the buffer
BarBuffer buffer = mBarBuffers[i];
@ -196,7 +195,7 @@ public class HorizontalBarChartRenderer extends BarChartRenderer {
BarEntry entry = dataSet.getEntryForIndex(j / 4);
float val = entry.getY();
String formattedValue = formatter.getFormattedValue(val, entry, i, mViewPortHandler);
String formattedValue = formatter.getBarLabel(entry);
// calculate the correct offset depending on the draw position of the value
float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
@ -265,9 +264,7 @@ public class HorizontalBarChartRenderer extends BarChartRenderer {
if (!mViewPortHandler.isInBoundsBottom(buffer.buffer[bufferIndex + 1]))
continue;
float val = entry.getY();
String formattedValue = formatter.getFormattedValue(val,
entry, i, mViewPortHandler);
String formattedValue = formatter.getBarLabel(entry);
// calculate the correct offset depending on the draw position of the value
float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
@ -337,8 +334,7 @@ public class HorizontalBarChartRenderer extends BarChartRenderer {
for (int k = 0; k < transformed.length; k += 2) {
final float val = vals[k / 2];
String formattedValue = formatter.getFormattedValue(val,
entry, i, mViewPortHandler);
String formattedValue = formatter.getBarStackedLabel(val, entry);
// calculate the correct offset depending on the draw position of the value
float valueTextWidth = Utils.calcTextWidth(mValuePaint, formattedValue);
@ -396,7 +392,8 @@ public class HorizontalBarChartRenderer extends BarChartRenderer {
}
}
protected void drawValue(Canvas c, String valueText, float x, float y, int color) {
@Override
public void drawValue(Canvas c, String valueText, float x, float y, int color) {
mValuePaint.setColor(color);
c.drawText(valueText, x, y, mValuePaint);
}

View file

@ -12,6 +12,7 @@ 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;
@ -294,7 +295,7 @@ public class LineChartRenderer extends LineRadarRenderer {
int entryCount = dataSet.getEntryCount();
final boolean isDrawSteppedEnabled = dataSet.isDrawSteppedEnabled();
final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED;
final int pointsPerEntryPair = isDrawSteppedEnabled ? 4 : 2;
Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
@ -547,6 +548,7 @@ 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);
@ -566,8 +568,7 @@ public class LineChartRenderer extends LineRadarRenderer {
Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
if (dataSet.isDrawValuesEnabled()) {
drawValue(c, dataSet.getValueFormatter(), entry.getY(), entry, i, x,
y - valOffset, dataSet.getValueTextColor(j / 2));
drawValue(c, formatter.getPointLabel(entry), x, y - valOffset, dataSet.getValueTextColor(j / 2));
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@ -589,6 +590,12 @@ 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);

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.renderer;
import android.graphics.Bitmap;
@ -22,7 +21,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.IValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
@ -438,7 +437,7 @@ public class PieChartRenderer extends DataRenderer {
float lineHeight = Utils.calcTextHeight(mValuePaint, "Q")
+ Utils.convertDpToPixel(4f);
IValueFormatter formatter = dataSet.getValueFormatter();
ValueFormatter formatter = dataSet.getValueFormatter();
int entryCount = dataSet.getEntryCount();
@ -472,6 +471,7 @@ public class PieChartRenderer extends DataRenderer {
float value = mChart.isUsePercentValuesEnabled() ? entry.getY()
/ yValueSum * 100f : entry.getY();
String formattedValue = formatter.getPieLabel(value, entry);
final float sliceXBase = (float) Math.cos(transformedAngle * Utils.FDEG2RAD);
final float sliceYBase = (float) Math.sin(transformedAngle * Utils.FDEG2RAD);
@ -550,14 +550,7 @@ public class PieChartRenderer extends DataRenderer {
// draw everything, depending on settings
if (drawXOutside && drawYOutside) {
drawValue(c,
formatter,
value,
entry,
0,
labelPtx,
labelPty,
dataSet.getValueTextColor(j));
drawValue(c, formattedValue, labelPtx, labelPty, dataSet.getValueTextColor(j));
if (j < data.getEntryCount() && entry.getLabel() != null) {
drawEntryLabel(c, entry.getLabel(), labelPtx, labelPty + lineHeight);
@ -569,8 +562,7 @@ public class PieChartRenderer extends DataRenderer {
}
} else if (drawYOutside) {
drawValue(c, formatter, value, entry, 0, labelPtx, labelPty + lineHeight / 2.f, dataSet
.getValueTextColor(j));
drawValue(c, formattedValue, labelPtx, labelPty + lineHeight / 2.f, dataSet.getValueTextColor(j));
}
}
@ -584,7 +576,7 @@ public class PieChartRenderer extends DataRenderer {
// draw everything, depending on settings
if (drawXInside && drawYInside) {
drawValue(c, formatter, value, entry, 0, x, y, dataSet.getValueTextColor(j));
drawValue(c, formattedValue, x, y, dataSet.getValueTextColor(j));
if (j < data.getEntryCount() && entry.getLabel() != null) {
drawEntryLabel(c, entry.getLabel(), x, y + lineHeight);
@ -595,8 +587,7 @@ public class PieChartRenderer extends DataRenderer {
drawEntryLabel(c, entry.getLabel(), x, y + lineHeight / 2f);
}
} else if (drawYInside) {
drawValue(c, formatter, value, entry, 0, x, y + lineHeight / 2f, dataSet.getValueTextColor(j));
drawValue(c, formattedValue, x, y + lineHeight / 2f, dataSet.getValueTextColor(j));
}
}
@ -626,6 +617,12 @@ 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.
*

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@ -11,6 +10,7 @@ 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,6 +174,8 @@ 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);
@ -189,15 +191,7 @@ public class RadarChartRenderer extends LineRadarRenderer {
pOut);
if (dataSet.isDrawValuesEnabled()) {
drawValue(c,
dataSet.getValueFormatter(),
entry.getY(),
entry,
i,
pOut.x,
pOut.y - yoffset,
dataSet.getValueTextColor
(j));
drawValue(c, formatter.getRadarLabel(entry), pOut.x, pOut.y - yoffset, dataSet.getValueTextColor(j));
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@ -231,6 +225,12 @@ public class RadarChartRenderer extends LineRadarRenderer {
MPPointF.recycleInstance(pIcon);
}
@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);

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@ -8,6 +7,7 @@ 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,6 +118,8 @@ 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);
@ -135,14 +137,7 @@ public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
if (dataSet.isDrawValuesEnabled()) {
drawValue(c,
dataSet.getValueFormatter(),
entry.getY(),
entry,
i,
positions[j],
positions[j + 1] - shapeSize,
dataSet.getValueTextColor(j / 2 + mXBounds.min));
drawValue(c, formatter.getPointLabel(entry), positions[j], positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + mXBounds.min));
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
@ -164,6 +159,12 @@ 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) {
}

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@ -202,7 +201,7 @@ public class XAxisRenderer extends AxisRenderer {
if (mViewPortHandler.isInBoundsX(x)) {
String label = mXAxis.getValueFormatter().getFormattedValue(mXAxis.mEntries[i / 2], mXAxis);
String label = mXAxis.getValueFormatter().getAxisLabel(mXAxis.mEntries[i / 2], mXAxis);
if (mXAxis.isAvoidFirstLastClippingEnabled()) {

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.renderer;
import android.graphics.Canvas;
@ -57,10 +56,10 @@ public class XAxisRendererHorizontalBarChart extends XAxisRenderer {
computeAxisValues(min, max);
}
@Override
protected void computeSize() {
mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
mAxisLabelPaint.setTextSize(mXAxis.getTextSize());
@ -156,7 +155,7 @@ public class XAxisRendererHorizontalBarChart extends XAxisRenderer {
if (mViewPortHandler.isInBoundsY(y)) {
String label = mXAxis.getValueFormatter().getFormattedValue(mXAxis.mEntries[i / 2], mXAxis);
String label = mXAxis.getValueFormatter().getAxisLabel(mXAxis.mEntries[i / 2], mXAxis);
drawLabel(c, label, pos, y, anchor, labelRotationAngleDegrees);
}
}

View file

@ -1,8 +1,6 @@
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;
@ -43,7 +41,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().getFormattedValue(i, mXAxis);
String label = mXAxis.getValueFormatter().getAxisLabel(i, mXAxis);
float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f;

View file

@ -1,4 +1,3 @@
package com.github.mikephil.charting.utils;
import android.annotation.SuppressLint;
@ -7,7 +6,6 @@ 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;
@ -15,14 +13,13 @@ 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.IValueFormatter;
import com.github.mikephil.charting.formatter.ValueFormatter;
import java.util.List;
@ -229,15 +226,14 @@ public abstract class Utils {
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
};
private static IValueFormatter mDefaultValueFormatter = generateDefaultValueFormatter();
private static ValueFormatter mDefaultValueFormatter = generateDefaultValueFormatter();
private static IValueFormatter generateDefaultValueFormatter() {
final DefaultValueFormatter formatter = new DefaultValueFormatter(1);
return formatter;
private static ValueFormatter generateDefaultValueFormatter() {
return new DefaultValueFormatter(1);
}
/// - returns: The default value formatter used for all chart components that needs a default
public static IValueFormatter getDefaultValueFormatter()
public static ValueFormatter getDefaultValueFormatter()
{
return mDefaultValueFormatter;
}
@ -353,11 +349,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);
@ -375,10 +371,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;
}

View file

@ -16,80 +16,80 @@ public class LargeValueFormatterTest {
LargeValueFormatter formatter = new LargeValueFormatter();
String result = formatter.getFormattedValue(5f, null);
String result = formatter.getFormattedValue(5f);
assertEquals("5", result);
result = formatter.getFormattedValue(5.5f, null);
result = formatter.getFormattedValue(5.5f);
assertEquals("5.5", result);
result = formatter.getFormattedValue(50f, null);
result = formatter.getFormattedValue(50f);
assertEquals("50", result);
result = formatter.getFormattedValue(50.5f, null);
result = formatter.getFormattedValue(50.5f);
assertEquals("50.5", result);
result = formatter.getFormattedValue(500f, null);
result = formatter.getFormattedValue(500f);
assertEquals("500", result);
result = formatter.getFormattedValue(1100f, null);
result = formatter.getFormattedValue(1100f);
assertEquals("1.1k", result);
result = formatter.getFormattedValue(10000f, null);
result = formatter.getFormattedValue(10000f);
assertEquals("10k", result);
result = formatter.getFormattedValue(10500f, null);
result = formatter.getFormattedValue(10500f);
assertEquals("10.5k", result);
result = formatter.getFormattedValue(100000f, null);
result = formatter.getFormattedValue(100000f);
assertEquals("100k", result);
result = formatter.getFormattedValue(1000000f, null);
result = formatter.getFormattedValue(1000000f);
assertEquals("1m", result);
result = formatter.getFormattedValue(1500000f, null);
result = formatter.getFormattedValue(1500000f);
assertEquals("1.5m", result);
result = formatter.getFormattedValue(9500000f, null);
result = formatter.getFormattedValue(9500000f);
assertEquals("9.5m", result);
result = formatter.getFormattedValue(22200000f, null);
result = formatter.getFormattedValue(22200000f);
assertEquals("22.2m", result);
result = formatter.getFormattedValue(222000000f, null);
result = formatter.getFormattedValue(222000000f);
assertEquals("222m", result);
result = formatter.getFormattedValue(1000000000f, null);
result = formatter.getFormattedValue(1000000000f);
assertEquals("1b", result);
result = formatter.getFormattedValue(9900000000f, null);
result = formatter.getFormattedValue(9900000000f);
assertEquals("9.9b", result);
result = formatter.getFormattedValue(99000000000f, null);
result = formatter.getFormattedValue(99000000000f);
assertEquals("99b", result);
result = formatter.getFormattedValue(99500000000f, null);
result = formatter.getFormattedValue(99500000000f);
assertEquals("99.5b", result);
result = formatter.getFormattedValue(999000000000f, null);
result = formatter.getFormattedValue(999000000000f);
assertEquals("999b", result);
result = formatter.getFormattedValue(1000000000000f, null);
result = formatter.getFormattedValue(1000000000000f);
assertEquals("1t", result);
formatter.setSuffix(new String[]{"", "k", "m", "b", "t", "q"}); // quadrillion support
result = formatter.getFormattedValue(1000000000000000f, null);
result = formatter.getFormattedValue(1000000000000000f);
assertEquals("1q", result);
result = formatter.getFormattedValue(1100000000000000f, null);
result = formatter.getFormattedValue(1100000000000000f);
assertEquals("1.1q", result);
result = formatter.getFormattedValue(10000000000000000f, null);
result = formatter.getFormattedValue(10000000000000000f);
assertEquals("10q", result);
result = formatter.getFormattedValue(13300000000000000f, null);
result = formatter.getFormattedValue(13300000000000000f);
assertEquals("13.3q", result);
result = formatter.getFormattedValue(100000000000000000f, null);
result = formatter.getFormattedValue(100000000000000000f);
assertEquals("100q", result);
}
}

View file

@ -2,7 +2,7 @@ package com.github.mikephil.charting.test;
import com.github.mikephil.charting.utils.ObjectPool;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;