Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix after call setMinMaxScaleX, when scaleX to bound value, chart wil… #5391

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public class BarLineChartTouchListener extends ChartTouchListener<BarLineChartBa
*/
private float mMinScalePointerDistance;


private final float[] matrixBuffer = new float[9];
private final Matrix tempMatrix = new Matrix();

/**
* Constructor with initialization parameters.
*
Expand Down Expand Up @@ -378,9 +382,8 @@ private void performZoom(MotionEvent event) {
float scaleY = (mChart.isScaleYEnabled()) ? scale : 1f;

if (canZoomMoreY || canZoomMoreX) {

mMatrix.set(mSavedMatrix);
mMatrix.postScale(scaleX, scaleY, t.x, t.y);
mMatrix.postScale(getLimitedScaleX(scaleX, t), getLimitedScaleY(scaleY, t), t.x, t.y);

if (l != null)
l.onChartScale(event, scaleX, scaleY);
Expand All @@ -399,9 +402,8 @@ private void performZoom(MotionEvent event) {
h.canZoomInMoreX();

if (canZoomMoreX) {

mMatrix.set(mSavedMatrix);
mMatrix.postScale(scaleX, 1f, t.x, t.y);
mMatrix.postScale(getLimitedScaleX(scaleX, t), 1f, t.x, t.y);

if (l != null)
l.onChartScale(event, scaleX, 1f);
Expand All @@ -420,9 +422,8 @@ private void performZoom(MotionEvent event) {
h.canZoomInMoreY();

if (canZoomMoreY) {

mMatrix.set(mSavedMatrix);
mMatrix.postScale(1f, scaleY, t.x, t.y);
mMatrix.postScale(1f, getLimitedScaleY(scaleY, t), t.x, t.y);

if (l != null)
l.onChartScale(event, 1f, scaleY);
Expand All @@ -434,6 +435,59 @@ private void performZoom(MotionEvent event) {
}
}

/**
* limit scaleX range
* @param scaleX
* @param t
* @return
*/
private float getLimitedScaleX(float scaleX, MPPointF t) {
ViewPortHandler h = mChart.getViewPortHandler();
tempMatrix.postScale(scaleX, 1f, t.x, t.y);

mSavedMatrix.getValues(matrixBuffer);
float lastScaleX = matrixBuffer[Matrix.MSCALE_X];

tempMatrix.getValues(matrixBuffer);
float calScaleX = matrixBuffer[Matrix.MSCALE_X];

float resultScaleX = scaleX;

if (calScaleX < h.getMinScaleX()) {
resultScaleX = h.getMinScaleX() / lastScaleX;
} else if (calScaleX > 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.getMinScaleY() / lastScaleY;
} else if (calScaleY > h.getMaxScaleY()) {
resultScaleY = h.getMaxScaleY() / lastScaleY;
}
return resultScaleY;
}

/**
* Highlights upon dragging, generates callbacks for the selection-listener.
*
Expand Down