Skip to content

Commit

Permalink
Add option for using slice color as value line color
Browse files Browse the repository at this point in the history
  • Loading branch information
sembozdemir committed Mar 28, 2018
1 parent 984e05f commit d652ca1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
Expand Down Expand Up @@ -226,6 +225,8 @@ private void setData(int count, float range) {
dataSet.setValueLinePart1OffsetPercentage(80.f);
dataSet.setValueLinePart1Length(0.2f);
dataSet.setValueLinePart2Length(0.4f);
//dataSet.setUsingSliceColorAsValueLineColor(true);

//dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PieDataSet extends DataSet<PieEntry> implements IPieDataSet {

private ValuePosition mXValuePosition = ValuePosition.INSIDE_SLICE;
private ValuePosition mYValuePosition = ValuePosition.INSIDE_SLICE;
private boolean mUsingSliceColorAsValueLineColor = false;
private int mValueLineColor = 0xff000000;
private float mValueLineWidth = 1.0f;
private float mValueLinePart1OffsetPercentage = 75.f;
Expand Down Expand Up @@ -134,15 +135,26 @@ public void setYValuePosition(ValuePosition yValuePosition)
this.mYValuePosition = yValuePosition;
}

/**
* When valuePosition is OutsideSlice, use slice colors as line color if true
* */
@Override
public boolean isUsingSliceColorAsValueLineColor() {
return mUsingSliceColorAsValueLineColor;
}

public void setUsingSliceColorAsValueLineColor(boolean usingSliceColorAsValueLineColor) {
this.mUsingSliceColorAsValueLineColor = usingSliceColorAsValueLineColor;
}

/** When valuePosition is OutsideSlice, indicates line color */
@Override
public int getValueLineColor()
{
return mValueLineColor;
}

public void setValueLineColor(int valueLineColor)
{
public void setValueLineColor(int valueLineColor) {
this.mValueLineColor = valueLineColor;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.mikephil.charting.interfaces.datasets;

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

Expand Down Expand Up @@ -36,6 +35,11 @@ public interface IPieDataSet extends IDataSet<PieEntry> {
PieDataSet.ValuePosition getXValuePosition();
PieDataSet.ValuePosition getYValuePosition();

/**
* When valuePosition is OutsideSlice, use slice colors as line color if true
* */
boolean isUsingSliceColorAsValueLineColor();

/**
* When valuePosition is OutsideSlice, indicates line color
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ public void drawValues(Canvas c) {
}

if (dataSet.getValueLineColor() != ColorTemplate.COLOR_NONE) {

if (dataSet.isUsingSliceColorAsValueLineColor()) {
mValueLinePaint.setColor(dataSet.getColor(j));
}

c.drawLine(pt0x, pt0y, pt1x, pt1y, mValueLinePaint);
c.drawLine(pt1x, pt1y, pt2x, pt2y, mValueLinePaint);
}
Expand Down

0 comments on commit d652ca1

Please sign in to comment.