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 22, 2020
1 parent c43c24b commit 65f9cf0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions MPChartLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
//provided 'io.realm:realm-android:0.87.5' // "optional" dependency to realm-database API
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.10.19"
implementation 'com.android.support:support-annotations:28.0.0'
}

android.libraryVariants.all { variant ->
Expand Down
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 @@ -24,6 +25,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 @@ -206,6 +208,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,6 +1,7 @@
package com.github.mikephil.charting.interfaces.datasets;

import com.github.mikephil.charting.data.Entry;
import android.support.annotation.Nullable;

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

Expand Down Expand Up @@ -66,5 +67,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 @@ -818,7 +818,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 65f9cf0

Please sign in to comment.