Skip to content

Commit

Permalink
Fix SpannableString PieChart center text issues (PhilJay#993).
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJay committed Oct 11, 2015
1 parent ad940c2 commit 4b8f1f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ private SpannableString generateCenterSpannableText() {

SpannableString s = new SpannableString("MPAndroidChart developed by Philipp Jahoda");
s.setSpan(new RelativeSizeSpan(1.7f), 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 StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 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 StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
return s;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public PieChartRenderer(PieChart chart, ChartAnimator animator,
mCenterTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mCenterTextPaint.setColor(Color.BLACK);
mCenterTextPaint.setTextSize(Utils.convertDpToPixel(12f));
mCenterTextPaint.setTextAlign(Align.CENTER);
//mCenterTextPaint.setTextAlign(Align.CENTER);

mValuePaint.setTextSize(Utils.convertDpToPixel(13f));
mValuePaint.setColor(Color.WHITE);
Expand Down Expand Up @@ -327,7 +327,7 @@ protected void drawCenterText(Canvas c) {
mCenterTextLayout = new StaticLayout(centerText, 0, centerText.length(),
mCenterTextPaint,
(int) Math.max(Math.ceil(width), 1.f),
Layout.Alignment.ALIGN_NORMAL, 1.f, 0.f, false);
Layout.Alignment.ALIGN_CENTER, 1.f, 0.f, false);
}

// I wish we could make an ellipse clipping path on Android to clip to the hole...
Expand All @@ -337,7 +337,7 @@ protected void drawCenterText(Canvas c) {
float layoutHeight = mCenterTextLayout.getHeight();

c.save();
c.translate(boundingRect.centerX(), boundingRect.top + (boundingRect.height() - layoutHeight) / 2.f);
c.translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2.f);
mCenterTextLayout.draw(c);
c.restore();

Expand Down

0 comments on commit 4b8f1f5

Please sign in to comment.