Skip to content

Commit

Permalink
Minor fixes related to polyline example
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJay committed May 28, 2016
1 parent 8bca4c7 commit 0270470
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected void onCreate(Bundle savedInstanceState) {
mChart.setCenterTextTypeface(Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf"));
mChart.setCenterText(generateCenterSpannableText());

mChart.setExtraOffsets(5.f, 5.f, 5.f, 5.f);
mChart.setExtraOffsets(20.f, 0.f, 20.f, 0.f);

mChart.setDrawHoleEnabled(true);
mChart.setHoleColor(Color.WHITE);
Expand Down Expand Up @@ -226,7 +226,7 @@ private void setData(int count, float range) {


dataSet.setValueLinePart1OffsetPercentage(80.f);
dataSet.setValueLinePart1Length(0.3f);
dataSet.setValueLinePart1Length(0.2f);
dataSet.setValueLinePart2Length(0.4f);
// dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
Expand All @@ -247,10 +247,10 @@ private void setData(int count, float range) {
private SpannableString generateCenterSpannableText() {

SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
s.setSpan(new RelativeSizeSpan(1.5f), 0, 14, 0);
s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
s.setSpan(new RelativeSizeSpan(.65f), 14, s.length() - 15, 0);
s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
return s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ protected float calculateMinimumRadiusForSpacedSlice(
float arcStartPointX,
float arcStartPointY,
float startAngle,
float sweepAngle)
{
float sweepAngle) {
final float angleMiddle = startAngle + sweepAngle / 2.f;

// Other point of the arc
Expand All @@ -163,7 +162,7 @@ protected float calculateMinimumRadiusForSpacedSlice(
// After reducing space from both sides of the "slice",
// the angle of the contained triangle should stay the same.
// So let's find out the height of that triangle.
float containedTriangleHeight = (float)(basePointsDistance / 2.0 *
float containedTriangleHeight = (float) (basePointsDistance / 2.0 *
Math.tan((180.0 - angle) / 2.0 * Utils.DEG2RAD));

// Now we subtract that from the radius
Expand Down Expand Up @@ -228,8 +227,7 @@ protected void drawDataSet(Canvas c, IPieDataSet dataSet) {
sliceSpace / (Utils.FDEG2RAD * radius);
final float startAngleOuter = rotationAngle + (angle + sliceSpaceAngleOuter / 2.f) * phaseY;
float sweepAngleOuter = (sliceAngle - sliceSpaceAngleOuter) * phaseY;
if (sweepAngleOuter < 0.f)
{
if (sweepAngleOuter < 0.f) {
sweepAngleOuter = 0.f;
}

Expand Down Expand Up @@ -284,8 +282,7 @@ protected void drawDataSet(Canvas c, IPieDataSet dataSet) {
sliceSpace / (Utils.FDEG2RAD * innerRadius);
final float startAngleInner = rotationAngle + (angle + sliceSpaceAngleInner / 2.f) * phaseY;
float sweepAngleInner = (sliceAngle - sliceSpaceAngleInner) * phaseY;
if (sweepAngleInner < 0.f)
{
if (sweepAngleInner < 0.f) {
sweepAngleInner = 0.f;
}
final float endAngleInner = startAngleInner + sweepAngleInner;
Expand All @@ -305,8 +302,7 @@ protected void drawDataSet(Canvas c, IPieDataSet dataSet) {
-sweepAngleInner
);
}
}
else {
} else {

if (sweepAngleOuter % 360f != 0.f) {
if (accountForSliceSpacing) {
Expand Down Expand Up @@ -411,6 +407,8 @@ public void drawValues(Canvas c) {
mValueLinePaint.setColor(dataSet.getValueLineColor());
mValueLinePaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getValueLineWidth()));

float offset = Utils.convertDpToPixel(5.f);

for (int j = 0; j < entryCount; j++) {

Entry entry = dataSet.getEntryForIndex(j);
Expand All @@ -434,8 +432,8 @@ public void drawValues(Canvas c) {
float value = mChart.isUsePercentValuesEnabled() ? entry.getVal()
/ yValueSum * 100f : entry.getVal();

final float sliceXBase = (float)Math.cos(transformedAngle * Utils.FDEG2RAD);
final float sliceYBase = (float)Math.sin(transformedAngle * Utils.FDEG2RAD);
final float sliceXBase = (float) Math.cos(transformedAngle * Utils.FDEG2RAD);
final float sliceYBase = (float) Math.sin(transformedAngle * Utils.FDEG2RAD);

final boolean drawXOutside = drawXVals &&
xValuePosition == PieDataSet.ValuePosition.OUTSIDE_SLICE;
Expand Down Expand Up @@ -465,9 +463,9 @@ public void drawValues(Canvas c) {
line1Radius = radius * valueLinePart1OffsetPercentage;

final float polyline2Width = dataSet.isValueLineVariableLength()
? labelRadius * valueLineLength2 * (float)Math.abs(Math.sin(
? labelRadius * valueLineLength2 * (float) Math.abs(Math.sin(
transformedAngle * Utils.FDEG2RAD))
: labelRadius * valueLineLength2;
: labelRadius * valueLineLength2;

final float pt0x = line1Radius * sliceXBase + center.x;
final float pt0y = line1Radius * sliceYBase + center.y;
Expand All @@ -479,13 +477,13 @@ public void drawValues(Canvas c) {
pt2x = pt1x - polyline2Width;
pt2y = pt1y;
mValuePaint.setTextAlign(Align.RIGHT);
labelPtx = pt2x - Utils.convertDpToPixel(5.f);
labelPtx = pt2x - offset;
labelPty = pt2y;
} else {
pt2x = pt1x + polyline2Width;
pt2y = pt1y;
mValuePaint.setTextAlign(Align.LEFT);
labelPtx = pt2x + Utils.convertDpToPixel(5.f);
labelPtx = pt2x + offset;
labelPty = pt2y;
}

Expand Down Expand Up @@ -518,7 +516,8 @@ public void drawValues(Canvas c) {
}
} else if (drawYOutside) {

drawValue(c, formatter, value, entry, 0, labelPtx, labelPty + lineHeight / 2.f, dataSet.getValueTextColor(j));
drawValue(c, formatter, value, entry, 0, labelPtx, labelPty + lineHeight / 2.f, dataSet
.getValueTextColor(j));
}
}

Expand Down Expand Up @@ -743,20 +742,18 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {

final float startAngleOuter = rotationAngle + (angle + sliceSpaceAngleOuter / 2.f) * phaseY;
float sweepAngleOuter = (sliceAngle - sliceSpaceAngleOuter) * phaseY;
if (sweepAngleOuter < 0.f)
{
if (sweepAngleOuter < 0.f) {
sweepAngleOuter = 0.f;
}

final float startAngleShifted = rotationAngle + (angle + sliceSpaceAngleShifted / 2.f) * phaseY;
float sweepAngleShifted = (sliceAngle - sliceSpaceAngleShifted) * phaseY;
if (sweepAngleShifted < 0.f)
{
if (sweepAngleShifted < 0.f) {
sweepAngleShifted = 0.f;
}

mPathBuffer.reset();

if (sweepAngleOuter % 360f == 0.f) {
// Android is doing "mod 360"
mPathBuffer.addCircle(center.x, center.y, highlightedRadius, Path.Direction.CW);
Expand Down Expand Up @@ -809,8 +806,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
sliceSpace / (Utils.FDEG2RAD * innerRadius);
final float startAngleInner = rotationAngle + (angle + sliceSpaceAngleInner / 2.f) * phaseY;
float sweepAngleInner = (sliceAngle - sliceSpaceAngleInner) * phaseY;
if (sweepAngleInner < 0.f)
{
if (sweepAngleInner < 0.f) {
sweepAngleInner = 0.f;
}
final float endAngleInner = startAngleInner + sweepAngleInner;
Expand All @@ -830,8 +826,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
-sweepAngleInner
);
}
}
else {
} else {

if (sweepAngleOuter % 360f != 0.f) {

Expand Down

0 comments on commit 0270470

Please sign in to comment.