Make automatically disabling slice-spacing an opt-in feature

This commit is contained in:
Daniel Cohen Gindi 2016-10-31 11:45:05 +02:00
parent 9a19bf6670
commit fb8094e9f2
3 changed files with 33 additions and 0 deletions

View file

@ -11,6 +11,7 @@ public class PieDataSet extends DataSet<PieEntry> implements IPieDataSet {
/** the space in pixels between the chart-slices, default 0f */
private float mSliceSpace = 0f;
private boolean mAutomaticallyDisableSliceSpacing;
/** indicates the selection distance of a pie slice */
private float mShift = 18f;
@ -75,6 +76,27 @@ public class PieDataSet extends DataSet<PieEntry> implements IPieDataSet {
return mSliceSpace;
}
/**
* When enabled, slice spacing will be 0.0 when the smallest value is going to be
* smaller than the slice spacing itself.
*
* @param autoDisable
*/
public void setAutomaticallyDisableSliceSpacing(boolean autoDisable) {
mAutomaticallyDisableSliceSpacing = autoDisable;
}
/**
* When enabled, slice spacing will be 0.0 when the smallest value is going to be
* smaller than the slice spacing itself.
*
* @return
*/
@Override
public boolean isAutomaticallyDisableSliceSpacing() {
return mAutomaticallyDisableSliceSpacing;
}
/**
* sets the distance the highlighted piechart-slice of this DataSet is
* "shifted" away from the center of the chart, default 12f

View file

@ -17,6 +17,14 @@ public interface IPieDataSet extends IDataSet<PieEntry> {
*/
float getSliceSpace();
/**
* When enabled, slice spacing will be 0.0 when the smallest value is going to be
* smaller than the slice spacing itself.
*
* @return
*/
boolean isAutomaticallyDisableSliceSpacing();
/**
* Returns the distance a highlighted piechart slice is "shifted" away from
* the chart-center in dp.

View file

@ -199,6 +199,9 @@ public class PieChartRenderer extends DataRenderer {
*/
protected float getSliceSpace(IPieDataSet dataSet) {
if (!dataSet.isAutomaticallyDisableSliceSpacing())
return dataSet.getSliceSpace();
float spaceSizeRatio = dataSet.getSliceSpace() / mViewPortHandler.getSmallestContentExtension();
float minValueRatio = dataSet.getYMin() / mChart.getData().getYValueSum() * 2;