Skip to content

Commit

Permalink
I hope this will position x-labels correctly vertically
Browse files Browse the repository at this point in the history
And without any weird hack.
But by just finally figuring out how to
correctly offset the drawing from the font glyph size
  • Loading branch information
danielgindi committed May 15, 2016
1 parent 92810c8 commit 4393b27
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions MPChartLib/src/com/github/mikephil/charting/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -611,17 +611,16 @@ public static void drawXAxisValue(Canvas c, String text, float x, float y,
float drawOffsetX = 0.f;
float drawOffsetY = 0.f;

final float lineHeight = paint.getFontMetrics(mFontMetricsBuffer);
paint.getTextBounds(text, 0, text.length(), mDrawTextRectBuffer);

final float lineHeight = mDrawTextRectBuffer.height();

// Android sometimes has pre-padding
drawOffsetX -= mDrawTextRectBuffer.left;

// Android does not snap the bounds to line boundaries,
// and draws from bottom to top.
// And we want to normalize it.
drawOffsetY += lineHeight;
drawOffsetY += -mFontMetricsBuffer.ascent;

// To have a consistent point of reference, we always draw left-aligned
Paint.Align originalTextAlign = paint.getTextAlign();
Expand Down

0 comments on commit 4393b27

Please sign in to comment.