From 0ab8397323d7d7f2ce91126befbc80b85a35af19 Mon Sep 17 00:00:00 2001 From: renzhenfei Date: Fri, 19 May 2023 11:12:22 +0800 Subject: [PATCH 1/2] fix after call setMinMaxScaleX, when scaleX to bound value, chart will jump --- .../listener/BarLineChartTouchListener.java | 66 +++++++++++++++++-- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java index 5685d32fa0..d407b9a6ec 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java @@ -74,6 +74,10 @@ public class BarLineChartTouchListener extends ChartTouchListener h.getMaxScaleX()) { + resultScaleX = h.getMaxScaleX() / lastScaleX; + } + return resultScaleX; + } + + /** + * limit scaleY range + * @param scaleY + * @param t + * @return + */ + private float getLimitedScaleY(float scaleY, MPPointF t) { + ViewPortHandler h = mChart.getViewPortHandler(); + tempMatrix.set(mSavedMatrix); + tempMatrix.postScale(1f, scaleY, t.x, t.y); + + mSavedMatrix.getValues(matrixBuffer); + float lastScaleY = matrixBuffer[Matrix.MSCALE_Y]; + + tempMatrix.getValues(matrixBuffer); + float calScaleY = matrixBuffer[Matrix.MSCALE_Y]; + + float resultScaleY = scaleY; + + if (calScaleY < h.getMinScaleY()) { + resultScaleY = h.getMinScaleX() / lastScaleY; + } else if (calScaleY > h.getMaxScaleY()) { + resultScaleY = h.getMaxScaleX() / lastScaleY; + } + return resultScaleY; + } + /** * Highlights upon dragging, generates callbacks for the selection-listener. * From a368e0cd533920f86fb98e0ee250e74c4968d472 Mon Sep 17 00:00:00 2001 From: renzhenfei Date: Fri, 19 May 2023 18:24:23 +0800 Subject: [PATCH 2/2] fix scaleY --- .../mikephil/charting/listener/BarLineChartTouchListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java index d407b9a6ec..578b282d40 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/listener/BarLineChartTouchListener.java @@ -481,9 +481,9 @@ private float getLimitedScaleY(float scaleY, MPPointF t) { float resultScaleY = scaleY; if (calScaleY < h.getMinScaleY()) { - resultScaleY = h.getMinScaleX() / lastScaleY; + resultScaleY = h.getMinScaleY() / lastScaleY; } else if (calScaleY > h.getMaxScaleY()) { - resultScaleY = h.getMaxScaleX() / lastScaleY; + resultScaleY = h.getMaxScaleY() / lastScaleY; } return resultScaleY; }