Skip to content

Commit

Permalink
Added highlightColor parameter for pie charts
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jan 23, 2020
1 parent 4192f52 commit 23d81cb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.github.mikephil.charting.interfaces.datasets.IPieDataSet;
import com.github.mikephil.charting.utils.Utils;
import android.support.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -29,6 +30,7 @@ public class PieDataSet extends DataSet<PieEntry> implements IPieDataSet {
private float mValueLinePart1Length = 0.3f;
private float mValueLinePart2Length = 0.4f;
private boolean mValueLineVariableLength = true;
private Integer mHighlightColor = null;

public PieDataSet(List<PieEntry> yVals, String label) {
super(yVals, label);
Expand Down Expand Up @@ -218,6 +220,21 @@ public void setValueLineVariableLength(boolean valueLineVariableLength) {
this.mValueLineVariableLength = valueLineVariableLength;
}

/** Gets the color for the highlighted sector */
@Override
@Nullable
public Integer getHighlightColor()
{
return mHighlightColor;
}

/** Sets the color for the highlighted sector (null for using entry color) */
public void setHighlightColor(@Nullable Integer color)
{
this.mHighlightColor = color;
}


public enum ValuePosition {
INSIDE_SLICE,
OUTSIDE_SLICE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.mikephil.charting.interfaces.datasets;

import android.support.annotation.Nullable;

import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;

Expand Down Expand Up @@ -70,5 +72,11 @@ public interface IPieDataSet extends IDataSet<PieEntry> {
* */
boolean isValueLineVariableLength();

/**
* Gets the color for the highlighted sector
* */
@Nullable
Integer getHighlightColor();

}

Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,10 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {

final boolean accountForSliceSpacing = sliceSpace > 0.f && sliceAngle <= 180.f;

mRenderPaint.setColor(set.getColor(index));
Integer highlightColor = set.getHighlightColor();
if (highlightColor == null)
highlightColor = set.getColor(index);
mRenderPaint.setColor(highlightColor);

final float sliceSpaceAngleOuter = visibleAngleCount == 1 ?
0.f :
Expand Down

0 comments on commit 23d81cb

Please sign in to comment.