@@ -74,6 +74,10 @@ public class BarLineChartTouchListener extends ChartTouchListener<BarLineChartBa
7474 */
7575 private float mMinScalePointerDistance ;
7676
77+
78+ private final float [] matrixBuffer = new float [9 ];
79+ private final Matrix tempMatrix = new Matrix ();
80+
7781 /**
7882 * Constructor with initialization parameters.
7983 *
@@ -378,9 +382,8 @@ private void performZoom(MotionEvent event) {
378382 float scaleY = (mChart .isScaleYEnabled ()) ? scale : 1f ;
379383
380384 if (canZoomMoreY || canZoomMoreX ) {
381-
382385 mMatrix .set (mSavedMatrix );
383- mMatrix .postScale (scaleX , scaleY , t .x , t .y );
386+ mMatrix .postScale (getLimitedScaleX ( scaleX , t ), getLimitedScaleY ( scaleY , t ) , t .x , t .y );
384387
385388 if (l != null )
386389 l .onChartScale (event , scaleX , scaleY );
@@ -399,9 +402,8 @@ private void performZoom(MotionEvent event) {
399402 h .canZoomInMoreX ();
400403
401404 if (canZoomMoreX ) {
402-
403405 mMatrix .set (mSavedMatrix );
404- mMatrix .postScale (scaleX , 1f , t .x , t .y );
406+ mMatrix .postScale (getLimitedScaleX ( scaleX , t ) , 1f , t .x , t .y );
405407
406408 if (l != null )
407409 l .onChartScale (event , scaleX , 1f );
@@ -420,9 +422,8 @@ private void performZoom(MotionEvent event) {
420422 h .canZoomInMoreY ();
421423
422424 if (canZoomMoreY ) {
423-
424425 mMatrix .set (mSavedMatrix );
425- mMatrix .postScale (1f , scaleY , t .x , t .y );
426+ mMatrix .postScale (1f , getLimitedScaleY ( scaleY , t ) , t .x , t .y );
426427
427428 if (l != null )
428429 l .onChartScale (event , 1f , scaleY );
@@ -434,6 +435,59 @@ private void performZoom(MotionEvent event) {
434435 }
435436 }
436437
438+ /**
439+ * limit scaleX range
440+ * @param scaleX
441+ * @param t
442+ * @return
443+ */
444+ private float getLimitedScaleX (float scaleX , MPPointF t ) {
445+ ViewPortHandler h = mChart .getViewPortHandler ();
446+ tempMatrix .postScale (scaleX , 1f , t .x , t .y );
447+
448+ mSavedMatrix .getValues (matrixBuffer );
449+ float lastScaleX = matrixBuffer [Matrix .MSCALE_X ];
450+
451+ tempMatrix .getValues (matrixBuffer );
452+ float calScaleX = matrixBuffer [Matrix .MSCALE_X ];
453+
454+ float resultScaleX = scaleX ;
455+
456+ if (calScaleX < h .getMinScaleX ()) {
457+ resultScaleX = h .getMinScaleX () / lastScaleX ;
458+ } else if (calScaleX > h .getMaxScaleX ()) {
459+ resultScaleX = h .getMaxScaleX () / lastScaleX ;
460+ }
461+ return resultScaleX ;
462+ }
463+
464+ /**
465+ * limit scaleY range
466+ * @param scaleY
467+ * @param t
468+ * @return
469+ */
470+ private float getLimitedScaleY (float scaleY , MPPointF t ) {
471+ ViewPortHandler h = mChart .getViewPortHandler ();
472+ tempMatrix .set (mSavedMatrix );
473+ tempMatrix .postScale (1f , scaleY , t .x , t .y );
474+
475+ mSavedMatrix .getValues (matrixBuffer );
476+ float lastScaleY = matrixBuffer [Matrix .MSCALE_Y ];
477+
478+ tempMatrix .getValues (matrixBuffer );
479+ float calScaleY = matrixBuffer [Matrix .MSCALE_Y ];
480+
481+ float resultScaleY = scaleY ;
482+
483+ if (calScaleY < h .getMinScaleY ()) {
484+ resultScaleY = h .getMinScaleY () / lastScaleY ;
485+ } else if (calScaleY > h .getMaxScaleY ()) {
486+ resultScaleY = h .getMaxScaleY () / lastScaleY ;
487+ }
488+ return resultScaleY ;
489+ }
490+
437491 /**
438492 * Highlights upon dragging, generates callbacks for the selection-listener.
439493 *
0 commit comments