Skip to content

Commit 497beac

Browse files
committed
Merge pull request #1061 from danielgindi/highlight-animation-fix
Fix highlight animation bug in stacked bar chart
2 parents 10a392d + 8bb5e1a commit 497beac

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
346346

347347
if (isStack) {
348348
y1 = h.getRange().from;
349-
y2 = h.getRange().to * mAnimator.getPhaseY();
349+
y2 = h.getRange().to;
350350
} else {
351351
y1 = e.getVal();
352352
y2 = 0.f;
@@ -370,7 +370,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
370370
final float arrowWidth = set.getBarSpace() / 2.f;
371371
final float arrowHeight = arrowWidth * xToYRel;
372372

373-
final float yArrow = y1 > -y2 ? y1 : y1;
373+
final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY();
374374

375375
Path arrow = new Path();
376376
arrow.moveTo(x + 0.4f, yArrow + offsetY);

MPChartLib/src/com/github/mikephil/charting/utils/Transformer.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,21 @@ public void rectValueToPixel(RectF r) {
334334
public void rectValueToPixel(RectF r, float phaseY) {
335335

336336
// multiply the height of the rect with the phase
337-
if (r.top > 0)
338-
r.top *= phaseY;
339-
else
340-
r.bottom *= phaseY;
337+
r.top *= phaseY;
338+
r.bottom *= phaseY;
339+
340+
mMatrixValueToPx.mapRect(r);
341+
mViewPortHandler.getMatrixTouch().mapRect(r);
342+
mMatrixOffset.mapRect(r);
343+
}
344+
345+
/**
346+
* Transform a rectangle with all matrices with potential animation phases.
347+
*
348+
* @param r
349+
350+
*/
351+
public void rectValueToPixelHorizontal(RectF r) {
341352

342353
mMatrixValueToPx.mapRect(r);
343354
mViewPortHandler.getMatrixTouch().mapRect(r);
@@ -353,10 +364,8 @@ public void rectValueToPixel(RectF r, float phaseY) {
353364
public void rectValueToPixelHorizontal(RectF r, float phaseY) {
354365

355366
// multiply the height of the rect with the phase
356-
if (r.left > 0)
357-
r.left *= phaseY;
358-
else
359-
r.right *= phaseY;
367+
r.left *= phaseY;
368+
r.right *= phaseY;
360369

361370
mMatrixValueToPx.mapRect(r);
362371
mViewPortHandler.getMatrixTouch().mapRect(r);

0 commit comments

Comments
 (0)