From 8bb5e1ad541ec85df2f1003ba08651a709249eec Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Fri, 2 Oct 2015 00:28:01 +0300 Subject: [PATCH] Fix highlight animation bug in stacked bar chart --- .../charting/renderer/BarChartRenderer.java | 4 +-- .../mikephil/charting/utils/Transformer.java | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/MPChartLib/src/com/github/mikephil/charting/renderer/BarChartRenderer.java b/MPChartLib/src/com/github/mikephil/charting/renderer/BarChartRenderer.java index 1f55d17d8..ce6036a8c 100644 --- a/MPChartLib/src/com/github/mikephil/charting/renderer/BarChartRenderer.java +++ b/MPChartLib/src/com/github/mikephil/charting/renderer/BarChartRenderer.java @@ -346,7 +346,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) { if (isStack) { y1 = h.getRange().from; - y2 = h.getRange().to * mAnimator.getPhaseY(); + y2 = h.getRange().to; } else { y1 = e.getVal(); y2 = 0.f; @@ -370,7 +370,7 @@ public void drawHighlighted(Canvas c, Highlight[] indices) { final float arrowWidth = set.getBarSpace() / 2.f; final float arrowHeight = arrowWidth * xToYRel; - final float yArrow = y1 > -y2 ? y1 : y1; + final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY(); Path arrow = new Path(); arrow.moveTo(x + 0.4f, yArrow + offsetY); diff --git a/MPChartLib/src/com/github/mikephil/charting/utils/Transformer.java b/MPChartLib/src/com/github/mikephil/charting/utils/Transformer.java index 978fa8684..cf8f5b2c4 100644 --- a/MPChartLib/src/com/github/mikephil/charting/utils/Transformer.java +++ b/MPChartLib/src/com/github/mikephil/charting/utils/Transformer.java @@ -334,10 +334,21 @@ public void rectValueToPixel(RectF r) { public void rectValueToPixel(RectF r, float phaseY) { // multiply the height of the rect with the phase - if (r.top > 0) - r.top *= phaseY; - else - r.bottom *= phaseY; + r.top *= phaseY; + r.bottom *= phaseY; + + mMatrixValueToPx.mapRect(r); + mViewPortHandler.getMatrixTouch().mapRect(r); + mMatrixOffset.mapRect(r); + } + + /** + * Transform a rectangle with all matrices with potential animation phases. + * + * @param r + + */ + public void rectValueToPixelHorizontal(RectF r) { mMatrixValueToPx.mapRect(r); mViewPortHandler.getMatrixTouch().mapRect(r); @@ -353,10 +364,8 @@ public void rectValueToPixel(RectF r, float phaseY) { public void rectValueToPixelHorizontal(RectF r, float phaseY) { // multiply the height of the rect with the phase - if (r.left > 0) - r.left *= phaseY; - else - r.right *= phaseY; + r.left *= phaseY; + r.right *= phaseY; mMatrixValueToPx.mapRect(r); mViewPortHandler.getMatrixTouch().mapRect(r);