Skip to content

Commit

Permalink
Multiple colors for valueline
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Jan 23, 2020
1 parent 04cfa21 commit 4e62248
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ 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 @@ -23,8 +23,8 @@ 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 boolean mUseValueColorForLine = false;
private float mValueLineWidth = 1.0f;
private float mValueLinePart1OffsetPercentage = 75.f;
private float mValueLinePart1Length = 0.3f;
Expand Down Expand Up @@ -137,15 +137,23 @@ public void setYValuePosition(ValuePosition yValuePosition) {
}

/**
* When valuePosition is OutsideSlice, use slice colors as line color if true
* This method is deprecated.
* Use isUseValueColorForLineEnabled() instead.
*/
@Override
@Deprecated
public boolean isUsingSliceColorAsValueLineColor() {
return mUsingSliceColorAsValueLineColor;
return isUseValueColorForLineEnabled();
}

public void setUsingSliceColorAsValueLineColor(boolean usingSliceColorAsValueLineColor) {
this.mUsingSliceColorAsValueLineColor = usingSliceColorAsValueLineColor;
/**
* This method is deprecated.
* Use setUseValueColorForLine(...) instead.
*
* @param enabled
*/
@Deprecated
public void setUsingSliceColorAsValueLineColor(boolean enabled) {
setUseValueColorForLine(enabled);
}

/**
Expand All @@ -160,6 +168,17 @@ public void setValueLineColor(int valueLineColor) {
this.mValueLineColor = valueLineColor;
}

@Override
public boolean isUseValueColorForLineEnabled()
{
return mUseValueColorForLine;
}

public void setUseValueColorForLine(boolean enabled)
{
mUseValueColorForLine = enabled;
}

/**
* When valuePosition is OutsideSlice, indicates line width
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public interface IPieDataSet extends IDataSet<PieEntry> {
PieDataSet.ValuePosition getYValuePosition();

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

/**
* When valuePosition is OutsideSlice, indicates line color
* When valuePosition is OutsideSlice and enabled, line will have the same color as the slice
* */
int getValueLineColor();
boolean isUseValueColorForLineEnabled();

/**
* When valuePosition is OutsideSlice, indicates line width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,9 @@ public void drawValues(Canvas c) {

int entryCount = dataSet.getEntryCount();

mValueLinePaint.setColor(dataSet.getValueLineColor());
boolean isUseValueColorForLineEnabled = dataSet.isUseValueColorForLineEnabled();
int valueLineColor = dataSet.getValueLineColor();

mValueLinePaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getValueLineWidth()));

final float sliceSpace = getSliceSpace(dataSet);
Expand Down Expand Up @@ -565,12 +567,15 @@ public void drawValues(Canvas c) {
labelPty = pt2y;
}

if (dataSet.getValueLineColor() != ColorTemplate.COLOR_NONE) {
int lineColor = ColorTemplate.COLOR_NONE;

if (dataSet.isUsingSliceColorAsValueLineColor()) {
mValueLinePaint.setColor(dataSet.getColor(j));
}
if (isUseValueColorForLineEnabled)
lineColor = dataSet.getColor(j);
else if (valueLineColor != ColorTemplate.COLOR_NONE)
lineColor = valueLineColor;

if (lineColor != ColorTemplate.COLOR_NONE) {
mValueLinePaint.setColor(lineColor);
c.drawLine(pt0x, pt0y, pt1x, pt1y, mValueLinePaint);
c.drawLine(pt1x, pt1y, pt2x, pt2y, mValueLinePaint);
}
Expand Down

0 comments on commit 4e62248

Please sign in to comment.