Fixes related to DefaultValueFormatter #1809
This commit is contained in:
parent
f75ea845e0
commit
8a6139b1fb
7 changed files with 49 additions and 31 deletions
|
@ -195,7 +195,7 @@ public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarC
|
|||
ArrayList<BarEntry> yVals2 = new ArrayList<BarEntry>();
|
||||
ArrayList<BarEntry> yVals3 = new ArrayList<BarEntry>();
|
||||
|
||||
float mult = mSeekBarY.getProgress() * 1000f;
|
||||
float mult = mSeekBarY.getProgress() * 100000f;
|
||||
|
||||
for (int i = startYear; i < endYear; i++) {
|
||||
float val = (float) (Math.random() * mult) + 3;
|
||||
|
|
|
@ -100,7 +100,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
/**
|
||||
* default value-formatter, number of digits depends on provided chart-data
|
||||
*/
|
||||
protected ValueFormatter mDefaultFormatter;
|
||||
protected DefaultValueFormatter mDefaultFormatter = new DefaultValueFormatter(0);
|
||||
|
||||
/**
|
||||
* paint object used for drawing the description text in the bottom right
|
||||
|
@ -232,8 +232,6 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
Utils.init(getContext());
|
||||
mMaxHighlightDistance = Utils.convertDpToPixel(70f);
|
||||
|
||||
mDefaultFormatter = new DefaultValueFormatter(1);
|
||||
|
||||
mViewPortHandler = new ViewPortHandler();
|
||||
|
||||
mLegend = new Legend();
|
||||
|
@ -308,10 +306,10 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
}
|
||||
|
||||
// calculate how many digits are needed
|
||||
calculateFormatter(data.getYMin(), data.getYMax());
|
||||
setupDefaultFormatter(data.getYMin(), data.getYMax());
|
||||
|
||||
for (IDataSet set : mData.getDataSets()) {
|
||||
if (Utils.needsDefaultFormatter(set.getValueFormatter()))
|
||||
if (set.needsFormatter() || set.getValueFormatter() == mDefaultFormatter)
|
||||
set.setValueFormatter(mDefaultFormatter);
|
||||
}
|
||||
|
||||
|
@ -382,10 +380,10 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
protected abstract void calcMinMax();
|
||||
|
||||
/**
|
||||
* calculates the required number of digits for the values that might be
|
||||
* Calculates the required number of digits for the values that might be
|
||||
* drawn in the chart (if enabled), and creates the default-value-formatter
|
||||
*/
|
||||
protected void calculateFormatter(float min, float max) {
|
||||
protected void setupDefaultFormatter(float min, float max) {
|
||||
|
||||
float reference = 0f;
|
||||
|
||||
|
@ -397,7 +395,9 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
}
|
||||
|
||||
int digits = Utils.getDecimals(reference);
|
||||
mDefaultFormatter = new DefaultValueFormatter(digits);
|
||||
|
||||
// setup the formatter with a new number of digits
|
||||
mDefaultFormatter.setup(digits);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -262,11 +262,16 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
|
|||
|
||||
@Override
|
||||
public ValueFormatter getValueFormatter() {
|
||||
if (mValueFormatter == null)
|
||||
if (needsFormatter())
|
||||
return new DefaultValueFormatter(1);
|
||||
return mValueFormatter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsFormatter() {
|
||||
return mValueFormatter == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueTextColor(int color) {
|
||||
mValueColors.clear();
|
||||
|
|
|
@ -21,7 +21,7 @@ public interface AxisValueFormatter {
|
|||
String getFormattedValue(float value, AxisBase axis);
|
||||
|
||||
/**
|
||||
* Returns the number of decimal digits this formatter uses.
|
||||
* Returns the number of decimal digits this formatter uses or -1, if unspecified.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
|
|
@ -14,16 +14,31 @@ import java.text.DecimalFormat;
|
|||
*/
|
||||
public class DefaultValueFormatter implements ValueFormatter {
|
||||
|
||||
/** decimalformat for formatting */
|
||||
/**
|
||||
* DecimalFormat for formatting
|
||||
*/
|
||||
protected DecimalFormat mFormat;
|
||||
|
||||
protected int mDecimalDigits;
|
||||
|
||||
/**
|
||||
* Constructor that specifies to how many digits the value should be
|
||||
* formatted.
|
||||
*
|
||||
*
|
||||
* @param digits
|
||||
*/
|
||||
public DefaultValueFormatter(int digits) {
|
||||
setup(digits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the formatter with a given number of decimal digits.
|
||||
*
|
||||
* @param digits
|
||||
*/
|
||||
public void setup(int digits) {
|
||||
|
||||
this.mDecimalDigits = digits;
|
||||
|
||||
StringBuffer b = new StringBuffer();
|
||||
for (int i = 0; i < digits; i++) {
|
||||
|
@ -43,4 +58,13 @@ public class DefaultValueFormatter implements ValueFormatter {
|
|||
|
||||
return mFormat.format(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of decimal digits this formatter uses.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getDecimalDigits() {
|
||||
return mDecimalDigits;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -303,6 +303,13 @@ public interface IDataSet<T extends Entry> {
|
|||
*/
|
||||
ValueFormatter getValueFormatter();
|
||||
|
||||
/**
|
||||
* Returns true if the valueFormatter object of this DataSet is null.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean needsFormatter();
|
||||
|
||||
/**
|
||||
* Sets the color the value-labels of this DataSet should have.
|
||||
*
|
||||
|
|
|
@ -19,9 +19,6 @@ 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 java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -380,21 +377,6 @@ public abstract class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If this component has no ValueFormatter or is only equipped with the
|
||||
* default one (no custom set), return true.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean needsDefaultFormatter(ValueFormatter formatter) {
|
||||
if (formatter == null)
|
||||
return true;
|
||||
if (formatter instanceof DefaultValueFormatter)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the position around a center point, depending on the distance
|
||||
* from the center, and the angle of the position around the center.
|
||||
|
|
Loading…
Add table
Reference in a new issue