Skip to content

Commit

Permalink
Merge pull request #1 from sembozdemir/pie_chart_min_angle
Browse files Browse the repository at this point in the history
Add option for setting min angle for pie slices
  • Loading branch information
sembozdemir authored Mar 28, 2018
2 parents 3e1eb14 + 4b6d4b6 commit c2bc2a9
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public class PieChart extends PieRadarChartBase<PieData> {

protected float mMaxAngle = 360f;

private float mMinAngleForSlices = 0f;

public PieChart(Context context) {
super(context);
}
Expand Down Expand Up @@ -236,7 +238,19 @@ private void calcAngles() {

for (int j = 0; j < set.getEntryCount(); j++) {

mDrawAngles[cnt] = calcAngle(Math.abs(set.getEntryForIndex(j).getY()), yValueSum);
float drawAngle = calcAngle(Math.abs(set.getEntryForIndex(j).getY()), yValueSum);

final boolean hasMinAngle = mMinAngleForSlices != 0f;
if (hasMinAngle) {
drawAngle = Math.max(drawAngle, mMinAngleForSlices);

if (cnt != 0 && cnt == set.getEntryCount() - 1) { // if it is the last slice
// drawAngle should be the rest of space
drawAngle = mMaxAngle - mAbsoluteAngles[cnt - 1];
}
}

mDrawAngles[cnt] = drawAngle;

if (cnt == 0) {
mAbsoluteAngles[cnt] = mDrawAngles[cnt];
Expand Down Expand Up @@ -719,6 +733,27 @@ public void setMaxAngle(float maxangle) {
this.mMaxAngle = maxangle;
}

public float getMinAngleForSlices() {
return mMinAngleForSlices;
}

/**
* Set the angle to set minimum size for slices (e.g 18f means 5% min percentage for full pie-chart).
* do not use huge values for this, it will break pie-chart. Default: 0f
*
* @param minAngle min 0, max 360
*/
public void setMinAngleForSlices(float minAngle) {

if (minAngle > 360)
minAngle = 360f;

if (minAngle < 0)
minAngle = 0f;

this.mMinAngleForSlices = minAngle;
}

@Override
protected void onDetachedFromWindow() {
// releases the bitmap in the renderer to avoid oom error
Expand Down

0 comments on commit c2bc2a9

Please sign in to comment.