Skip to content

Commit 996948e

Browse files
committed
Fix pie chart values animation on X axis
1 parent ae231be commit 996948e

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

MPChartLib/src/com/github/mikephil/charting/renderer/PieChartRenderer.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ public void drawValues(Canvas c) {
190190

191191
boolean drawXVals = mChart.isDrawSliceTextEnabled();
192192

193-
int cnt = 0;
193+
float angle;
194+
int xIndex = 0;
194195

195196
for (int i = 0; i < dataSets.size(); i++) {
196197

@@ -212,10 +213,19 @@ public void drawValues(Canvas c) {
212213

213214
Entry entry = dataSet.getEntryForIndex(j);
214215

216+
if (xIndex == 0)
217+
angle = 0.f;
218+
else
219+
angle = absoluteAngles[xIndex - 1] * phaseX;
220+
221+
final float sliceAngle = drawAngles[xIndex];
222+
final float sliceSpace = dataSet.getSliceSpace();
223+
215224
// offset needed to center the drawn text in the slice
216-
float offset = drawAngles[cnt] / 2;
225+
final float offset = (sliceAngle - sliceSpace / 2.f) / 2.f;
226+
227+
angle = angle + offset;
217228

218-
float angle = (absoluteAngles[cnt] - offset) * phaseY;
219229
// calculate the text position
220230
float x = (float) (r
221231
* Math.cos(Math.toRadians(rotationAngle + angle))
@@ -248,7 +258,7 @@ public void drawValues(Canvas c) {
248258
drawValue(c, formatter, value, entry, 0, x, y + lineHeight / 2f);
249259
}
250260

251-
cnt++;
261+
xIndex++;
252262
}
253263
}
254264
}

0 commit comments

Comments
 (0)